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

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

Issue 2674163002: Convert BrowserTest.NoStopDuringTransferUntilCommit to use the new navigation callbacks. (Closed)
Patch Set: Created 3 years, 10 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 | no next file » | 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 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); 714 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading());
715 715
716 // Clear the beforeunload handler so the test can easily exit. 716 // Clear the beforeunload handler so the test can easily exit.
717 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> 717 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
718 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); 718 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;"));
719 } 719 }
720 720
721 class RedirectObserver : public content::WebContentsObserver { 721 class RedirectObserver : public content::WebContentsObserver {
722 public: 722 public:
723 explicit RedirectObserver(content::WebContents* web_contents) 723 explicit RedirectObserver(content::WebContents* web_contents)
724 : WebContentsObserver(web_contents) { 724 : WebContentsObserver(web_contents),
725 transition_(ui::PageTransition::PAGE_TRANSITION_LINK) {
725 } 726 }
726 727
727 void DidNavigateAnyFrame( 728 void DidFinishNavigation(
728 content::RenderFrameHost* render_frame_host, 729 content::NavigationHandle* navigation_handle) override {
729 const content::LoadCommittedDetails& details, 730 if (!navigation_handle->HasCommitted())
730 const content::FrameNavigateParams& params) override { 731 return;
731 params_ = params; 732 transition_ = navigation_handle->GetPageTransition();
733 redirects_ = navigation_handle->GetRedirectChain();
732 } 734 }
733 735
734 void WebContentsDestroyed() override { 736 void WebContentsDestroyed() override {
735 // Make sure we don't close the tab while the observer is in scope. 737 // Make sure we don't close the tab while the observer is in scope.
736 // See http://crbug.com/314036. 738 // See http://crbug.com/314036.
737 FAIL() << "WebContents closed during navigation (http://crbug.com/314036)."; 739 FAIL() << "WebContents closed during navigation (http://crbug.com/314036).";
738 } 740 }
739 741
740 const content::FrameNavigateParams& params() const { 742 ui::PageTransition transition() const { return transition_; }
741 return params_; 743 const std::vector<GURL> redirects() const { return redirects_; }
742 }
743 744
744 private: 745 private:
745 content::FrameNavigateParams params_; 746 ui::PageTransition transition_;
747 std::vector<GURL> redirects_;
746 748
747 DISALLOW_COPY_AND_ASSIGN(RedirectObserver); 749 DISALLOW_COPY_AND_ASSIGN(RedirectObserver);
748 }; 750 };
749 751
750 // Ensure that a transferred cross-process navigation does not generate 752 // Ensure that a transferred cross-process navigation does not generate
751 // DidStopLoading events until the navigation commits. If it did, then 753 // DidStopLoading events until the navigation commits. If it did, then
752 // ui_test_utils::NavigateToURL would proceed before the URL had committed. 754 // ui_test_utils::NavigateToURL would proceed before the URL had committed.
753 // http://crbug.com/243957. 755 // http://crbug.com/243957.
754 IN_PROC_BROWSER_TEST_F(BrowserTest, NoStopDuringTransferUntilCommit) { 756 IN_PROC_BROWSER_TEST_F(BrowserTest, NoStopDuringTransferUntilCommit) {
755 // Create HTTP and HTTPS servers for a cross-site transition. 757 // Create HTTP and HTTPS servers for a cross-site transition.
(...skipping 26 matching lines...) Expand all
782 // We should immediately see the new committed entry. 784 // We should immediately see the new committed entry.
783 EXPECT_FALSE(contents->GetController().GetPendingEntry()); 785 EXPECT_FALSE(contents->GetController().GetPendingEntry());
784 EXPECT_EQ(dest_url, 786 EXPECT_EQ(dest_url,
785 contents->GetController().GetLastCommittedEntry()->GetURL()); 787 contents->GetController().GetLastCommittedEntry()->GetURL());
786 788
787 // We should keep track of the original request URL, redirect chain, and 789 // We should keep track of the original request URL, redirect chain, and
788 // page transition type during a transfer, since these are necessary for 790 // page transition type during a transfer, since these are necessary for
789 // history autocomplete to work. 791 // history autocomplete to work.
790 EXPECT_EQ(redirect_url, contents->GetController().GetLastCommittedEntry()-> 792 EXPECT_EQ(redirect_url, contents->GetController().GetLastCommittedEntry()->
791 GetOriginalRequestURL()); 793 GetOriginalRequestURL());
792 EXPECT_EQ(2U, redirect_observer.params().redirects.size()); 794 EXPECT_EQ(2U, redirect_observer.redirects().size());
793 EXPECT_EQ(redirect_url, redirect_observer.params().redirects.at(0)); 795 EXPECT_EQ(redirect_url, redirect_observer.redirects().at(0));
794 EXPECT_EQ(dest_url, redirect_observer.params().redirects.at(1)); 796 EXPECT_EQ(dest_url, redirect_observer.redirects().at(1));
795 EXPECT_TRUE(ui::PageTransitionCoreTypeIs( 797 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(
796 redirect_observer.params().transition, ui::PAGE_TRANSITION_TYPED)); 798 redirect_observer.transition(), ui::PAGE_TRANSITION_TYPED));
797 } 799 }
798 800
799 // Restore previous browser client. 801 // Restore previous browser client.
800 SetBrowserClientForTesting(old_client); 802 SetBrowserClientForTesting(old_client);
801 } 803 }
802 804
803 // Tests that a cross-process redirect will only cause the beforeunload 805 // Tests that a cross-process redirect will only cause the beforeunload
804 // handler to run once. 806 // handler to run once.
805 IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterRedirect) { 807 IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterRedirect) {
806 // Create HTTP and HTTPS servers for a cross-site transition. 808 // Create HTTP and HTTPS servers for a cross-site transition.
(...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 Browser* browser = new Browser(params); 2935 Browser* browser = new Browser(params);
2934 gfx::Rect bounds = browser->window()->GetBounds(); 2936 gfx::Rect bounds = browser->window()->GetBounds();
2935 2937
2936 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2938 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2937 // See https://crbug.com/567925. 2939 // See https://crbug.com/567925.
2938 EXPECT_GE(bounds.width(), 100); 2940 EXPECT_GE(bounds.width(), 100);
2939 EXPECT_EQ(122, bounds.height()); 2941 EXPECT_EQ(122, bounds.height());
2940 browser->window()->Close(); 2942 browser->window()->Close();
2941 } 2943 }
2942 } 2944 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698