| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/cancelable_callback.h" | 6 #include "base/cancelable_callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" | 16 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
| 17 #include "chrome/browser/devtools/devtools_window.h" | 17 #include "chrome/browser/devtools/devtools_window_testing.h" |
| 18 #include "chrome/browser/extensions/extension_apitest.h" | 18 #include "chrome/browser/extensions/extension_apitest.h" |
| 19 #include "chrome/browser/extensions/extension_browsertest.h" | 19 #include "chrome/browser/extensions/extension_browsertest.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/unpacked_installer.h" | 21 #include "chrome/browser/extensions/unpacked_installer.h" |
| 22 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 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" | 25 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
| 26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_commands.h" | 27 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const char kSlowTestPage[] = | 77 const char kSlowTestPage[] = |
| 78 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; | 78 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
| 79 const char kSharedWorkerTestPage[] = | 79 const char kSharedWorkerTestPage[] = |
| 80 "files/workers/workers_ui_shared_worker.html"; | 80 "files/workers/workers_ui_shared_worker.html"; |
| 81 const char kReloadSharedWorkerTestPage[] = | 81 const char kReloadSharedWorkerTestPage[] = |
| 82 "files/workers/debug_shared_worker_initialization.html"; | 82 "files/workers/debug_shared_worker_initialization.html"; |
| 83 | 83 |
| 84 void RunTestFunction(DevToolsWindow* window, const char* test_name) { | 84 void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
| 85 std::string result; | 85 std::string result; |
| 86 | 86 |
| 87 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)-> |
| 88 main_web_contents()->GetRenderViewHost(); |
| 87 // At first check that JavaScript part of the front-end is loaded by | 89 // 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 | 90 // checking that global variable uiTests exists(it's created after all js |
| 89 // files have been loaded) and has runTest method. | 91 // files have been loaded) and has runTest method. |
| 90 ASSERT_TRUE( | 92 ASSERT_TRUE( |
| 91 content::ExecuteScriptAndExtractString( | 93 content::ExecuteScriptAndExtractString( |
| 92 window->web_contents_for_test()->GetRenderViewHost(), | 94 rvh, |
| 93 "window.domAutomationController.send(" | 95 "window.domAutomationController.send(" |
| 94 " '' + (window.uiTests && (typeof uiTests.runTest)));", | 96 " '' + (window.uiTests && (typeof uiTests.runTest)));", |
| 95 &result)); | 97 &result)); |
| 96 | 98 |
| 97 ASSERT_EQ("function", result) << "DevTools front-end is broken."; | 99 ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
| 98 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 100 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 99 window->web_contents_for_test()->GetRenderViewHost(), | 101 rvh, |
| 100 base::StringPrintf("uiTests.runTest('%s')", test_name), | 102 base::StringPrintf("uiTests.runTest('%s')", test_name), |
| 101 &result)); | 103 &result)); |
| 102 EXPECT_EQ("[OK]", result); | 104 EXPECT_EQ("[OK]", result); |
| 103 } | 105 } |
| 104 | 106 |
| 105 } // namespace | 107 } // namespace |
| 106 | 108 |
| 107 class DevToolsSanityTest : public InProcessBrowserTest { | 109 class DevToolsSanityTest : public InProcessBrowserTest { |
| 108 public: | 110 public: |
| 109 DevToolsSanityTest() | 111 DevToolsSanityTest() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 void LoadTestPage(const std::string& test_page) { | 122 void LoadTestPage(const std::string& test_page) { |
| 121 GURL url = test_server()->GetURL(test_page); | 123 GURL url = test_server()->GetURL(test_page); |
| 122 ui_test_utils::NavigateToURL(browser(), url); | 124 ui_test_utils::NavigateToURL(browser(), url); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { | 127 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
| 126 ASSERT_TRUE(test_server()->Start()); | 128 ASSERT_TRUE(test_server()->Start()); |
| 127 LoadTestPage(test_page); | 129 LoadTestPage(test_page); |
| 128 | 130 |
| 129 inspected_rvh_ = GetInspectedTab()->GetRenderViewHost(); | 131 inspected_rvh_ = GetInspectedTab()->GetRenderViewHost(); |
| 130 window_ = | 132 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 131 DevToolsWindow::OpenDevToolsWindowForTest(inspected_rvh_, is_docked); | 133 inspected_rvh_, is_docked); |
| 132 ui_test_utils::WaitUntilDevToolsWindowLoaded(window_); | |
| 133 } | 134 } |
| 134 | 135 |
| 135 WebContents* GetInspectedTab() { | 136 WebContents* GetInspectedTab() { |
| 136 return browser()->tab_strip_model()->GetWebContentsAt(0); | 137 return browser()->tab_strip_model()->GetWebContentsAt(0); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void ToggleDevToolsWindow() { | 140 void CloseDevToolsWindow() { |
| 140 content::WindowedNotificationObserver close_observer( | 141 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
| 141 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 142 content::Source<content::WebContents>( | |
| 143 window_->web_contents_for_test())); | |
| 144 DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false, | |
| 145 DevToolsToggleAction::Toggle()); | |
| 146 close_observer.Wait(); | |
| 147 } | 142 } |
| 148 | 143 |
| 149 void ToggleDevToolsWindowDontWait() { | 144 WebContents* main_web_contents() { |
| 150 DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false, | 145 return DevToolsWindowTesting::Get(window_)->main_web_contents(); |
| 151 DevToolsToggleAction::Toggle()); | |
| 152 } | 146 } |
| 153 | 147 |
| 154 void CloseDevToolsWindow() { | 148 WebContents* toolbox_web_contents() { |
| 155 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 149 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); |
| 156 content::WindowedNotificationObserver close_observer( | |
| 157 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 158 content::Source<content::WebContents>( | |
| 159 window_->web_contents_for_test())); | |
| 160 devtools_manager->CloseAllClientHosts(); | |
| 161 close_observer.Wait(); | |
| 162 } | 150 } |
| 163 | 151 |
| 164 DevToolsWindow* window_; | 152 DevToolsWindow* window_; |
| 165 RenderViewHost* inspected_rvh_; | 153 RenderViewHost* inspected_rvh_; |
| 166 }; | 154 }; |
| 167 | 155 |
| 168 // Used to block until a dev tools window gets beforeunload event. | 156 // Used to block until a dev tools window gets beforeunload event. |
| 169 class DevToolsWindowBeforeUnloadObserver | 157 class DevToolsWindowBeforeUnloadObserver |
| 170 : public content::WebContentsObserver { | 158 : public content::WebContentsObserver { |
| 171 public: | 159 public: |
| 172 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); | 160 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
| 173 void Wait(); | 161 void Wait(); |
| 174 private: | 162 private: |
| 175 // Invoked when the beforeunload handler fires. | 163 // Invoked when the beforeunload handler fires. |
| 176 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; | 164 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; |
| 177 | 165 |
| 178 bool m_fired; | 166 bool m_fired; |
| 179 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 167 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 180 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); | 168 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); |
| 181 }; | 169 }; |
| 182 | 170 |
| 183 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( | 171 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( |
| 184 DevToolsWindow* devtools_window) | 172 DevToolsWindow* devtools_window) |
| 185 : WebContentsObserver(devtools_window->web_contents_for_test()), | 173 : WebContentsObserver( |
| 174 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), |
| 186 m_fired(false) { | 175 m_fired(false) { |
| 187 } | 176 } |
| 188 | 177 |
| 189 void DevToolsWindowBeforeUnloadObserver::Wait() { | 178 void DevToolsWindowBeforeUnloadObserver::Wait() { |
| 190 if (m_fired) | 179 if (m_fired) |
| 191 return; | 180 return; |
| 192 message_loop_runner_ = new content::MessageLoopRunner; | 181 message_loop_runner_ = new content::MessageLoopRunner; |
| 193 message_loop_runner_->Run(); | 182 message_loop_runner_->Run(); |
| 194 } | 183 } |
| 195 | 184 |
| 196 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( | 185 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
| 197 const base::TimeTicks& proceed_time) { | 186 const base::TimeTicks& proceed_time) { |
| 198 m_fired = true; | 187 m_fired = true; |
| 199 if (message_loop_runner_.get()) | 188 if (message_loop_runner_.get()) |
| 200 message_loop_runner_->Quit(); | 189 message_loop_runner_->Quit(); |
| 201 } | 190 } |
| 202 | 191 |
| 203 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { | 192 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
| 204 public: | 193 public: |
| 205 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 194 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 206 command_line->AppendSwitch( | 195 command_line->AppendSwitch( |
| 207 switches::kDisableHangMonitor); | 196 switches::kDisableHangMonitor); |
| 208 } | 197 } |
| 209 | 198 |
| 210 void CloseInspectedTab() { | 199 void CloseInspectedTab() { |
| 211 browser()->tab_strip_model()->CloseWebContentsAt(0, | 200 browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 212 TabStripModel::CLOSE_NONE); | 201 TabStripModel::CLOSE_NONE); |
| 213 } | 202 } |
| 214 | 203 |
| 215 void CloseDockedDevTools() { | 204 void CloseDevToolsWindowAsync() { |
| 216 ToggleDevToolsWindowDontWait(); | 205 DevToolsWindowTesting::CloseDevToolsWindow(window_); |
| 217 } | |
| 218 | |
| 219 void CloseUndockedDevTools() { | |
| 220 chrome::CloseWindow(window_->browser_for_test()); | |
| 221 } | 206 } |
| 222 | 207 |
| 223 void CloseInspectedBrowser() { | 208 void CloseInspectedBrowser() { |
| 224 chrome::CloseWindow(browser()); | 209 chrome::CloseWindow(browser()); |
| 225 } | 210 } |
| 211 |
| 226 protected: | 212 protected: |
| 227 void InjectBeforeUnloadListener(content::WebContents* web_contents) { | 213 void InjectBeforeUnloadListener(content::WebContents* web_contents) { |
| 228 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), | 214 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), |
| 229 "window.addEventListener('beforeunload'," | 215 "window.addEventListener('beforeunload'," |
| 230 "function(event) { event.returnValue = 'Foo'; });")); | 216 "function(event) { event.returnValue = 'Foo'; });")); |
| 231 } | 217 } |
| 232 | 218 |
| 233 void RunBeforeUnloadSanityTest(bool is_docked, | 219 void RunBeforeUnloadSanityTest(bool is_docked, |
| 234 base::Callback<void(void)> close_method, | 220 base::Callback<void(void)> close_method, |
| 235 bool wait_for_browser_close = true) { | 221 bool wait_for_browser_close = true) { |
| 236 OpenDevToolsWindow(kDebuggerTestPage, is_docked); | 222 OpenDevToolsWindow(kDebuggerTestPage, is_docked); |
| 237 content::WindowedNotificationObserver devtools_close_observer( | 223 scoped_refptr<content::MessageLoopRunner> runner = |
| 238 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 224 new content::MessageLoopRunner; |
| 239 content::Source<content::WebContents>( | 225 DevToolsWindowTesting::Get(window_)-> |
| 240 window_->web_contents_for_test())); | 226 SetCloseCallback(runner->QuitClosure()); |
| 241 InjectBeforeUnloadListener(window_->web_contents_for_test()); | 227 InjectBeforeUnloadListener(main_web_contents()); |
| 242 { | 228 { |
| 243 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); | 229 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); |
| 244 close_method.Run(); | 230 close_method.Run(); |
| 245 CancelModalDialog(); | 231 CancelModalDialog(); |
| 246 before_unload_observer.Wait(); | 232 before_unload_observer.Wait(); |
| 247 } | 233 } |
| 248 { | 234 { |
| 249 content::WindowedNotificationObserver close_observer( | 235 content::WindowedNotificationObserver close_observer( |
| 250 chrome::NOTIFICATION_BROWSER_CLOSED, | 236 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 251 content::Source<Browser>(browser())); | 237 content::Source<Browser>(browser())); |
| 252 close_method.Run(); | 238 close_method.Run(); |
| 253 AcceptModalDialog(); | 239 AcceptModalDialog(); |
| 254 if (wait_for_browser_close) | 240 if (wait_for_browser_close) |
| 255 close_observer.Wait(); | 241 close_observer.Wait(); |
| 256 } | 242 } |
| 257 devtools_close_observer.Wait(); | 243 runner->Run(); |
| 258 } | 244 } |
| 259 | 245 |
| 260 DevToolsWindow* OpenDevToolWindowOnWebContents( | 246 DevToolsWindow* OpenDevToolWindowOnWebContents( |
| 261 content::WebContents* contents, bool is_docked) { | 247 content::WebContents* contents, bool is_docked) { |
| 262 DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest( | 248 DevToolsWindow* window = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 263 contents->GetRenderViewHost(), is_docked); | 249 contents->GetRenderViewHost(), is_docked); |
| 264 ui_test_utils::WaitUntilDevToolsWindowLoaded(window); | |
| 265 return window; | 250 return window; |
| 266 } | 251 } |
| 267 | 252 |
| 268 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { | 253 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 269 content::WindowedNotificationObserver observer( | 254 content::WindowedNotificationObserver observer( |
| 270 content::NOTIFICATION_LOAD_STOP, | 255 content::NOTIFICATION_LOAD_STOP, |
| 271 content::NotificationService::AllSources()); | 256 content::NotificationService::AllSources()); |
| 272 ASSERT_TRUE(content::ExecuteScript( | 257 ASSERT_TRUE(content::ExecuteScript( |
| 273 devtools_window->web_contents_for_test()->GetRenderViewHost(), | 258 DevToolsWindowTesting::Get(devtools_window)-> |
| 259 main_web_contents()->GetRenderViewHost(), |
| 274 "window.open(\"\", \"\", \"location=0\");")); | 260 "window.open(\"\", \"\", \"location=0\");")); |
| 275 observer.Wait(); | 261 observer.Wait(); |
| 276 } | 262 } |
| 277 | 263 |
| 278 void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) { | 264 void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 279 Browser* popup_browser = NULL; | 265 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); |
| 280 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
| 281 if (it->is_devtools()) { | |
| 282 content::WebContents* contents = | |
| 283 it->tab_strip_model()->GetWebContentsAt(0); | |
| 284 if (devtools_window->web_contents_for_test() != contents) { | |
| 285 popup_browser = *it; | |
| 286 break; | |
| 287 } | |
| 288 } | |
| 289 } | |
| 290 ASSERT_FALSE(popup_browser == NULL); | |
| 291 content::WindowedNotificationObserver close_observer( | |
| 292 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 293 content::Source<Browser>(popup_browser)); | |
| 294 chrome::CloseWindow(popup_browser); | |
| 295 close_observer.Wait(); | |
| 296 } | 266 } |
| 297 | 267 |
| 298 void AcceptModalDialog() { | 268 void AcceptModalDialog() { |
| 299 NativeAppModalDialog* native_dialog = GetDialog(); | 269 NativeAppModalDialog* native_dialog = GetDialog(); |
| 300 native_dialog->AcceptAppModalDialog(); | 270 native_dialog->AcceptAppModalDialog(); |
| 301 } | 271 } |
| 302 | 272 |
| 303 void CancelModalDialog() { | 273 void CancelModalDialog() { |
| 304 NativeAppModalDialog* native_dialog = GetDialog(); | 274 NativeAppModalDialog* native_dialog = GetDialog(); |
| 305 native_dialog->CancelAppModalDialog(); | 275 native_dialog->CancelAppModalDialog(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 content::RunMessageLoop(); | 504 content::RunMessageLoop(); |
| 535 return worker_data; | 505 return worker_data; |
| 536 } | 506 } |
| 537 | 507 |
| 538 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) { | 508 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) { |
| 539 Profile* profile = browser()->profile(); | 509 Profile* profile = browser()->profile(); |
| 540 scoped_refptr<DevToolsAgentHost> agent_host( | 510 scoped_refptr<DevToolsAgentHost> agent_host( |
| 541 DevToolsAgentHost::GetForWorker( | 511 DevToolsAgentHost::GetForWorker( |
| 542 worker_data->worker_process_id, | 512 worker_data->worker_process_id, |
| 543 worker_data->worker_route_id)); | 513 worker_data->worker_route_id)); |
| 544 window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 514 window_ = DevToolsWindowTesting::OpenDevToolsWindowForWorkerSync( |
| 545 content::WaitForLoadStop(window_->web_contents_for_test()); | 515 profile, agent_host); |
| 546 } | 516 } |
| 547 | 517 |
| 548 void CloseDevToolsWindow() { | 518 void CloseDevToolsWindow() { |
| 549 Browser* browser = window_->browser_for_test(); | 519 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
| 550 content::WindowedNotificationObserver close_observer( | |
| 551 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 552 content::Source<content::WebContents>( | |
| 553 window_->web_contents_for_test())); | |
| 554 browser->tab_strip_model()->CloseAllTabs(); | |
| 555 close_observer.Wait(); | |
| 556 } | 520 } |
| 557 | 521 |
| 558 DevToolsWindow* window_; | 522 DevToolsWindow* window_; |
| 559 }; | 523 }; |
| 560 | 524 |
| 561 // Tests that BeforeUnload event gets called on docked devtools if | 525 // Tests that BeforeUnload event gets called on docked devtools if |
| 562 // we try to close them. | 526 // we try to close them. |
| 563 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { | 527 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { |
| 564 RunBeforeUnloadSanityTest(true, base::Bind( | 528 RunBeforeUnloadSanityTest(true, base::Bind( |
| 565 &DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false); | 529 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false); |
| 566 } | 530 } |
| 567 | 531 |
| 568 // Tests that BeforeUnload event gets called on docked devtools if | 532 // Tests that BeforeUnload event gets called on docked devtools if |
| 569 // we try to close the inspected page. | 533 // we try to close the inspected page. |
| 570 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 534 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 571 TestDockedDevToolsInspectedTabClose) { | 535 TestDockedDevToolsInspectedTabClose) { |
| 572 RunBeforeUnloadSanityTest(true, base::Bind( | 536 RunBeforeUnloadSanityTest(true, base::Bind( |
| 573 &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); | 537 &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); |
| 574 } | 538 } |
| 575 | 539 |
| 576 // Tests that BeforeUnload event gets called on docked devtools if | 540 // Tests that BeforeUnload event gets called on docked devtools if |
| 577 // we try to close the inspected browser. | 541 // we try to close the inspected browser. |
| 578 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 542 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 579 TestDockedDevToolsInspectedBrowserClose) { | 543 TestDockedDevToolsInspectedBrowserClose) { |
| 580 RunBeforeUnloadSanityTest(true, base::Bind( | 544 RunBeforeUnloadSanityTest(true, base::Bind( |
| 581 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this)); | 545 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this)); |
| 582 } | 546 } |
| 583 | 547 |
| 584 // Tests that BeforeUnload event gets called on undocked devtools if | 548 // Tests that BeforeUnload event gets called on undocked devtools if |
| 585 // we try to close them. | 549 // we try to close them. |
| 586 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) { | 550 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) { |
| 587 RunBeforeUnloadSanityTest(false, base::Bind( | 551 RunBeforeUnloadSanityTest(false, base::Bind( |
| 588 &DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false); | 552 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false); |
| 589 } | 553 } |
| 590 | 554 |
| 591 // Tests that BeforeUnload event gets called on undocked devtools if | 555 // Tests that BeforeUnload event gets called on undocked devtools if |
| 592 // we try to close the inspected page. | 556 // we try to close the inspected page. |
| 593 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 557 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 594 TestUndockedDevToolsInspectedTabClose) { | 558 TestUndockedDevToolsInspectedTabClose) { |
| 595 RunBeforeUnloadSanityTest(false, base::Bind( | 559 RunBeforeUnloadSanityTest(false, base::Bind( |
| 596 &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); | 560 &DevToolsBeforeUnloadTest::CloseInspectedTab, this)); |
| 597 } | 561 } |
| 598 | 562 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 614 | 578 |
| 615 // Tests that inspected tab gets closed if devtools renderer | 579 // Tests that inspected tab gets closed if devtools renderer |
| 616 // becomes unresponsive during beforeunload event interception. | 580 // becomes unresponsive during beforeunload event interception. |
| 617 // @see http://crbug.com/322380 | 581 // @see http://crbug.com/322380 |
| 618 IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest, | 582 IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest, |
| 619 TestUndockedDevToolsUnresponsive) { | 583 TestUndockedDevToolsUnresponsive) { |
| 620 ASSERT_TRUE(test_server()->Start()); | 584 ASSERT_TRUE(test_server()->Start()); |
| 621 LoadTestPage(kDebuggerTestPage); | 585 LoadTestPage(kDebuggerTestPage); |
| 622 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( | 586 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
| 623 GetInspectedTab(), false); | 587 GetInspectedTab(), false); |
| 624 content::WindowedNotificationObserver devtools_close_observer( | 588 |
| 625 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 589 scoped_refptr<content::MessageLoopRunner> runner = |
| 626 content::Source<content::WebContents>( | 590 new content::MessageLoopRunner; |
| 627 devtools_window->web_contents_for_test())); | 591 DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback( |
| 592 runner->QuitClosure()); |
| 628 | 593 |
| 629 ASSERT_TRUE(content::ExecuteScript( | 594 ASSERT_TRUE(content::ExecuteScript( |
| 630 devtools_window->web_contents_for_test()->GetRenderViewHost(), | 595 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()-> |
| 596 GetRenderViewHost(), |
| 631 "window.addEventListener('beforeunload'," | 597 "window.addEventListener('beforeunload'," |
| 632 "function(event) { while (true); });")); | 598 "function(event) { while (true); });")); |
| 633 CloseInspectedTab(); | 599 CloseInspectedTab(); |
| 634 devtools_close_observer.Wait(); | 600 runner->Run(); |
| 635 } | 601 } |
| 636 | 602 |
| 637 // Tests that closing worker inspector window does not cause browser crash | 603 // Tests that closing worker inspector window does not cause browser crash |
| 638 // @see http://crbug.com/323031 | 604 // @see http://crbug.com/323031 |
| 639 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 605 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 640 TestWorkerWindowClosing) { | 606 TestWorkerWindowClosing) { |
| 641 ASSERT_TRUE(test_server()->Start()); | 607 ASSERT_TRUE(test_server()->Start()); |
| 642 LoadTestPage(kDebuggerTestPage); | 608 LoadTestPage(kDebuggerTestPage); |
| 643 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( | 609 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
| 644 GetInspectedTab(), false); | 610 GetInspectedTab(), false); |
| 645 content::WindowedNotificationObserver devtools_close_observer( | |
| 646 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 647 content::Source<content::WebContents>( | |
| 648 devtools_window->web_contents_for_test())); | |
| 649 | 611 |
| 650 OpenDevToolsPopupWindow(devtools_window); | 612 OpenDevToolsPopupWindow(devtools_window); |
| 651 CloseDevToolsPopupWindow(devtools_window); | 613 CloseDevToolsPopupWindow(devtools_window); |
| 652 } | 614 } |
| 653 | 615 |
| 654 // Tests that BeforeUnload event gets called on devtools that are opened | 616 // Tests that BeforeUnload event gets called on devtools that are opened |
| 655 // on another devtools. | 617 // on another devtools. |
| 656 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 618 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 657 TestDevToolsOnDevTools) { | 619 TestDevToolsOnDevTools) { |
| 658 ASSERT_TRUE(test_server()->Start()); | 620 ASSERT_TRUE(test_server()->Start()); |
| 659 LoadTestPage(kDebuggerTestPage); | 621 LoadTestPage(kDebuggerTestPage); |
| 660 | 622 |
| 661 std::vector<DevToolsWindow*> windows; | 623 std::vector<DevToolsWindow*> windows; |
| 662 std::vector<content::WindowedNotificationObserver*> close_observers; | 624 std::vector<content::WindowedNotificationObserver*> close_observers; |
| 663 content::WebContents* inspected_web_contents = GetInspectedTab(); | 625 content::WebContents* inspected_web_contents = GetInspectedTab(); |
| 664 for (int i = 0; i < 3; ++i) { | 626 for (int i = 0; i < 3; ++i) { |
| 665 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( | 627 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
| 666 inspected_web_contents, i == 0); | 628 inspected_web_contents, i == 0); |
| 667 windows.push_back(devtools_window); | 629 windows.push_back(devtools_window); |
| 668 content::WindowedNotificationObserver* close_observer = | 630 content::WindowedNotificationObserver* close_observer = |
| 669 new content::WindowedNotificationObserver( | 631 new content::WindowedNotificationObserver( |
| 670 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 632 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 671 content::Source<content::WebContents>( | 633 content::Source<content::WebContents>( |
| 672 devtools_window->web_contents_for_test())); | 634 DevToolsWindowTesting::Get(devtools_window)-> |
| 635 main_web_contents())); |
| 673 close_observers.push_back(close_observer); | 636 close_observers.push_back(close_observer); |
| 674 inspected_web_contents = devtools_window->web_contents_for_test(); | 637 inspected_web_contents = |
| 638 DevToolsWindowTesting::Get(devtools_window)->main_web_contents(); |
| 675 } | 639 } |
| 676 | 640 |
| 677 InjectBeforeUnloadListener(windows[0]->web_contents_for_test()); | 641 InjectBeforeUnloadListener( |
| 678 InjectBeforeUnloadListener(windows[2]->web_contents_for_test()); | 642 DevToolsWindowTesting::Get(windows[0])->main_web_contents()); |
| 643 InjectBeforeUnloadListener( |
| 644 DevToolsWindowTesting::Get(windows[2])->main_web_contents()); |
| 679 // Try to close second devtools. | 645 // Try to close second devtools. |
| 680 { | 646 { |
| 681 content::WindowedNotificationObserver cancel_browser( | 647 content::WindowedNotificationObserver cancel_browser( |
| 682 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 648 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 683 content::NotificationService::AllSources()); | 649 content::NotificationService::AllSources()); |
| 684 chrome::CloseWindow(windows[1]->browser_for_test()); | 650 chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser()); |
| 685 CancelModalDialog(); | 651 CancelModalDialog(); |
| 686 cancel_browser.Wait(); | 652 cancel_browser.Wait(); |
| 687 } | 653 } |
| 688 // Try to close browser window. | 654 // Try to close browser window. |
| 689 { | 655 { |
| 690 content::WindowedNotificationObserver cancel_browser( | 656 content::WindowedNotificationObserver cancel_browser( |
| 691 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 657 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 692 content::NotificationService::AllSources()); | 658 content::NotificationService::AllSources()); |
| 693 chrome::CloseWindow(browser()); | 659 chrome::CloseWindow(browser()); |
| 694 AcceptModalDialog(); | 660 AcceptModalDialog(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDeviceEmulation) { | 798 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDeviceEmulation) { |
| 833 RunTest("testDeviceMetricsOverrides", "about:blank"); | 799 RunTest("testDeviceMetricsOverrides", "about:blank"); |
| 834 } | 800 } |
| 835 | 801 |
| 836 | 802 |
| 837 // Tests that external navigation from inspector page is always handled by | 803 // Tests that external navigation from inspector page is always handled by |
| 838 // DevToolsWindow and results in inspected page navigation. | 804 // DevToolsWindow and results in inspected page navigation. |
| 839 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) { | 805 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) { |
| 840 OpenDevToolsWindow(kDebuggerTestPage, true); | 806 OpenDevToolsWindow(kDebuggerTestPage, true); |
| 841 GURL url = test_server()->GetURL(kNavigateBackTestPage); | 807 GURL url = test_server()->GetURL(kNavigateBackTestPage); |
| 842 // TODO(dgozman): remove this once notifications are gone. | |
| 843 // Right now notifications happen after observers, so DevTools window is | |
| 844 // already loaded, but we still catch it's notification when looking for | |
| 845 // all sources. | |
| 846 content::WaitForLoadStop(window_->web_contents_for_test()); | |
| 847 content::WindowedNotificationObserver observer( | 808 content::WindowedNotificationObserver observer( |
| 848 content::NOTIFICATION_LOAD_STOP, | 809 content::NOTIFICATION_LOAD_STOP, |
| 849 content::NotificationService::AllSources()); | 810 content::NotificationService::AllSources()); |
| 850 ASSERT_TRUE(content::ExecuteScript( | 811 ASSERT_TRUE(content::ExecuteScript( |
| 851 window_->web_contents_for_test(), | 812 main_web_contents(), |
| 852 std::string("window.location = \"") + url.spec() + "\"")); | 813 std::string("window.location = \"") + url.spec() + "\"")); |
| 853 observer.Wait(); | 814 observer.Wait(); |
| 854 | 815 |
| 855 ASSERT_TRUE(window_->web_contents_for_test()->GetURL(). | 816 ASSERT_TRUE(main_web_contents()->GetURL(). |
| 856 SchemeIs(content::kChromeDevToolsScheme)); | 817 SchemeIs(content::kChromeDevToolsScheme)); |
| 857 ASSERT_EQ(url, GetInspectedTab()->GetURL()); | 818 ASSERT_EQ(url, GetInspectedTab()->GetURL()); |
| 858 CloseDevToolsWindow(); | 819 CloseDevToolsWindow(); |
| 859 } | 820 } |
| 860 | 821 |
| 822 // Tests that toolbox window is loaded when DevTools window is undocked. |
| 823 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) { |
| 824 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 825 ASSERT_TRUE(toolbox_web_contents()); |
| 826 DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 827 main_web_contents()->GetRenderViewHost(), false); |
| 828 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 829 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 830 CloseDevToolsWindow(); |
| 831 } |
| 832 |
| 833 // Tests that toolbox window is not loaded when DevTools window is docked. |
| 834 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) { |
| 835 OpenDevToolsWindow(kDebuggerTestPage, true); |
| 836 ASSERT_FALSE(toolbox_web_contents()); |
| 837 DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync( |
| 838 main_web_contents()->GetRenderViewHost(), false); |
| 839 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 840 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 841 CloseDevToolsWindow(); |
| 842 } |
| 843 |
| 861 // Tests that inspector will reattach to inspected page when it is reloaded | 844 // Tests that inspector will reattach to inspected page when it is reloaded |
| 862 // after a crash. See http://crbug.com/101952 | 845 // after a crash. See http://crbug.com/101952 |
| 863 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestReattachAfterCrash) { | 846 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestReattachAfterCrash) { |
| 864 RunTest("testReattachAfterCrash", std::string()); | 847 RunTest("testReattachAfterCrash", std::string()); |
| 865 } | 848 } |
| 866 | 849 |
| 867 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { | 850 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { |
| 868 OpenDevToolsWindow("about:blank", false); | 851 OpenDevToolsWindow("about:blank", false); |
| 869 std::string result; | 852 std::string result; |
| 870 ASSERT_TRUE( | 853 ASSERT_TRUE( |
| 871 content::ExecuteScriptAndExtractString( | 854 content::ExecuteScriptAndExtractString( |
| 872 window_->web_contents_for_test()->GetRenderViewHost(), | 855 main_web_contents()->GetRenderViewHost(), |
| 873 "window.domAutomationController.send(" | 856 "window.domAutomationController.send(" |
| 874 " '' + (window.uiTests && (typeof uiTests.runTest)));", | 857 " '' + (window.uiTests && (typeof uiTests.runTest)));", |
| 875 &result)); | 858 &result)); |
| 876 ASSERT_EQ("function", result) << "DevTools front-end is broken."; | 859 ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
| 877 CloseDevToolsWindow(); | 860 CloseDevToolsWindow(); |
| 878 } | 861 } |
| 879 | 862 |
| 880 #if defined(OS_MACOSX) | 863 #if defined(OS_MACOSX) |
| 881 #define MAYBE_InspectSharedWorker DISABLED_InspectSharedWorker | 864 #define MAYBE_InspectSharedWorker DISABLED_InspectSharedWorker |
| 882 #else | 865 #else |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 935 |
| 953 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { | 936 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
| 954 #if defined(OS_WIN) && defined(USE_ASH) | 937 #if defined(OS_WIN) && defined(USE_ASH) |
| 955 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 938 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 956 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 939 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 957 return; | 940 return; |
| 958 #endif | 941 #endif |
| 959 | 942 |
| 960 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 943 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
| 961 } | 944 } |
| OLD | NEW |