OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); | 623 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); |
624 } | 624 } |
625 | 625 |
626 // Make sure that dialogs are closed after a renderer process dies, and that | 626 // Make sure that dialogs are closed after a renderer process dies, and that |
627 // subsequent navigations work. See http://crbug/com/343265. | 627 // subsequent navigations work. See http://crbug/com/343265. |
628 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { | 628 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { |
629 ASSERT_TRUE(embedded_test_server()->Start()); | 629 ASSERT_TRUE(embedded_test_server()->Start()); |
630 GURL beforeunload_url(embedded_test_server()->GetURL("/beforeunload.html")); | 630 GURL beforeunload_url(embedded_test_server()->GetURL("/beforeunload.html")); |
631 ui_test_utils::NavigateToURL(browser(), beforeunload_url); | 631 ui_test_utils::NavigateToURL(browser(), beforeunload_url); |
632 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 632 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
633 // Disable the hang monitor, otherwise there will be a race between the | 633 content::PrepContentsForBeforeUnloadTest(contents); |
634 // beforeunload dialog and the beforeunload hang timer. | |
635 contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
636 | 634 |
637 // Start a navigation to trigger the beforeunload dialog. | 635 // Start a navigation to trigger the beforeunload dialog. |
638 contents->GetMainFrame()->ExecuteJavaScriptForTests( | 636 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
639 ASCIIToUTF16("window.location.href = 'about:blank'")); | 637 ASCIIToUTF16("window.location.href = 'about:blank'")); |
640 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 638 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
641 EXPECT_TRUE(alert->IsValid()); | 639 EXPECT_TRUE(alert->IsValid()); |
642 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 640 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
643 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 641 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
644 | 642 |
645 // Crash the renderer process and ensure the dialog is gone. | 643 // Crash the renderer process and ensure the dialog is gone. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 | 714 |
717 interstitial->DontProceed(); | 715 interstitial->DontProceed(); |
718 } | 716 } |
719 | 717 |
720 // Test for crbug.com/22004. Reloading a page with a before unload handler and | 718 // Test for crbug.com/22004. Reloading a page with a before unload handler and |
721 // then canceling the dialog should not leave the throbber spinning. | 719 // then canceling the dialog should not leave the throbber spinning. |
722 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { | 720 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { |
723 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 721 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
724 ui_test_utils::NavigateToURL(browser(), url); | 722 ui_test_utils::NavigateToURL(browser(), url); |
725 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 723 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
726 // Disable the hang monitor, otherwise there will be a race between the | 724 content::PrepContentsForBeforeUnloadTest(contents); |
727 // beforeunload dialog and the beforeunload hang timer. | |
728 contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
729 | 725 |
730 // Navigate to another page, but click cancel in the dialog. Make sure that | 726 // Navigate to another page, but click cancel in the dialog. Make sure that |
731 // the throbber stops spinning. | 727 // the throbber stops spinning. |
732 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 728 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
733 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 729 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
734 | 730 |
735 FailedCommitWatcher watcher(contents); | 731 FailedCommitWatcher watcher(contents); |
736 alert->CloseModalDialog(); | 732 alert->CloseModalDialog(); |
737 if (content::IsBrowserSideNavigationEnabled()) | 733 if (content::IsBrowserSideNavigationEnabled()) |
738 watcher.Wait(); | 734 watcher.Wait(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 // Temporarily replace ContentBrowserClient with one that will cause a | 836 // Temporarily replace ContentBrowserClient with one that will cause a |
841 // process swap on all redirects to HTTPS URLs. | 837 // process swap on all redirects to HTTPS URLs. |
842 TransferHttpsRedirectsContentBrowserClient new_client; | 838 TransferHttpsRedirectsContentBrowserClient new_client; |
843 content::ContentBrowserClient* old_client = | 839 content::ContentBrowserClient* old_client = |
844 SetBrowserClientForTesting(&new_client); | 840 SetBrowserClientForTesting(&new_client); |
845 | 841 |
846 // Navigate to a page with a beforeunload handler. | 842 // Navigate to a page with a beforeunload handler. |
847 GURL url(embedded_test_server()->GetURL("/beforeunload.html")); | 843 GURL url(embedded_test_server()->GetURL("/beforeunload.html")); |
848 ui_test_utils::NavigateToURL(browser(), url); | 844 ui_test_utils::NavigateToURL(browser(), url); |
849 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 845 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
850 // Disable the hang monitor, otherwise there will be a race between the | 846 content::PrepContentsForBeforeUnloadTest(contents); |
851 // beforeunload dialog and the beforeunload hang timer. | |
852 contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
853 | 847 |
854 // Navigate to a URL that redirects to another process and approve the | 848 // Navigate to a URL that redirects to another process and approve the |
855 // beforeunload dialog that pops up. | 849 // beforeunload dialog that pops up. |
856 content::WindowedNotificationObserver nav_observer( | 850 content::WindowedNotificationObserver nav_observer( |
857 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 851 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
858 content::NotificationService::AllSources()); | 852 content::NotificationService::AllSources()); |
859 GURL https_url(https_test_server.GetURL("/title1.html")); | 853 GURL https_url(https_test_server.GetURL("/title1.html")); |
860 GURL redirect_url( | 854 GURL redirect_url( |
861 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); | 855 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); |
862 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), | 856 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), |
863 WindowOpenDisposition::CURRENT_TAB, | 857 WindowOpenDisposition::CURRENT_TAB, |
864 ui::PAGE_TRANSITION_TYPED, false)); | 858 ui::PAGE_TRANSITION_TYPED, false)); |
865 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 859 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
866 EXPECT_TRUE( | 860 EXPECT_TRUE( |
867 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); | 861 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); |
868 alert->native_dialog()->AcceptAppModalDialog(); | 862 alert->native_dialog()->AcceptAppModalDialog(); |
869 nav_observer.Wait(); | 863 nav_observer.Wait(); |
870 | 864 |
871 // Restore previous browser client. | 865 // Restore previous browser client. |
872 SetBrowserClientForTesting(old_client); | 866 SetBrowserClientForTesting(old_client); |
873 } | 867 } |
874 | 868 |
875 // Test for crbug.com/80401. Canceling a before unload dialog should reset | 869 // Test for crbug.com/80401. Canceling a before unload dialog should reset |
876 // the URL to the previous page's URL. | 870 // the URL to the previous page's URL. |
877 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { | 871 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { |
878 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 872 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
879 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); | 873 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); |
880 ui_test_utils::NavigateToURL(browser(), url); | 874 ui_test_utils::NavigateToURL(browser(), url); |
881 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 875 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
882 // Disable the hang monitor, otherwise there will be a race between the | 876 content::PrepContentsForBeforeUnloadTest(contents); |
883 // beforeunload dialog and the beforeunload hang timer. | |
884 contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
885 | 877 |
886 // Navigate to a page that triggers a cross-site transition. | 878 // Navigate to a page that triggers a cross-site transition. |
887 ASSERT_TRUE(embedded_test_server()->Start()); | 879 ASSERT_TRUE(embedded_test_server()->Start()); |
888 GURL url2(embedded_test_server()->GetURL("/title1.html")); | 880 GURL url2(embedded_test_server()->GetURL("/title1.html")); |
889 browser()->OpenURL(OpenURLParams(url2, Referrer(), | 881 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
890 WindowOpenDisposition::CURRENT_TAB, | 882 WindowOpenDisposition::CURRENT_TAB, |
891 ui::PAGE_TRANSITION_TYPED, false)); | 883 ui::PAGE_TRANSITION_TYPED, false)); |
892 | 884 |
893 content::WindowedNotificationObserver host_destroyed_observer( | 885 content::WindowedNotificationObserver host_destroyed_observer( |
894 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 886 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 is_before_unload_dialog()); | 938 is_before_unload_dialog()); |
947 alert->native_dialog()->AcceptAppModalDialog(); | 939 alert->native_dialog()->AcceptAppModalDialog(); |
948 } | 940 } |
949 | 941 |
950 // Test that when a page has an onbeforeunload handler, reloading a page shows a | 942 // Test that when a page has an onbeforeunload handler, reloading a page shows a |
951 // different dialog than navigating to a different page. | 943 // different dialog than navigating to a different page. |
952 IN_PROC_BROWSER_TEST_F(BrowserTest, BeforeUnloadVsBeforeReload) { | 944 IN_PROC_BROWSER_TEST_F(BrowserTest, BeforeUnloadVsBeforeReload) { |
953 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 945 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
954 ui_test_utils::NavigateToURL(browser(), url); | 946 ui_test_utils::NavigateToURL(browser(), url); |
955 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 947 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
956 // Disable the hang monitor, otherwise there will be a race between the | 948 content::PrepContentsForBeforeUnloadTest(contents); |
957 // beforeunload dialog and the beforeunload hang timer. | |
958 contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
959 | 949 |
960 // Reload the page, and check that we get a "before reload" dialog. | 950 // Reload the page, and check that we get a "before reload" dialog. |
961 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 951 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
962 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 952 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
963 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 953 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
964 | 954 |
965 // Cancel the reload. | 955 // Cancel the reload. |
966 FailedCommitWatcher watcher(contents); | 956 FailedCommitWatcher watcher(contents); |
967 alert->native_dialog()->CancelAppModalDialog(); | 957 alert->native_dialog()->CancelAppModalDialog(); |
968 if (content::IsBrowserSideNavigationEnabled()) | 958 if (content::IsBrowserSideNavigationEnabled()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 #endif | 1009 #endif |
1020 } | 1010 } |
1021 }; | 1011 }; |
1022 | 1012 |
1023 // Disabled, http://crbug.com/159214 . | 1013 // Disabled, http://crbug.com/159214 . |
1024 IN_PROC_BROWSER_TEST_F(BeforeUnloadAtQuitWithTwoWindows, | 1014 IN_PROC_BROWSER_TEST_F(BeforeUnloadAtQuitWithTwoWindows, |
1025 DISABLED_IfThisTestTimesOutItIndicatesFAILURE) { | 1015 DISABLED_IfThisTestTimesOutItIndicatesFAILURE) { |
1026 // In the first browser, set up a page that has a beforeunload handler. | 1016 // In the first browser, set up a page that has a beforeunload handler. |
1027 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 1017 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
1028 ui_test_utils::NavigateToURL(browser(), url); | 1018 ui_test_utils::NavigateToURL(browser(), url); |
| 1019 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1020 content::PrepContentsForBeforeUnloadTest(contents); |
1029 | 1021 |
1030 // Open a second browser window at about:blank. | 1022 // Open a second browser window at about:blank. |
1031 ui_test_utils::BrowserAddedObserver browser_added_observer; | 1023 ui_test_utils::BrowserAddedObserver browser_added_observer; |
1032 chrome::NewEmptyWindow(browser()->profile()); | 1024 chrome::NewEmptyWindow(browser()->profile()); |
1033 Browser* second_window = browser_added_observer.WaitForSingleNewBrowser(); | 1025 Browser* second_window = browser_added_observer.WaitForSingleNewBrowser(); |
1034 ui_test_utils::NavigateToURL(second_window, GURL(url::kAboutBlankURL)); | 1026 ui_test_utils::NavigateToURL(second_window, GURL(url::kAboutBlankURL)); |
1035 | 1027 |
1036 // Tell the application to quit. IDC_EXIT calls AttemptUserExit, which on | 1028 // Tell the application to quit. IDC_EXIT calls AttemptUserExit, which on |
1037 // everything but ChromeOS allows unload handlers to block exit. On that | 1029 // everything but ChromeOS allows unload handlers to block exit. On that |
1038 // platform, though, it exits unconditionally. See the comment and bug ID | 1030 // platform, though, it exits unconditionally. See the comment and bug ID |
(...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 Browser* browser = new Browser(params); | 2875 Browser* browser = new Browser(params); |
2884 gfx::Rect bounds = browser->window()->GetBounds(); | 2876 gfx::Rect bounds = browser->window()->GetBounds(); |
2885 | 2877 |
2886 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 2878 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
2887 // See https://crbug.com/567925. | 2879 // See https://crbug.com/567925. |
2888 EXPECT_GE(bounds.width(), 100); | 2880 EXPECT_GE(bounds.width(), 100); |
2889 EXPECT_EQ(122, bounds.height()); | 2881 EXPECT_EQ(122, bounds.height()); |
2890 browser->window()->Close(); | 2882 browser->window()->Close(); |
2891 } | 2883 } |
2892 } | 2884 } |
OLD | NEW |