Upstream version 5.34.92.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* ensureShadowRoot(Element* host, ExceptionState&);
99     ShadowRoot* shadowRoot(Element* host, ExceptionState&);
100     ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&);
101     ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&);
102     ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
103     ShadowRoot* olderShadowRoot(Node* shadow, ExceptionState&);
104     String shadowRootType(const Node*, ExceptionState&) const;
105     bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
106     bool hasContentElement(const Node*, ExceptionState&) const;
107     size_t countElementShadow(const Node*, ExceptionState&) const;
108     const AtomicString& shadowPseudoId(Element*, ExceptionState&);
109     void setShadowPseudoId(Element*, const AtomicString&, ExceptionState&);
110
111     // CSS Animation / Transition testing.
112     unsigned numberOfActiveAnimations() const;
113     void pauseAnimations(double pauseTime, ExceptionState&);
114
115     PassRefPtr<Element> createContentElement(ExceptionState&);
116     bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
117     Node* treeScopeRootNode(Node*, ExceptionState&);
118     Node* parentTreeScope(Node*, ExceptionState&);
119     bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
120     bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
121     bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
122     bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
123     unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
124
125     // FIXME: Rename these functions if walker is prefered.
126     Node* nextSiblingByWalker(Node*, ExceptionState&);
127     Node* firstChildByWalker(Node*, ExceptionState&);
128     Node* lastChildByWalker(Node*, ExceptionState&);
129     Node* nextNodeByWalker(Node*, ExceptionState&);
130     Node* previousNodeByWalker(Node*, ExceptionState&);
131
132     unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
133     unsigned needsLayoutCount(ExceptionState&) const;
134
135     String visiblePlaceholder(Element*);
136     void selectColorInColorChooser(Element*, const String& colorValue);
137     bool hasAutofocusRequest(Document*);
138     bool hasAutofocusRequest();
139     Vector<String> formControlStateOfHistoryItem(ExceptionState&);
140     void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&);
141     void setEnableMockPagePopup(bool, ExceptionState&);
142     PassRefPtr<PagePopupController> pagePopupController();
143
144     PassRefPtr<ClientRect> unscaledViewportRect(ExceptionState&);
145
146     PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
147
148     PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&);
149
150     PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&);
151
152     unsigned markerCountForNode(Node*, const String&, ExceptionState&);
153     unsigned activeMarkerCountForNode(Node*, ExceptionState&);
154     PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
155     String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
156     void addTextMatchMarker(const Range*, bool isActive);
157     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&);
158
159     void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
160     void setPagination(Document* document, const String& mode, int gap, ExceptionState& ec) { setPagination(document, mode, gap, 0, ec); }
161     void setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionState&);
162     String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
163
164     bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
165     bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
166     String suggestedValue(Element*, ExceptionState&);
167     void setSuggestedValue(Element*, const String&, ExceptionState&);
168     void setEditingValue(Element* inputElement, const String&, ExceptionState&);
169     void setAutofilled(Element*, bool enabled, ExceptionState&);
170     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
171
172     void paintControlTints(Document*, ExceptionState&);
173
174     PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
175     unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
176     unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
177     String rangeAsText(const Range*, ExceptionState&);
178
179     PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
180     Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
181     PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
182     Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
183     PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
184
185     int lastSpellCheckRequestSequence(Document*, ExceptionState&);
186     int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
187
188     Vector<AtomicString> userPreferredLanguages() const;
189     void setUserPreferredLanguages(const Vector<String>&);
190
191     unsigned wheelEventHandlerCount(Document*, ExceptionState&);
192     unsigned touchEventHandlerCount(Document*, ExceptionState&);
193     PassRefPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&);
194
195     // This is used to test rect based hit testing like what's done on touch screens.
196     PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
197         unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const;
198
199     void emitInspectorDidBeginFrame(int frameId = 0);
200     void emitInspectorDidCancelFrame();
201
202     bool hasSpellingMarker(Document*, int from, int length, ExceptionState&);
203     bool hasGrammarMarker(Document*, int from, int length, ExceptionState&);
204     void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&);
205
206     bool isOverwriteModeEnabled(Document*, ExceptionState&);
207     void toggleOverwriteModeEnabled(Document*, ExceptionState&);
208
209     unsigned numberOfScrollableAreas(Document*, ExceptionState&);
210
211     bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&);
212
213     static const char* internalsId;
214
215     InternalSettings* settings() const;
216     InternalRuntimeFlags* runtimeFlags() const;
217     InternalProfilers* profilers();
218     unsigned workerThreadCount() const;
219
220     void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
221
222     String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
223     String layerTreeAsText(Document*, ExceptionState&) const;
224     String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
225     String elementLayerTreeAsText(Element*, ExceptionState&) const;
226
227     PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&);
228     PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&);
229
230     bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
231     bool isUnclippedDescendant(Element*, ExceptionState&);
232     bool needsCompositedScrolling(Element*, ExceptionState&);
233
234     void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
235
236     String repaintRectsAsText(Document*, ExceptionState&) const;
237     PassRefPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const;
238
239     String scrollingStateTreeAsText(Document*, ExceptionState&) const;
240     String mainThreadScrollingReasons(Document*, ExceptionState&) const;
241     PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
242
243     void garbageCollectDocumentResources(Document*, ExceptionState&) const;
244     void evictAllResources() const;
245
246     void allowRoundingHacks() const;
247
248     unsigned numberOfLiveNodes() const;
249     unsigned numberOfLiveDocuments() const;
250     String dumpRefCountedInstanceCounts() const;
251     Vector<String> consoleMessageArgumentCounts(Document*) const;
252     PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
253     void closeDummyInspectorFrontend();
254     Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
255     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
256
257     String counterValue(Element*);
258
259     int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
260     Vector<String> shortcutIconURLs(Document*) const;
261     Vector<String> allIconURLs(Document*) const;
262
263     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
264     String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
265     String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
266
267     void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
268
269     void setIsCursorVisible(Document*, bool, ExceptionState&);
270
271     void webkitWillEnterFullScreenForElement(Document*, Element*);
272     void webkitDidEnterFullScreenForElement(Document*, Element*);
273     void webkitWillExitFullScreenForElement(Document*, Element*);
274     void webkitDidExitFullScreenForElement(Document*, Element*);
275
276     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
277     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
278
279     PassRefPtr<MallocStatistics> mallocStatistics() const;
280     PassRefPtr<TypeConversions> typeConversions() const;
281
282     Vector<String> getReferencedFilePaths() const;
283
284     void startTrackingRepaints(Document*, ExceptionState&);
285     void stopTrackingRepaints(Document*, ExceptionState&);
286     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
287     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
288
289     PassRefPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
290     PassRefPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
291
292     PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
293     PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
294
295     String getCurrentCursorInfo(Document*, ExceptionState&);
296
297     String markerTextForListItem(Element*, ExceptionState&);
298
299     void forceReload(bool endToEnd);
300
301     String getImageSourceURL(Element*, ExceptionState&);
302
303     bool isSelectPopupVisible(Node*);
304
305     PassRefPtr<ClientRect> selectionBounds(ExceptionState&);
306     String baseURL(Document*, ExceptionState&);
307
308     bool loseSharedGraphicsContext3D();
309
310     void forceCompositingUpdate(Document*, ExceptionState&);
311
312     void setZoomFactor(float);
313
314     ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise);
315
316 private:
317     explicit Internals(Document*);
318     Document* contextDocument() const;
319     Frame* frame() const;
320     Vector<String> iconURLs(Document*, int iconTypesMask) const;
321     PassRefPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
322
323     DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
324     RefPtr<DOMWindow> m_frontendWindow;
325     OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel;
326     RefPtr<InternalRuntimeFlags> m_runtimeFlags;
327     RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
328     RefPtr<InternalProfilers> m_profilers;
329 };
330
331 } // namespace WebCore
332
333 #endif