~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/DumpRenderTree/chromium/TestShell.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "DRTTestRunner.h"
 
35
#include "NotificationPresenter.h"
 
36
#include "TestEventPrinter.h"
 
37
#include "WebPreferences.h"
 
38
#include "WebTestInterfaces.h"
 
39
#include "WebViewHost.h"
 
40
#include <string>
 
41
#include <wtf/OwnPtr.h>
 
42
#include <wtf/Vector.h>
 
43
 
 
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.
 
46
 
 
47
namespace WebKit {
 
48
class WebDevToolsAgentClient;
 
49
class WebFrame;
 
50
class WebNotificationPresenter;
 
51
class WebThread;
 
52
class WebView;
 
53
class WebURL;
 
54
}
 
55
 
 
56
class DRTDevToolsAgent;
 
57
class DRTDevToolsCallArgs;
 
58
class DRTDevToolsClient;
 
59
class MockWebPrerenderingSupport;
 
60
class WebPermissions;
 
61
 
 
62
struct TestParams {
 
63
    bool dumpTree;
 
64
    bool debugRenderTree;
 
65
    bool debugLayerTree;
 
66
    bool printSeparators;
 
67
    WebKit::WebURL testUrl;
 
68
    std::string pixelHash;
 
69
 
 
70
    TestParams()
 
71
        : dumpTree(true)
 
72
        , debugRenderTree(false)
 
73
        , debugLayerTree(false)
 
74
        , printSeparators(false) { }
 
75
};
 
76
 
 
77
class TestShell {
 
78
public:
 
79
    TestShell();
 
80
    ~TestShell();
 
81
 
 
82
    void initialize();
 
83
 
 
84
    // The main WebView.
 
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(); }
 
93
#endif
 
94
    const TestEventPrinter* printer() const { return &m_printer; }
 
95
 
 
96
    WebPreferences* preferences() { return &m_prefs; }
 
97
    void applyPreferences() { m_prefs.applyTo(m_webView); }
 
98
 
 
99
    WebPermissions* webPermissions() { return m_webPermissions.get(); }
 
100
 
 
101
    void bindJSObjectsToWindow(WebKit::WebFrame*);
 
102
    void runFileTest(const TestParams&, bool shouldDumpPixelTests);
 
103
    void callJSGC();
 
104
    void resetTestController();
 
105
    void waitTestFinished();
 
106
 
 
107
    // Operations to the main window.
 
108
    void loadURL(const WebKit::WebURL&);
 
109
    void reload();
 
110
    void goToOffset(int offset);
 
111
    int navigationEntryCount() const;
 
112
 
 
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; }
 
120
 
 
121
    // Called by the DRTTestRunner to signal test completion.
 
122
    void testFinished();
 
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
 
125
    // the test results.
 
126
    void testTimedOut();
 
127
 
 
128
    bool allowExternalPages() const { return m_allowExternalPages; }
 
129
    void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; }
 
130
 
 
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; }
 
143
#if defined(OS_WIN)
 
144
    // Access to the finished event. Used by the static WatchDog thread.
 
145
    HANDLE finishedEvent() { return m_finishedEvent; }
 
146
#endif
 
147
 
 
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; }
 
152
 
 
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; }
 
158
 
 
159
    // The JavaScript flags specified as a strings.
 
160
    std::string javaScriptFlags() { return m_javaScriptFlags; }
 
161
    void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = javaScriptFlags; }
 
162
 
 
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; }
 
166
 
 
167
    void setIsDisplayingModalDialog(bool isDisplayingModalDialog) { m_isDisplayingModalDialog = isDisplayingModalDialog; }
 
168
    bool isDisplayingModalDialog() const { return m_isDisplayingModalDialog; }
 
169
 
 
170
    // Set whether the binary data output should be encoded in base64 text.
 
171
    void setEncodeBinary(bool encodeBinary) { m_printer.setEncodeBinary(encodeBinary); }
 
172
 
 
173
    WebViewHost* createNewWindow(const WebKit::WebURL&);
 
174
    void closeWindow(WebViewHost*);
 
175
    void closeRemainingWindows();
 
176
    int windowCount();
 
177
    static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
 
178
 
 
179
    void showDevTools();
 
180
    void closeDevTools();
 
181
 
 
182
    DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); }
 
183
    DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); }
 
184
    WebViewHost* devToolsWebView() { return m_devTools; }
 
185
 
 
186
    static const int virtualWindowBorder = 3;
 
187
 
 
188
    typedef Vector<WebViewHost*> WindowList;
 
189
    WindowList windowList() const { return m_windowList; }
 
190
 
 
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&);
 
194
 
 
195
private:
 
196
    WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*);
 
197
    void createMainWindow();
 
198
    void createDRTDevToolsClient(DRTDevToolsAgent*);
 
199
 
 
200
    void resetWebSettings(WebKit::WebView&);
 
201
    void dump();
 
202
    std::string dumpAllBackForwardLists();
 
203
    void dumpImage(SkCanvas*) const;
 
204
 
 
205
    bool m_testIsPending;
 
206
    bool m_testIsPreparing;
 
207
    bool m_isLoading;
 
208
    WebKit::WebView* m_webView;
 
209
    WebKit::WebWidget* m_focusedWidget;
 
210
    WebViewHost* m_devTools;
 
211
 
 
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;
 
221
#endif
 
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;
 
227
#endif
 
228
 
 
229
    TestParams m_params;
 
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;
 
245
    bool m_stressOpt;
 
246
    bool m_stressDeopt;
 
247
    std::string m_javaScriptFlags;
 
248
    bool m_dumpWhenFinished;
 
249
    bool m_isDisplayingModalDialog;
 
250
 
 
251
 
 
252
    // List of all windows in this process.
 
253
    // The main window should be put into windowList[0].
 
254
    WindowList m_windowList;
 
255
 
 
256
#if defined(OS_WIN)
 
257
    // Used by the watchdog to know when it's finished.
 
258
    HANDLE m_finishedEvent;
 
259
#endif
 
260
};
 
261
 
 
262
void platformInit(int*, char***);
 
263
void openStartupDialog();
 
264
bool checkLayoutTestSystemDependencies();
 
265
 
 
266
#endif // TestShell_h