Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 #include "components/content_settings/core/browser/host_content_settings_map.h" | 76 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 77 #include "components/prefs/pref_service.h" | 77 #include "components/prefs/pref_service.h" |
| 78 #include "components/sessions/core/base_session_service_test_helper.h" | 78 #include "components/sessions/core/base_session_service_test_helper.h" |
| 79 #include "components/translate/core/browser/language_state.h" | 79 #include "components/translate/core/browser/language_state.h" |
| 80 #include "components/translate/core/common/language_detection_details.h" | 80 #include "components/translate/core/common/language_detection_details.h" |
| 81 #include "content/public/browser/favicon_status.h" | 81 #include "content/public/browser/favicon_status.h" |
| 82 #include "content/public/browser/host_zoom_map.h" | 82 #include "content/public/browser/host_zoom_map.h" |
| 83 #include "content/public/browser/interstitial_page.h" | 83 #include "content/public/browser/interstitial_page.h" |
| 84 #include "content/public/browser/interstitial_page_delegate.h" | 84 #include "content/public/browser/interstitial_page_delegate.h" |
| 85 #include "content/public/browser/navigation_entry.h" | 85 #include "content/public/browser/navigation_entry.h" |
| 86 #include "content/public/browser/navigation_handle.h" | |
| 86 #include "content/public/browser/notification_service.h" | 87 #include "content/public/browser/notification_service.h" |
| 87 #include "content/public/browser/reload_type.h" | 88 #include "content/public/browser/reload_type.h" |
| 88 #include "content/public/browser/render_frame_host.h" | 89 #include "content/public/browser/render_frame_host.h" |
| 89 #include "content/public/browser/render_process_host.h" | 90 #include "content/public/browser/render_process_host.h" |
| 90 #include "content/public/browser/render_view_host.h" | 91 #include "content/public/browser/render_view_host.h" |
| 91 #include "content/public/browser/render_widget_host.h" | 92 #include "content/public/browser/render_widget_host.h" |
| 92 #include "content/public/browser/render_widget_host_view.h" | 93 #include "content/public/browser/render_widget_host_view.h" |
| 93 #include "content/public/browser/resource_context.h" | 94 #include "content/public/browser/resource_context.h" |
| 94 #include "content/public/browser/ssl_status.h" | 95 #include "content/public/browser/ssl_status.h" |
| 95 #include "content/public/browser/web_contents.h" | 96 #include "content/public/browser/web_contents.h" |
| 96 #include "content/public/browser/web_contents_observer.h" | 97 #include "content/public/browser/web_contents_observer.h" |
| 98 #include "content/public/common/browser_side_navigation_policy.h" | |
| 97 #include "content/public/common/frame_navigate_params.h" | 99 #include "content/public/common/frame_navigate_params.h" |
| 98 #include "content/public/common/renderer_preferences.h" | 100 #include "content/public/common/renderer_preferences.h" |
| 99 #include "content/public/common/url_constants.h" | 101 #include "content/public/common/url_constants.h" |
| 100 #include "content/public/test/browser_test_utils.h" | 102 #include "content/public/test/browser_test_utils.h" |
| 101 #include "content/public/test/test_navigation_observer.h" | 103 #include "content/public/test/test_navigation_observer.h" |
| 102 #include "extensions/browser/extension_registry.h" | 104 #include "extensions/browser/extension_registry.h" |
| 103 #include "extensions/browser/extension_system.h" | 105 #include "extensions/browser/extension_system.h" |
| 104 #include "extensions/browser/uninstall_reason.h" | 106 #include "extensions/browser/uninstall_reason.h" |
| 105 #include "extensions/common/constants.h" | 107 #include "extensions/common/constants.h" |
| 106 #include "extensions/common/extension.h" | 108 #include "extensions/common/extension.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; | 327 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; |
| 326 RenderViewSizes render_view_sizes_; | 328 RenderViewSizes render_view_sizes_; |
| 327 // Enlarge WebContentsView by this size insets in | 329 // Enlarge WebContentsView by this size insets in |
| 328 // DidStartNavigationToPendingEntry. | 330 // DidStartNavigationToPendingEntry. |
| 329 gfx::Size wcv_resize_insets_; | 331 gfx::Size wcv_resize_insets_; |
| 330 BrowserWindow* browser_window_; // Weak ptr. | 332 BrowserWindow* browser_window_; // Weak ptr. |
| 331 | 333 |
| 332 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); | 334 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); |
| 333 }; | 335 }; |
| 334 | 336 |
| 337 // Waits for a failed commit notification. | |
| 338 class FailedCommitWatcher : public content::WebContentsObserver { | |
| 339 public: | |
| 340 explicit FailedCommitWatcher(content::WebContents* wc) | |
| 341 : content::WebContentsObserver(wc) {} | |
| 342 void Wait() { | |
| 343 run_loop_.Run(); | |
| 344 } | |
| 345 | |
| 346 private: | |
| 347 void DidFinishNavigation( | |
| 348 content::NavigationHandle* navigation_handle) override { | |
| 349 CHECK(!navigation_handle->HasCommitted()); | |
| 350 run_loop_.Quit(); | |
| 351 } | |
| 352 base::RunLoop run_loop_; | |
| 353 }; | |
| 354 | |
| 335 } // namespace | 355 } // namespace |
| 336 | 356 |
| 337 class BrowserTest : public ExtensionBrowserTest { | 357 class BrowserTest : public ExtensionBrowserTest { |
| 338 protected: | 358 protected: |
| 339 // In RTL locales wrap the page title with RTL embedding characters so that it | 359 // In RTL locales wrap the page title with RTL embedding characters so that it |
| 340 // matches the value returned by GetWindowTitle(). | 360 // matches the value returned by GetWindowTitle(). |
| 341 base::string16 LocaleWindowCaptionFromPageTitle( | 361 base::string16 LocaleWindowCaptionFromPageTitle( |
| 342 const base::string16& expected_title) { | 362 const base::string16& expected_title) { |
| 343 base::string16 page_title = WindowCaptionFromPageTitle(expected_title); | 363 base::string16 page_title = WindowCaptionFromPageTitle(expected_title); |
| 344 #if defined(OS_WIN) | 364 #if defined(OS_WIN) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 // Test for crbug.com/22004. Reloading a page with a before unload handler and | 685 // Test for crbug.com/22004. Reloading a page with a before unload handler and |
| 666 // then canceling the dialog should not leave the throbber spinning. | 686 // then canceling the dialog should not leave the throbber spinning. |
| 667 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { | 687 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { |
| 668 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 688 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 669 ui_test_utils::NavigateToURL(browser(), url); | 689 ui_test_utils::NavigateToURL(browser(), url); |
| 670 | 690 |
| 671 // Navigate to another page, but click cancel in the dialog. Make sure that | 691 // Navigate to another page, but click cancel in the dialog. Make sure that |
| 672 // the throbber stops spinning. | 692 // the throbber stops spinning. |
| 673 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 693 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 674 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 694 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 695 | |
| 696 FailedCommitWatcher watcher( | |
| 697 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 675 alert->CloseModalDialog(); | 698 alert->CloseModalDialog(); |
| 699 if (content::IsBrowserSideNavigationEnabled()) | |
| 700 watcher.Wait(); | |
| 676 EXPECT_FALSE( | 701 EXPECT_FALSE( |
| 677 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); | 702 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| 678 | 703 |
| 679 // Clear the beforeunload handler so the test can easily exit. | 704 // Clear the beforeunload handler so the test can easily exit. |
| 680 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 705 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
| 681 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); | 706 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); |
| 682 } | 707 } |
| 683 | 708 |
| 684 class RedirectObserver : public content::WebContentsObserver { | 709 class RedirectObserver : public content::WebContentsObserver { |
| 685 public: | 710 public: |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 browser()->OpenURL(OpenURLParams(url2, Referrer(), | 842 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
| 818 WindowOpenDisposition::CURRENT_TAB, | 843 WindowOpenDisposition::CURRENT_TAB, |
| 819 ui::PAGE_TRANSITION_TYPED, false)); | 844 ui::PAGE_TRANSITION_TYPED, false)); |
| 820 | 845 |
| 821 content::WindowedNotificationObserver host_destroyed_observer( | 846 content::WindowedNotificationObserver host_destroyed_observer( |
| 822 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 847 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 823 content::NotificationService::AllSources()); | 848 content::NotificationService::AllSources()); |
| 824 | 849 |
| 825 // Cancel the dialog. | 850 // Cancel the dialog. |
| 826 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 851 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 852 FailedCommitWatcher watcher( | |
| 853 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 827 alert->CloseModalDialog(); | 854 alert->CloseModalDialog(); |
| 855 if (content::IsBrowserSideNavigationEnabled()) | |
| 856 watcher.Wait(); | |
| 828 EXPECT_FALSE( | 857 EXPECT_FALSE( |
| 829 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); | 858 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| 830 | 859 |
| 831 // Verify there are no pending history items after the dialog is cancelled. | 860 // Verify there are no pending history items after the dialog is cancelled. |
| 832 // (see crbug.com/93858) | 861 // (see crbug.com/93858) |
| 833 NavigationEntry* entry = browser()->tab_strip_model()-> | 862 NavigationEntry* entry = browser()->tab_strip_model()-> |
| 834 GetActiveWebContents()->GetController().GetPendingEntry(); | 863 GetActiveWebContents()->GetController().GetPendingEntry(); |
| 835 EXPECT_EQ(NULL, entry); | 864 EXPECT_EQ(NULL, entry); |
| 836 | 865 |
| 837 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for | 866 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 } | 904 } |
| 876 | 905 |
| 877 // BrowserTest.BeforeUnloadVsBeforeReload times out on Windows. | 906 // BrowserTest.BeforeUnloadVsBeforeReload times out on Windows. |
| 878 // http://crbug.com/130411 | 907 // http://crbug.com/130411 |
| 879 #if defined(OS_WIN) | 908 #if defined(OS_WIN) |
| 880 #define MAYBE_BeforeUnloadVsBeforeReload DISABLED_BeforeUnloadVsBeforeReload | 909 #define MAYBE_BeforeUnloadVsBeforeReload DISABLED_BeforeUnloadVsBeforeReload |
| 881 #else | 910 #else |
| 882 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload | 911 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload |
| 883 #endif | 912 #endif |
| 884 | 913 |
| 885 // Test that when a page has an onunload handler, reloading a page shows a | 914 // Test that when a page has an onunload handler, reloading a page shows a |
|
Charlie Reis
2016/09/30 17:36:10
nit: onbeforeunload? (Looks like a typo from long
jam
2016/09/30 22:42:07
Done.
| |
| 886 // different dialog than navigating to a different page. | 915 // different dialog than navigating to a different page. |
| 887 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { | 916 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { |
| 888 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 917 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 889 ui_test_utils::NavigateToURL(browser(), url); | 918 ui_test_utils::NavigateToURL(browser(), url); |
| 890 | 919 |
| 891 // Reload the page, and check that we get a "before reload" dialog. | 920 // Reload the page, and check that we get a "before reload" dialog. |
| 892 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 921 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 893 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 922 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 894 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 923 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| 895 | 924 |
| 896 // Cancel the reload. | 925 // Cancel the reload. Wait for the ack from the renderer because the OpenURL |
| 926 // call below tries to put up an unload dialog synchronously in the | |
|
Charlie Reis
2016/09/30 17:36:10
nit: a beforeunload dialog
Also, I'm curious abou
jam
2016/09/30 22:42:07
I don't actually remember why I wrote it that way.
| |
| 927 // PlzNavigate case. | |
| 928 FailedCommitWatcher watcher( | |
| 929 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 897 alert->native_dialog()->CancelAppModalDialog(); | 930 alert->native_dialog()->CancelAppModalDialog(); |
| 931 if (content::IsBrowserSideNavigationEnabled()) | |
| 932 watcher.Wait(); | |
| 898 | 933 |
| 899 // Navigate to another url, and check that we get a "before unload" dialog. | 934 // Navigate to another url, and check that we get a "before unload" dialog. |
| 900 GURL url2(url::kAboutBlankURL); | 935 GURL url2(url::kAboutBlankURL); |
| 901 browser()->OpenURL(OpenURLParams(url2, Referrer(), | 936 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
| 902 WindowOpenDisposition::CURRENT_TAB, | 937 WindowOpenDisposition::CURRENT_TAB, |
| 903 ui::PAGE_TRANSITION_TYPED, false)); | 938 ui::PAGE_TRANSITION_TYPED, false)); |
| 904 | 939 |
| 905 alert = ui_test_utils::WaitForAppModalDialog(); | 940 alert = ui_test_utils::WaitForAppModalDialog(); |
| 906 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 941 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| 907 | 942 |
| (...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2848 Browser* browser = new Browser(params); | 2883 Browser* browser = new Browser(params); |
| 2849 gfx::Rect bounds = browser->window()->GetBounds(); | 2884 gfx::Rect bounds = browser->window()->GetBounds(); |
| 2850 | 2885 |
| 2851 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 2886 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
| 2852 // See https://crbug.com/567925. | 2887 // See https://crbug.com/567925. |
| 2853 EXPECT_GE(bounds.width(), 100); | 2888 EXPECT_GE(bounds.width(), 100); |
| 2854 EXPECT_EQ(122, bounds.height()); | 2889 EXPECT_EQ(122, bounds.height()); |
| 2855 browser->window()->Close(); | 2890 browser->window()->Close(); |
| 2856 } | 2891 } |
| 2857 } | 2892 } |
| OLD | NEW |