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

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: Fix 2 WebContentsImplTest by assigning a document_sequence_number. 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);
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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 // intent. 1127 // intent.
1125 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1128 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1126 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1129 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1127 GURL url1(std::string(kChromeUIScheme) + "://" + 1130 GURL url1(std::string(kChromeUIScheme) + "://" +
1128 std::string(kChromeUIGpuHost)); 1131 std::string(kChromeUIGpuHost));
1129 controller().LoadURL( 1132 controller().LoadURL(
1130 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1133 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1131 int entry_id = controller().GetPendingEntry()->GetUniqueID(); 1134 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1132 TestRenderFrameHost* webui_rfh = main_test_rfh(); 1135 TestRenderFrameHost* webui_rfh = main_test_rfh();
1133 webui_rfh->PrepareForCommit(); 1136 webui_rfh->PrepareForCommit();
1134 contents()->TestDidNavigate(webui_rfh, entry_id, true, url1, 1137 contents()->TestDidNavigateWithSequenceNumber(
1135 ui::PAGE_TRANSITION_TYPED); 1138 webui_rfh, entry_id, true, url1, Referrer(), ui::PAGE_TRANSITION_TYPED,
1139 false, 0, 0);
1136 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1140 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1137 SiteInstance* instance1 = contents()->GetSiteInstance(); 1141 SiteInstance* instance1 = contents()->GetSiteInstance();
1138 1142
1139 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1143 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1140 EXPECT_EQ(webui_rfh, main_test_rfh()); 1144 EXPECT_EQ(webui_rfh, main_test_rfh());
1141 EXPECT_EQ(url1, entry1->GetURL()); 1145 EXPECT_EQ(url1, entry1->GetURL());
1142 EXPECT_EQ(instance1, 1146 EXPECT_EQ(instance1,
1143 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1147 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1144 EXPECT_TRUE(webui_rfh->GetRenderViewHost()->GetEnabledBindings() & 1148 EXPECT_TRUE(webui_rfh->GetRenderViewHost()->GetEnabledBindings() &
1145 BINDINGS_POLICY_WEB_UI); 1149 BINDINGS_POLICY_WEB_UI);
1146 1150
1147 // Navigate to new site. 1151 // Navigate to new site.
1148 const GURL url2("http://www.google.com"); 1152 const GURL url2("http://www.google.com");
1149 controller().LoadURL( 1153 controller().LoadURL(
1150 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1154 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1151 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1155 entry_id = controller().GetPendingEntry()->GetUniqueID();
1152 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 1156 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
1153 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1157 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1154 1158
1155 // Simulate beforeunload approval. 1159 // Simulate beforeunload approval.
1156 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack()); 1160 EXPECT_TRUE(webui_rfh->is_waiting_for_beforeunload_ack());
1157 webui_rfh->PrepareForCommit(); 1161 webui_rfh->PrepareForCommit();
1158 1162
1159 // DidNavigate from the pending page. 1163 // DidNavigate from the pending page.
1160 contents()->TestDidNavigate(google_rfh, entry_id, true, url2, 1164 contents()->TestDidNavigateWithSequenceNumber(
1161 ui::PAGE_TRANSITION_TYPED); 1165 google_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
1166 false, 1, 1);
1162 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1167 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1163 SiteInstance* instance2 = contents()->GetSiteInstance(); 1168 SiteInstance* instance2 = contents()->GetSiteInstance();
1164 1169
1165 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1170 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1166 EXPECT_EQ(google_rfh, main_test_rfh()); 1171 EXPECT_EQ(google_rfh, main_test_rfh());
1167 EXPECT_NE(instance1, instance2); 1172 EXPECT_NE(instance1, instance2);
1168 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1173 EXPECT_FALSE(contents()->GetPendingMainFrame());
1169 EXPECT_EQ(url2, entry2->GetURL()); 1174 EXPECT_EQ(url2, entry2->GetURL());
1170 EXPECT_EQ(instance2, 1175 EXPECT_EQ(instance2,
1171 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1176 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1172 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1177 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1173 BINDINGS_POLICY_WEB_UI); 1178 BINDINGS_POLICY_WEB_UI);
1174 1179
1175 // Navigate to third page on same site. 1180 // Navigate to third page on same site.
1176 const GURL url3("http://news.google.com"); 1181 const GURL url3("http://news.google.com");
1177 controller().LoadURL( 1182 controller().LoadURL(
1178 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1183 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1179 entry_id = controller().GetPendingEntry()->GetUniqueID(); 1184 entry_id = controller().GetPendingEntry()->GetUniqueID();
1180 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1185 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1181 main_test_rfh()->PrepareForCommit(); 1186 main_test_rfh()->PrepareForCommit();
1182 contents()->TestDidNavigate(google_rfh, entry_id, true, url3, 1187 contents()->TestDidNavigateWithSequenceNumber(
1183 ui::PAGE_TRANSITION_TYPED); 1188 google_rfh, entry_id, true, url3, Referrer(), ui::PAGE_TRANSITION_TYPED,
1189 false, 2, 2);
1184 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1190 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1185 SiteInstance* instance3 = contents()->GetSiteInstance(); 1191 SiteInstance* instance3 = contents()->GetSiteInstance();
1186 1192
1187 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1193 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1188 EXPECT_EQ(google_rfh, main_test_rfh()); 1194 EXPECT_EQ(google_rfh, main_test_rfh());
1189 EXPECT_EQ(instance2, instance3); 1195 EXPECT_EQ(instance2, instance3);
1190 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1196 EXPECT_FALSE(contents()->GetPendingMainFrame());
1191 EXPECT_EQ(url3, entry3->GetURL()); 1197 EXPECT_EQ(url3, entry3->GetURL());
1192 EXPECT_EQ(instance3, 1198 EXPECT_EQ(instance3,
1193 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1199 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
(...skipping 11 matching lines...) Expand all
1205 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1211 EXPECT_EQ(entry1, controller().GetPendingEntry());
1206 1212
1207 // Simulate beforeunload approval. 1213 // Simulate beforeunload approval.
1208 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); 1214 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack());
1209 base::TimeTicks now = base::TimeTicks::Now(); 1215 base::TimeTicks now = base::TimeTicks::Now();
1210 google_rfh->PrepareForCommit(); 1216 google_rfh->PrepareForCommit();
1211 google_rfh->OnMessageReceived( 1217 google_rfh->OnMessageReceived(
1212 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1218 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1213 1219
1214 // DidNavigate from the first back. This aborts the second back's pending RFH. 1220 // DidNavigate from the first back. This aborts the second back's pending RFH.
1215 contents()->TestDidNavigate(google_rfh, goback_entry->GetUniqueID(), false, 1221 contents()->TestDidNavigateWithSequenceNumber(
1216 url2, ui::PAGE_TRANSITION_TYPED); 1222 google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(),
1223 ui::PAGE_TRANSITION_TYPED, false, 3, 1);
1217 1224
1218 // We should commit this page and forget about the second back. 1225 // We should commit this page and forget about the second back.
1219 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 1226 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
1220 EXPECT_FALSE(controller().GetPendingEntry()); 1227 EXPECT_FALSE(controller().GetPendingEntry());
1221 EXPECT_EQ(google_rfh, main_test_rfh()); 1228 EXPECT_EQ(google_rfh, main_test_rfh());
1222 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); 1229 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL());
1223 1230
1224 // We should not have corrupted the NTP entry. 1231 // We should not have corrupted the NTP entry.
1225 EXPECT_EQ(instance3, 1232 EXPECT_EQ(instance3,
1226 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1233 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3431 // An automatic navigation. 3438 // An automatic navigation.
3432 main_test_rfh()->SendNavigateWithModificationCallback( 3439 main_test_rfh()->SendNavigateWithModificationCallback(
3433 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); 3440 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture));
3434 3441
3435 EXPECT_EQ(1u, dialog_manager.reset_count()); 3442 EXPECT_EQ(1u, dialog_manager.reset_count());
3436 3443
3437 contents()->SetJavaScriptDialogManagerForTesting(nullptr); 3444 contents()->SetJavaScriptDialogManagerForTesting(nullptr);
3438 } 3445 }
3439 3446
3440 } // namespace content 3447 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698