Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 2901833002: Create NavigationHandle after beforeunload with PlzNavigate. (Closed)
Patch Set: small fix from jam Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/browser_instant_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; 342 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes;
343 RenderViewSizes render_view_sizes_; 343 RenderViewSizes render_view_sizes_;
344 // Enlarge WebContentsView by this size insets in 344 // Enlarge WebContentsView by this size insets in
345 // DidStartNavigation. 345 // DidStartNavigation.
346 gfx::Size wcv_resize_insets_; 346 gfx::Size wcv_resize_insets_;
347 BrowserWindow* browser_window_; // Weak ptr. 347 BrowserWindow* browser_window_; // Weak ptr.
348 348
349 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); 349 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver);
350 }; 350 };
351 351
352 // Waits for a failed commit notification.
353 class FailedCommitWatcher : public content::WebContentsObserver {
354 public:
355 explicit FailedCommitWatcher(content::WebContents* wc)
356 : content::WebContentsObserver(wc) {}
357 void Wait() {
358 run_loop_.Run();
359 }
360
361 private:
362 void DidFinishNavigation(
363 content::NavigationHandle* navigation_handle) override {
364 CHECK(!navigation_handle->HasCommitted());
365 run_loop_.Quit();
366 }
367 base::RunLoop run_loop_;
368 };
369
370 } // namespace 352 } // namespace
371 353
372 class BrowserTest : public ExtensionBrowserTest { 354 class BrowserTest : public ExtensionBrowserTest {
373 protected: 355 protected:
374 void SetUpOnMainThread() override { 356 void SetUpOnMainThread() override {
375 ExtensionBrowserTest::SetUpOnMainThread(); 357 ExtensionBrowserTest::SetUpOnMainThread();
376 host_resolver()->AddRule("*", "127.0.0.1"); 358 host_resolver()->AddRule("*", "127.0.0.1");
377 } 359 }
378 360
379 // In RTL locales wrap the page title with RTL embedding characters so that it 361 // In RTL locales wrap the page title with RTL embedding characters so that it
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); 703 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML);
722 ui_test_utils::NavigateToURL(browser(), url); 704 ui_test_utils::NavigateToURL(browser(), url);
723 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 705 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
724 content::PrepContentsForBeforeUnloadTest(contents); 706 content::PrepContentsForBeforeUnloadTest(contents);
725 707
726 // Navigate to another page, but click cancel in the dialog. Make sure that 708 // Navigate to another page, but click cancel in the dialog. Make sure that
727 // the throbber stops spinning. 709 // the throbber stops spinning.
728 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); 710 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
729 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 711 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
730 712
731 FailedCommitWatcher watcher(contents);
732 alert->CloseModalDialog(); 713 alert->CloseModalDialog();
733 if (content::IsBrowserSideNavigationEnabled())
734 watcher.Wait();
735 EXPECT_FALSE(contents->IsLoading()); 714 EXPECT_FALSE(contents->IsLoading());
736 715
737 // Clear the beforeunload handler so the test can easily exit. 716 // Clear the beforeunload handler so the test can easily exit.
738 contents->GetMainFrame()->ExecuteJavaScriptForTests( 717 contents->GetMainFrame()->ExecuteJavaScriptForTests(
739 ASCIIToUTF16("onbeforeunload=null;")); 718 ASCIIToUTF16("onbeforeunload=null;"));
740 } 719 }
741 720
742 class RedirectObserver : public content::WebContentsObserver { 721 class RedirectObserver : public content::WebContentsObserver {
743 public: 722 public:
744 explicit RedirectObserver(content::WebContents* web_contents) 723 explicit RedirectObserver(content::WebContents* web_contents)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 browser()->OpenURL(OpenURLParams(url2, Referrer(), 860 browser()->OpenURL(OpenURLParams(url2, Referrer(),
882 WindowOpenDisposition::CURRENT_TAB, 861 WindowOpenDisposition::CURRENT_TAB,
883 ui::PAGE_TRANSITION_TYPED, false)); 862 ui::PAGE_TRANSITION_TYPED, false));
884 863
885 content::WindowedNotificationObserver host_destroyed_observer( 864 content::WindowedNotificationObserver host_destroyed_observer(
886 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 865 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
887 content::NotificationService::AllSources()); 866 content::NotificationService::AllSources());
888 867
889 // Cancel the dialog. 868 // Cancel the dialog.
890 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 869 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
891 FailedCommitWatcher watcher(contents);
892 alert->CloseModalDialog(); 870 alert->CloseModalDialog();
893 if (content::IsBrowserSideNavigationEnabled())
894 watcher.Wait();
895 EXPECT_FALSE(contents->IsLoading()); 871 EXPECT_FALSE(contents->IsLoading());
896 872
897 // Verify there are no pending history items after the dialog is cancelled. 873 // Verify there are no pending history items after the dialog is cancelled.
898 // (see crbug.com/93858) 874 // (see crbug.com/93858)
899 NavigationEntry* entry = contents->GetController().GetPendingEntry(); 875 NavigationEntry* entry = contents->GetController().GetPendingEntry();
900 EXPECT_EQ(NULL, entry); 876 EXPECT_EQ(NULL, entry);
901 877
902 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for 878 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for
903 // the pending RVH to be destroyed. 879 // the pending RVH to be destroyed.
904 host_destroyed_observer.Wait(); 880 host_destroyed_observer.Wait();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); 921 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML);
946 ui_test_utils::NavigateToURL(browser(), url); 922 ui_test_utils::NavigateToURL(browser(), url);
947 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 923 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
948 content::PrepContentsForBeforeUnloadTest(contents); 924 content::PrepContentsForBeforeUnloadTest(contents);
949 925
950 // Reload the page, and check that we get a "before reload" dialog. 926 // Reload the page, and check that we get a "before reload" dialog.
951 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); 927 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
952 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 928 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
953 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); 929 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload());
954 930
955 // Cancel the reload. 931 // Proceed with the reload.
956 FailedCommitWatcher watcher(contents); 932 alert->native_dialog()->AcceptAppModalDialog();
957 alert->native_dialog()->CancelAppModalDialog(); 933 EXPECT_TRUE(content::WaitForLoadStop(contents));
958 if (content::IsBrowserSideNavigationEnabled()) 934
959 watcher.Wait(); 935 content::PrepContentsForBeforeUnloadTest(contents);
960 936
961 // Navigate to another url, and check that we get a "before unload" dialog. 937 // Navigate to another url, and check that we get a "before unload" dialog.
962 GURL url2(url::kAboutBlankURL); 938 GURL url2(url::kAboutBlankURL);
963 browser()->OpenURL(OpenURLParams(url2, Referrer(), 939 browser()->OpenURL(OpenURLParams(url2, Referrer(),
964 WindowOpenDisposition::CURRENT_TAB, 940 WindowOpenDisposition::CURRENT_TAB,
965 ui::PAGE_TRANSITION_TYPED, false)); 941 ui::PAGE_TRANSITION_TYPED, false));
966 942
967 alert = ui_test_utils::WaitForAppModalDialog(); 943 alert = ui_test_utils::WaitForAppModalDialog();
968 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); 944 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload());
969 945
(...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 Browser* browser = new Browser(params); 2851 Browser* browser = new Browser(params);
2876 gfx::Rect bounds = browser->window()->GetBounds(); 2852 gfx::Rect bounds = browser->window()->GetBounds();
2877 2853
2878 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2854 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2879 // See https://crbug.com/567925. 2855 // See https://crbug.com/567925.
2880 EXPECT_GE(bounds.width(), 100); 2856 EXPECT_GE(bounds.width(), 100);
2881 EXPECT_EQ(122, bounds.height()); 2857 EXPECT_EQ(122, bounds.height());
2882 browser->window()->Close(); 2858 browser->window()->Close();
2883 } 2859 }
2884 } 2860 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser_instant_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698