| 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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 } | 613 } |
| 614 | 614 |
| 615 // Make sure that dialogs are closed after a renderer process dies, and that | 615 // Make sure that dialogs are closed after a renderer process dies, and that |
| 616 // subsequent navigations work. See http://crbug/com/343265. | 616 // subsequent navigations work. See http://crbug/com/343265. |
| 617 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { | 617 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { |
| 618 ASSERT_TRUE(embedded_test_server()->Start()); | 618 ASSERT_TRUE(embedded_test_server()->Start()); |
| 619 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 619 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 620 GURL beforeunload_url(embedded_test_server()->GetURL("/beforeunload.html")); | 620 GURL beforeunload_url(embedded_test_server()->GetURL("/beforeunload.html")); |
| 621 ui_test_utils::NavigateToURL(browser(), beforeunload_url); | 621 ui_test_utils::NavigateToURL(browser(), beforeunload_url); |
| 622 | 622 |
| 623 // JavaScript onbeforeunload dialogs require a user gesture. |
| 624 for (auto* frame : |
| 625 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 626 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 627 } |
| 628 |
| 623 // Start a navigation to trigger the beforeunload dialog. | 629 // Start a navigation to trigger the beforeunload dialog. |
| 624 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 630 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 625 contents->GetMainFrame()->ExecuteJavaScriptForTests( | 631 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
| 626 ASCIIToUTF16("window.location.href = 'about:blank'")); | 632 ASCIIToUTF16("window.location.href = 'about:blank'")); |
| 627 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 633 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 628 EXPECT_TRUE(alert->IsValid()); | 634 EXPECT_TRUE(alert->IsValid()); |
| 629 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 635 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
| 630 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 636 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
| 631 | 637 |
| 632 // Crash the renderer process and ensure the dialog is gone. | 638 // Crash the renderer process and ensure the dialog is gone. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 705 |
| 700 interstitial->DontProceed(); | 706 interstitial->DontProceed(); |
| 701 } | 707 } |
| 702 | 708 |
| 703 // Test for crbug.com/22004. Reloading a page with a before unload handler and | 709 // Test for crbug.com/22004. Reloading a page with a before unload handler and |
| 704 // then canceling the dialog should not leave the throbber spinning. | 710 // then canceling the dialog should not leave the throbber spinning. |
| 705 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { | 711 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { |
| 706 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 712 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 707 ui_test_utils::NavigateToURL(browser(), url); | 713 ui_test_utils::NavigateToURL(browser(), url); |
| 708 | 714 |
| 715 // JavaScript onbeforeunload dialogs require a user gesture. |
| 716 for (auto* frame : |
| 717 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 718 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 719 } |
| 720 |
| 709 // Navigate to another page, but click cancel in the dialog. Make sure that | 721 // Navigate to another page, but click cancel in the dialog. Make sure that |
| 710 // the throbber stops spinning. | 722 // the throbber stops spinning. |
| 711 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 723 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 712 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 724 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 713 | 725 |
| 714 FailedCommitWatcher watcher( | 726 FailedCommitWatcher watcher( |
| 715 browser()->tab_strip_model()->GetActiveWebContents()); | 727 browser()->tab_strip_model()->GetActiveWebContents()); |
| 716 alert->CloseModalDialog(); | 728 alert->CloseModalDialog(); |
| 717 if (content::IsBrowserSideNavigationEnabled()) | 729 if (content::IsBrowserSideNavigationEnabled()) |
| 718 watcher.Wait(); | 730 watcher.Wait(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 // Temporarily replace ContentBrowserClient with one that will cause a | 833 // Temporarily replace ContentBrowserClient with one that will cause a |
| 822 // process swap on all redirects to HTTPS URLs. | 834 // process swap on all redirects to HTTPS URLs. |
| 823 TransferHttpsRedirectsContentBrowserClient new_client; | 835 TransferHttpsRedirectsContentBrowserClient new_client; |
| 824 content::ContentBrowserClient* old_client = | 836 content::ContentBrowserClient* old_client = |
| 825 SetBrowserClientForTesting(&new_client); | 837 SetBrowserClientForTesting(&new_client); |
| 826 | 838 |
| 827 // Navigate to a page with a beforeunload handler. | 839 // Navigate to a page with a beforeunload handler. |
| 828 GURL url(embedded_test_server()->GetURL("/beforeunload.html")); | 840 GURL url(embedded_test_server()->GetURL("/beforeunload.html")); |
| 829 ui_test_utils::NavigateToURL(browser(), url); | 841 ui_test_utils::NavigateToURL(browser(), url); |
| 830 | 842 |
| 843 // JavaScript onbeforeunload dialogs require a user gesture. |
| 844 for (auto* frame : |
| 845 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 846 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 847 } |
| 848 |
| 831 // Navigate to a URL that redirects to another process and approve the | 849 // Navigate to a URL that redirects to another process and approve the |
| 832 // beforeunload dialog that pops up. | 850 // beforeunload dialog that pops up. |
| 833 content::WindowedNotificationObserver nav_observer( | 851 content::WindowedNotificationObserver nav_observer( |
| 834 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 852 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 835 content::NotificationService::AllSources()); | 853 content::NotificationService::AllSources()); |
| 836 GURL https_url(https_test_server.GetURL("/title1.html")); | 854 GURL https_url(https_test_server.GetURL("/title1.html")); |
| 837 GURL redirect_url( | 855 GURL redirect_url( |
| 838 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); | 856 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); |
| 839 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), | 857 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), |
| 840 WindowOpenDisposition::CURRENT_TAB, | 858 WindowOpenDisposition::CURRENT_TAB, |
| 841 ui::PAGE_TRANSITION_TYPED, false)); | 859 ui::PAGE_TRANSITION_TYPED, false)); |
| 842 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 860 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 843 EXPECT_TRUE( | 861 EXPECT_TRUE( |
| 844 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); | 862 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); |
| 845 alert->native_dialog()->AcceptAppModalDialog(); | 863 alert->native_dialog()->AcceptAppModalDialog(); |
| 846 nav_observer.Wait(); | 864 nav_observer.Wait(); |
| 847 | 865 |
| 848 // Restore previous browser client. | 866 // Restore previous browser client. |
| 849 SetBrowserClientForTesting(old_client); | 867 SetBrowserClientForTesting(old_client); |
| 850 } | 868 } |
| 851 | 869 |
| 852 // Test for crbug.com/80401. Canceling a before unload dialog should reset | 870 // Test for crbug.com/80401. Canceling a before unload dialog should reset |
| 853 // the URL to the previous page's URL. | 871 // the URL to the previous page's URL. |
| 854 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { | 872 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { |
| 855 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 873 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
| 856 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); | 874 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); |
| 857 ui_test_utils::NavigateToURL(browser(), url); | 875 ui_test_utils::NavigateToURL(browser(), url); |
| 858 | 876 |
| 877 // JavaScript onbeforeunload dialogs require a user gesture. |
| 878 for (auto* frame : |
| 879 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 880 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 881 } |
| 882 |
| 859 // Navigate to a page that triggers a cross-site transition. | 883 // Navigate to a page that triggers a cross-site transition. |
| 860 ASSERT_TRUE(embedded_test_server()->Start()); | 884 ASSERT_TRUE(embedded_test_server()->Start()); |
| 861 GURL url2(embedded_test_server()->GetURL("/title1.html")); | 885 GURL url2(embedded_test_server()->GetURL("/title1.html")); |
| 862 browser()->OpenURL(OpenURLParams(url2, Referrer(), | 886 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
| 863 WindowOpenDisposition::CURRENT_TAB, | 887 WindowOpenDisposition::CURRENT_TAB, |
| 864 ui::PAGE_TRANSITION_TYPED, false)); | 888 ui::PAGE_TRANSITION_TYPED, false)); |
| 865 | 889 |
| 866 content::WindowedNotificationObserver host_destroyed_observer( | 890 content::WindowedNotificationObserver host_destroyed_observer( |
| 867 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 891 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 868 content::NotificationService::AllSources()); | 892 content::NotificationService::AllSources()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 #else | 954 #else |
| 931 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload | 955 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload |
| 932 #endif | 956 #endif |
| 933 | 957 |
| 934 // Test that when a page has an onbeforeunload handler, reloading a page shows a | 958 // Test that when a page has an onbeforeunload handler, reloading a page shows a |
| 935 // different dialog than navigating to a different page. | 959 // different dialog than navigating to a different page. |
| 936 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { | 960 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { |
| 937 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 961 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 938 ui_test_utils::NavigateToURL(browser(), url); | 962 ui_test_utils::NavigateToURL(browser(), url); |
| 939 | 963 |
| 964 // JavaScript onbeforeunload dialogs require a user gesture. |
| 965 for (auto* frame : |
| 966 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 967 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 968 } |
| 969 |
| 940 // Reload the page, and check that we get a "before reload" dialog. | 970 // Reload the page, and check that we get a "before reload" dialog. |
| 941 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 971 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 942 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 972 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 943 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 973 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| 944 | 974 |
| 945 // Cancel the reload. | 975 // Cancel the reload. |
| 946 FailedCommitWatcher watcher( | 976 FailedCommitWatcher watcher( |
| 947 browser()->tab_strip_model()->GetActiveWebContents()); | 977 browser()->tab_strip_model()->GetActiveWebContents()); |
| 948 alert->native_dialog()->CancelAppModalDialog(); | 978 alert->native_dialog()->CancelAppModalDialog(); |
| 949 if (content::IsBrowserSideNavigationEnabled()) | 979 if (content::IsBrowserSideNavigationEnabled()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } | 1031 } |
| 1002 }; | 1032 }; |
| 1003 | 1033 |
| 1004 // Disabled, http://crbug.com/159214 . | 1034 // Disabled, http://crbug.com/159214 . |
| 1005 IN_PROC_BROWSER_TEST_F(BeforeUnloadAtQuitWithTwoWindows, | 1035 IN_PROC_BROWSER_TEST_F(BeforeUnloadAtQuitWithTwoWindows, |
| 1006 DISABLED_IfThisTestTimesOutItIndicatesFAILURE) { | 1036 DISABLED_IfThisTestTimesOutItIndicatesFAILURE) { |
| 1007 // In the first browser, set up a page that has a beforeunload handler. | 1037 // In the first browser, set up a page that has a beforeunload handler. |
| 1008 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 1038 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 1009 ui_test_utils::NavigateToURL(browser(), url); | 1039 ui_test_utils::NavigateToURL(browser(), url); |
| 1010 | 1040 |
| 1041 // JavaScript onbeforeunload dialogs require a user gesture. |
| 1042 for (auto* frame : |
| 1043 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) { |
| 1044 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 1045 } |
| 1046 |
| 1011 // Open a second browser window at about:blank. | 1047 // Open a second browser window at about:blank. |
| 1012 ui_test_utils::BrowserAddedObserver browser_added_observer; | 1048 ui_test_utils::BrowserAddedObserver browser_added_observer; |
| 1013 chrome::NewEmptyWindow(browser()->profile()); | 1049 chrome::NewEmptyWindow(browser()->profile()); |
| 1014 Browser* second_window = browser_added_observer.WaitForSingleNewBrowser(); | 1050 Browser* second_window = browser_added_observer.WaitForSingleNewBrowser(); |
| 1015 ui_test_utils::NavigateToURL(second_window, GURL(url::kAboutBlankURL)); | 1051 ui_test_utils::NavigateToURL(second_window, GURL(url::kAboutBlankURL)); |
| 1016 | 1052 |
| 1017 // Tell the application to quit. IDC_EXIT calls AttemptUserExit, which on | 1053 // Tell the application to quit. IDC_EXIT calls AttemptUserExit, which on |
| 1018 // everything but ChromeOS allows unload handlers to block exit. On that | 1054 // everything but ChromeOS allows unload handlers to block exit. On that |
| 1019 // platform, though, it exits unconditionally. See the comment and bug ID | 1055 // platform, though, it exits unconditionally. See the comment and bug ID |
| 1020 // in AttemptUserExit() in application_lifetime.cc. | 1056 // in AttemptUserExit() in application_lifetime.cc. |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2995 Browser* browser = new Browser(params); | 3031 Browser* browser = new Browser(params); |
| 2996 gfx::Rect bounds = browser->window()->GetBounds(); | 3032 gfx::Rect bounds = browser->window()->GetBounds(); |
| 2997 | 3033 |
| 2998 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 3034 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
| 2999 // See https://crbug.com/567925. | 3035 // See https://crbug.com/567925. |
| 3000 EXPECT_GE(bounds.width(), 100); | 3036 EXPECT_GE(bounds.width(), 100); |
| 3001 EXPECT_EQ(122, bounds.height()); | 3037 EXPECT_EQ(122, bounds.height()); |
| 3002 browser->window()->Close(); | 3038 browser->window()->Close(); |
| 3003 } | 3039 } |
| 3004 } | 3040 } |
| OLD | NEW |