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 "LayoutTestController.h" |
|
37 #include "NotificationPresenter.h" |
|
38 #include "PlainTextController.h" |
|
39 #include "TestEventPrinter.h" |
|
40 #include "TextInputController.h" |
|
41 #include "WebViewHost.h" |
|
42 #include <string> |
|
43 #include <wtf/OwnPtr.h> |
|
44 #include <wtf/Vector.h> |
|
45 |
|
46 // TestShell is a container of global variables and has bridge functions between |
|
47 // various objects. Only one instance is created in one DRT process. |
|
48 |
|
49 namespace WebKit { |
|
50 class WebDevToolsAgentClient; |
|
51 class WebFrame; |
|
52 class WebNotificationPresenter; |
|
53 class WebPreferences; |
|
54 class WebView; |
|
55 class WebURL; |
|
56 } |
|
57 namespace skia { |
|
58 class PlatformCanvas; |
|
59 } |
|
60 |
|
61 class DRTDevToolsAgent; |
|
62 class DRTDevToolsCallArgs; |
|
63 class DRTDevToolsClient; |
|
64 |
|
65 struct TestParams { |
|
66 bool dumpTree; |
|
67 bool dumpPixels; |
|
68 bool printSeparators; |
|
69 WebKit::WebURL testUrl; |
|
70 // Resultant image file name. Reqruired only if the test_shell mode. |
|
71 std::string pixelFileName; |
|
72 std::string pixelHash; |
|
73 |
|
74 TestParams() |
|
75 : dumpTree(true) |
|
76 , dumpPixels(false) |
|
77 , printSeparators(false) {} |
|
78 }; |
|
79 |
|
80 class TestShell { |
|
81 public: |
|
82 TestShell(bool testShellMode); |
|
83 ~TestShell(); |
|
84 |
|
85 // The main WebView. |
|
86 WebKit::WebView* webView() const { return m_webView; } |
|
87 // Returns the host for the main WebView. |
|
88 WebViewHost* webViewHost() const { return m_webViewHost; } |
|
89 LayoutTestController* layoutTestController() const { return m_layoutTestController.get(); } |
|
90 EventSender* eventSender() const { return m_eventSender.get(); } |
|
91 AccessibilityController* accessibilityController() const { return m_accessibilityController.get(); } |
|
92 NotificationPresenter* notificationPresenter() const { return m_notificationPresenter.get(); } |
|
93 TestEventPrinter* printer() const { return m_printer.get(); } |
|
94 |
|
95 void bindJSObjectsToWindow(WebKit::WebFrame*); |
|
96 void runFileTest(const TestParams&); |
|
97 void callJSGC(); |
|
98 void resetTestController(); |
|
99 void waitTestFinished(); |
|
100 |
|
101 // Operations to the main window. |
|
102 void loadURL(const WebKit::WebURL& url); |
|
103 void reload(); |
|
104 void goToOffset(int offset); |
|
105 int navigationEntryCount() const; |
|
106 |
|
107 void setFocus(WebKit::WebWidget*, bool enable); |
|
108 bool shouldDumpFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpFrameLoadCallbacks(); } |
|
109 bool shouldDumpResourceLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpResourceLoadCallbacks(); } |
|
110 void setIsLoading(bool flag) { m_isLoading = flag; } |
|
111 |
|
112 // Called by the LayoutTestController to signal test completion. |
|
113 void testFinished(); |
|
114 // Called by LayoutTestController when a test hits the timeout, but does not |
|
115 // cause a hang. We can avoid killing TestShell in this case and still dump |
|
116 // the test results. |
|
117 void testTimedOut(); |
|
118 |
|
119 bool allowExternalPages() const { return m_allowExternalPages; } |
|
120 void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; } |
|
121 |
|
122 #if defined(OS_WIN) |
|
123 // Access to the finished event. Used by the static WatchDog thread. |
|
124 HANDLE finishedEvent() { return m_finishedEvent; } |
|
125 #endif |
|
126 |
|
127 // Get the timeout for running a test in milliseconds. |
|
128 int layoutTestTimeout() { return m_timeout; } |
|
129 int layoutTestTimeoutForWatchDog() { return layoutTestTimeout() + 1000; } |
|
130 void setLayoutTestTimeout(int timeout) { m_timeout = timeout; } |
|
131 |
|
132 WebViewHost* createWebView(); |
|
133 WebViewHost* createNewWindow(const WebKit::WebURL&); |
|
134 void closeWindow(WebViewHost*); |
|
135 void closeRemainingWindows(); |
|
136 int windowCount(); |
|
137 static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&); |
|
138 |
|
139 void showDevTools(); |
|
140 void closeDevTools(); |
|
141 |
|
142 DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); } |
|
143 DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); } |
|
144 |
|
145 static const int virtualWindowBorder = 3; |
|
146 |
|
147 private: |
|
148 void createDRTDevToolsClient(DRTDevToolsAgent*); |
|
149 |
|
150 static void resetWebSettings(WebKit::WebView&); |
|
151 void dump(); |
|
152 std::string dumpAllBackForwardLists(); |
|
153 void dumpImage(skia::PlatformCanvas*) const; |
|
154 |
|
155 bool m_testIsPending; |
|
156 bool m_testIsPreparing; |
|
157 bool m_isLoading; |
|
158 WebKit::WebView* m_webView; |
|
159 WebKit::WebWidget* m_focusedWidget; |
|
160 bool m_testShellMode; |
|
161 WebViewHost* m_webViewHost; |
|
162 WebViewHost* m_devTools; |
|
163 OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent; |
|
164 OwnPtr<DRTDevToolsClient> m_drtDevToolsClient; |
|
165 OwnPtr<AccessibilityController> m_accessibilityController; |
|
166 OwnPtr<EventSender> m_eventSender; |
|
167 OwnPtr<LayoutTestController> m_layoutTestController; |
|
168 OwnPtr<PlainTextController> m_plainTextController; |
|
169 OwnPtr<TextInputController> m_textInputController; |
|
170 OwnPtr<NotificationPresenter> m_notificationPresenter; |
|
171 OwnPtr<TestEventPrinter> m_printer; |
|
172 TestParams m_params; |
|
173 int m_timeout; // timeout value in millisecond |
|
174 bool m_allowExternalPages; |
|
175 |
|
176 // List of all windows in this process. |
|
177 // The main window should be put into windowList[0]. |
|
178 typedef Vector<WebViewHost*> WindowList; |
|
179 WindowList m_windowList; |
|
180 |
|
181 #if defined(OS_WIN) |
|
182 // Used by the watchdog to know when it's finished. |
|
183 HANDLE m_finishedEvent; |
|
184 #endif |
|
185 }; |
|
186 |
|
187 void platformInit(); |
|
188 |
|
189 #endif // TestShell_h |
|