Upstream version 10.39.225.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/core/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/core/v8/ScriptPromise.h"
32 #include "bindings/core/v8/ScriptValue.h"
33 #include "bindings/core/v8/ScriptWrappable.h"
34 #include "core/css/CSSComputedStyleDeclaration.h"
35 #include "core/dom/ContextLifecycleObserver.h"
36 #include "core/page/scrolling/ScrollingCoordinator.h"
37 #include "platform/heap/Handle.h"
38 #include "wtf/ArrayBuffer.h"
39 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/text/WTFString.h"
42
43 namespace blink {
44
45 class CanvasRenderingContext2D;
46 class ClientRect;
47 class ClientRectList;
48 class DOMPoint;
49 class DOMStringList;
50 class LocalDOMWindow;
51 class DictionaryTest;
52 class Document;
53 class DocumentMarker;
54 class Element;
55 class ExceptionState;
56 class ExecutionContext;
57 class GCObservation;
58 class HTMLElement;
59 class HTMLMediaElement;
60 class InternalProfilers;
61 class InternalRuntimeFlags;
62 class InternalSettings;
63 class Iterator;
64 class LayerRectList;
65 class LocalFrame;
66 class Node;
67 class Page;
68 class PagePopupController;
69 class PrivateScriptTest;
70 class Range;
71 class SerializedScriptValue;
72 class ShadowRoot;
73 template <typename NodeType> class StaticNodeTypeList;
74 typedef StaticNodeTypeList<Node> StaticNodeList;
75 class TypeConversions;
76
77 class Internals FINAL : public GarbageCollectedFinalized<Internals>, public ScriptWrappable, public ContextLifecycleObserver {
78     DEFINE_WRAPPERTYPEINFO();
79 public:
80     static Internals* create(Document*);
81     virtual ~Internals();
82
83     static void resetToConsistentState(Page*);
84
85     String elementRenderTreeAsText(Element*, ExceptionState&);
86
87     String address(Node*);
88
89     GCObservation* observeGC(ScriptValue);
90
91     bool isPreloaded(const String& url);
92     bool isLoadingFromMemoryCache(const String& url);
93
94     bool isSharingStyle(Element*, Element*) const;
95
96     PassRefPtrWillBeRawPtr<CSSStyleDeclaration> computedStyleIncludingVisitedInfo(Node*) const;
97
98     ShadowRoot* shadowRoot(Element* host);
99     ShadowRoot* youngestShadowRoot(Element* host);
100     ShadowRoot* oldestShadowRoot(Element* host);
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*);
107
108     // CSS Animation / Transition testing.
109     void pauseAnimations(double pauseTime, ExceptionState&);
110
111     bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
112     Node* treeScopeRootNode(Node*);
113     Node* parentTreeScope(Node*);
114     bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
115     bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
116     bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
117     bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
118     unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
119
120     // FIXME: Rename these functions if walker is preferred.
121     Node* nextSiblingByWalker(Node*);
122     Node* firstChildByWalker(Node*);
123     Node* lastChildByWalker(Node*);
124     Node* nextNodeByWalker(Node*);
125     Node* previousNodeByWalker(Node*);
126
127     unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
128     unsigned needsLayoutCount(ExceptionState&) const;
129     unsigned hitTestCount(Document*, ExceptionState&) const;
130
131     String visiblePlaceholder(Element*);
132     void selectColorInColorChooser(Element*, const String& colorValue);
133     void endColorChooser(Element*);
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     PassRefPtrWillBeRawPtr<PagePopupController> pagePopupController();
140
141     PassRefPtrWillBeRawPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
142
143     PassRefPtrWillBeRawPtr<ClientRect> boundingBox(Element*);
144
145     unsigned markerCountForNode(Node*, const String&, ExceptionState&);
146     unsigned activeMarkerCountForNode(Node*);
147     PassRefPtrWillBeRawPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
148     String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
149     void addTextMatchMarker(const Range*, bool isActive);
150     void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
151     void setMarkedTextMatchesAreHighlighted(Document*, bool);
152
153     void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
154     String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
155
156     bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
157     bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
158     String suggestedValue(Element*, ExceptionState&);
159     void setSuggestedValue(Element*, const String&, ExceptionState&);
160     void setEditingValue(Element* inputElement, const String&, ExceptionState&);
161     void setAutofilled(Element*, bool enabled, ExceptionState&);
162     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
163
164     PassRefPtrWillBeRawPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength);
165     unsigned locationFromRange(Element* scope, const Range*);
166     unsigned lengthFromRange(Element* scope, const Range*);
167     String rangeAsText(const Range*);
168
169     DOMPoint* touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
170     Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
171     DOMPoint* touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
172     Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
173     PassRefPtrWillBeRawPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
174
175     int lastSpellCheckRequestSequence(Document*, ExceptionState&);
176     int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
177
178     Vector<AtomicString> userPreferredLanguages() const;
179     void setUserPreferredLanguages(const Vector<String>&);
180
181     unsigned activeDOMObjectCount(Document*);
182     unsigned wheelEventHandlerCount(Document*);
183     unsigned scrollEventHandlerCount(Document*);
184     unsigned touchEventHandlerCount(Document*);
185     LayerRectList* touchEventTargetLayerRects(Document*, ExceptionState&);
186
187     // This is used to test rect based hit testing like what's done on touch screens.
188     PassRefPtrWillBeRawPtr<StaticNodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
189         unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowChildFrameContent, ExceptionState&) const;
190
191     bool hasSpellingMarker(Document*, int from, int length);
192     bool hasGrammarMarker(Document*, int from, int length);
193     void setContinuousSpellCheckingEnabled(bool);
194
195     bool isOverwriteModeEnabled(Document*);
196     void toggleOverwriteModeEnabled(Document*);
197
198     unsigned numberOfScrollableAreas(Document*);
199
200     bool isPageBoxVisible(Document*, int pageNumber);
201
202     static const char* internalsId;
203
204     InternalSettings* settings() const;
205     InternalRuntimeFlags* runtimeFlags() const;
206     InternalProfilers* profilers();
207     unsigned workerThreadCount() const;
208
209     void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
210
211     String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
212     String layerTreeAsText(Document*, ExceptionState&) const;
213     String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
214     String elementLayerTreeAsText(Element*, ExceptionState&) const;
215
216     bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
217     bool isUnclippedDescendant(Element*, ExceptionState&);
218
219     String scrollingStateTreeAsText(Document*) const;
220     String mainThreadScrollingReasons(Document*, ExceptionState&) const;
221     PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
222
223     void garbageCollectDocumentResources(Document*) const;
224     void evictAllResources() const;
225
226     unsigned numberOfLiveNodes() const;
227     unsigned numberOfLiveDocuments() const;
228     String dumpRefCountedInstanceCounts() const;
229     Vector<String> consoleMessageArgumentCounts(Document*) const;
230     PassRefPtrWillBeRawPtr<LocalDOMWindow> openDummyInspectorFrontend(const String& url);
231     void closeDummyInspectorFrontend();
232     Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
233     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
234
235     String counterValue(Element*);
236
237     int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
238     Vector<String> shortcutIconURLs(Document*) const;
239     Vector<String> allIconURLs(Document*) const;
240
241     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
242     String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
243     String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
244
245     void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
246
247     void setIsCursorVisible(Document*, bool, ExceptionState&);
248
249     void mediaPlayerRequestFullscreen(HTMLMediaElement*);
250     double effectiveMediaVolume(HTMLMediaElement*);
251
252     void mediaPlayerRemoteRouteAvailabilityChanged(HTMLMediaElement *, bool);
253
254     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
255     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
256
257     TypeConversions* typeConversions() const;
258     PrivateScriptTest* privateScriptTest() const;
259     DictionaryTest* dictionaryTest() const;
260
261     Vector<String> getReferencedFilePaths() const;
262
263     void startTrackingRepaints(Document*, ExceptionState&);
264     void stopTrackingRepaints(Document*, ExceptionState&);
265     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
266     void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
267     void forceFullRepaint(Document*, ExceptionState&);
268
269     PassRefPtrWillBeRawPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
270     PassRefPtrWillBeRawPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
271
272     PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
273     PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
274
275     String getCurrentCursorInfo(Document*, ExceptionState&);
276
277     String markerTextForListItem(Element*);
278
279     void forceReload(bool endToEnd);
280
281     String getImageSourceURL(Element*);
282
283     bool isSelectPopupVisible(Node*);
284     bool selectPopupItemStyleIsRtl(Node*, int);
285     int selectPopupItemStyleFontHeight(Node*, int);
286
287     PassRefPtrWillBeRawPtr<ClientRect> selectionBounds(ExceptionState&);
288
289     bool loseSharedGraphicsContext3D();
290
291     void forceCompositingUpdate(Document*, ExceptionState&);
292
293     void setZoomFactor(float);
294
295     void setShouldRevealPassword(Element*, bool, ExceptionState&);
296
297     ScriptPromise createResolvedPromise(ScriptState*, ScriptValue);
298     ScriptPromise createRejectedPromise(ScriptState*, ScriptValue);
299     ScriptPromise addOneToPromise(ScriptState*, ScriptPromise);
300     ScriptPromise promiseCheck(ScriptState*, long, bool, const Dictionary&, const String&, const Vector<String>&, ExceptionState&);
301     ScriptPromise promiseCheckWithoutExceptionState(ScriptState*, const Dictionary&, const String&, const Vector<String>&);
302     ScriptPromise promiseCheckRange(ScriptState*, long);
303
304     void trace(Visitor*);
305
306     void setValueForUser(Element*, const String&);
307
308     String textSurroundingNode(Node*, int x, int y, unsigned long maxLength);
309
310     void setFocused(bool);
311
312     bool ignoreLayoutWithPendingStylesheets(Document*);
313
314     void setNetworkStateNotifierTestOnly(bool);
315     // Test must call setNetworkStateNotifierTestOnly(true) before calling setNetworkConnectionInfo.
316     void setNetworkConnectionInfo(const String&, ExceptionState&);
317     String serializeNavigationMarkup();
318     void hideAllTransitionElements();
319
320     unsigned countHitRegions(CanvasRenderingContext2D*);
321
322     void forcePluginPlaceholder(HTMLElement* plugin, const String& htmlSource, ExceptionState&);
323     void forcePluginPlaceholder(HTMLElement* plugin, const Dictionary& options, ExceptionState&);
324
325     Iterator* iterator(ScriptState*, ExceptionState&);
326
327 private:
328     explicit Internals(Document*);
329     Document* contextDocument() const;
330     LocalFrame* frame() const;
331     Vector<String> iconURLs(Document*, int iconTypesMask) const;
332     PassRefPtrWillBeRawPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
333
334     DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
335     Member<InternalRuntimeFlags> m_runtimeFlags;
336     Member<InternalProfilers> m_profilers;
337 };
338
339 } // namespace blink
340
341 #endif // Internals_h