2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
34 #include "AccessibilityController.h"
35 #include "EventSender.h"
36 #include "GamepadController.h"
37 #include "LayoutTestController.h"
38 #include "NotificationPresenter.h"
39 #include "PlainTextController.h"
40 #include "TestEventPrinter.h"
41 #include "TextInputController.h"
42 #include "WebPreferences.h"
43 #include "WebViewHost.h"
45 #include <wtf/OwnPtr.h>
46 #include <wtf/Vector.h>
48 // TestShell is a container of global variables and has bridge functions between
49 // various objects. Only one instance is created in one DRT process.
52 class WebDevToolsAgentClient;
54 class WebNotificationPresenter;
59 class DRTDevToolsAgent;
60 class DRTDevToolsCallArgs;
61 class DRTDevToolsClient;
70 WebKit::WebURL testUrl;
71 // Resultant image file name. Required only if the test_shell mode.
72 std::string pixelFileName;
73 std::string pixelHash;
78 , debugRenderTree(false)
79 , debugLayerTree(false)
80 , printSeparators(false) { }
85 TestShell(bool testShellMode);
89 WebKit::WebView* webView() const { return m_webView; }
90 // Returns the host for the main WebView.
91 WebViewHost* webViewHost() const { return m_webViewHost.get(); }
92 LayoutTestController* layoutTestController() const { return m_layoutTestController.get(); }
93 EventSender* eventSender() const { return m_eventSender.get(); }
94 AccessibilityController* accessibilityController() const { return m_accessibilityController.get(); }
95 GamepadController* gamepadController() const { return m_gamepadController.get(); }
96 NotificationPresenter* notificationPresenter() const { return m_notificationPresenter.get(); }
97 TestEventPrinter* printer() const { return m_printer.get(); }
99 WebPreferences* preferences() { return &m_prefs; }
100 void applyPreferences() { m_prefs.applyTo(m_webView); }
102 WebPermissions* webPermissions() { return m_webPermissions.get(); }
104 void bindJSObjectsToWindow(WebKit::WebFrame*);
105 void runFileTest(const TestParams&);
107 void resetTestController();
108 void waitTestFinished();
110 // Operations to the main window.
111 void loadURL(const WebKit::WebURL&);
113 void goToOffset(int offset);
114 int navigationEntryCount() const;
116 void setFocus(WebKit::WebWidget*, bool enable);
117 bool shouldDumpFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpFrameLoadCallbacks(); }
118 bool shouldDumpUserGestureInFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpUserGestureInFrameLoadCallbacks(); }
119 bool shouldDumpResourceLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpResourceLoadCallbacks(); }
120 bool shouldDumpResourceResponseMIMETypes() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpResourceResponseMIMETypes(); }
121 void setIsLoading(bool flag) { m_isLoading = flag; }
123 // Called by the LayoutTestController to signal test completion.
125 // Called by LayoutTestController when a test hits the timeout, but does not
126 // cause a hang. We can avoid killing TestShell in this case and still dump
130 bool allowExternalPages() const { return m_allowExternalPages; }
131 void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; }
133 void setAcceleratedCompositingForVideoEnabled(bool enabled) { m_acceleratedCompositingForVideoEnabled = enabled; }
134 void setThreadedCompositingEnabled(bool enabled) { m_threadedCompositingEnabled = enabled; }
135 void setCompositeToTexture(bool enabled) { m_compositeToTexture = enabled; }
136 void setForceCompositingMode(bool enabled) { m_forceCompositingMode = enabled; }
137 void setAccelerated2dCanvasEnabled(bool enabled) { m_accelerated2dCanvasEnabled = enabled; }
138 void setLegacyAccelerated2dCanvasEnabled(bool enabled) { m_legacyAccelerated2dCanvasEnabled = enabled; }
139 void setAcceleratedDrawingEnabled(bool enabled) { m_acceleratedDrawingEnabled = enabled; }
141 // Access to the finished event. Used by the static WatchDog thread.
142 HANDLE finishedEvent() { return m_finishedEvent; }
145 // Get the timeout for running a test in milliseconds.
146 int layoutTestTimeout() { return m_timeout; }
147 int layoutTestTimeoutForWatchDog() { return layoutTestTimeout() + 1000; }
148 void setLayoutTestTimeout(int timeout) { m_timeout = timeout; }
150 // V8 JavaScript stress test options.
151 int stressOpt() { return m_stressOpt; }
152 void setStressOpt(bool stressOpt) { m_stressOpt = stressOpt; }
153 int stressDeopt() { return m_stressDeopt; }
154 void setStressDeopt(int stressDeopt) { m_stressDeopt = stressDeopt; }
156 // The JavaScript flags specified as a strings.
157 std::string javaScriptFlags() { return m_javaScriptFlags; }
158 void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = javaScriptFlags; }
160 // Set whether to dump when the loaded page has finished processing. This is used with multiple load
161 // testing where we only want to have the output from the last load.
162 void setDumpWhenFinished(bool dumpWhenFinished) { m_dumpWhenFinished = dumpWhenFinished; }
164 WebViewHost* createNewWindow(const WebKit::WebURL&);
165 void closeWindow(WebViewHost*);
166 void closeRemainingWindows();
168 static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
171 void closeDevTools();
173 DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); }
174 DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); }
175 WebViewHost* devToolsWebView() { return m_devTools; }
177 static const int virtualWindowBorder = 3;
179 typedef Vector<WebViewHost*> WindowList;
180 WindowList windowList() const { return m_windowList; }
182 // Returns a string representation of an URL's spec that does not depend on
183 // the location of the layout test in the file system.
184 std::string normalizeLayoutTestURL(const std::string&);
187 WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*);
188 void createMainWindow();
189 void createDRTDevToolsClient(DRTDevToolsAgent*);
191 void resetWebSettings(WebKit::WebView&);
193 std::string dumpAllBackForwardLists();
194 void dumpImage(SkCanvas*) const;
196 bool m_testIsPending;
197 bool m_testIsPreparing;
199 WebKit::WebView* m_webView;
200 WebKit::WebWidget* m_focusedWidget;
201 bool m_testShellMode;
202 WebViewHost* m_devTools;
204 // Be careful of the destruction order of the following objects.
205 OwnPtr<TestEventPrinter> m_printer;
206 OwnPtr<WebPermissions> m_webPermissions;
207 OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent;
208 OwnPtr<DRTDevToolsClient> m_drtDevToolsClient;
209 OwnPtr<AccessibilityController> m_accessibilityController;
210 OwnPtr<GamepadController> m_gamepadController;
211 OwnPtr<EventSender> m_eventSender;
212 OwnPtr<LayoutTestController> m_layoutTestController;
213 OwnPtr<PlainTextController> m_plainTextController;
214 OwnPtr<TextInputController> m_textInputController;
215 OwnPtr<NotificationPresenter> m_notificationPresenter;
216 OwnPtr<WebViewHost> m_webViewHost;
219 int m_timeout; // timeout value in millisecond
220 bool m_allowExternalPages;
221 bool m_acceleratedCompositingForVideoEnabled;
222 bool m_threadedCompositingEnabled;
223 bool m_compositeToTexture;
224 bool m_forceCompositingMode;
225 bool m_accelerated2dCanvasEnabled;
226 bool m_legacyAccelerated2dCanvasEnabled;
227 bool m_acceleratedDrawingEnabled;
228 WebPreferences m_prefs;
231 std::string m_javaScriptFlags;
232 bool m_dumpWhenFinished;
235 // List of all windows in this process.
236 // The main window should be put into windowList[0].
237 WindowList m_windowList;
240 // Used by the watchdog to know when it's finished.
241 HANDLE m_finishedEvent;
245 void platformInit(int*, char***);
246 void openStartupDialog();
247 bool checkLayoutTestSystemDependencies();
249 #endif // TestShell_h