tizen beta release
[framework/web/webkit-efl.git] / Tools / DumpRenderTree / chromium / TestShell.h
1 /*
2  * Copyright (C) 2010 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 "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"
44 #include <string>
45 #include <wtf/OwnPtr.h>
46 #include <wtf/Vector.h>
47
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.
50
51 namespace WebKit {
52 class WebDevToolsAgentClient;
53 class WebFrame;
54 class WebNotificationPresenter;
55 class WebView;
56 class WebURL;
57 }
58
59 class DRTDevToolsAgent;
60 class DRTDevToolsCallArgs;
61 class DRTDevToolsClient;
62 class WebPermissions;
63
64 struct TestParams {
65     bool dumpTree;
66     bool dumpPixels;
67     bool debugRenderTree;
68     bool debugLayerTree;
69     bool printSeparators;
70     WebKit::WebURL testUrl;
71     // Resultant image file name. Required only if the test_shell mode.
72     std::string pixelFileName;
73     std::string pixelHash;
74
75     TestParams()
76         : dumpTree(true)
77         , dumpPixels(false)
78         , debugRenderTree(false)
79         , debugLayerTree(false)
80         , printSeparators(false) { }
81 };
82
83 class TestShell {
84 public:
85     TestShell(bool testShellMode);
86     ~TestShell();
87
88     // The main WebView.
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(); }
98
99     WebPreferences* preferences() { return &m_prefs; }
100     void applyPreferences() { m_prefs.applyTo(m_webView); }
101
102     WebPermissions* webPermissions() { return m_webPermissions.get(); }
103
104     void bindJSObjectsToWindow(WebKit::WebFrame*);
105     void runFileTest(const TestParams&);
106     void callJSGC();
107     void resetTestController();
108     void waitTestFinished();
109
110     // Operations to the main window.
111     void loadURL(const WebKit::WebURL&);
112     void reload();
113     void goToOffset(int offset);
114     int navigationEntryCount() const;
115
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; }
122
123     // Called by the LayoutTestController to signal test completion.
124     void testFinished();
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
127     // the test results.
128     void testTimedOut();
129
130     bool allowExternalPages() const { return m_allowExternalPages; }
131     void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; }
132
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; }
140 #if defined(OS_WIN)
141     // Access to the finished event. Used by the static WatchDog thread.
142     HANDLE finishedEvent() { return m_finishedEvent; }
143 #endif
144
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; }
149
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; }
155
156     // The JavaScript flags specified as a strings.
157     std::string javaScriptFlags() { return m_javaScriptFlags; }
158     void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = javaScriptFlags; }
159
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; }
163
164     WebViewHost* createNewWindow(const WebKit::WebURL&);
165     void closeWindow(WebViewHost*);
166     void closeRemainingWindows();
167     int windowCount();
168     static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
169
170     void showDevTools();
171     void closeDevTools();
172
173     DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); }
174     DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); }
175     WebViewHost* devToolsWebView() { return m_devTools; }
176
177     static const int virtualWindowBorder = 3;
178
179     typedef Vector<WebViewHost*> WindowList;
180     WindowList windowList() const { return m_windowList; }
181
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&);
185
186 private:
187     WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*);
188     void createMainWindow();
189     void createDRTDevToolsClient(DRTDevToolsAgent*);
190
191     void resetWebSettings(WebKit::WebView&);
192     void dump();
193     std::string dumpAllBackForwardLists();
194     void dumpImage(SkCanvas*) const;
195
196     bool m_testIsPending;
197     bool m_testIsPreparing;
198     bool m_isLoading;
199     WebKit::WebView* m_webView;
200     WebKit::WebWidget* m_focusedWidget;
201     bool m_testShellMode;
202     WebViewHost* m_devTools;
203
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;
217
218     TestParams m_params;
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;
229     bool m_stressOpt;
230     bool m_stressDeopt;
231     std::string m_javaScriptFlags;
232     bool m_dumpWhenFinished;
233
234
235     // List of all windows in this process.
236     // The main window should be put into windowList[0].
237     WindowList m_windowList;
238
239 #if defined(OS_WIN)
240     // Used by the watchdog to know when it's finished.
241     HANDLE m_finishedEvent;
242 #endif
243 };
244
245 void platformInit(int*, char***);
246 void openStartupDialog();
247 bool checkLayoutTestSystemDependencies();
248
249 #endif // TestShell_h