Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / testing / Internals.h
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #ifndef Internals_h
28 #define Internals_h
29
30 #include "bindings/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/v8/ScriptPromise.h"
32 #include "bindings/v8/ScriptValue.h"
33 #include "core/css/CSSComputedStyleDeclaration.h"
34 #include "core/dom/ContextLifecycleObserver.h"
35 #include "core/dom/NodeList.h"
36 #include "core/page/scrolling/ScrollingCoordinator.h"
37 #include "wtf/ArrayBuffer.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/text/WTFString.h"
41
42 namespace WebCore {
43
44 class ClientRect;
45 class ClientRectList;
46 class DOMPoint;
47 class DOMStringList;
48 class DOMWindow;
49 class Document;
50 class DocumentMarker;
51 class Element;
52 class ExceptionState;
53 class Frame;
54 class GCObservation;
55 class InspectorFrontendChannelDummy;
56 class InternalProfilers;
57 class InternalRuntimeFlags;
58 class InternalSettings;
59 class LayerRectList;
60 class MallocStatistics;
61 class Node;
62 class Page;
63 class PagePopupController;
64 class Range;
65 class ExecutionContext;
66 class SerializedScriptValue;
67 class ShadowRoot;
68 class TypeConversions;
69
70 class Internals FINAL : public RefCounted<Internals>
71     , public ContextLifecycleObserver {
72 public:
73     static PassRefPtr<Internals> create(Document*);
74     virtual ~Internals();
75
76     static void resetToConsistentState(Page*);
77
78     String elementRenderTreeAsText(Element*, ExceptionState&);
79
80     String address(Node*);
81
82     PassRefPtr<GCObservation> observeGC(ScriptValue);
83
84     bool isPreloaded(const String& url);
85     bool isLoadingFromMemoryCache(const String& url);
86
87     void crash();
88
89     void setStyleResolverStatsEnabled(bool);
90     String styleResolverStatsReport(ExceptionState&) const;
91     String styleResolverStatsTotalsReport(ExceptionState&) const;
92
93     bool isSharingStyle(Element*, Element*, ExceptionState&) const;
94
95     size_t numberOfScopedHTMLStyleChildren(const Node*, ExceptionState&) const;
96     PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionState&) const;
97
98     ShadowRoot* shadowRoot(Element* host, ExceptionState&);
99     ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&);
100     ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&);
101     ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
102     String shadowRootType(const Node*, ExceptionState&) const;
103     bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
104     bool hasContentElement(const Node*, ExceptionState&) const;
105     size_t countElementShadow(const Node*, ExceptionState&) const;
106     const AtomicString& shadowPseudoId(Element*, ExceptionState&);
107     void setShadowPseudoId(Element*, const AtomicString&, ExceptionState&);
108
109     // CSS Animation / Transition testing.
110     unsigned numberOfActiveAnimations() const;
111     void pauseAnimations(double pauseTime, ExceptionState&);
112
113     bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
114     Node* treeScopeRootNode(Node*, ExceptionState&);
115     Node* parentTreeScope(Node*, ExceptionState&);
116     bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
117     bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
118     bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
119     bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
120     unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
121
122     // FIXME: Rename these functions if walker is prefered.
123     Node* nextSiblingByWalker(Node*, ExceptionState&);
124     Node* firstChildByWalker(Node*, ExceptionState&);
125     Node* lastChildByWalker(Node*, ExceptionState&);
126     Node* nextNodeByWalker(Node*, ExceptionState&);
127     Node* previousNodeByWalker(Node*, ExceptionState&);
128
129     unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
130     unsigned needsLayoutCount(ExceptionState&) const;
131
132     String visiblePlaceholder(Element*);
133     void selectColorInColorChooser(Element*, const String& colorValue);
134     bool hasAutofocusRequest(Document*);
135     bool hasAutofocusRequest();
136     Vector<String> formControlStateOfHistoryItem(ExceptionState&);
137     void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&);
138     void setEnableMockPagePopup(bool, ExceptionState&);
139     PassRefPtr<PagePopupController> pagePopupController();
140
141     PassRefPtr<ClientRect> unscaledViewportRect(ExceptionState&);
142
143     PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
144
145     PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&);
146
147     PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&);
148
149     unsigned markerCountForNode(Node*, const String&, ExceptionState&);
150     unsigned activeMarkerCountForNode(Node*, ExceptionState&);
151     PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
152     String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
153     void addTextMatchMarker(const Range*, bool isActive);
154     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&);
155     void setMarkedTextMatchesAreHighlighted(Document*, bool, ExceptionState&);
156
157     void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
158     String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
159
160     bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
161     bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
162     String suggestedValue(Element*, ExceptionState&);
163     void setSuggestedValue(Element*, const String&, ExceptionState&);
164     void setEditingValue(Element* inputElement, const String&, ExceptionState&);
165     void setAutofilled(Element*, bool enabled, ExceptionState&);
166     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
167
168     PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
169     unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
170     unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
171     String rangeAsText(const Range*, ExceptionState&);
172
173     PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
174     Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
175     PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
176     Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
177     PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
178
179     int lastSpellCheckRequestSequence(Document*, ExceptionState&);
180     int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
181
182     Vector<AtomicString> userPreferredLanguages() const;
183     void setUserPreferredLanguages(const Vector<String>&);
184
185     unsigned wheelEventHandlerCount(Document*, ExceptionState&);
186     unsigned touchEventHandlerCount(Document*, ExceptionState&);
187     PassRefPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&);
188
189     // This is used to test rect based hit testing like what's done on touch screens.
190     PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
191         unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const;
192
193     void emitInspectorDidBeginFrame(int frameId = 0);
194     void emitInspectorDidCancelFrame();
195
196     bool hasSpellingMarker(Document*, int from, int length, ExceptionState&);
197     bool hasGrammarMarker(Document*, int from, int length, ExceptionState&);
198     void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&);
199
200     bool isOverwriteModeEnabled(Document*, ExceptionState&);
201     void toggleOverwriteModeEnabled(Document*, ExceptionState&);
202
203     unsigned numberOfScrollableAreas(Document*, ExceptionState&);
204
205     bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&);
206
207     static const char* internalsId;
208
209     InternalSettings* settings() const;
210     InternalRuntimeFlags* runtimeFlags() const;
211     InternalProfilers* profilers();
212     unsigned workerThreadCount() const;
213
214     void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
215
216     String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
217     String layerTreeAsText(Document*, ExceptionState&) const;
218     String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
219     String elementLayerTreeAsText(Element*, ExceptionState&) const;
220
221     PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&);
222     PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&);
223
224     bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
225     bool isUnclippedDescendant(Element*, ExceptionState&);
226     bool needsCompositedScrolling(Element*, ExceptionState&);
227
228     void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
229
230     String repaintRectsAsText(Document*, ExceptionState&) const;
231     PassRefPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const;
232
233     String scrollingStateTreeAsText(Document*, ExceptionState&) const;
234     String mainThreadScrollingReasons(Document*, ExceptionState&) const;
235     PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
236
237     void garbageCollectDocumentResources(Document*, ExceptionState&) const;
238     void evictAllResources() const;
239
240     void allowRoundingHacks() const;
241
242     unsigned numberOfLiveNodes() const;
243     unsigned numberOfLiveDocuments() const;
244     String dumpRefCountedInstanceCounts() const;
245     Vector<String> consoleMessageArgumentCounts(Document*) const;
246     PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
247     void closeDummyInspectorFrontend();
248     Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
249     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
250
251     String counterValue(Element*);
252
253     int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
254     Vector<String> shortcutIconURLs(Document*) const;
255     Vector<String> allIconURLs(Document*) const;
256
257     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
258     String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
259     String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
260
261     void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
262
263     void setIsCursorVisible(Document*, bool, ExceptionState&);
264
265     void webkitWillEnterFullScreenForElement(Document*, Element*);
266     void webkitDidEnterFullScreenForElement(Document*, Element*);
267     void webkitWillExitFullScreenForElement(Document*, Element*);
268     void webkitDidExitFullScreenForElement(Document*, Element*);
269
270     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
271     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
272
273     PassRefPtr<MallocStatistics> mallocStatistics() const;
274     PassRefPtr<TypeConversions> typeConversions() const;
275
276     Vector<String> getReferencedFilePaths() const;
277
278     void startTrackingRepaints(Document*, ExceptionState&);
279     void stopTrackingRepaints(Document*, ExceptionState&);
280     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
281     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
282
283     PassRefPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
284     PassRefPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
285
286     PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
287     PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
288
289     String getCurrentCursorInfo(Document*, ExceptionState&);
290
291     String markerTextForListItem(Element*, ExceptionState&);
292
293     void forceReload(bool endToEnd);
294
295     String getImageSourceURL(Element*, ExceptionState&);
296
297     bool isSelectPopupVisible(Node*);
298
299     PassRefPtr<ClientRect> selectionBounds(ExceptionState&);
300     String baseURL(Document*, ExceptionState&);
301
302     bool loseSharedGraphicsContext3D();
303
304     void forceCompositingUpdate(Document*, ExceptionState&);
305
306     bool isCompositorFramePending(Document*, ExceptionState&);
307
308     void setZoomFactor(float);
309
310     void setShouldRevealPassword(Element*, bool, ExceptionState&);
311
312     ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise);
313
314 private:
315     explicit Internals(Document*);
316     Document* contextDocument() const;
317     Frame* frame() const;
318     Vector<String> iconURLs(Document*, int iconTypesMask) const;
319     PassRefPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
320
321     DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
322     RefPtr<DOMWindow> m_frontendWindow;
323     OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel;
324     RefPtr<InternalRuntimeFlags> m_runtimeFlags;
325     RefPtr<InternalProfilers> m_profilers;
326 };
327
328 } // namespace WebCore
329
330 #endif