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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 1794513003: Don't rely on the pending NavigationEntry for location.replace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 678 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
679 NavigationEntry* entry = controller.GetLastCommittedEntry(); 679 NavigationEntry* entry = controller.GetLastCommittedEntry();
680 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); 680 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
681 EXPECT_EQ(2, controller.GetEntryCount()); 681 EXPECT_EQ(2, controller.GetEntryCount());
682 } 682 }
683 683
684 // Make a new entry ... 684 // Make a new entry ...
685 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 685 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
686 EXPECT_EQ(3, controller.GetEntryCount()); 686 EXPECT_EQ(3, controller.GetEntryCount());
687 687
688 // ... and replace it with a failed load. (Note that when you set the 688 // ... and replace it with a failed load.
689 // should_replace_current_entry flag, the navigation is classified as NEW_PAGE 689 // TODO(creis): Make this be NEW_PAGE along with the other location.replace
690 // because that is a classification of the renderer's behavior, and the flag 690 // cases. There isn't much impact to having this be EXISTING_PAGE for now.
691 // is a browser-side flag.) 691 // See https://crbug.com/317872.
692 { 692 {
693 FrameNavigateParamsCapturer capturer(root); 693 FrameNavigateParamsCapturer capturer(root);
694 NavigateToURLAndReplace(shell(), error_url); 694 NavigateToURLAndReplace(shell(), error_url);
695 capturer.Wait(); 695 capturer.Wait();
696 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); 696 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
697 NavigationEntry* entry = controller.GetLastCommittedEntry(); 697 NavigationEntry* entry = controller.GetLastCommittedEntry();
698 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); 698 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
699 EXPECT_EQ(3, controller.GetEntryCount()); 699 EXPECT_EQ(3, controller.GetEntryCount());
700 } 700 }
701 701
702 // Make a new web ui page to force a process swap ... 702 // Make a new web ui page to force a process swap ...
703 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + 703 GURL web_ui_page(std::string(kChromeUIScheme) + "://" +
704 std::string(kChromeUIGpuHost)); 704 std::string(kChromeUIGpuHost));
705 NavigateToURL(shell(), web_ui_page); 705 NavigateToURL(shell(), web_ui_page);
706 EXPECT_EQ(4, controller.GetEntryCount()); 706 EXPECT_EQ(4, controller.GetEntryCount());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 FrameNavigateParamsCapturer capturer(root); 786 FrameNavigateParamsCapturer capturer(root);
787 std::string script = 787 std::string script =
788 "history.pushState({}, 'page 1', 'simple_page_1.html')"; 788 "history.pushState({}, 'page 1', 'simple_page_1.html')";
789 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 789 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
790 capturer.Wait(); 790 capturer.Wait();
791 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, 791 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
792 capturer.params().transition); 792 capturer.params().transition);
793 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); 793 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
794 EXPECT_TRUE(capturer.details().is_in_page); 794 EXPECT_TRUE(capturer.details().is_in_page);
795 } 795 }
796
797 if (AreAllSitesIsolatedForTesting()) {
798 // Cross-process location.replace().
799 FrameNavigateParamsCapturer capturer(root);
800 GURL frame_url(embedded_test_server()->GetURL(
801 "foo.com", "/navigation_controller/simple_page_1.html"));
802 std::string script = "location.replace('" + frame_url.spec() + "')";
803 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
804 capturer.Wait();
805 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
806 capturer.params().transition);
807 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
808 EXPECT_FALSE(capturer.details().is_in_page);
809 }
796 } 810 }
797 811
798 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly 812 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly
799 // classified. 813 // classified.
800 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 814 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
801 NavigationTypeClassification_ExistingPage) { 815 NavigationTypeClassification_ExistingPage) {
802 GURL url1(embedded_test_server()->GetURL( 816 GURL url1(embedded_test_server()->GetURL(
803 "/navigation_controller/simple_page_1.html")); 817 "/navigation_controller/simple_page_1.html"));
804 NavigateToURL(shell(), url1); 818 NavigateToURL(shell(), url1);
805 GURL url2(embedded_test_server()->GetURL( 819 GURL url2(embedded_test_server()->GetURL(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 "location.reload()")); 923 "location.reload()"));
910 capturer.Wait(); 924 capturer.Wait();
911 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, 925 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
912 capturer.params().transition); 926 capturer.params().transition);
913 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 927 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
914 EXPECT_FALSE(capturer.details().is_in_page); 928 EXPECT_FALSE(capturer.details().is_in_page);
915 } 929 }
916 930
917 { 931 {
918 // location.replace(). 932 // location.replace().
933 // TODO(creis): Change this to be NEW_PAGE with replacement in
934 // https://crbug.com/317872.
919 FrameNavigateParamsCapturer capturer(root); 935 FrameNavigateParamsCapturer capturer(root);
920 GURL frame_url(embedded_test_server()->GetURL( 936 GURL frame_url(embedded_test_server()->GetURL(
921 "/navigation_controller/simple_page_1.html")); 937 "/navigation_controller/simple_page_1.html"));
922 std::string script = "location.replace('" + frame_url.spec() + "')"; 938 std::string script = "location.replace('" + frame_url.spec() + "')";
923 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 939 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
924 capturer.Wait(); 940 capturer.Wait();
925 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, 941 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
926 capturer.params().transition); 942 capturer.params().transition);
927 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 943 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
928 EXPECT_FALSE(capturer.details().is_in_page); 944 EXPECT_FALSE(capturer.details().is_in_page);
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 DoReplaceStateWhilePending(shell(), url, url, "x"); 2923 DoReplaceStateWhilePending(shell(), url, url, "x");
2908 } 2924 }
2909 2925
2910 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 2926 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2911 NavigationTypeClassification_On1InPageTo1While1Pending) { 2927 NavigationTypeClassification_On1InPageTo1While1Pending) {
2912 GURL url(embedded_test_server()->GetURL( 2928 GURL url(embedded_test_server()->GetURL(
2913 "/navigation_controller/simple_page_1.html")); 2929 "/navigation_controller/simple_page_1.html"));
2914 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); 2930 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html");
2915 } 2931 }
2916 2932
2933 // Ensure that a pending NavigationEntry for a different navigation doesn't
2934 // cause a commit to be incorrectly treated as a replacement.
2935 // See https://crbug.com/593153.
2936 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2937 OtherCommitDuringPendingEntryWithReplacement) {
2938 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>(
2939 shell()->web_contents()->GetController());
2940
2941 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2942 ->GetFrameTree()
2943 ->root();
2944
2945 // Load an initial page.
2946 GURL start_url(embedded_test_server()->GetURL(
2947 "/navigation_controller/simple_page_1.html"));
2948 EXPECT_TRUE(NavigateToURL(shell(), start_url));
2949 int entry_count = controller.GetEntryCount();
2950 EXPECT_EQ(1, controller.GetEntryCount());
2951 EXPECT_EQ(start_url, controller.GetLastCommittedEntry()->GetURL());
2952
2953 // Start a cross-process navigation with replacement, which never completes.
2954 GURL foo_url(embedded_test_server()->GetURL(
2955 "foo.com", "/navigation_controller/page_with_links.html"));
2956 NavigationStallDelegate stall_delegate(foo_url);
2957 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate);
2958 NavigationController::LoadURLParams params(foo_url);
2959 params.should_replace_current_entry = true;
2960 controller.LoadURLWithParams(params);
2961
2962 // That should be the pending entry.
2963 NavigationEntryImpl* entry = controller.GetPendingEntry();
2964 ASSERT_NE(nullptr, entry);
2965 EXPECT_EQ(foo_url, entry->GetURL());
2966 EXPECT_EQ(entry_count, controller.GetEntryCount());
2967
2968 {
2969 // Now the existing page uses history.pushState() while the pending entry
2970 // for the other navigation still exists.
2971 FrameNavigateParamsCapturer capturer(root);
2972 capturer.set_wait_for_load(false);
2973 std::string script = "history.pushState({}, '', 'pushed')";
2974 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
2975 capturer.Wait();
2976 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type);
2977 EXPECT_TRUE(capturer.details().is_in_page);
2978 }
2979
2980 // The in-page navigation should not have replaced the previous entry.
2981 GURL push_state_url(
2982 embedded_test_server()->GetURL("/navigation_controller/pushed"));
2983 EXPECT_EQ(entry_count + 1, controller.GetEntryCount());
2984 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL());
2985 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL());
2986
2987 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
2988 }
2989
2917 // Ensure the renderer process does not get confused about the current entry 2990 // Ensure the renderer process does not get confused about the current entry
2918 // due to subframes and replaced entries. See https://crbug.com/480201. 2991 // due to subframes and replaced entries. See https://crbug.com/480201.
2919 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317. 2992 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317.
2920 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 2993 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2921 PreventSpoofFromSubframeAndReplace) { 2994 PreventSpoofFromSubframeAndReplace) {
2922 // Start at an initial URL. 2995 // Start at an initial URL.
2923 GURL url1(embedded_test_server()->GetURL( 2996 GURL url1(embedded_test_server()->GetURL(
2924 "/navigation_controller/simple_page_1.html")); 2997 "/navigation_controller/simple_page_1.html"));
2925 NavigateToURL(shell(), url1); 2998 NavigateToURL(shell(), url1);
2926 2999
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
3401 observer.Wait(); 3474 observer.Wait();
3402 3475
3403 EXPECT_EQ(3, controller.GetEntryCount()); 3476 EXPECT_EQ(3, controller.GetEntryCount());
3404 EXPECT_EQ(3, RendererHistoryLength(shell())); 3477 EXPECT_EQ(3, RendererHistoryLength(shell()));
3405 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3478 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3406 3479
3407 EXPECT_EQ(frame_url_1, frame->current_url()); 3480 EXPECT_EQ(frame_url_1, frame->current_url());
3408 } 3481 }
3409 3482
3410 } // namespace content 3483 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698