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

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

Issue 1114403002: Fix mis-classification of navigations when there is a pending page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "content/browser/frame_host/frame_navigation_entry.h" 8 #include "content/browser/frame_host/frame_navigation_entry.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 net::URLRequest* request, 1018 net::URLRequest* request,
1019 content::ResourceContext* resource_context, 1019 content::ResourceContext* resource_context,
1020 content::AppCacheService* appcache_service, 1020 content::AppCacheService* appcache_service,
1021 ResourceType resource_type, 1021 ResourceType resource_type,
1022 ScopedVector<content::ResourceThrottle>* throttles) override { 1022 ScopedVector<content::ResourceThrottle>* throttles) override {
1023 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1023 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1024 throttles->push_back(new HttpThrottle); 1024 throttles->push_back(new HttpThrottle);
1025 } 1025 }
1026 }; 1026 };
1027 1027
1028 } // namespace 1028 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is
1029 1029 // stalled, an in-page navigation happens. Make sure that all the navigations
1030 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 1030 // are properly classified.
1031 NavigationTypeClassification_InPageWhilePending) { 1031 void DoReplaceStateWhilePending(Shell* shell,
1032 const GURL& start_url,
1033 const GURL& stalled_url) {
1032 NavigationControllerImpl& controller = 1034 NavigationControllerImpl& controller =
1033 static_cast<NavigationControllerImpl&>( 1035 static_cast<NavigationControllerImpl&>(
1034 shell()->web_contents()->GetController()); 1036 shell->web_contents()->GetController());
1035 1037
1036 FrameTreeNode* root = 1038 FrameTreeNode* root =
1037 static_cast<WebContentsImpl*>(shell()->web_contents())-> 1039 static_cast<WebContentsImpl*>(shell->web_contents())->
1038 GetFrameTree()->root(); 1040 GetFrameTree()->root();
1039 1041
1040 // Start with a normal page. 1042 // Start with one page.
1041 GURL url1(embedded_test_server()->GetURL( 1043 EXPECT_TRUE(NavigateToURL(shell, start_url));
1042 "/navigation_controller/simple_page_1.html"));
1043 EXPECT_TRUE(NavigateToURL(shell(), url1));
1044 1044
1045 // Have the user decide to go to a different page which is very slow. 1045 // Have the user decide to go to a different page which is very slow.
1046 StallDelegate stall_delegate; 1046 StallDelegate stall_delegate;
1047 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); 1047 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate);
1048 GURL url2(embedded_test_server()->GetURL( 1048 controller.LoadURL(
1049 "/navigation_controller/simple_page_2.html")); 1049 stalled_url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1050 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1051 1050
1052 // That should be the pending entry. 1051 // That should be the pending entry.
1053 NavigationEntryImpl* entry = controller.GetPendingEntry(); 1052 NavigationEntryImpl* entry = controller.GetPendingEntry();
1054 ASSERT_NE(nullptr, entry); 1053 ASSERT_NE(nullptr, entry);
1055 EXPECT_EQ(url2, entry->GetURL()); 1054 EXPECT_EQ(stalled_url, entry->GetURL());
1056 1055
1057 { 1056 {
1058 // Now the existing page uses history.replaceState(). 1057 // Now the existing page uses history.replaceState().
1059 FrameNavigateParamsCapturer capturer(root); 1058 FrameNavigateParamsCapturer capturer(root);
1060 capturer.set_wait_for_load(false); 1059 capturer.set_wait_for_load(false);
1061 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), 1060 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(),
1062 "history.replaceState({}, '', 'x')")); 1061 "history.replaceState({}, '', 'x')"));
1063 capturer.Wait(); 1062 capturer.Wait();
1064 1063
1065 // The fact that there was a pending entry shouldn't interfere with the 1064 // The fact that there was a pending entry shouldn't interfere with the
1066 // classification. 1065 // classification.
1067 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); 1066 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
1068 } 1067 }
1069 1068
1070 ResourceDispatcherHost::Get()->SetDelegate(nullptr); 1069 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
1071 } 1070 }
1072 1071
1072 } // namespace
1073
1074 IN_PROC_BROWSER_TEST_F(
1075 NavigationControllerBrowserTest,
1076 NavigationTypeClassification_InPageWhileDifferentPending) {
1077 GURL url1(embedded_test_server()->GetURL(
1078 "/navigation_controller/simple_page_1.html"));
1079 GURL url2(embedded_test_server()->GetURL(
1080 "/navigation_controller/simple_page_2.html"));
1081 DoReplaceStateWhilePending(shell(), url1, url2);
1082 }
1083
1084 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1085 NavigationTypeClassification_InPageWhileSamePending) {
1086 GURL url(embedded_test_server()->GetURL(
1087 "/navigation_controller/simple_page_1.html"));
1088 DoReplaceStateWhilePending(shell(), url, url);
Charlie Reis 2015/05/01 19:40:48 Nice. Can we add a test that does a replaceState
Avi (use Gerrit) 2015/05/01 20:30:57 Done.
1089 }
1090
1073 // Ensure the renderer process does not get confused about the current entry 1091 // Ensure the renderer process does not get confused about the current entry
1074 // due to subframes and replaced entries. See https://crbug.com/480201. 1092 // due to subframes and replaced entries. See https://crbug.com/480201.
1075 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 1093 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1076 PreventSpoofFromSubframeAndReplace) { 1094 PreventSpoofFromSubframeAndReplace) {
1077 // Start at an initial URL. 1095 // Start at an initial URL.
1078 GURL url1(embedded_test_server()->GetURL( 1096 GURL url1(embedded_test_server()->GetURL(
1079 "/navigation_controller/simple_page_1.html")); 1097 "/navigation_controller/simple_page_1.html"));
1080 NavigateToURL(shell(), url1); 1098 NavigateToURL(shell(), url1);
1081 1099
1082 // Now go to a page with a real iframe. 1100 // Now go to a page with a real iframe.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1182
1165 // Make sure the URL is correct for both the entry and the main frame, and 1183 // Make sure the URL is correct for both the entry and the main frame, and
1166 // that the process hasn't been killed for showing a spoof. 1184 // that the process hasn't been killed for showing a spoof.
1167 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); 1185 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
1168 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL()); 1186 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL());
1169 EXPECT_EQ(url3, root->current_url()); 1187 EXPECT_EQ(url3, root->current_url());
1170 } 1188 }
1171 } 1189 }
1172 1190
1173 } // namespace content 1191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698