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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Very minor fix. Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 int orig_rvh_delete_count = 0; 513 int orig_rvh_delete_count = 0;
514 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 514 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
515 SiteInstance* instance1 = contents()->GetSiteInstance(); 515 SiteInstance* instance1 = contents()->GetSiteInstance();
516 516
517 // Navigate to URL. First URL should use first RenderViewHost. 517 // Navigate to URL. First URL should use first RenderViewHost.
518 const GURL url("http://www.google.com"); 518 const GURL url("http://www.google.com");
519 controller().LoadURL( 519 controller().LoadURL(
520 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 520 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
521 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 521 int entry_id = controller().GetPendingEntry()->GetUniqueID();
522 orig_rfh->PrepareForCommit(); 522 orig_rfh->PrepareForCommit();
523 contents()->TestDidNavigate(orig_rfh, entry_id, true, url, 523 contents()->TestDidNavigateWithSequenceNumber(
524 ui::PAGE_TRANSITION_TYPED); 524 orig_rfh, entry_id, true, url, Referrer(), ui::PAGE_TRANSITION_TYPED,
525 false, 0, 0);
nasko 2017/01/13 02:51:10 Why were those changes necessary? This test case d
arthursonzogni 2017/01/13 15:18:37 Yes these navigation are not same-document. Withou
525 526
526 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 527 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
527 // that orig_rfh doesn't get deleted when it gets swapped out. 528 // that orig_rfh doesn't get deleted when it gets swapped out.
528 orig_rfh->GetSiteInstance()->IncrementActiveFrameCount(); 529 orig_rfh->GetSiteInstance()->IncrementActiveFrameCount();
529 530
530 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 531 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
531 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 532 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
532 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 533 EXPECT_EQ(url, contents()->GetLastCommittedURL());
533 EXPECT_EQ(url, contents()->GetVisibleURL()); 534 EXPECT_EQ(url, contents()->GetVisibleURL());
534 535
(...skipping 14 matching lines...) Expand all
549 &pending_rvh_delete_count); 550 &pending_rvh_delete_count);
550 551
551 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 552 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
552 if (!IsBrowserSideNavigationEnabled()) { 553 if (!IsBrowserSideNavigationEnabled()) {
553 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 554 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
554 orig_rfh->SendBeforeUnloadACK(true); 555 orig_rfh->SendBeforeUnloadACK(true);
555 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 556 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
556 } 557 }
557 558
558 // DidNavigate from the pending page 559 // DidNavigate from the pending page
559 contents()->TestDidNavigate(pending_rfh, entry_id, true, url2, 560 contents()->TestDidNavigateWithSequenceNumber(
560 ui::PAGE_TRANSITION_TYPED); 561 pending_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
562 false, 1, 1);
561 SiteInstance* instance2 = contents()->GetSiteInstance(); 563 SiteInstance* instance2 = contents()->GetSiteInstance();
562 564
563 // Keep the number of active frames in pending_rfh's SiteInstance 565 // Keep the number of active frames in pending_rfh's SiteInstance
564 // non-zero so that orig_rfh doesn't get deleted when it gets 566 // non-zero so that orig_rfh doesn't get deleted when it gets
565 // swapped out. 567 // swapped out.
566 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount(); 568 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount();
567 569
568 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 570 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
569 EXPECT_EQ(pending_rfh, main_test_rfh()); 571 EXPECT_EQ(pending_rfh, main_test_rfh());
570 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 572 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
(...skipping 16 matching lines...) Expand all
587 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 589 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
588 590
589 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 591 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
590 if (!IsBrowserSideNavigationEnabled()) { 592 if (!IsBrowserSideNavigationEnabled()) {
591 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 593 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
592 pending_rfh->SendBeforeUnloadACK(true); 594 pending_rfh->SendBeforeUnloadACK(true);
593 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); 595 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
594 } 596 }
595 597
596 // DidNavigate from the back action 598 // DidNavigate from the back action
597 contents()->TestDidNavigate(goback_rfh, entry_id, false, url2, 599 contents()->TestDidNavigateWithSequenceNumber(
598 ui::PAGE_TRANSITION_TYPED); 600 goback_rfh, entry_id, false, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
601 false, 2, 0);
599 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 602 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
600 EXPECT_EQ(goback_rfh, main_test_rfh()); 603 EXPECT_EQ(goback_rfh, main_test_rfh());
601 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 604 EXPECT_EQ(instance1, contents()->GetSiteInstance());
602 // There should be a proxy for the pending RFH SiteInstance. 605 // There should be a proxy for the pending RFH SiteInstance.
603 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 606 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
604 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance())); 607 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance()));
605 EXPECT_EQ(pending_rvh_delete_count, 0); 608 EXPECT_EQ(pending_rvh_delete_count, 0);
606 pending_rfh->OnSwappedOut(); 609 pending_rfh->OnSwappedOut();
607 610
608 // Close contents and ensure RVHs are deleted. 611 // Close contents and ensure RVHs are deleted.
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 // intent. 1136 // intent.
1134 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1137 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1135 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1138 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1136 GURL url1(std::string(kChromeUIScheme) + "://" + 1139 GURL url1(std::string(kChromeUIScheme) + "://" +
1137 std::string(kChromeUIGpuHost)); 1140 std::string(kChromeUIGpuHost));
1138 controller().LoadURL( 1141 controller().LoadURL(
1139 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1142 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1140 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 1143 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1141 TestRenderFrameHost* webui_rfh = main_test_rfh(); 1144 TestRenderFrameHost* webui_rfh = main_test_rfh();
1142 webui_rfh->PrepareForCommit(); 1145 webui_rfh->PrepareForCommit();
1143 contents()->TestDidNavigate(webui_rfh, entry_id, true, url1, 1146 contents()->TestDidNavigateWithSequenceNumber(
1144 ui::PAGE_TRANSITION_TYPED); 1147 webui_rfh, entry_id, true, url1, Referrer(), ui::PAGE_TRANSITION_TYPED,
1148 false, 0, 0);
1145 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1149 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1146 SiteInstance* instance1 = contents()->GetSiteInstance(); 1150 SiteInstance* instance1 = contents()->GetSiteInstance();
1147 1151
1148 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1152 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1149 EXPECT_EQ(webui_rfh, main_test_rfh()); 1153 EXPECT_EQ(webui_rfh, main_test_rfh());
1150 EXPECT_EQ(url1, entry1->GetURL()); 1154 EXPECT_EQ(url1, entry1->GetURL());
1151 EXPECT_EQ(instance1, 1155 EXPECT_EQ(instance1,
1152 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1156 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1153 EXPECT_TRUE(webui_rfh->GetRenderViewHost()->GetEnabledBindings() & 1157 EXPECT_TRUE(webui_rfh->GetRenderViewHost()->GetEnabledBindings() &
1154 BINDINGS_POLICY_WEB_UI); 1158 BINDINGS_POLICY_WEB_UI);
1155 1159
1156 // Navigate to new site. 1160 // Navigate to new site.
1157 const GURL url2("http://www.google.com"); 1161 const GURL url2("http://www.google.com");
1158 controller().LoadURL( 1162 controller().LoadURL(
1159 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1163 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1160 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1164 entry_id = controller().GetPendingEntry()->GetUniqueID();
1161 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1165 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1162 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1166 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1163 1167
1164 // Simulate beforeunload approval. 1168 // Simulate beforeunload approval.
1165 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack()); 1169 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack());
1166 webui_rfh->PrepareForCommit(); 1170 webui_rfh->PrepareForCommit();
1167 1171
1168 // DidNavigate from the pending page. 1172 // DidNavigate from the pending page.
1169 contents()->TestDidNavigate(google_rfh, entry_id, true, url2, 1173 contents()->TestDidNavigateWithSequenceNumber(
1170 ui::PAGE_TRANSITION_TYPED); 1174 google_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
1175 false, 1, 1);
1171 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1176 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1172 SiteInstance* instance2 = contents()->GetSiteInstance(); 1177 SiteInstance* instance2 = contents()->GetSiteInstance();
1173 1178
1174 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1179 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1175 EXPECT_EQ(google_rfh, main_test_rfh()); 1180 EXPECT_EQ(google_rfh, main_test_rfh());
1176 EXPECT_NE(instance1, instance2); 1181 EXPECT_NE(instance1, instance2);
1177 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1182 EXPECT_FALSE(contents()->GetPendingMainFrame());
1178 EXPECT_EQ(url2, entry2->GetURL()); 1183 EXPECT_EQ(url2, entry2->GetURL());
1179 EXPECT_EQ(instance2, 1184 EXPECT_EQ(instance2,
1180 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1185 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1181 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1186 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1182 BINDINGS_POLICY_WEB_UI); 1187 BINDINGS_POLICY_WEB_UI);
1183 1188
1184 // Navigate to third page on same site. 1189 // Navigate to third page on same site.
1185 const GURL url3("http://news.google.com"); 1190 const GURL url3("http://news.google.com");
1186 controller().LoadURL( 1191 controller().LoadURL(
1187 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1192 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1188 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1193 entry_id = controller().GetPendingEntry()->GetUniqueID();
1189 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1194 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1190 main_test_rfh()->PrepareForCommit(); 1195 main_test_rfh()->PrepareForCommit();
1191 contents()->TestDidNavigate(google_rfh, entry_id, true, url3, 1196 contents()->TestDidNavigateWithSequenceNumber(
1192 ui::PAGE_TRANSITION_TYPED); 1197 google_rfh, entry_id, true, url3, Referrer(), ui::PAGE_TRANSITION_TYPED,
1198 false, 2, 2);
1193 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1199 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1194 SiteInstance* instance3 = contents()->GetSiteInstance(); 1200 SiteInstance* instance3 = contents()->GetSiteInstance();
1195 1201
1196 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1202 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1197 EXPECT_EQ(google_rfh, main_test_rfh()); 1203 EXPECT_EQ(google_rfh, main_test_rfh());
1198 EXPECT_EQ(instance2, instance3); 1204 EXPECT_EQ(instance2, instance3);
1199 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1205 EXPECT_FALSE(contents()->GetPendingMainFrame());
1200 EXPECT_EQ(url3, entry3->GetURL()); 1206 EXPECT_EQ(url3, entry3->GetURL());
1201 EXPECT_EQ(instance3, 1207 EXPECT_EQ(instance3,
1202 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1208 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
(...skipping 11 matching lines...) Expand all
1214 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1220 EXPECT_EQ(entry1, controller().GetPendingEntry());
1215 1221
1216 // Simulate beforeunload approval. 1222 // Simulate beforeunload approval.
1217 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); 1223 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack());
1218 base::TimeTicks now = base::TimeTicks::Now(); 1224 base::TimeTicks now = base::TimeTicks::Now();
1219 google_rfh->PrepareForCommit(); 1225 google_rfh->PrepareForCommit();
1220 google_rfh->OnMessageReceived( 1226 google_rfh->OnMessageReceived(
1221 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1227 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1222 1228
1223 // DidNavigate from the first back. This aborts the second back's pending RFH. 1229 // DidNavigate from the first back. This aborts the second back's pending RFH.
1224 contents()->TestDidNavigate(google_rfh, goback_entry->GetUniqueID(), false, 1230 contents()->TestDidNavigateWithSequenceNumber(
1225 url2, ui::PAGE_TRANSITION_TYPED); 1231 google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(),
1232 ui::PAGE_TRANSITION_TYPED, false, 1, 1);
1226 1233
1227 // We should commit this page and forget about the second back. 1234 // We should commit this page and forget about the second back.
1228 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1235 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1229 EXPECT_FALSE(controller().GetPendingEntry()); 1236 EXPECT_FALSE(controller().GetPendingEntry());
1230 EXPECT_EQ(google_rfh, main_test_rfh()); 1237 EXPECT_EQ(google_rfh, main_test_rfh());
1231 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); 1238 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL());
1232 1239
1233 // We should not have corrupted the NTP entry. 1240 // We should not have corrupted the NTP entry.
1234 EXPECT_EQ(instance3, 1241 EXPECT_EQ(instance3,
1235 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1242 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3440 // An automatic navigation. 3447 // An automatic navigation.
3441 main_test_rfh()->SendNavigateWithModificationCallback( 3448 main_test_rfh()->SendNavigateWithModificationCallback(
3442 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); 3449 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture));
3443 3450
3444 EXPECT_EQ(1u, dialog_manager.reset_count()); 3451 EXPECT_EQ(1u, dialog_manager.reset_count());
3445 3452
3446 contents()->SetJavaScriptDialogManagerForTesting(nullptr); 3453 contents()->SetJavaScriptDialogManagerForTesting(nullptr);
3447 } 3454 }
3448 3455
3449 } // namespace content 3456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698