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 "WebPreferences.h" 42 #include "WebViewHost.h" 43 #include <string> 44 #include <wtf/OwnPtr.h> 45 #include <wtf/Vector.h> 46 47 // TestShell is a container of global variables and has bridge functions between 48 // various objects. Only one instance is created in one DRT process. 49 50 namespace WebKit { 51 class WebDevToolsAgentClient; 52 class WebFrame; 53 class WebNotificationPresenter; 54 class WebView; 55 class WebURL; 56 } 57 58 class DRTDevToolsAgent; 59 class DRTDevToolsCallArgs; 60 class DRTDevToolsClient; 61 62 struct TestParams { 63 bool dumpTree; 64 bool dumpPixels; 65 bool debugRenderTree; 66 bool debugLayerTree; 67 bool printSeparators; 68 WebKit::WebURL testUrl; 69 // Resultant image file name. Required only if the test_shell mode. 70 std::string pixelFileName; 71 std::string pixelHash; 72 73 TestParams() 74 : dumpTree(true) 75 , dumpPixels(false) 76 , debugRenderTree(false) 77 , debugLayerTree(false) 78 , printSeparators(false) {} 79 }; 80 81 class TestShell { 82 public: 83 TestShell(bool testShellMode); 84 ~TestShell(); 85 86 // The main WebView. 87 WebKit::WebView* webView() const { return m_webView; } 88 // Returns the host for the main WebView. 89 WebViewHost* webViewHost() const { return m_webViewHost; } 90 LayoutTestController* layoutTestController() const { return m_layoutTestController.get(); } 91 EventSender* eventSender() const { return m_eventSender.get(); } 92 AccessibilityController* accessibilityController() const { return m_accessibilityController.get(); } 93 NotificationPresenter* notificationPresenter() const { return m_notificationPresenter.get(); } 94 TestEventPrinter* printer() const { return m_printer.get(); } 95 96 WebPreferences* preferences() { return &m_prefs; } 97 void applyPreferences() { m_prefs.applyTo(m_webView); } 98 99 void bindJSObjectsToWindow(WebKit::WebFrame*); 100 void runFileTest(const TestParams&); 101 void callJSGC(); 102 void resetTestController(); 103 void waitTestFinished(); 104 105 // Operations to the main window. 106 void loadURL(const WebKit::WebURL& url); 107 void reload(); 108 void goToOffset(int offset); 109 int navigationEntryCount() const; 110 111 void setFocus(WebKit::WebWidget*, bool enable); 112 bool shouldDumpFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpFrameLoadCallbacks(); } 113 bool shouldDumpUserGestureInFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpUserGestureInFrameLoadCallbacks(); } 114 bool shouldDumpResourceLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpResourceLoadCallbacks(); } 115 bool shouldDumpResourceResponseMIMETypes() const { return (m_testIsPreparing || m_testIsPending) && layoutTestController()->shouldDumpResourceResponseMIMETypes(); } 116 void setIsLoading(bool flag) { m_isLoading = flag; } 117 118 // Called by the LayoutTestController to signal test completion. 119 void testFinished(); 120 // Called by LayoutTestController when a test hits the timeout, but does not 121 // cause a hang. We can avoid killing TestShell in this case and still dump 122 // the test results. 123 void testTimedOut(); 124 125 bool allowExternalPages() const { return m_allowExternalPages; } 126 void setAllowExternalPages(bool allowExternalPages) { m_allowExternalPages = allowExternalPages; } 127 128 void setAcceleratedCompositingEnabled(bool enabled) { m_acceleratedCompositingEnabled = enabled; } 129 void setForceCompositingMode(bool enabled) { m_forceCompositingMode = enabled; } 130 void setAccelerated2dCanvasEnabled(bool enabled) { m_accelerated2dCanvasEnabled = enabled; } 131 132 #if defined(OS_WIN) 133 // Access to the finished event. Used by the static WatchDog thread. 134 HANDLE finishedEvent() { return m_finishedEvent; } 135 #endif 136 137 // Get the timeout for running a test in milliseconds. 138 int layoutTestTimeout() { return m_timeout; } 139 int layoutTestTimeoutForWatchDog() { return layoutTestTimeout() + 1000; } 140 void setLayoutTestTimeout(int timeout) { m_timeout = timeout; } 141 142 // V8 JavaScript stress test options. 143 int stressOpt() { return m_stressOpt; } 144 void setStressOpt(bool stressOpt) { m_stressOpt = stressOpt; } 145 int stressDeopt() { return m_stressDeopt; } 146 void setStressDeopt(int stressDeopt) { m_stressDeopt = stressDeopt; } 147 148 // The JavaScript flags specified as a strings. 149 std::string javaScriptFlags() { return m_javaScriptFlags; } 150 void setJavaScriptFlags(std::string javaScriptFlags) { m_javaScriptFlags = javaScriptFlags; } 151 152 // Set whether to dump when the loaded page has finished processing. This is used with multiple load 153 // testing where we only want to have the output from the last load. 154 void setDumpWhenFinished(bool dumpWhenFinished) { m_dumpWhenFinished = dumpWhenFinished; } 155 156 WebViewHost* createNewWindow(const WebKit::WebURL&); 157 void closeWindow(WebViewHost*); 158 void closeRemainingWindows(); 159 int windowCount(); 160 static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&); 161 162 void showDevTools(); 163 void closeDevTools(); 164 165 DRTDevToolsAgent* drtDevToolsAgent() { return m_drtDevToolsAgent.get(); } 166 DRTDevToolsClient* drtDevToolsClient() { return m_drtDevToolsClient.get(); } 167 WebViewHost* devToolsWebView() { return m_devTools; } 168 169 static const int virtualWindowBorder = 3; 170 171 typedef Vector<WebViewHost*> WindowList; 172 WindowList windowList() const { return m_windowList; } 173 174 private: 175 WebViewHost* createNewWindow(const WebKit::WebURL&, DRTDevToolsAgent*); 176 void createMainWindow(); 177 void createDRTDevToolsClient(DRTDevToolsAgent*); 178 179 void resetWebSettings(WebKit::WebView&); 180 void dump(); 181 std::string dumpAllBackForwardLists(); 182 void dumpImage(SkCanvas*) const; 183 184 bool m_testIsPending; 185 bool m_testIsPreparing; 186 bool m_isLoading; 187 WebKit::WebView* m_webView; 188 WebKit::WebWidget* m_focusedWidget; 189 bool m_testShellMode; 190 WebViewHost* m_webViewHost; 191 WebViewHost* m_devTools; 192 OwnPtr<DRTDevToolsAgent> m_drtDevToolsAgent; 193 OwnPtr<DRTDevToolsClient> m_drtDevToolsClient; 194 OwnPtr<AccessibilityController> m_accessibilityController; 195 OwnPtr<EventSender> m_eventSender; 196 OwnPtr<LayoutTestController> m_layoutTestController; 197 OwnPtr<PlainTextController> m_plainTextController; 198 OwnPtr<TextInputController> m_textInputController; 199 OwnPtr<NotificationPresenter> m_notificationPresenter; 200 OwnPtr<TestEventPrinter> m_printer; 201 TestParams m_params; 202 int m_timeout; // timeout value in millisecond 203 bool m_allowExternalPages; 204 bool m_acceleratedCompositingEnabled; 205 bool m_forceCompositingMode; 206 bool m_accelerated2dCanvasEnabled; 207 WebPreferences m_prefs; 208 bool m_stressOpt; 209 bool m_stressDeopt; 210 std::string m_javaScriptFlags; 211 bool m_dumpWhenFinished; 212 213 214 // List of all windows in this process. 215 // The main window should be put into windowList[0]. 216 WindowList m_windowList; 217 218 #if defined(OS_WIN) 219 // Used by the watchdog to know when it's finished. 220 HANDLE m_finishedEvent; 221 #endif 222 }; 223 224 void platformInit(int*, char***); 225 void openStartupDialog(); 226 bool checkLayoutTestSystemDependencies(); 227 228 #endif // TestShell_h 229