initial import
[vuplus_webkit] / Tools / WebKitTestRunner / InjectedBundle / LayoutTestController.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef LayoutTestController_h
27 #define LayoutTestController_h
28
29 #include "JSWrappable.h"
30 #include <JavaScriptCore/JSRetainPtr.h>
31 #include <WebKit2/WKBundleScriptWorld.h>
32 #include <string>
33 #include <wtf/PassRefPtr.h>
34
35 #if PLATFORM(MAC)
36 #include <wtf/RetainPtr.h>
37 #include <CoreFoundation/CFRunLoop.h>
38 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
39 #elif PLATFORM(WIN)
40 typedef UINT_PTR PlatformTimerRef;
41 #elif PLATFORM(QT)
42 #include <QTimer>
43 typedef QTimer PlatformTimerRef;
44 #elif PLATFORM(GTK)
45 typedef unsigned int PlatformTimerRef;
46 #endif
47
48 namespace WTR {
49
50 class LayoutTestController : public JSWrappable {
51 public:
52     static PassRefPtr<LayoutTestController> create();
53     virtual ~LayoutTestController();
54
55     // JSWrappable
56     virtual JSClassRef wrapperClass();
57
58     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
59
60     // The basics.
61     void dumpAsText(bool dumpPixels);
62     void waitForPolicyDelegate();
63     void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
64     void waitUntilDone();
65     void notifyDone();
66
67     // Other dumping.
68     void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
69     void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
70     void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
71     void dumpSelectionRect() { } // Will need to do something when we support pixel tests.
72     void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
73     void dumpTitleChanges() { m_dumpTitleChanges = true; }
74     void dumpFullScreenCallbacks() { m_dumpFullScreenCallbacks = true; }
75
76     // Special options.
77     void keepWebHistory();
78     void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
79     void setCanOpenWindows(bool);
80     void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
81     void setXSSAuditorEnabled(bool);
82     void setAllowUniversalAccessFromFileURLs(bool);
83     void setAllowFileAccessFromFileURLs(bool);
84     void setFrameFlatteningEnabled(bool);
85     void setJavaScriptCanAccessClipboard(bool);
86     void setPrivateBrowsingEnabled(bool);
87     void setAuthorAndUserStylesEnabled(bool);
88     void setCustomPolicyDelegate(bool enabled, bool permissive = false);
89     void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
90     void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
91
92     // Special DOM functions.
93     JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
94     JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef elementId);
95     void clearBackForwardList();
96     void execCommand(JSStringRef name, JSStringRef argument);
97     bool isCommandEnabled(JSStringRef name);
98     JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
99     unsigned windowCount();
100
101     // Repaint testing.
102     void testRepaint() { m_testRepaint = true; }
103     void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
104     void display();
105
106     // Animation testing.
107     unsigned numberOfActiveAnimations() const;
108     bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
109     bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
110     void suspendAnimations();
111     void resumeAnimations();
112     
113     // Compositing testing.
114     JSRetainPtr<JSStringRef> layerTreeAsText() const;
115     
116     // UserContent testing.
117     void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
118     void addUserStyleSheet(JSStringRef source, bool allFrames);
119
120     // Text search testing.
121     bool findString(JSStringRef, JSValueRef optionsArray);
122
123     // Local storage
124     void clearAllDatabases();
125     void setDatabaseQuota(uint64_t);
126     JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
127
128     // Printing
129     int numberOfPages(double pageWidthInPixels, double pageHeightInPixels);
130     int pageNumberForElementById(JSStringRef, double pageWidthInPixels, double pageHeightInPixels);
131     JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
132     bool isPageBoxVisible(int pageIndex);
133
134     enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
135     WhatToDump whatToDump() const { return m_whatToDump; }
136
137     bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
138     bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
139     bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
140     bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
141     bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
142     bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
143     bool shouldDumpPixels() const { return m_dumpPixels; }
144     bool shouldDumpFullScreenCallbacks() const { return m_dumpFullScreenCallbacks; }
145     bool isPolicyDelegateEnabled() const { return m_policyDelegateEnabled; }
146     bool isPolicyDelegatePermissive() const { return m_policyDelegatePermissive; }
147
148     bool waitToDump() const { return m_waitToDump; }
149     void waitToDumpWatchdogTimerFired();
150     void invalidateWaitToDumpWatchdogTimer();
151
152     bool shouldAllowEditing() const { return m_shouldAllowEditing; }
153
154     bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
155
156     void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
157     static unsigned worldIDForWorld(WKBundleScriptWorldRef);
158
159     void showWebInspector();
160     void closeWebInspector();
161     void evaluateInWebInspector(long callId, JSStringRef script);
162     void setJavaScriptProfilingEnabled(bool);
163
164     void setPOSIXLocale(JSStringRef);
165
166     bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
167     void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
168
169     void setTextDirection(JSStringRef);
170
171     void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
172     
173     bool globalFlag() const { return m_globalFlag; }
174     void setGlobalFlag(bool value) { m_globalFlag = value; }
175
176 private:
177     static const double waitToDumpWatchdogTimerInterval;
178
179     LayoutTestController();
180
181     void platformInitialize();
182     void initializeWaitToDumpWatchdogTimerIfNeeded();
183
184     WhatToDump m_whatToDump;
185     bool m_shouldDumpAllFrameScrollPositions;
186     bool m_shouldDumpBackForwardListsForAllWindows;
187
188     bool m_shouldAllowEditing;
189     bool m_shouldCloseExtraWindows;
190
191     bool m_dumpEditingCallbacks;
192     bool m_dumpStatusCallbacks;
193     bool m_dumpTitleChanges;
194     bool m_dumpPixels;
195     bool m_dumpFullScreenCallbacks;
196     bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
197     bool m_testRepaint;
198     bool m_testRepaintSweepHorizontally;
199
200     bool m_willSendRequestReturnsNull;
201
202     bool m_policyDelegateEnabled;
203     bool m_policyDelegatePermissive;
204     
205     bool m_globalFlag;
206
207     PlatformTimerRef m_waitToDumpWatchdogTimer;
208 };
209
210 } // namespace WTR
211
212 #endif // LayoutTestController_h