[email protected] | 98cd1512 | 2012-01-05 16:27:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 900c3b2 | 2011-10-22 00:55:29 | [diff] [blame] | 5 | #include "base/bind.h" |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 6 | #include "base/cancelable_callback.h" |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 11 | #include "base/prefs/pref_service.h" |
[email protected] | 340f55d7c | 2013-06-10 20:49:11 | [diff] [blame] | 12 | #include "base/strings/stringprintf.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 13 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c711fe71 | 2011-07-25 12:43:30 | [diff] [blame] | 14 | #include "base/test/test_timeouts.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 15 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 16 | #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 17 | #include "chrome/browser/devtools/devtools_window.h" |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 21 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 22 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 23 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 24 | #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 25 | #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 26 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 27 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 28 | #include "chrome/browser/ui/browser_iterator.h" |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 29 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 30 | #include "chrome/common/chrome_paths.h" |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 31 | #include "chrome/common/chrome_switches.h" |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 32 | #include "chrome/common/pref_names.h" |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 33 | #include "chrome/common/url_constants.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 34 | #include "chrome/test/base/in_process_browser_test.h" |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 35 | #include "chrome/test/base/test_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 36 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 37 | #include "content/public/browser/child_process_data.h" |
[email protected] | b0b67cfe | 2012-01-18 21:59:57 | [diff] [blame] | 38 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 39 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 40 | #include "content/public/browser/devtools_client_host.h" |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 41 | #include "content/public/browser/devtools_http_handler.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 42 | #include "content/public/browser/devtools_manager.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 43 | #include "content/public/browser/notification_registrar.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 44 | #include "content/public/browser/notification_service.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 45 | #include "content/public/browser/render_view_host.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 46 | #include "content/public/browser/web_contents.h" |
[email protected] | 724214ae | 2011-12-29 23:58:00 | [diff] [blame] | 47 | #include "content/public/browser/worker_service.h" |
| 48 | #include "content/public/browser/worker_service_observer.h" |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 49 | #include "content/public/common/content_switches.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 50 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 51 | #include "extensions/browser/extension_system.h" |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 52 | #include "extensions/common/switches.h" |
[email protected] | 1946d9e | 2013-04-09 01:43:37 | [diff] [blame] | 53 | #include "net/socket/tcp_listen_socket.h" |
[email protected] | 89b3252 | 2013-05-07 20:04:21 | [diff] [blame] | 54 | #include "net/test/spawned_test_server/spawned_test_server.h" |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 55 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 56 | using content::BrowserThread; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 57 | using content::DevToolsManager; |
| 58 | using content::DevToolsAgentHost; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 59 | using content::NavigationController; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 60 | using content::RenderViewHost; |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 61 | using content::WebContents; |
[email protected] | 724214ae | 2011-12-29 23:58:00 | [diff] [blame] | 62 | using content::WorkerService; |
| 63 | using content::WorkerServiceObserver; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 64 | |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 65 | namespace { |
| 66 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 67 | const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 68 | const char kPauseWhenLoadingDevTools[] = |
| 69 | "files/devtools/pause_when_loading_devtools.html"; |
| 70 | const char kPauseWhenScriptIsRunning[] = |
| 71 | "files/devtools/pause_when_script_is_running.html"; |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 72 | const char kPageWithContentScript[] = |
| 73 | "files/devtools/page_with_content_script.html"; |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 74 | const char kNavigateBackTestPage[] = |
| 75 | "files/devtools/navigate_back.html"; |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 76 | const char kChunkedTestPage[] = "chunked"; |
| 77 | const char kSlowTestPage[] = |
| 78 | "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 79 | const char kSharedWorkerTestPage[] = |
| 80 | "files/workers/workers_ui_shared_worker.html"; |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 81 | const char kReloadSharedWorkerTestPage[] = |
| 82 | "files/workers/debug_shared_worker_initialization.html"; |
[email protected] | 81762dd | 2009-09-24 15:16:18 | [diff] [blame] | 83 | |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 84 | void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 85 | std::string result; |
| 86 | |
| 87 | // At first check that JavaScript part of the front-end is loaded by |
| 88 | // checking that global variable uiTests exists(it's created after all js |
| 89 | // files have been loaded) and has runTest method. |
| 90 | ASSERT_TRUE( |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 91 | content::ExecuteScriptAndExtractString( |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 92 | window->GetRenderViewHost(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 93 | "window.domAutomationController.send(" |
| 94 | " '' + (window.uiTests && (typeof uiTests.runTest)));", |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 95 | &result)); |
| 96 | |
[email protected] | b946b42 | 2014-03-18 22:53:40 | [diff] [blame^] | 97 | ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
| 98 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 99 | window->GetRenderViewHost(), |
| 100 | base::StringPrintf("uiTests.runTest('%s')", test_name), |
| 101 | &result)); |
| 102 | EXPECT_EQ("[OK]", result); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 103 | } |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 104 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 105 | } // namespace |
| 106 | |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 107 | class DevToolsSanityTest : public InProcessBrowserTest { |
| 108 | public: |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 109 | DevToolsSanityTest() |
| 110 | : window_(NULL), |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 111 | inspected_rvh_(NULL) {} |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 112 | |
[email protected] | ff7a8f6f | 2009-06-10 09:44:36 | [diff] [blame] | 113 | protected: |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 114 | void RunTest(const std::string& test_name, const std::string& test_page) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 115 | OpenDevToolsWindow(test_page, false); |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 116 | RunTestFunction(window_, test_name.c_str()); |
[email protected] | ff7a8f6f | 2009-06-10 09:44:36 | [diff] [blame] | 117 | CloseDevToolsWindow(); |
| 118 | } |
| 119 | |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 120 | void LoadTestPage(const std::string& test_page) { |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 121 | GURL url = test_server()->GetURL(test_page); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 122 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 125 | void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 126 | ASSERT_TRUE(test_server()->Start()); |
| 127 | LoadTestPage(test_page); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 128 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 129 | inspected_rvh_ = GetInspectedTab()->GetRenderViewHost(); |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 130 | window_ = |
| 131 | DevToolsWindow::OpenDevToolsWindowForTest(inspected_rvh_, is_docked); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 132 | ui_test_utils::WaitUntilDevToolsWindowLoaded(window_); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 135 | WebContents* GetInspectedTab() { |
[email protected] | 3695357 | 2013-01-14 18:38:10 | [diff] [blame] | 136 | return browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 139 | void ToggleDevToolsWindow() { |
| 140 | content::WindowedNotificationObserver close_observer( |
| 141 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 142 | content::Source<content::WebContents>(window_->web_contents())); |
| 143 | DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false, |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 144 | DevToolsToggleAction::Toggle()); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 145 | close_observer.Wait(); |
| 146 | } |
| 147 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 148 | void ToggleDevToolsWindowDontWait() { |
| 149 | DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false, |
| 150 | DevToolsToggleAction::Toggle()); |
| 151 | } |
| 152 | |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 153 | void CloseDevToolsWindow() { |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 154 | DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 155 | content::WindowedNotificationObserver close_observer( |
| 156 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 157 | content::Source<content::WebContents>(window_->web_contents())); |
[email protected] | 94305ee9 | 2013-04-01 14:19:58 | [diff] [blame] | 158 | devtools_manager->CloseAllClientHosts(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 159 | close_observer.Wait(); |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 162 | DevToolsWindow* window_; |
| 163 | RenderViewHost* inspected_rvh_; |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 164 | }; |
| 165 | |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 166 | // Used to block until a dev tools window gets beforeunload event. |
| 167 | class DevToolsWindowBeforeUnloadObserver |
| 168 | : public content::WebContentsObserver { |
| 169 | public: |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 170 | explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
| 171 | void Wait(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 172 | private: |
| 173 | // Invoked when the beforeunload handler fires. |
| 174 | virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; |
| 175 | |
| 176 | bool m_fired; |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 177 | scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 178 | DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); |
| 179 | }; |
| 180 | |
| 181 | DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 182 | DevToolsWindow* devtools_window) |
| 183 | : WebContentsObserver(devtools_window->web_contents()), |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 184 | m_fired(false) { |
| 185 | } |
| 186 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 187 | void DevToolsWindowBeforeUnloadObserver::Wait() { |
| 188 | if (m_fired) |
| 189 | return; |
| 190 | message_loop_runner_ = new content::MessageLoopRunner; |
| 191 | message_loop_runner_->Run(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
| 195 | const base::TimeTicks& proceed_time) { |
| 196 | m_fired = true; |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 197 | if (message_loop_runner_.get()) |
| 198 | message_loop_runner_->Quit(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 201 | class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
| 202 | public: |
[email protected] | f9631b9 | 2013-12-10 22:19:48 | [diff] [blame] | 203 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 204 | command_line->AppendSwitch( |
| 205 | switches::kDisableHangMonitor); |
| 206 | } |
| 207 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 208 | void CloseInspectedTab() { |
| 209 | browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 210 | TabStripModel::CLOSE_NONE); |
| 211 | } |
| 212 | |
| 213 | void CloseDockedDevTools() { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 214 | ToggleDevToolsWindowDontWait(); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void CloseUndockedDevTools() { |
| 218 | chrome::CloseWindow(window_->browser()); |
| 219 | } |
| 220 | |
| 221 | void CloseInspectedBrowser() { |
| 222 | chrome::CloseWindow(browser()); |
| 223 | } |
| 224 | protected: |
| 225 | void InjectBeforeUnloadListener(content::WebContents* web_contents) { |
| 226 | ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), |
| 227 | "window.addEventListener('beforeunload'," |
| 228 | "function(event) { event.returnValue = 'Foo'; });")); |
| 229 | } |
| 230 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 231 | void RunBeforeUnloadSanityTest(bool is_docked, |
| 232 | base::Callback<void(void)> close_method, |
| 233 | bool wait_for_browser_close = true) { |
| 234 | OpenDevToolsWindow(kDebuggerTestPage, is_docked); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 235 | content::WindowedNotificationObserver devtools_close_observer( |
| 236 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 237 | content::Source<content::WebContents>(window_->web_contents())); |
| 238 | InjectBeforeUnloadListener(window_->web_contents()); |
| 239 | { |
| 240 | DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); |
| 241 | close_method.Run(); |
| 242 | CancelModalDialog(); |
| 243 | before_unload_observer.Wait(); |
| 244 | } |
| 245 | { |
| 246 | content::WindowedNotificationObserver close_observer( |
| 247 | chrome::NOTIFICATION_BROWSER_CLOSED, |
| 248 | content::Source<Browser>(browser())); |
| 249 | close_method.Run(); |
| 250 | AcceptModalDialog(); |
| 251 | if (wait_for_browser_close) |
| 252 | close_observer.Wait(); |
| 253 | } |
| 254 | devtools_close_observer.Wait(); |
| 255 | } |
| 256 | |
| 257 | DevToolsWindow* OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 258 | content::WebContents* contents, bool is_docked) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 259 | DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest( |
| 260 | contents->GetRenderViewHost(), is_docked); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 261 | ui_test_utils::WaitUntilDevToolsWindowLoaded(window); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 262 | return window; |
| 263 | } |
| 264 | |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 265 | void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 266 | content::WindowedNotificationObserver observer( |
| 267 | content::NOTIFICATION_LOAD_STOP, |
| 268 | content::NotificationService::AllSources()); |
| 269 | ASSERT_TRUE(content::ExecuteScript( |
| 270 | devtools_window->web_contents()->GetRenderViewHost(), |
| 271 | "window.open(\"\", \"\", \"location=0\");")); |
| 272 | observer.Wait(); |
| 273 | } |
| 274 | |
| 275 | void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 276 | Browser* popup_browser = NULL; |
| 277 | for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 278 | if (it->is_devtools()) { |
| 279 | content::WebContents* contents = |
| 280 | it->tab_strip_model()->GetWebContentsAt(0); |
| 281 | if (devtools_window->web_contents() != contents) { |
| 282 | popup_browser = *it; |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | ASSERT_FALSE(popup_browser == NULL); |
| 288 | content::WindowedNotificationObserver close_observer( |
| 289 | chrome::NOTIFICATION_BROWSER_CLOSED, |
| 290 | content::Source<Browser>(popup_browser)); |
| 291 | chrome::CloseWindow(popup_browser); |
| 292 | close_observer.Wait(); |
| 293 | } |
| 294 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 295 | void AcceptModalDialog() { |
| 296 | NativeAppModalDialog* native_dialog = GetDialog(); |
| 297 | native_dialog->AcceptAppModalDialog(); |
| 298 | } |
| 299 | |
| 300 | void CancelModalDialog() { |
| 301 | NativeAppModalDialog* native_dialog = GetDialog(); |
| 302 | native_dialog->CancelAppModalDialog(); |
| 303 | } |
| 304 | |
| 305 | NativeAppModalDialog* GetDialog() { |
| 306 | AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 307 | EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 308 | JavaScriptAppModalDialog* js_dialog = |
| 309 | static_cast<JavaScriptAppModalDialog*>(dialog); |
| 310 | NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); |
| 311 | EXPECT_TRUE(native_dialog); |
| 312 | return native_dialog; |
| 313 | } |
| 314 | }; |
| 315 | |
[email protected] | f9631b9 | 2013-12-10 22:19:48 | [diff] [blame] | 316 | class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { |
| 317 | public: |
| 318 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {} |
| 319 | }; |
| 320 | |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 321 | void TimeoutCallback(const std::string& timeout_message) { |
[email protected] | b946b42 | 2014-03-18 22:53:40 | [diff] [blame^] | 322 | ADD_FAILURE() << timeout_message; |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 323 | base::MessageLoop::current()->Quit(); |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 324 | } |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 325 | |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 326 | // Base class for DevTools tests that test devtools functionality for |
| 327 | // extensions and content scripts. |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 328 | class DevToolsExtensionTest : public DevToolsSanityTest, |
| 329 | public content::NotificationObserver { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 330 | public: |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 331 | DevToolsExtensionTest() : DevToolsSanityTest() { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 332 | PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); |
| 333 | test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); |
| 334 | test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); |
| 335 | } |
| 336 | |
| 337 | protected: |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 338 | // Load an extension from test\data\devtools\extensions\<extension_name> |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 339 | void LoadExtension(const char* extension_name) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 340 | base::FilePath path = test_extensions_dir_.AppendASCII(extension_name); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 341 | ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; |
| 342 | } |
| 343 | |
| 344 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 345 | bool LoadExtensionFromPath(const base::FilePath& path) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 346 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 347 | browser()->profile())->extension_service(); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 348 | size_t num_before = service->extensions()->size(); |
| 349 | { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 350 | content::NotificationRegistrar registrar; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 351 | registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 352 | content::NotificationService::AllSources()); |
[email protected] | d4d57df | 2011-11-30 20:33:52 | [diff] [blame] | 353 | base::CancelableClosure timeout( |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 354 | base::Bind(&TimeoutCallback, "Extension load timed out.")); |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 355 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 4173deb | 2013-06-07 15:21:04 | [diff] [blame] | 356 | FROM_HERE, timeout.callback(), TestTimeouts::action_timeout()); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 357 | extensions::UnpackedInstaller::Create(service)->Load(path); |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 358 | content::RunMessageLoop(); |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 359 | timeout.Cancel(); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 360 | } |
| 361 | size_t num_after = service->extensions()->size(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 362 | if (num_after != (num_before + 1)) |
| 363 | return false; |
| 364 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 365 | return WaitForExtensionViewsToLoad(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 368 | bool WaitForExtensionViewsToLoad() { |
| 369 | // Wait for all the extension render views that exist to finish loading. |
| 370 | // NOTE: This assumes that the extension views list is not changing while |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 371 | // this method is running. |
| 372 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 373 | content::NotificationRegistrar registrar; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 374 | registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 375 | content::NotificationService::AllSources()); |
[email protected] | d4d57df | 2011-11-30 20:33:52 | [diff] [blame] | 376 | base::CancelableClosure timeout( |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 377 | base::Bind(&TimeoutCallback, "Extension host load timed out.")); |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 378 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 4173deb | 2013-06-07 15:21:04 | [diff] [blame] | 379 | FROM_HERE, timeout.callback(), TestTimeouts::action_timeout()); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 380 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 381 | extensions::ProcessManager* manager = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 382 | extensions::ExtensionSystem::Get(browser()->profile())-> |
| 383 | process_manager(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 384 | extensions::ProcessManager::ViewSet all_views = manager->GetAllViews(); |
| 385 | for (extensions::ProcessManager::ViewSet::const_iterator iter = |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 386 | all_views.begin(); |
| 387 | iter != all_views.end();) { |
| 388 | if (!(*iter)->IsLoading()) |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 389 | ++iter; |
| 390 | else |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 391 | content::RunMessageLoop(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 394 | timeout.Cancel(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 395 | return true; |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 398 | virtual void Observe(int type, |
| 399 | const content::NotificationSource& source, |
| 400 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 401 | switch (type) { |
| 402 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 403 | case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 404 | base::MessageLoopForUI::current()->Quit(); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 405 | break; |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 406 | default: |
| 407 | NOTREACHED(); |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 412 | base::FilePath test_extensions_dir_; |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 413 | }; |
| 414 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 415 | class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { |
| 416 | public: |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 417 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 418 | command_line->AppendSwitch( |
| 419 | extensions::switches::kEnableExperimentalExtensionApis); |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 420 | } |
| 421 | }; |
| 422 | |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 423 | class WorkerDevToolsSanityTest : public InProcessBrowserTest { |
| 424 | public: |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 425 | WorkerDevToolsSanityTest() : window_(NULL) {} |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 426 | |
| 427 | protected: |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 428 | class WorkerData : public base::RefCountedThreadSafe<WorkerData> { |
| 429 | public: |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 430 | WorkerData() : worker_process_id(0), worker_route_id(0) {} |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 431 | int worker_process_id; |
| 432 | int worker_route_id; |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 433 | |
| 434 | private: |
| 435 | friend class base::RefCountedThreadSafe<WorkerData>; |
| 436 | ~WorkerData() {} |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | class WorkerCreationObserver : public WorkerServiceObserver { |
| 440 | public: |
| 441 | explicit WorkerCreationObserver(WorkerData* worker_data) |
| 442 | : worker_data_(worker_data) { |
| 443 | } |
| 444 | |
| 445 | private: |
| 446 | virtual ~WorkerCreationObserver() {} |
| 447 | |
| 448 | virtual void WorkerCreated ( |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 449 | const GURL& url, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 450 | const base::string16& name, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 451 | int process_id, |
| 452 | int route_id) OVERRIDE { |
| 453 | worker_data_->worker_process_id = process_id; |
| 454 | worker_data_->worker_route_id = route_id; |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 455 | WorkerService::GetInstance()->RemoveObserver(this); |
| 456 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 457 | base::MessageLoop::QuitClosure()); |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 458 | delete this; |
| 459 | } |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 460 | scoped_refptr<WorkerData> worker_data_; |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 461 | }; |
| 462 | |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 463 | class WorkerTerminationObserver : public WorkerServiceObserver { |
| 464 | public: |
| 465 | explicit WorkerTerminationObserver(WorkerData* worker_data) |
| 466 | : worker_data_(worker_data) { |
| 467 | } |
| 468 | |
| 469 | private: |
| 470 | virtual ~WorkerTerminationObserver() {} |
| 471 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 472 | virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE { |
| 473 | ASSERT_EQ(worker_data_->worker_process_id, process_id); |
| 474 | ASSERT_EQ(worker_data_->worker_route_id, route_id); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 475 | WorkerService::GetInstance()->RemoveObserver(this); |
| 476 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 477 | base::MessageLoop::QuitClosure()); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 478 | delete this; |
| 479 | } |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 480 | scoped_refptr<WorkerData> worker_data_; |
| 481 | }; |
| 482 | |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 483 | void RunTest(const char* test_name, const char* test_page) { |
| 484 | ASSERT_TRUE(test_server()->Start()); |
| 485 | GURL url = test_server()->GetURL(test_page); |
| 486 | ui_test_utils::NavigateToURL(browser(), url); |
| 487 | |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 488 | scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); |
| 489 | OpenDevToolsWindowForSharedWorker(worker_data.get()); |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 490 | RunTestFunction(window_, test_name); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 491 | CloseDevToolsWindow(); |
| 492 | } |
| 493 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 494 | static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) { |
[email protected] | b946b42 | 2014-03-18 22:53:40 | [diff] [blame^] | 495 | if (!WorkerService::GetInstance()->TerminateWorker( |
| 496 | worker_data->worker_process_id, worker_data->worker_route_id)) |
| 497 | FAIL() << "Failed to terminate worker.\n"; |
| 498 | WorkerService::GetInstance()->AddObserver( |
| 499 | new WorkerTerminationObserver(worker_data.get())); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static void TerminateWorker(scoped_refptr<WorkerData> worker_data) { |
[email protected] | 900c3b2 | 2011-10-22 00:55:29 | [diff] [blame] | 503 | BrowserThread::PostTask( |
| 504 | BrowserThread::IO, FROM_HERE, |
| 505 | base::Bind(&TerminateWorkerOnIOThread, worker_data)); |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 506 | content::RunMessageLoop(); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 509 | static void WaitForFirstSharedWorkerOnIOThread( |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 510 | scoped_refptr<WorkerData> worker_data) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 511 | std::vector<WorkerService::WorkerInfo> worker_info = |
| 512 | WorkerService::GetInstance()->GetWorkers(); |
| 513 | if (!worker_info.empty()) { |
| 514 | worker_data->worker_process_id = worker_info[0].process_id; |
| 515 | worker_data->worker_route_id = worker_info[0].route_id; |
| 516 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 517 | base::MessageLoop::QuitClosure()); |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 518 | return; |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 519 | } |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 520 | |
| 521 | WorkerService::GetInstance()->AddObserver( |
| 522 | new WorkerCreationObserver(worker_data.get())); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 525 | static scoped_refptr<WorkerData> WaitForFirstSharedWorker() { |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 526 | scoped_refptr<WorkerData> worker_data(new WorkerData()); |
[email protected] | 900c3b2 | 2011-10-22 00:55:29 | [diff] [blame] | 527 | BrowserThread::PostTask( |
| 528 | BrowserThread::IO, FROM_HERE, |
| 529 | base::Bind(&WaitForFirstSharedWorkerOnIOThread, worker_data)); |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 530 | content::RunMessageLoop(); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 531 | return worker_data; |
| 532 | } |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 533 | |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 534 | void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) { |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 535 | Profile* profile = browser()->profile(); |
[email protected] | 70fd1e8 | 2012-12-26 15:08:10 | [diff] [blame] | 536 | scoped_refptr<DevToolsAgentHost> agent_host( |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 537 | DevToolsAgentHost::GetForWorker( |
[email protected] | b3762af | 2011-09-08 06:23:46 | [diff] [blame] | 538 | worker_data->worker_process_id, |
[email protected] | 70fd1e8 | 2012-12-26 15:08:10 | [diff] [blame] | 539 | worker_data->worker_route_id)); |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 540 | window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 541 | RenderViewHost* client_rvh = window_->GetRenderViewHost(); |
[email protected] | 7320a44e | 2012-05-22 17:01:11 | [diff] [blame] | 542 | WebContents* client_contents = WebContents::FromRenderViewHost(client_rvh); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 543 | content::WaitForLoadStop(client_contents); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | void CloseDevToolsWindow() { |
| 547 | Browser* browser = window_->browser(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 548 | content::WindowedNotificationObserver close_observer( |
| 549 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 550 | content::Source<content::WebContents>(window_->web_contents())); |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 551 | browser->tab_strip_model()->CloseAllTabs(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 552 | close_observer.Wait(); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | DevToolsWindow* window_; |
| 556 | }; |
| 557 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 558 | // Tests that BeforeUnload event gets called on docked devtools if |
| 559 | // we try to close them. |
| 560 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 561 | RunBeforeUnloadSanityTest(true, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 562 | &DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false); |
| 563 | } |
| 564 | |
| 565 | // Tests that BeforeUnload event gets called on docked devtools if |
| 566 | // we try to close the inspected page. |
| 567 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 568 | TestDockedDevToolsInspectedTabClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 569 | RunBeforeUnloadSanityTest(true, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 570 | &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); |
| 571 | } |
| 572 | |
| 573 | // Tests that BeforeUnload event gets called on docked devtools if |
| 574 | // we try to close the inspected browser. |
| 575 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 576 | TestDockedDevToolsInspectedBrowserClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 577 | RunBeforeUnloadSanityTest(true, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 578 | &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this)); |
| 579 | } |
| 580 | |
| 581 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 582 | // we try to close them. |
| 583 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 584 | RunBeforeUnloadSanityTest(false, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 585 | &DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false); |
| 586 | } |
| 587 | |
| 588 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 589 | // we try to close the inspected page. |
| 590 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 591 | TestUndockedDevToolsInspectedTabClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 592 | RunBeforeUnloadSanityTest(false, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 593 | &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); |
| 594 | } |
| 595 | |
| 596 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 597 | // we try to close the inspected browser. |
| 598 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 599 | TestUndockedDevToolsInspectedBrowserClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 600 | RunBeforeUnloadSanityTest(false, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 601 | &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this)); |
| 602 | } |
| 603 | |
| 604 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 605 | // we try to exit application. |
| 606 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 607 | TestUndockedDevToolsApplicationClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 608 | RunBeforeUnloadSanityTest(false, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 609 | &chrome::CloseAllBrowsers)); |
| 610 | } |
| 611 | |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 612 | // Tests that inspected tab gets closed if devtools renderer |
| 613 | // becomes unresponsive during beforeunload event interception. |
| 614 | // @see http://crbug.com/322380 |
[email protected] | f9631b9 | 2013-12-10 22:19:48 | [diff] [blame] | 615 | IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest, |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 616 | TestUndockedDevToolsUnresponsive) { |
| 617 | ASSERT_TRUE(test_server()->Start()); |
| 618 | LoadTestPage(kDebuggerTestPage); |
| 619 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 620 | GetInspectedTab(), false); |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 621 | content::WindowedNotificationObserver devtools_close_observer( |
| 622 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 623 | content::Source<content::WebContents>( |
| 624 | devtools_window->web_contents())); |
| 625 | |
| 626 | ASSERT_TRUE(content::ExecuteScript( |
| 627 | devtools_window->web_contents()->GetRenderViewHost(), |
| 628 | "window.addEventListener('beforeunload'," |
| 629 | "function(event) { while (true); });")); |
| 630 | CloseInspectedTab(); |
| 631 | devtools_close_observer.Wait(); |
| 632 | } |
| 633 | |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 634 | // Tests that closing worker inspector window does not cause browser crash |
| 635 | // @see http://crbug.com/323031 |
| 636 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 637 | TestWorkerWindowClosing) { |
| 638 | ASSERT_TRUE(test_server()->Start()); |
| 639 | LoadTestPage(kDebuggerTestPage); |
| 640 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 641 | GetInspectedTab(), false); |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 642 | content::WindowedNotificationObserver devtools_close_observer( |
| 643 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 644 | content::Source<content::WebContents>( |
| 645 | devtools_window->web_contents())); |
| 646 | |
| 647 | OpenDevToolsPopupWindow(devtools_window); |
| 648 | CloseDevToolsPopupWindow(devtools_window); |
| 649 | } |
| 650 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 651 | // Tests that BeforeUnload event gets called on devtools that are opened |
| 652 | // on another devtools. |
[email protected] | 68b36ac | 2013-11-19 23:56:03 | [diff] [blame] | 653 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
[email protected] | 21f0b4c4 | 2014-01-21 12:59:26 | [diff] [blame] | 654 | TestDevToolsOnDevTools) { |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 655 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 656 | LoadTestPage(kDebuggerTestPage); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 657 | |
| 658 | std::vector<DevToolsWindow*> windows; |
| 659 | std::vector<content::WindowedNotificationObserver*> close_observers; |
| 660 | content::WebContents* inspected_web_contents = GetInspectedTab(); |
| 661 | for (int i = 0; i < 3; ++i) { |
| 662 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 663 | inspected_web_contents, i == 0); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 664 | windows.push_back(devtools_window); |
| 665 | content::WindowedNotificationObserver* close_observer = |
| 666 | new content::WindowedNotificationObserver( |
| 667 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 668 | content::Source<content::WebContents>( |
| 669 | devtools_window->web_contents())); |
| 670 | close_observers.push_back(close_observer); |
| 671 | inspected_web_contents = devtools_window->web_contents(); |
| 672 | } |
| 673 | |
| 674 | InjectBeforeUnloadListener(windows[0]->web_contents()); |
| 675 | InjectBeforeUnloadListener(windows[2]->web_contents()); |
| 676 | // Try to close second devtools. |
| 677 | { |
| 678 | content::WindowedNotificationObserver cancel_browser( |
| 679 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 680 | content::NotificationService::AllSources()); |
| 681 | chrome::CloseWindow(windows[1]->browser()); |
| 682 | CancelModalDialog(); |
| 683 | cancel_browser.Wait(); |
| 684 | } |
| 685 | // Try to close browser window. |
| 686 | { |
| 687 | content::WindowedNotificationObserver cancel_browser( |
| 688 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 689 | content::NotificationService::AllSources()); |
| 690 | chrome::CloseWindow(browser()); |
| 691 | AcceptModalDialog(); |
| 692 | CancelModalDialog(); |
| 693 | cancel_browser.Wait(); |
| 694 | } |
| 695 | // Try to exit application. |
| 696 | { |
| 697 | content::WindowedNotificationObserver close_observer( |
| 698 | chrome::NOTIFICATION_BROWSER_CLOSED, |
| 699 | content::Source<Browser>(browser())); |
[email protected] | 9a718b2 | 2014-02-25 15:17:27 | [diff] [blame] | 700 | chrome::IncrementKeepAliveCount(); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 701 | chrome::CloseAllBrowsers(); |
| 702 | AcceptModalDialog(); |
| 703 | AcceptModalDialog(); |
| 704 | close_observer.Wait(); |
| 705 | } |
| 706 | for (size_t i = 0; i < close_observers.size(); ++i) { |
| 707 | close_observers[i]->Wait(); |
| 708 | delete close_observers[i]; |
| 709 | } |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 710 | } |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 711 | |
[email protected] | 3f5866e | 2009-07-01 07:25:16 | [diff] [blame] | 712 | // Tests scripts panel showing. |
[email protected] | 92094f31 | 2013-11-12 18:09:26 | [diff] [blame] | 713 | // TODO(pfeldman): figure out flake. |
| 714 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_TestShowScriptsTab) { |
[email protected] | 3f5866e | 2009-07-01 07:25:16 | [diff] [blame] | 715 | RunTest("testShowScriptsTab", kDebuggerTestPage); |
[email protected] | a2f2023 | 2009-06-30 15:06:57 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 718 | // Tests that scripts tab is populated with inspected scripts even if it |
| 719 | // hadn't been shown by the moment inspected paged refreshed. |
| 720 | // @see http://crbug.com/26312 |
[email protected] | a9b82d3 | 2012-01-25 19:55:38 | [diff] [blame] | 721 | IN_PROC_BROWSER_TEST_F( |
| 722 | DevToolsSanityTest, |
[email protected] | 53cd43d | 2013-11-02 17:15:07 | [diff] [blame] | 723 | TestScriptsTabIsPopulatedOnInspectedPageRefresh) { |
[email protected] | 45aafc9 | 2010-06-07 14:18:53 | [diff] [blame] | 724 | // Clear inspector settings to ensure that Elements will be |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 725 | // current panel when DevTools window is open. |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 726 | content::BrowserContext* browser_context = |
| 727 | GetInspectedTab()->GetBrowserContext(); |
| 728 | Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 729 | ClearPref(prefs::kWebKitInspectorSettings); |
| 730 | |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 731 | RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh", |
| 732 | kDebuggerTestPage); |
| 733 | } |
| 734 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 735 | // Tests that chrome.devtools extension is correctly exposed. |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 736 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 737 | TestDevToolsExtensionAPI) { |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 738 | LoadExtension("devtools_extension"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 739 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 740 | } |
| 741 | |
[email protected] | 43466b9 | 2013-12-27 22:00:11 | [diff] [blame] | 742 | // Disabled on Windows due to flakiness. http://crbug.com/183649 |
| 743 | #if defined(OS_WIN) |
[email protected] | 4319aa30 | 2013-06-12 19:59:45 | [diff] [blame] | 744 | #define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessaging |
| 745 | #else |
| 746 | #define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging |
| 747 | #endif |
| 748 | |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 749 | // Tests that chrome.devtools extension can communicate with background page |
| 750 | // using extension messaging. |
| 751 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
[email protected] | 4319aa30 | 2013-06-12 19:59:45 | [diff] [blame] | 752 | MAYBE_TestDevToolsExtensionMessaging) { |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 753 | LoadExtension("devtools_messaging"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 754 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 757 | // Tests that chrome.experimental.devtools extension is correctly exposed |
| 758 | // when the extension has experimental permission. |
| 759 | IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest, |
| 760 | TestDevToolsExperimentalExtensionAPI) { |
| 761 | LoadExtension("devtools_experimental"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 762 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | 92094f31 | 2013-11-12 18:09:26 | [diff] [blame] | 765 | // Tests that a content script is in the scripts list. |
| 766 | // History of flakiness: http://crbug.com/114104, http://crbug.com/315288. |
| 767 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 768 | DISABLED_TestContentScriptIsPresent) { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 769 | LoadExtension("simple_content_script"); |
| 770 | RunTest("testContentScriptIsPresent", kPageWithContentScript); |
| 771 | } |
| 772 | |
[email protected] | 77b9ab8 | 2013-11-11 16:11:34 | [diff] [blame] | 773 | // Fails quite consistently on Win XP: crbug.com/317725. |
[email protected] | 3af1042 | 2013-12-27 06:22:39 | [diff] [blame] | 774 | #if defined(OS_WIN) || defined(OS_MACOSX) |
[email protected] | 77b9ab8 | 2013-11-11 16:11:34 | [diff] [blame] | 775 | #define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \ |
| 776 | DISABLED_TestNoScriptDuplicatesOnPanelSwitch |
| 777 | #else |
| 778 | #define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \ |
| 779 | TestNoScriptDuplicatesOnPanelSwitch |
| 780 | #endif |
| 781 | |
[email protected] | f099ba3 | 2009-09-18 13:43:17 | [diff] [blame] | 782 | // Tests that scripts are not duplicated after Scripts Panel switch. |
| 783 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
[email protected] | 77b9ab8 | 2013-11-11 16:11:34 | [diff] [blame] | 784 | MAYBE_TestNoScriptDuplicatesOnPanelSwitch) { |
[email protected] | f099ba3 | 2009-09-18 13:43:17 | [diff] [blame] | 785 | RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); |
| 786 | } |
| 787 | |
[email protected] | 53976e8 | 2009-11-11 17:08:31 | [diff] [blame] | 788 | // Tests that debugger works correctly if pause event occurs when DevTools |
| 789 | // frontend is being loaded. |
[email protected] | 4c9fd7c50 | 2013-12-18 10:18:02 | [diff] [blame] | 790 | // Disabled because of flakiness on all platforms: crbug.com/329036 |
[email protected] | e043c2a | 2011-12-02 00:08:17 | [diff] [blame] | 791 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
[email protected] | 4c9fd7c50 | 2013-12-18 10:18:02 | [diff] [blame] | 792 | DISABLED_TestPauseWhenLoadingDevTools) { |
[email protected] | 53976e8 | 2009-11-11 17:08:31 | [diff] [blame] | 793 | RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools); |
| 794 | } |
| 795 | |
[email protected] | 28ce8eb | 2009-11-30 09:20:45 | [diff] [blame] | 796 | // Tests that pressing 'Pause' will pause script execution if the script |
| 797 | // is already running. |
[email protected] | b1179ef | 2013-04-08 12:33:48 | [diff] [blame] | 798 | #if defined(OS_WIN) |
| 799 | // Timing out on windows tryservers: http://crbug.com/219515 |
| 800 | #define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning |
[email protected] | 5808fe1 | 2013-05-10 02:42:45 | [diff] [blame] | 801 | #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
| 802 | // Timing out on linux ARM bot: https://crbug/238453 |
| 803 | #define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning |
[email protected] | b1179ef | 2013-04-08 12:33:48 | [diff] [blame] | 804 | #else |
| 805 | #define MAYBE_TestPauseWhenScriptIsRunning TestPauseWhenScriptIsRunning |
| 806 | #endif |
[email protected] | 8128438 | 2013-10-21 23:08:54 | [diff] [blame] | 807 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
[email protected] | 53cd43d | 2013-11-02 17:15:07 | [diff] [blame] | 808 | MAYBE_TestPauseWhenScriptIsRunning) { |
[email protected] | 6303b28 | 2012-02-14 00:55:37 | [diff] [blame] | 809 | RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning); |
[email protected] | 28ce8eb | 2009-11-30 09:20:45 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 812 | // Tests network timing. |
[email protected] | 5c80747a1 | 2011-08-26 01:35:57 | [diff] [blame] | 813 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 814 | RunTest("testNetworkTiming", kSlowTestPage); |
| 815 | } |
| 816 | |
| 817 | // Tests network size. |
[email protected] | 689a480 | 2012-10-12 15:12:22 | [diff] [blame] | 818 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 819 | RunTest("testNetworkSize", kChunkedTestPage); |
| 820 | } |
| 821 | |
| 822 | // Tests raw headers text. |
[email protected] | 689a480 | 2012-10-12 15:12:22 | [diff] [blame] | 823 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 824 | RunTest("testNetworkSyncSize", kChunkedTestPage); |
| 825 | } |
| 826 | |
| 827 | // Tests raw headers text. |
[email protected] | 689a480 | 2012-10-12 15:12:22 | [diff] [blame] | 828 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 829 | RunTest("testNetworkRawHeadersText", kChunkedTestPage); |
| 830 | } |
| 831 | |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 832 | // Tests that console messages are not duplicated on navigation back. |
[email protected] | 3045cb84 | 2013-12-04 14:09:55 | [diff] [blame] | 833 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleOnNavigateBack) { |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 834 | RunTest("testConsoleOnNavigateBack", kNavigateBackTestPage); |
| 835 | } |
| 836 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 837 | |
| 838 | // Tests that external navigation from inspector page is always handled by |
| 839 | // DevToolsWindow and results in inspected page navigation. |
| 840 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 841 | OpenDevToolsWindow(kDebuggerTestPage, true); |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 842 | GURL url = test_server()->GetURL(kNavigateBackTestPage); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 843 | // TODO(dgozman): remove this once notifications are gone. |
| 844 | // Right now notifications happen after observers, so DevTools window is |
| 845 | // already loaded, but we still catch it's notification when looking for |
| 846 | // all sources. |
| 847 | content::WaitForLoadStop(window_->web_contents()); |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 848 | content::WindowedNotificationObserver observer( |
| 849 | content::NOTIFICATION_LOAD_STOP, |
| 850 | content::NotificationService::AllSources()); |
| 851 | ASSERT_TRUE(content::ExecuteScript( |
| 852 | window_->web_contents(), |
| 853 | std::string("window.location = \"") + url.spec() + "\"")); |
| 854 | observer.Wait(); |
| 855 | |
| 856 | ASSERT_TRUE(window_->web_contents()->GetURL(). |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 857 | SchemeIs(content::kChromeDevToolsScheme)); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 858 | ASSERT_EQ(url, GetInspectedTab()->GetURL()); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 859 | CloseDevToolsWindow(); |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 860 | } |
| 861 | |
[email protected] | c5eb493a | 2013-12-28 00:14:41 | [diff] [blame] | 862 | #if defined(OS_WIN) || defined(OS_MACOSX) |
[email protected] | f25da5e2 | 2013-07-01 11:21:13 | [diff] [blame] | 863 | // Flakily times out: http://crbug.com/163411 |
| 864 | #define MAYBE_TestReattachAfterCrash DISABLED_TestReattachAfterCrash |
| 865 | #else |
| 866 | #define MAYBE_TestReattachAfterCrash TestReattachAfterCrash |
| 867 | #endif |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 868 | // Tests that inspector will reattach to inspected page when it is reloaded |
| 869 | // after a crash. See http://crbug.com/101952 |
[email protected] | f25da5e2 | 2013-07-01 11:21:13 | [diff] [blame] | 870 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestReattachAfterCrash) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 871 | OpenDevToolsWindow(kDebuggerTestPage, false); |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 872 | |
[email protected] | e0f3e14 | 2012-07-26 03:31:34 | [diff] [blame] | 873 | content::CrashTab(GetInspectedTab()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 874 | content::WindowedNotificationObserver observer( |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 875 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 876 | content::Source<NavigationController>( |
[email protected] | 3695357 | 2013-01-14 18:38:10 | [diff] [blame] | 877 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 878 | GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 879 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 880 | observer.Wait(); |
| 881 | |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 882 | RunTestFunction(window_, "testReattachAfterCrash"); |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 883 | CloseDevToolsWindow(); |
| 884 | } |
| 885 | |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 886 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 887 | OpenDevToolsWindow("about:blank", false); |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 888 | std::string result; |
| 889 | ASSERT_TRUE( |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 890 | content::ExecuteScriptAndExtractString( |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 891 | window_->GetRenderViewHost(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 892 | "window.domAutomationController.send(" |
| 893 | " '' + (window.uiTests && (typeof uiTests.runTest)));", |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 894 | &result)); |
| 895 | ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
| 896 | CloseDevToolsWindow(); |
| 897 | } |
| 898 | |
[email protected] | 72e7af0 | 2011-11-28 09:11:09 | [diff] [blame] | 899 | #if defined(OS_MACOSX) |
| 900 | #define MAYBE_InspectSharedWorker DISABLED_InspectSharedWorker |
| 901 | #else |
| 902 | #define MAYBE_InspectSharedWorker InspectSharedWorker |
| 903 | #endif |
[email protected] | 1b1dc99b | 2011-07-26 11:23:14 | [diff] [blame] | 904 | // Flakily fails with 25s timeout: http://crbug.com/89845 |
[email protected] | 72e7af0 | 2011-11-28 09:11:09 | [diff] [blame] | 905 | IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, MAYBE_InspectSharedWorker) { |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 906 | #if defined(OS_WIN) && defined(USE_ASH) |
| 907 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 908 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 909 | return; |
| 910 | #endif |
| 911 | |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 912 | RunTest("testSharedWorker", kSharedWorkerTestPage); |
| 913 | } |
| 914 | |
[email protected] | 72e7af0 | 2011-11-28 09:11:09 | [diff] [blame] | 915 | // http://crbug.com/100538 |
[email protected] | 3292ee0 | 2012-12-21 19:24:13 | [diff] [blame] | 916 | #if defined(OS_MACOSX) || defined(OS_WIN) |
[email protected] | 72e7af0 | 2011-11-28 09:11:09 | [diff] [blame] | 917 | #define MAYBE_PauseInSharedWorkerInitialization DISABLED_PauseInSharedWorkerInitialization |
[email protected] | 72e7af0 | 2011-11-28 09:11:09 | [diff] [blame] | 918 | #else |
| 919 | #define MAYBE_PauseInSharedWorkerInitialization PauseInSharedWorkerInitialization |
| 920 | #endif |
[email protected] | e043c2a | 2011-12-02 00:08:17 | [diff] [blame] | 921 | |
[email protected] | 8d54beb | 2011-12-02 20:39:32 | [diff] [blame] | 922 | // http://crbug.com/106114 is masking |
| 923 | // MAYBE_PauseInSharedWorkerInitialization into |
| 924 | // DISABLED_PauseInSharedWorkerInitialization |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 925 | IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, |
[email protected] | 0f391bf0 | 2012-05-18 13:02:52 | [diff] [blame] | 926 | MAYBE_PauseInSharedWorkerInitialization) { |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 927 | ASSERT_TRUE(test_server()->Start()); |
| 928 | GURL url = test_server()->GetURL(kReloadSharedWorkerTestPage); |
| 929 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 930 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 931 | scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); |
| 932 | OpenDevToolsWindowForSharedWorker(worker_data.get()); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 933 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 934 | TerminateWorker(worker_data); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 935 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 936 | // Reload page to restart the worker. |
| 937 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 938 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 939 | // Wait until worker script is paused on the debugger statement. |
| 940 | RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); |
| 941 | CloseDevToolsWindow(); |
| 942 | } |
| 943 | |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 944 | class DevToolsAgentHostTest : public InProcessBrowserTest {}; |
| 945 | |
| 946 | // Tests DevToolsAgentHost retention by its target. |
| 947 | IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) { |
| 948 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 949 | RenderViewHost* rvh = browser()->tab_strip_model()->GetWebContentsAt(0)-> |
| 950 | GetRenderViewHost(); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 951 | DevToolsAgentHost* agent_raw = DevToolsAgentHost::GetOrCreateFor(rvh).get(); |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 952 | const std::string agent_id = agent_raw->GetId(); |
| 953 | ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id)) << |
| 954 | "DevToolsAgentHost cannot be found by id"; |
| 955 | browser()->tab_strip_model()-> |
| 956 | CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 957 | ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) |
| 958 | << "DevToolsAgentHost is not released when the tab is closed"; |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 959 | } |
| 960 | |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 961 | class RemoteDebuggingTest: public ExtensionApiTest { |
| 962 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 963 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 964 | command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 965 | |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 966 | // Override the extension root path. |
| 967 | PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 968 | test_data_dir_ = test_data_dir_.AppendASCII("devtools"); |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 969 | } |
| 970 | }; |
| 971 | |
[email protected] | 8971c80 | 2013-10-26 01:44:57 | [diff] [blame] | 972 | IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 973 | #if defined(OS_WIN) && defined(USE_ASH) |
| 974 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 975 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 976 | return; |
| 977 | #endif |
| 978 | |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 979 | ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 980 | } |