2
* Copyright (C) 2012 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 "DRTTestRunner.h"
35
#include "NotificationPresenter.h"
36
#include "TestEventPrinter.h"
37
#include "WebPreferences.h"
38
#include "WebTestInterfaces.h"
39
#include "WebViewHost.h"
41
#include <wtf/OwnPtr.h>
42
#include <wtf/Vector.h>
44
// TestShell is a container of global variables and has bridge functions between
45
// various objects. Only one instance is created in one DRT process.
48
class WebDevToolsAgentClient;
50
class WebNotificationPresenter;
56
class DRTDevToolsAgent;
57
class DRTDevToolsCallArgs;
58
class DRTDevToolsClient;
59
class MockWebPrerenderingSupport;
67
WebKit::WebURL testUrl;
68
std::string pixelHash;
72
, debugRenderTree(false)
73
, debugLayerTree(false)
74
, printSeparators(false) { }
85
WebKit::WebView* webView() const { return m_webView; }
86
// Returns the host for the main WebView.
87
WebViewHost* webViewHost() const { return m_webViewHost.get(); }
88
DRTTestRunner* testRunner() const { return m_testRunner.get(); }
89
WebTestRunner::WebEventSender* eventSender() const { return m_testInterfaces->eventSender(); }
90
WebTestRunner::WebAccessibilityController* accessibilityController() const { return m_testInterfaces->accessibilityController(); }
91
#if ENABLE(NOTIFICATIONS)
92
NotificationPresenter* notificationPresenter() const { return m_notificationPresenter.get(); }
94
const TestEventPrinter* printer() const { return &m_printer; }
96
WebPreferences* preferences() { return &m_prefs; }
97
void applyPreferences() { m_prefs.applyTo(m_webView); }
99
WebPermissions* webPermissions() { return m_webPermissions.get(); }
101
void bindJSObjectsToWindow(WebKit::WebFrame*);
102
void runFileTest(const TestParams&, bool shouldDumpPixelTests);
104
void resetTestController();
105
void waitTestFinished();
107
// Operations to the main window.
108
void loadURL(const WebKit::WebURL&);
110
void goToOffset(int offset);
111
int navigationEntryCount() const;
113
void setFocus(WebKit::WebWidget*, bool enable);
114
bool shouldDumpFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpFrameLoadCallbacks(); }
115
bool shouldDumpResourceRequestCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceRequestCallbacks(); }
116
bool shouldDumpUserGestureInFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpUserGestureInFrameLoadCallbacks(); }
117
bool shouldDumpResourceLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceLoadCallbacks(); }
118
bool shouldDumpResourceResponseMIMETypes() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceResponseMIMETypes(); }
119
void setIsLoading(bool flag) { m_isLoading = flag; }
121
// Called by the DRTTestRunner to signal test completion.
123
// Called by DRTTestRunner when a test hits the timeout, but does not
124
// cause a hang. We can avoid killing TestShell in this case and still dump
128
bool allowExternalPages() const { return m_allowExternalPages; }
129
void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; }
131
void setAcceleratedCompositingForVideoEnabled(bool enabled) { m_acceleratedCompositingForVideoEnabled = enabled; }
132
void setAcceleratedCompositingForFixedPositionEnabled(bool enabled) { m_acceleratedCompositingForFixedPositionEnabled = enabled; }
133
bool softwareCompositingEnabled() { return m_softwareCompositingEnabled; }
134
void setSoftwareCompositingEnabled(bool enabled) { m_softwareCompositingEnabled = enabled; }
135
void setThreadedCompositingEnabled(bool enabled) { m_threadedCompositingEnabled = enabled; }
136
void setForceCompositingMode(bool enabled) { m_forceCompositingMode = enabled; }
137
void setAccelerated2dCanvasEnabled(bool enabled) { m_accelerated2dCanvasEnabled = enabled; }
138
void setDeferred2dCanvasEnabled(bool enabled) { m_deferred2dCanvasEnabled = enabled; }
139
void setAcceleratedPaintingEnabled(bool enabled) { m_acceleratedPaintingEnabled = enabled; }
140
void setPerTilePaintingEnabled(bool enabled) { m_perTilePaintingEnabled = enabled; }
141
void setAcceleratedAnimationEnabled(bool enabled) { m_acceleratedAnimationEnabled = enabled; }
142
void setDeferredImageDecodingEnabled(bool enabled) { m_deferredImageDecodingEnabled = enabled; }
144
// Access to the finished event. Used by the static WatchDog thread.
145
HANDLE finishedEvent() { return m_finishedEvent; }
148
// Get the timeout for running a test in milliseconds.
149
int layoutTestTimeout() { return m_timeout; }
150
int layoutTestTimeoutForWatchDog() { return layoutTestTimeout() + 1000; }
151
void setLayoutTestTimeout(int timeout) { m_timeout = timeout; }
153
// V8 JavaScript stress test options.
154
int stressOpt() { return m_stressOpt; }
155
void setStressOpt(bool stressOpt) { m_stressOpt = stressOpt; }
156
int stressDeopt() { return m_stressDeopt; }
157
void setStressDeopt(int stressDeopt) { m_stressDeopt = stressDeopt; }
159
// The JavaScript flags specified as a strings.
160
std::string javaScriptFlags() { return m_javaScriptFlags; }
161
void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = javaScriptFlags; }
163
// Set whether to dump when the loaded page has finished processing. This is used with multiple load
164
// testing where we only want to have the output from the last load.
165
void setDumpWhenFinished(bool dumpWhenFinished) { m_dumpWhenFinished = dumpWhenFinished; }
167
void setIsDisplayingModalDialog(bool isDisplayingModalDialog) { m_isDisplayingModalDialog = isDisplayingModalDialog; }
168
bool isDisplayingModalDialog() const { return m_isDisplayingModalDialog; }
170
// Set whether the binary data output should be encoded in base64 text.
171
void setEncodeBinary(bool encodeBinary) { m_printer.setEncodeBinary(encodeBinary); }
173
WebViewHost* createNewWindow(const WebKit::WebURL&);
174
void closeWindow(WebViewHost*);
175
void closeRemainingWindows();
177
static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
180
void closeDevTools();
182
DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); }
183
DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); }
184
WebViewHost* devToolsWebView() { return m_devTools; }
186
static const int virtualWindowBorder = 3;
188
typedef Vector<WebViewHost*> WindowList;
189
WindowList windowList() const { return m_windowList; }
191
// Returns a string representation of an URL's spec that does not depend on
192
// the location of the layout test in the file system.
193
std::string normalizeLayoutTestURL(const std::string&);
196
WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*);
197
void createMainWindow();
198
void createDRTDevToolsClient(DRTDevToolsAgent*);
200
void resetWebSettings(WebKit::WebView&);
202
std::string dumpAllBackForwardLists();
203
void dumpImage(SkCanvas*) const;
205
bool m_testIsPending;
206
bool m_testIsPreparing;
208
WebKit::WebView* m_webView;
209
WebKit::WebWidget* m_focusedWidget;
210
WebViewHost* m_devTools;
212
// Be careful of the destruction order of the following objects.
213
TestEventPrinter m_printer;
214
OwnPtr<WebPermissions> m_webPermissions;
215
OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent;
216
OwnPtr<DRTDevToolsClient> m_drtDevToolsClient;
217
OwnPtr<WebTestRunner::WebTestInterfaces> m_testInterfaces;
218
OwnPtr<DRTTestRunner> m_testRunner;
219
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
220
OwnPtr<NotificationPresenter> m_notificationPresenter;
222
// It's important that this thread is destroyed after the WebViewHost.
223
OwnPtr<WebKit::WebThread> m_webCompositorThread;
224
OwnPtr<WebViewHost> m_webViewHost;
225
#if ENABLE(LINK_PRERENDER)
226
OwnPtr<MockWebPrerenderingSupport> m_prerenderingSupport;
230
bool m_dumpPixelsForCurrentTest;
231
int m_timeout; // timeout value in millisecond
232
bool m_allowExternalPages;
233
bool m_acceleratedCompositingForVideoEnabled;
234
bool m_acceleratedCompositingForFixedPositionEnabled;
235
bool m_softwareCompositingEnabled;
236
bool m_threadedCompositingEnabled;
237
bool m_forceCompositingMode;
238
bool m_accelerated2dCanvasEnabled;
239
bool m_deferred2dCanvasEnabled;
240
bool m_acceleratedPaintingEnabled;
241
bool m_perTilePaintingEnabled;
242
bool m_acceleratedAnimationEnabled;
243
bool m_deferredImageDecodingEnabled;
244
WebPreferences m_prefs;
247
std::string m_javaScriptFlags;
248
bool m_dumpWhenFinished;
249
bool m_isDisplayingModalDialog;
252
// List of all windows in this process.
253
// The main window should be put into windowList[0].
254
WindowList m_windowList;
257
// Used by the watchdog to know when it's finished.
258
HANDLE m_finishedEvent;
262
void platformInit(int*, char***);
263
void openStartupDialog();
264
bool checkLayoutTestSystemDependencies();
266
#endif // TestShell_h