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