| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 46 #include "chrome/test/base/ui_test_utils.h" | 46 #include "chrome/test/base/ui_test_utils.h" |
| 47 #include "components/app_modal/javascript_app_modal_dialog.h" | 47 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 48 #include "components/app_modal/native_app_modal_dialog.h" | 48 #include "components/app_modal/native_app_modal_dialog.h" |
| 49 #include "components/prefs/pref_service.h" | 49 #include "components/prefs/pref_service.h" |
| 50 #include "content/public/browser/child_process_data.h" | 50 #include "content/public/browser/child_process_data.h" |
| 51 #include "content/public/browser/content_browser_client.h" | 51 #include "content/public/browser/content_browser_client.h" |
| 52 #include "content/public/browser/devtools_agent_host.h" | 52 #include "content/public/browser/devtools_agent_host.h" |
| 53 #include "content/public/browser/notification_registrar.h" | 53 #include "content/public/browser/notification_registrar.h" |
| 54 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
| 55 #include "content/public/browser/render_frame_host.h" |
| 55 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/render_widget_host.h" | 57 #include "content/public/browser/render_widget_host.h" |
| 57 #include "content/public/browser/render_widget_host_view.h" | 58 #include "content/public/browser/render_widget_host_view.h" |
| 58 #include "content/public/browser/url_data_source.h" | 59 #include "content/public/browser/url_data_source.h" |
| 59 #include "content/public/browser/web_contents.h" | 60 #include "content/public/browser/web_contents.h" |
| 60 #include "content/public/browser/web_ui_controller.h" | 61 #include "content/public/browser/web_ui_controller.h" |
| 61 #include "content/public/browser/worker_service.h" | 62 #include "content/public/browser/worker_service.h" |
| 62 #include "content/public/browser/worker_service_observer.h" | 63 #include "content/public/browser/worker_service_observer.h" |
| 63 #include "content/public/common/content_switches.h" | 64 #include "content/public/common/content_switches.h" |
| 64 #include "content/public/test/browser_test_utils.h" | 65 #include "content/public/test/browser_test_utils.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 357 |
| 357 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( | 358 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
| 358 const base::TimeTicks& proceed_time) { | 359 const base::TimeTicks& proceed_time) { |
| 359 m_fired = true; | 360 m_fired = true; |
| 360 if (message_loop_runner_.get()) | 361 if (message_loop_runner_.get()) |
| 361 message_loop_runner_->Quit(); | 362 message_loop_runner_->Quit(); |
| 362 } | 363 } |
| 363 | 364 |
| 364 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { | 365 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
| 365 public: | 366 public: |
| 366 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 367 command_line->AppendSwitch( | |
| 368 switches::kDisableHangMonitor); | |
| 369 } | |
| 370 | |
| 371 void CloseInspectedTab() { | 367 void CloseInspectedTab() { |
| 372 browser()->tab_strip_model()->CloseWebContentsAt(0, | 368 browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 373 TabStripModel::CLOSE_NONE); | 369 TabStripModel::CLOSE_NONE); |
| 374 } | 370 } |
| 375 | 371 |
| 376 void CloseDevToolsWindowAsync() { | 372 void CloseDevToolsWindowAsync() { |
| 377 DevToolsWindowTesting::CloseDevToolsWindow(window_); | 373 DevToolsWindowTesting::CloseDevToolsWindow(window_); |
| 378 } | 374 } |
| 379 | 375 |
| 380 void CloseInspectedBrowser() { | 376 void CloseInspectedBrowser() { |
| 381 chrome::CloseWindow(browser()); | 377 chrome::CloseWindow(browser()); |
| 382 } | 378 } |
| 383 | 379 |
| 384 protected: | 380 protected: |
| 385 void InjectBeforeUnloadListener(content::WebContents* web_contents) { | 381 void InjectBeforeUnloadListener(content::WebContents* web_contents) { |
| 386 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), | 382 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), |
| 387 "window.addEventListener('beforeunload'," | 383 "window.addEventListener('beforeunload'," |
| 388 "function(event) { event.returnValue = 'Foo'; });")); | 384 "function(event) { event.returnValue = 'Foo'; });")); |
| 389 } | 385 } |
| 390 | 386 |
| 391 void RunBeforeUnloadSanityTest(bool is_docked, | 387 void RunBeforeUnloadSanityTest(bool is_docked, |
| 392 base::Callback<void(void)> close_method, | 388 base::Callback<void(void)> close_method, |
| 393 bool wait_for_browser_close = true) { | 389 bool wait_for_browser_close = true) { |
| 394 OpenDevToolsWindow(kDebuggerTestPage, is_docked); | 390 OpenDevToolsWindow(kDebuggerTestPage, is_docked); |
| 395 scoped_refptr<content::MessageLoopRunner> runner = | 391 scoped_refptr<content::MessageLoopRunner> runner = |
| 396 new content::MessageLoopRunner; | 392 new content::MessageLoopRunner; |
| 397 DevToolsWindowTesting::Get(window_)-> | 393 DevToolsWindowTesting::Get(window_)-> |
| 398 SetCloseCallback(runner->QuitClosure()); | 394 SetCloseCallback(runner->QuitClosure()); |
| 399 InjectBeforeUnloadListener(main_web_contents()); | 395 InjectBeforeUnloadListener(main_web_contents()); |
| 396 main_web_contents() |
| 397 ->GetMainFrame() |
| 398 ->DisableBeforeUnloadHangMonitorForTesting(); |
| 400 { | 399 { |
| 401 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); | 400 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); |
| 402 close_method.Run(); | 401 close_method.Run(); |
| 403 CancelModalDialog(); | 402 CancelModalDialog(); |
| 404 before_unload_observer.Wait(); | 403 before_unload_observer.Wait(); |
| 405 } | 404 } |
| 406 { | 405 { |
| 407 content::WindowedNotificationObserver close_observer( | 406 content::WindowedNotificationObserver close_observer( |
| 408 chrome::NOTIFICATION_BROWSER_CLOSED, | 407 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 409 content::Source<Browser>(browser())); | 408 content::Source<Browser>(browser())); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 450 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 452 EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); | 451 EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 453 JavaScriptAppModalDialog* js_dialog = | 452 JavaScriptAppModalDialog* js_dialog = |
| 454 static_cast<JavaScriptAppModalDialog*>(dialog); | 453 static_cast<JavaScriptAppModalDialog*>(dialog); |
| 455 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); | 454 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); |
| 456 EXPECT_TRUE(native_dialog); | 455 EXPECT_TRUE(native_dialog); |
| 457 return native_dialog; | 456 return native_dialog; |
| 458 } | 457 } |
| 459 }; | 458 }; |
| 460 | 459 |
| 461 class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { | |
| 462 public: | |
| 463 void SetUpCommandLine(base::CommandLine* command_line) override {} | |
| 464 }; | |
| 465 | |
| 466 void TimeoutCallback(const std::string& timeout_message) { | 460 void TimeoutCallback(const std::string& timeout_message) { |
| 467 ADD_FAILURE() << timeout_message; | 461 ADD_FAILURE() << timeout_message; |
| 468 base::MessageLoop::current()->QuitWhenIdle(); | 462 base::MessageLoop::current()->QuitWhenIdle(); |
| 469 } | 463 } |
| 470 | 464 |
| 471 // Base class for DevTools tests that test devtools functionality for | 465 // Base class for DevTools tests that test devtools functionality for |
| 472 // extensions and content scripts. | 466 // extensions and content scripts. |
| 473 class DevToolsExtensionTest : public DevToolsSanityTest, | 467 class DevToolsExtensionTest : public DevToolsSanityTest, |
| 474 public content::NotificationObserver { | 468 public content::NotificationObserver { |
| 475 public: | 469 public: |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // Tests that BeforeUnload event gets called on docked devtools if | 698 // Tests that BeforeUnload event gets called on docked devtools if |
| 705 // we try to close them. | 699 // we try to close them. |
| 706 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { | 700 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { |
| 707 RunBeforeUnloadSanityTest(true, base::Bind( | 701 RunBeforeUnloadSanityTest(true, base::Bind( |
| 708 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, | 702 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, |
| 709 base::Unretained(this)), false); | 703 base::Unretained(this)), false); |
| 710 } | 704 } |
| 711 | 705 |
| 712 // Tests that BeforeUnload event gets called on docked devtools if | 706 // Tests that BeforeUnload event gets called on docked devtools if |
| 713 // we try to close the inspected page. | 707 // we try to close the inspected page. |
| 714 // Flaky on Windows, Linux and ChromiumOS. http://crbug.com/702171 | |
| 715 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 716 #define MAYBE_TestDockedDevToolsInspectedTabClose \ | |
| 717 DISABLED_TestDockedDevToolsInspectedTabClose | |
| 718 #else | |
| 719 #define MAYBE_TestDockedDevToolsInspectedTabClose \ | |
| 720 TestDockedDevToolsInspectedTabClose | |
| 721 #endif | |
| 722 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 708 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 723 MAYBE_TestDockedDevToolsInspectedTabClose) { | 709 TestDockedDevToolsInspectedTabClose) { |
| 724 RunBeforeUnloadSanityTest(true, base::Bind( | 710 RunBeforeUnloadSanityTest(true, base::Bind( |
| 725 &DevToolsBeforeUnloadTest::CloseInspectedTab, | 711 &DevToolsBeforeUnloadTest::CloseInspectedTab, |
| 726 base::Unretained(this))); | 712 base::Unretained(this))); |
| 727 } | 713 } |
| 728 | 714 |
| 729 // Tests that BeforeUnload event gets called on docked devtools if | 715 // Tests that BeforeUnload event gets called on docked devtools if |
| 730 // we try to close the inspected browser. | 716 // we try to close the inspected browser. |
| 731 // Flaky on Windows. http://crbug.com/702171 | |
| 732 #if defined(OS_WIN) | |
| 733 #define MAYBE_TestDockedDevToolsInspectedBrowserClose \ | |
| 734 DISABLED_TestDockedDevToolsInspectedBrowserClose | |
| 735 #else | |
| 736 #define MAYBE_TestDockedDevToolsInspectedBrowserClose \ | |
| 737 TestDockedDevToolsInspectedBrowserClose | |
| 738 #endif | |
| 739 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 717 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 740 MAYBE_TestDockedDevToolsInspectedBrowserClose) { | 718 TestDockedDevToolsInspectedBrowserClose) { |
| 741 RunBeforeUnloadSanityTest(true, base::Bind( | 719 RunBeforeUnloadSanityTest(true, base::Bind( |
| 742 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, | 720 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, |
| 743 base::Unretained(this))); | 721 base::Unretained(this))); |
| 744 } | 722 } |
| 745 | 723 |
| 746 // Tests that BeforeUnload event gets called on undocked devtools if | 724 // Tests that BeforeUnload event gets called on undocked devtools if |
| 747 // we try to close them. | 725 // we try to close them. |
| 748 // Flaky on Windows, Linux and ChromiumOS. http://crbug.com/702171 | 726 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) { |
| 749 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 750 #define MAYBE_TestUndockedDevToolsClose DISABLED_TestUndockedDevToolsClose | |
| 751 #else | |
| 752 #define MAYBE_TestUndockedDevToolsClose TestUndockedDevToolsClose | |
| 753 #endif | |
| 754 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | |
| 755 MAYBE_TestUndockedDevToolsClose) { | |
| 756 RunBeforeUnloadSanityTest(false, base::Bind( | 727 RunBeforeUnloadSanityTest(false, base::Bind( |
| 757 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, | 728 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, |
| 758 base::Unretained(this)), false); | 729 base::Unretained(this)), false); |
| 759 } | 730 } |
| 760 | 731 |
| 761 // Tests that BeforeUnload event gets called on undocked devtools if | 732 // Tests that BeforeUnload event gets called on undocked devtools if |
| 762 // we try to close the inspected page. | 733 // we try to close the inspected page. |
| 763 // Flaky on Windows. http://crbug.com/702171 | |
| 764 #if defined(OS_WIN) | |
| 765 #define MAYBE_TestUndockedDevToolsInspectedTabClose \ | |
| 766 DISABLED_TestUndockedDevToolsInspectedTabClose | |
| 767 #else | |
| 768 #define MAYBE_TestUndockedDevToolsInspectedTabClose \ | |
| 769 TestUndockedDevToolsInspectedTabClose | |
| 770 #endif | |
| 771 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 734 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 772 MAYBE_TestUndockedDevToolsInspectedTabClose) { | 735 TestUndockedDevToolsInspectedTabClose) { |
| 773 RunBeforeUnloadSanityTest(false, base::Bind( | 736 RunBeforeUnloadSanityTest(false, base::Bind( |
| 774 &DevToolsBeforeUnloadTest::CloseInspectedTab, | 737 &DevToolsBeforeUnloadTest::CloseInspectedTab, |
| 775 base::Unretained(this))); | 738 base::Unretained(this))); |
| 776 } | 739 } |
| 777 | 740 |
| 778 // Tests that BeforeUnload event gets called on undocked devtools if | 741 // Tests that BeforeUnload event gets called on undocked devtools if |
| 779 // we try to close the inspected browser. | 742 // we try to close the inspected browser. |
| 780 // Flaky on Windows, Linux and ChromiumOS. http://crbug.com/702171 | |
| 781 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 782 #define MAYBE_TestUndockedDevToolsInspectedBrowserClose \ | |
| 783 DISABLED_TestUndockedDevToolsInspectedBrowserClose | |
| 784 #else | |
| 785 #define MAYBE_TestUndockedDevToolsInspectedBrowserClose \ | |
| 786 TestUndockedDevToolsInspectedBrowserClose | |
| 787 #endif | |
| 788 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 743 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 789 MAYBE_TestUndockedDevToolsInspectedBrowserClose) { | 744 TestUndockedDevToolsInspectedBrowserClose) { |
| 790 RunBeforeUnloadSanityTest(false, base::Bind( | 745 RunBeforeUnloadSanityTest(false, base::Bind( |
| 791 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, | 746 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, |
| 792 base::Unretained(this))); | 747 base::Unretained(this))); |
| 793 } | 748 } |
| 794 | 749 |
| 795 // Tests that BeforeUnload event gets called on undocked devtools if | 750 // Tests that BeforeUnload event gets called on undocked devtools if |
| 796 // we try to exit application. | 751 // we try to exit application. |
| 797 // Flaky on Windows, Linux and ChromiumOS. http://crbug.com/702171 | |
| 798 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 799 #define MAYBE_TestUndockedDevToolsApplicationClose \ | |
| 800 DISABLED_TestUndockedDevToolsApplicationClose | |
| 801 #else | |
| 802 #define MAYBE_TestUndockedDevToolsApplicationClose \ | |
| 803 TestUndockedDevToolsApplicationClose | |
| 804 #endif | |
| 805 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, | 752 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 806 MAYBE_TestUndockedDevToolsApplicationClose) { | 753 TestUndockedDevToolsApplicationClose) { |
| 807 RunBeforeUnloadSanityTest(false, base::Bind( | 754 RunBeforeUnloadSanityTest(false, base::Bind( |
| 808 &chrome::CloseAllBrowsers)); | 755 &chrome::CloseAllBrowsers)); |
| 809 } | 756 } |
| 810 | 757 |
| 811 // Tests that inspected tab gets closed if devtools renderer | 758 // Tests that inspected tab gets closed if devtools renderer |
| 812 // becomes unresponsive during beforeunload event interception. | 759 // becomes unresponsive during beforeunload event interception. |
| 813 // @see http://crbug.com/322380 | 760 // @see http://crbug.com/322380 |
| 814 // Disabled because of http://crbug.com/410327 | 761 // Disabled because of http://crbug.com/410327 |
| 815 IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest, | 762 IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 816 DISABLED_TestUndockedDevToolsUnresponsive) { | 763 DISABLED_TestUndockedDevToolsUnresponsive) { |
| 817 ASSERT_TRUE(spawned_test_server()->Start()); | 764 ASSERT_TRUE(spawned_test_server()->Start()); |
| 818 LoadTestPage(kDebuggerTestPage); | 765 LoadTestPage(kDebuggerTestPage); |
| 819 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( | 766 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
| 820 GetInspectedTab(), false); | 767 GetInspectedTab(), false); |
| 821 | 768 |
| 822 scoped_refptr<content::MessageLoopRunner> runner = | 769 scoped_refptr<content::MessageLoopRunner> runner = |
| 823 new content::MessageLoopRunner; | 770 new content::MessageLoopRunner; |
| 824 DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback( | 771 DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback( |
| 825 runner->QuitClosure()); | 772 runner->QuitClosure()); |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); | 1541 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); |
| 1595 | 1542 |
| 1596 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | 1543 DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 1597 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | 1544 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
| 1598 } | 1545 } |
| 1599 | 1546 |
| 1600 // Tests scripts panel showing. | 1547 // Tests scripts panel showing. |
| 1601 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { | 1548 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { |
| 1602 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); | 1549 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); |
| 1603 } | 1550 } |
| OLD | NEW |