| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ | |
| 6 #define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ | |
| 7 | |
| 8 | |
| 9 #include <list> | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/files/file_path.h" | |
| 16 #include "base/files/scoped_temp_dir.h" | |
| 17 #include "base/lazy_instance.h" | |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "base/memory/weak_ptr.h" | |
| 20 #include "base/strings/string_piece.h" | |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h
" | |
| 22 #include "ui/gfx/native_widget_types.h" | |
| 23 #include "webkit/tools/test_shell/webview_host.h" | |
| 24 #include "webkit/tools/test_shell/webwidget_host.h" | |
| 25 | |
| 26 typedef std::list<gfx::NativeWindow> WindowList; | |
| 27 | |
| 28 #if defined(OS_WIN) | |
| 29 namespace ui { | |
| 30 class ScopedOleInitializer; | |
| 31 } | |
| 32 #endif | |
| 33 | |
| 34 class GURL; | |
| 35 class TestNavigationEntry; | |
| 36 class TestNavigationController; | |
| 37 class TestNotificationPresenter; | |
| 38 class TestShellDevToolsAgent; | |
| 39 class TestShellDevToolsClient; | |
| 40 class TestWebViewDelegate; | |
| 41 struct WebPreferences; | |
| 42 | |
| 43 namespace WebKit { | |
| 44 class WebDeviceOrientationClientMock; | |
| 45 class WebGeolocationClientMock; | |
| 46 } | |
| 47 | |
| 48 class TestShell : public base::SupportsWeakPtr<TestShell> { | |
| 49 public: | |
| 50 struct TestParams { | |
| 51 // Load the test defaults. | |
| 52 TestParams(); | |
| 53 | |
| 54 // The kind of output we want from this test. | |
| 55 bool dump_tree; | |
| 56 bool dump_pixels; | |
| 57 | |
| 58 // Filename we dump pixels to (when pixel testing is enabled). | |
| 59 base::FilePath pixel_file_name; | |
| 60 // The md5 hash of the bitmap dump (when pixel testing is enabled). | |
| 61 std::string pixel_hash; | |
| 62 // URL of the test. | |
| 63 std::string test_url; | |
| 64 }; | |
| 65 | |
| 66 TestShell(); | |
| 67 virtual ~TestShell(); | |
| 68 | |
| 69 // Initialization and clean up of logging. | |
| 70 static void InitLogging(bool suppress_error_dialogs, | |
| 71 bool running_layout_tests, | |
| 72 bool enable_gp_fault_error_box); | |
| 73 static void CleanupLogging(); | |
| 74 | |
| 75 // Initialization and clean up of a static member variable. | |
| 76 static void InitializeTestShell(bool layout_test_mode, | |
| 77 bool allow_external_pages); | |
| 78 static void ShutdownTestShell(); | |
| 79 | |
| 80 static bool layout_test_mode() { return layout_test_mode_; } | |
| 81 static bool allow_external_pages() { return allow_external_pages_; } | |
| 82 | |
| 83 // Called from the destructor to let each platform do any necessary | |
| 84 // cleanup. | |
| 85 void PlatformCleanUp(); | |
| 86 | |
| 87 WebKit::WebView* webView() { | |
| 88 return m_webViewHost.get() ? m_webViewHost->webview() : NULL; | |
| 89 } | |
| 90 WebViewHost* webViewHost() { return m_webViewHost.get(); } | |
| 91 WebKit::WebWidget* popup() { | |
| 92 return m_popupHost ? m_popupHost->webwidget() : NULL; | |
| 93 } | |
| 94 WebWidgetHost* popupHost() { return m_popupHost; } | |
| 95 | |
| 96 bool is_loading() const { return is_loading_; } | |
| 97 void set_is_loading(bool is_loading) { is_loading_ = is_loading; } | |
| 98 | |
| 99 bool allow_images() const { return allow_images_; } | |
| 100 void set_allow_images(bool allow) { allow_images_ = allow; } | |
| 101 | |
| 102 bool allow_plugins() const { return allow_plugins_; } | |
| 103 void set_allow_plugins(bool allow) { allow_plugins_ = allow; } | |
| 104 | |
| 105 bool allow_scripts() const { return allow_scripts_; } | |
| 106 void set_allow_scripts(bool allow) { allow_scripts_ = allow; } | |
| 107 | |
| 108 void UpdateNavigationControls(); | |
| 109 | |
| 110 // A new TestShell window will be opened with devtools url. | |
| 111 // DevTools window can be opened manually via menu or automatically when | |
| 112 // inspector's layout test url is passed from command line or console. | |
| 113 void ShowDevTools(); | |
| 114 void CloseDevTools(); | |
| 115 | |
| 116 void Show(WebKit::WebNavigationPolicy policy); | |
| 117 | |
| 118 // We use this to avoid relying on Windows focus during layout test mode. | |
| 119 void SetFocus(WebWidgetHost* host, bool enable); | |
| 120 | |
| 121 TestWebViewDelegate* delegate() { return delegate_.get(); } | |
| 122 TestWebViewDelegate* popup_delegate() { return popup_delegate_.get(); } | |
| 123 TestNavigationController* navigation_controller() { | |
| 124 return navigation_controller_.get(); | |
| 125 } | |
| 126 TestNotificationPresenter* notification_presenter() { | |
| 127 return notification_presenter_.get(); | |
| 128 } | |
| 129 | |
| 130 // Resets TestWebViewDelegate. Should be called before loading a page, | |
| 131 // since some end-editing event notifications may arrive after the previous | |
| 132 // page has finished dumping its text and therefore end up in the next | |
| 133 // test's results if the messages are still enabled. | |
| 134 void ResetTestController(); | |
| 135 | |
| 136 bool AcceptsEditing() { | |
| 137 return true; | |
| 138 } | |
| 139 | |
| 140 void LoadFile(const base::FilePath& file); | |
| 141 void LoadURL(const GURL& url); | |
| 142 void LoadURLForFrame(const GURL& url, const base::string16& frame_name); | |
| 143 void GoBackOrForward(int offset); | |
| 144 void Reload(); | |
| 145 bool Navigate(const TestNavigationEntry& entry, bool reload); | |
| 146 | |
| 147 bool PromptForSaveFile(const wchar_t* prompt_title, base::FilePath* result); | |
| 148 base::string16 GetDocumentText(); | |
| 149 void DumpDocumentText(); | |
| 150 void DumpRenderTree(); | |
| 151 | |
| 152 gfx::NativeWindow mainWnd() const { return m_mainWnd; } | |
| 153 gfx::NativeView webViewWnd() const { return m_webViewHost->view_handle(); } | |
| 154 gfx::NativeEditView editWnd() const { return m_editWnd; } | |
| 155 gfx::NativeView popupWnd() const { return m_popupHost->view_handle(); } | |
| 156 | |
| 157 static WindowList* windowList() { return window_list_; } | |
| 158 | |
| 159 // If shell is non-null, then *shell is assigned upon successful return | |
| 160 static bool CreateNewWindow(const GURL& starting_url, | |
| 161 TestShell** shell = NULL); | |
| 162 | |
| 163 static void DestroyWindow(gfx::NativeWindow windowHandle); | |
| 164 | |
| 165 // Remove the given window from window_list_, return true if it was in the | |
| 166 // list and was removed and false otherwise. | |
| 167 static bool RemoveWindowFromList(gfx::NativeWindow window); | |
| 168 | |
| 169 // Implements CreateWebView for TestWebViewDelegate, which in turn | |
| 170 // is called as a WebViewDelegate. | |
| 171 WebKit::WebView* CreateWebView(); | |
| 172 WebKit::WebWidget* CreatePopupWidget(); | |
| 173 void ClosePopup(); | |
| 174 | |
| 175 #if defined(OS_WIN) | |
| 176 static ATOM RegisterWindowClass(); | |
| 177 #endif | |
| 178 | |
| 179 // Writes the back-forward list data for every open window into result. | |
| 180 // Should call DumpBackForwardListOfWindow on each TestShell window. | |
| 181 static void DumpAllBackForwardLists(base::string16* result); | |
| 182 | |
| 183 // Writes the single back-forward entry into result. | |
| 184 void DumpBackForwardEntry(int index, base::string16* result); | |
| 185 | |
| 186 // Writes the back-forward list data for this test shell into result. | |
| 187 void DumpBackForwardList(base::string16* result); | |
| 188 | |
| 189 static void ResetWebPreferences(); | |
| 190 | |
| 191 static void SetAllowScriptsToCloseWindows(); | |
| 192 | |
| 193 static void SetAccelerated2dCanvasEnabled(bool enabled); | |
| 194 static void SetAcceleratedCompositingEnabled(bool enabled); | |
| 195 | |
| 196 static WebPreferences* GetWebPreferences(); | |
| 197 | |
| 198 // Some layout tests hardcode a file:///tmp/LayoutTests URL. We get around | |
| 199 // this by substituting "tmp" with the path to the LayoutTests parent dir. | |
| 200 static std::string RewriteLocalUrl(const std::string& url); | |
| 201 | |
| 202 // Set the JavaScript flags to use. This is a vector as when multiple loads | |
| 203 // are specified each load can have different flags passed. | |
| 204 static void SetJavaScriptFlags(std::vector<std::string> js_flags) { | |
| 205 js_flags_ = js_flags; | |
| 206 } | |
| 207 | |
| 208 // Get the JavaScript flags for a specific load | |
| 209 static std::string GetJSFlagsForLoad(size_t load) { | |
| 210 if (load >= js_flags_.size()) | |
| 211 return std::string(); | |
| 212 return js_flags_[load]; | |
| 213 } | |
| 214 | |
| 215 // Have the shell print the StatsTable to stdout on teardown. | |
| 216 void DumpStatsTableOnExit() { dump_stats_table_on_exit_ = true; } | |
| 217 | |
| 218 void CallJSGC(); | |
| 219 | |
| 220 void set_is_modal(bool value) { is_modal_ = value; } | |
| 221 bool is_modal() const { return is_modal_; } | |
| 222 | |
| 223 const TestParams* test_params() { return test_params_; } | |
| 224 void set_test_params(const TestParams* test_params) { | |
| 225 test_params_ = test_params; | |
| 226 } | |
| 227 | |
| 228 #if defined(OS_MACOSX) | |
| 229 // handle cleaning up a shell given the associated window | |
| 230 static void DestroyAssociatedShell(gfx::NativeWindow handle); | |
| 231 #endif | |
| 232 | |
| 233 // Show the "attach to me" dialog, for debugging test shell startup. | |
| 234 static void ShowStartupDebuggingDialog(); | |
| 235 | |
| 236 // This is called indirectly by the modules that need access resources. | |
| 237 static base::StringPiece ResourceProvider(int key); | |
| 238 | |
| 239 TestShellDevToolsAgent* dev_tools_agent() { | |
| 240 return dev_tools_agent_.get(); | |
| 241 } | |
| 242 | |
| 243 WebKit::WebDeviceOrientationClientMock* device_orientation_client_mock(); | |
| 244 | |
| 245 WebKit::WebGeolocationClientMock* geolocation_client_mock(); | |
| 246 | |
| 247 protected: | |
| 248 void CreateDevToolsClient(TestShellDevToolsAgent* agent); | |
| 249 bool Initialize(const GURL& starting_url); | |
| 250 bool IsSVGTestURL(const GURL& url); | |
| 251 void SizeToSVG(); | |
| 252 void SizeToDefault(); | |
| 253 void SizeTo(int width, int height); | |
| 254 void ResizeSubViews(); | |
| 255 | |
| 256 // Set the focus in interactive mode (pass through to relevant system call). | |
| 257 void InteractiveSetFocus(WebWidgetHost* host, bool enable); | |
| 258 | |
| 259 enum UIControl { | |
| 260 BACK_BUTTON, | |
| 261 FORWARD_BUTTON, | |
| 262 STOP_BUTTON | |
| 263 }; | |
| 264 | |
| 265 void EnableUIControl(UIControl control, bool is_enabled); | |
| 266 | |
| 267 #if defined(OS_WIN) | |
| 268 static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); | |
| 269 static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM); | |
| 270 #endif | |
| 271 | |
| 272 static void PlatformShutdown(); | |
| 273 | |
| 274 gfx::NativeWindow m_mainWnd; | |
| 275 gfx::NativeEditView m_editWnd; | |
| 276 scoped_ptr<WebViewHost> m_webViewHost; | |
| 277 WebWidgetHost* m_popupHost; | |
| 278 #if defined(OS_WIN) | |
| 279 WNDPROC default_edit_wnd_proc_; | |
| 280 #endif | |
| 281 | |
| 282 // Primitive focus controller for layout test mode. | |
| 283 WebWidgetHost* m_focusedWidgetHost; | |
| 284 | |
| 285 private: | |
| 286 // A set of all our windows. | |
| 287 static WindowList* window_list_; | |
| 288 #if defined(OS_MACOSX) | |
| 289 typedef std::map<gfx::NativeWindow, TestShell *> WindowMap; | |
| 290 static base::LazyInstance<WindowMap> window_map_; | |
| 291 #endif | |
| 292 | |
| 293 #if defined(OS_WIN) | |
| 294 static HINSTANCE instance_handle_; | |
| 295 | |
| 296 static ui::ScopedOleInitializer* ole_initializer_; | |
| 297 #endif | |
| 298 | |
| 299 // True when the app is being run using the --layout-tests switch. | |
| 300 static bool layout_test_mode_; | |
| 301 | |
| 302 // True when we wish to allow test shell to load external pages like | |
| 303 // www.google.com even when in --layout-test mode (used for QA to | |
| 304 // produce images of the rendered page) | |
| 305 static bool allow_external_pages_; | |
| 306 | |
| 307 scoped_ptr<TestNavigationController> navigation_controller_; | |
| 308 scoped_ptr<TestNotificationPresenter> notification_presenter_; | |
| 309 | |
| 310 scoped_ptr<TestWebViewDelegate> delegate_; | |
| 311 scoped_ptr<TestWebViewDelegate> popup_delegate_; | |
| 312 | |
| 313 base::WeakPtr<TestShell> devtools_shell_; | |
| 314 scoped_ptr<TestShellDevToolsAgent> dev_tools_agent_; | |
| 315 scoped_ptr<TestShellDevToolsClient> dev_tools_client_; | |
| 316 scoped_ptr<WebKit::WebDeviceOrientationClientMock> | |
| 317 device_orientation_client_mock_; | |
| 318 scoped_ptr<WebKit::WebGeolocationClientMock> geolocation_client_mock_; | |
| 319 | |
| 320 const TestParams* test_params_; | |
| 321 | |
| 322 // JavaScript flags. Each element in the vector contains a set of flags as | |
| 323 // a string (e.g. "--xxx --yyy"). Each flag set is used for separate loads | |
| 324 // of each URL. | |
| 325 static std::vector<std::string> js_flags_; | |
| 326 | |
| 327 // True if we're testing the accelerated canvas 2d path. | |
| 328 static bool accelerated_2d_canvas_enabled_; | |
| 329 | |
| 330 // True if we're testing the accelerated compositing. | |
| 331 static bool accelerated_compositing_enabled_; | |
| 332 | |
| 333 // True if driven from a nested message loop. | |
| 334 bool is_modal_; | |
| 335 | |
| 336 // True if the page is loading. | |
| 337 bool is_loading_; | |
| 338 | |
| 339 bool allow_images_; | |
| 340 bool allow_plugins_; | |
| 341 bool allow_scripts_; | |
| 342 | |
| 343 // The preferences for the test shell. | |
| 344 static WebPreferences* web_prefs_; | |
| 345 | |
| 346 // Dump the stats table counters on exit. | |
| 347 bool dump_stats_table_on_exit_; | |
| 348 }; | |
| 349 | |
| 350 #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ | |
| OLD | NEW |