OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef TestShell_h | |
32 #define TestShell_h | |
33 | |
34 #include "TestEventPrinter.h" | |
35 #include "WebPreferences.h" | |
36 #include "WebTestInterfaces.h" | |
37 #include "WebViewHost.h" | |
38 #include <string> | |
39 #include <wtf/OwnPtr.h> | |
40 #include <wtf/Vector.h> | |
41 | |
42 // TestShell is a container of global variables and has bridge functions between | |
43 // various objects. Only one instance is created in one DRT process. | |
44 | |
45 namespace WebKit { | |
46 class WebDevToolsAgentClient; | |
47 class WebFrame; | |
48 class WebThread; | |
49 class WebView; | |
50 class WebThemeEngine; | |
51 class WebURL; | |
52 } | |
53 | |
54 class DRTDevToolsAgent; | |
55 class DRTDevToolsCallArgs; | |
56 class DRTDevToolsClient; | |
57 class MockWebPrerenderingSupport; | |
58 class MockPlatform; | |
59 | |
60 struct TestParams { | |
61 bool dumpTree; | |
62 bool debugRenderTree; | |
63 bool debugLayerTree; | |
64 bool printSeparators; | |
65 WebKit::WebURL testUrl; | |
66 std::string pixelHash; | |
67 | |
68 TestParams() | |
69 : dumpTree(true) | |
70 , debugRenderTree(false) | |
71 , debugLayerTree(false) | |
72 , printSeparators(false) { } | |
73 }; | |
74 | |
75 class TestShell { | |
76 public: | |
77 TestShell(); | |
78 ~TestShell(); | |
79 | |
80 void initialize(MockPlatform*); | |
81 | |
82 // The main WebView. | |
83 WebKit::WebView* webView() const { return m_webView; } | |
84 // Returns the host for the main WebView. | |
85 WebViewHost* webViewHost() const { return m_webViewHost.get(); } | |
86 WebTestRunner::WebTestRunner* testRunner() const { return m_testInterfaces->
testRunner(); } | |
87 const TestEventPrinter* printer() const { return &m_printer; } | |
88 | |
89 WebTestRunner::WebPreferences* preferences() { return &m_prefs; } | |
90 void applyPreferences() { m_prefs.applyTo(m_webView); } | |
91 | |
92 void bindJSObjectsToWindow(WebKit::WebFrame*); | |
93 void runFileTest(const TestParams&, bool shouldDumpPixelTests); | |
94 void callJSGC(); | |
95 void resetTestController(); | |
96 void waitTestFinished(); | |
97 | |
98 // Operations to the main window. | |
99 void loadURL(const WebKit::WebURL&); | |
100 void reload(); | |
101 void goToOffset(int offset); | |
102 int navigationEntryCount() const; | |
103 | |
104 void setFocus(WebKit::WebWidget*, bool enable); | |
105 | |
106 // Called by the DRTTestRunner to signal test completion. | |
107 void testFinished(WebViewHost*); | |
108 // Called by DRTTestRunner when a test hits the timeout, but does not | |
109 // cause a hang. We can avoid killing TestShell in this case and still dump | |
110 // the test results. | |
111 void testTimedOut(); | |
112 | |
113 bool allowExternalPages() const { return m_allowExternalPages; } | |
114 void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages =
allowExternalPages; } | |
115 | |
116 void setAcceleratedCompositingForVideoEnabled(bool enabled) { m_acceleratedC
ompositingForVideoEnabled = enabled; } | |
117 void setAcceleratedCompositingForFixedPositionEnabled(bool enabled) { m_acce
leratedCompositingForFixedPositionEnabled = enabled; } | |
118 void setAcceleratedCompositingForOverflowScrollEnabled(bool enabled) { m_acc
eleratedCompositingForOverflowScrollEnabled = enabled; } | |
119 void setAcceleratedCompositingForTransitionEnabled(bool enabled) { m_acceler
atedCompositingForTransitionEnabled = enabled; } | |
120 bool softwareCompositingEnabled() { return m_softwareCompositingEnabled; } | |
121 void setSoftwareCompositingEnabled(bool enabled) { m_softwareCompositingEnab
led = enabled; } | |
122 void setThreadedCompositingEnabled(bool enabled) { m_threadedCompositingEnab
led = enabled; } | |
123 void setForceCompositingMode(bool enabled) { m_forceCompositingMode = enable
d; } | |
124 void setThreadedHTMLParser(bool enabled) { m_threadedHTMLParser = enabled; } | |
125 void setAccelerated2dCanvasEnabled(bool enabled) { m_accelerated2dCanvasEnab
led = enabled; } | |
126 void setPerTilePaintingEnabled(bool enabled) { m_perTilePaintingEnabled = en
abled; } | |
127 void setDeferredImageDecodingEnabled(bool enabled) { m_deferredImageDecoding
Enabled = enabled; } | |
128 #if defined(OS_WIN) | |
129 // Access to the finished event. Used by the static WatchDog thread. | |
130 HANDLE finishedEvent() { return m_finishedEvent; } | |
131 #endif | |
132 | |
133 // Get the timeout for running a test in milliseconds. | |
134 int layoutTestTimeout() { return m_timeout; } | |
135 int layoutTestTimeoutForWatchDog() { return layoutTestTimeout() + 1000; } | |
136 void setLayoutTestTimeout(int timeout) { m_timeout = timeout; } | |
137 | |
138 // V8 JavaScript stress test options. | |
139 int stressOpt() { return m_stressOpt; } | |
140 void setStressOpt(bool stressOpt) { m_stressOpt = stressOpt; } | |
141 int stressDeopt() { return m_stressDeopt; } | |
142 void setStressDeopt(int stressDeopt) { m_stressDeopt = stressDeopt; } | |
143 | |
144 // The JavaScript flags specified as a strings. | |
145 std::string javaScriptFlags() { return m_javaScriptFlags; } | |
146 void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = j
avaScriptFlags; } | |
147 | |
148 // Set whether to dump when the loaded page has finished processing. This is
used with multiple load | |
149 // testing where we only want to have the output from the last load. | |
150 void setDumpWhenFinished(bool dumpWhenFinished) { m_dumpWhenFinished = dumpW
henFinished; } | |
151 | |
152 void setIsDisplayingModalDialog(bool isDisplayingModalDialog) { m_isDisplayi
ngModalDialog = isDisplayingModalDialog; } | |
153 bool isDisplayingModalDialog() const { return m_isDisplayingModalDialog; } | |
154 | |
155 // Set whether the binary data output should be encoded in base64 text. | |
156 void setEncodeBinary(bool encodeBinary) { m_printer.setEncodeBinary(encodeBi
nary); } | |
157 | |
158 WebViewHost* createNewWindow(const WebKit::WebURL&); | |
159 void closeWindow(WebViewHost*); | |
160 void closeRemainingWindows(); | |
161 int windowCount(); | |
162 void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::W
ebHistoryItem>*, size_t* currentEntryIndex); | |
163 static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&); | |
164 | |
165 void showDevTools(); | |
166 void closeDevTools(); | |
167 | |
168 DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); } | |
169 DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); } | |
170 WebViewHost* devToolsWebView() { return m_devTools; } | |
171 | |
172 static const int virtualWindowBorder = 3; | |
173 | |
174 typedef Vector<WebViewHost*> WindowList; | |
175 WindowList windowList() const { return m_windowList; } | |
176 | |
177 WebKit::WebThread* webCompositorThread() const { return m_webCompositorThrea
d.get(); } | |
178 | |
179 private: | |
180 WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*, WebTe
stRunner::WebTestInterfaces*); | |
181 void createMainWindow(); | |
182 void createDRTDevToolsClient(DRTDevToolsAgent*); | |
183 | |
184 void resetWebSettings(WebKit::WebView&); | |
185 void dump(); | |
186 std::string dumpAllBackForwardLists(); | |
187 void dumpImage(SkCanvas*) const; | |
188 | |
189 bool m_testIsPending; | |
190 bool m_testIsPreparing; | |
191 WebKit::WebView* m_webView; | |
192 WebKit::WebWidget* m_focusedWidget; | |
193 WebViewHost* m_devTools; | |
194 | |
195 // Be careful of the destruction order of the following objects. | |
196 TestEventPrinter m_printer; | |
197 OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent; | |
198 OwnPtr<DRTDevToolsClient> m_drtDevToolsClient; | |
199 OwnPtr<WebTestRunner::WebTestInterfaces> m_testInterfaces; | |
200 OwnPtr<WebTestRunner::WebTestInterfaces> m_devToolsTestInterfaces; | |
201 // It's important that this thread is destroyed after the WebViewHost. | |
202 OwnPtr<WebKit::WebThread> m_webCompositorThread; | |
203 OwnPtr<WebViewHost> m_webViewHost; | |
204 OwnPtr<MockWebPrerenderingSupport> m_prerenderingSupport; | |
205 | |
206 TestParams m_params; | |
207 bool m_dumpPixelsForCurrentTest; | |
208 int m_timeout; // timeout value in millisecond | |
209 bool m_allowExternalPages; | |
210 bool m_acceleratedCompositingForVideoEnabled; | |
211 bool m_acceleratedCompositingForFixedPositionEnabled; | |
212 bool m_acceleratedCompositingForOverflowScrollEnabled; | |
213 bool m_acceleratedCompositingForTransitionEnabled; | |
214 bool m_softwareCompositingEnabled; | |
215 bool m_threadedCompositingEnabled; | |
216 bool m_forceCompositingMode; | |
217 bool m_threadedHTMLParser; | |
218 bool m_accelerated2dCanvasEnabled; | |
219 bool m_perTilePaintingEnabled; | |
220 bool m_deferredImageDecodingEnabled; | |
221 WebTestRunner::WebPreferences m_prefs; | |
222 bool m_stressOpt; | |
223 bool m_stressDeopt; | |
224 std::string m_javaScriptFlags; | |
225 bool m_dumpWhenFinished; | |
226 bool m_isDisplayingModalDialog; | |
227 | |
228 | |
229 // List of all windows in this process. | |
230 // The main window should be put into windowList[0]. | |
231 WindowList m_windowList; | |
232 | |
233 #if defined(OS_WIN) | |
234 // Used by the watchdog to know when it's finished. | |
235 HANDLE m_finishedEvent; | |
236 #endif | |
237 }; | |
238 | |
239 void platformInit(int*, char***); | |
240 void openStartupDialog(); | |
241 bool checkLayoutTestSystemDependencies(); | |
242 | |
243 #endif // TestShell_h | |
OLD | NEW |