| OLD | NEW |
| 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 int orig_rvh_delete_count = 0; | 514 int orig_rvh_delete_count = 0; |
| 515 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); | 515 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); |
| 516 SiteInstance* instance1 = contents()->GetSiteInstance(); | 516 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 517 | 517 |
| 518 // Navigate to URL. First URL should use first RenderViewHost. | 518 // Navigate to URL. First URL should use first RenderViewHost. |
| 519 const GURL url("http://www.google.com"); | 519 const GURL url("http://www.google.com"); |
| 520 controller().LoadURL( | 520 controller().LoadURL( |
| 521 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 521 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 522 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 522 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 523 orig_rfh->PrepareForCommit(); | 523 orig_rfh->PrepareForCommit(); |
| 524 contents()->TestDidNavigate(orig_rfh, entry_id, true, url, | 524 contents()->TestDidNavigateWithSequenceNumber( |
| 525 ui::PAGE_TRANSITION_TYPED); | 525 orig_rfh, entry_id, true, url, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 526 false, 0, 0); |
| 526 | 527 |
| 527 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so | 528 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so |
| 528 // that orig_rfh doesn't get deleted when it gets swapped out. | 529 // that orig_rfh doesn't get deleted when it gets swapped out. |
| 529 orig_rfh->GetSiteInstance()->IncrementActiveFrameCount(); | 530 orig_rfh->GetSiteInstance()->IncrementActiveFrameCount(); |
| 530 | 531 |
| 531 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 532 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 532 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); | 533 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); |
| 533 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 534 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
| 534 EXPECT_EQ(url, contents()->GetVisibleURL()); | 535 EXPECT_EQ(url, contents()->GetVisibleURL()); |
| 535 | 536 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 550 &pending_rvh_delete_count); | 551 &pending_rvh_delete_count); |
| 551 | 552 |
| 552 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. | 553 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. |
| 553 if (!IsBrowserSideNavigationEnabled()) { | 554 if (!IsBrowserSideNavigationEnabled()) { |
| 554 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); | 555 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); |
| 555 orig_rfh->SendBeforeUnloadACK(true); | 556 orig_rfh->SendBeforeUnloadACK(true); |
| 556 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); | 557 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); |
| 557 } | 558 } |
| 558 | 559 |
| 559 // DidNavigate from the pending page | 560 // DidNavigate from the pending page |
| 560 contents()->TestDidNavigate(pending_rfh, entry_id, true, url2, | 561 contents()->TestDidNavigateWithSequenceNumber( |
| 561 ui::PAGE_TRANSITION_TYPED); | 562 pending_rfh, entry_id, true, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 563 false, 1, 1); |
| 562 SiteInstance* instance2 = contents()->GetSiteInstance(); | 564 SiteInstance* instance2 = contents()->GetSiteInstance(); |
| 563 | 565 |
| 564 // Keep the number of active frames in pending_rfh's SiteInstance | 566 // Keep the number of active frames in pending_rfh's SiteInstance |
| 565 // non-zero so that orig_rfh doesn't get deleted when it gets | 567 // non-zero so that orig_rfh doesn't get deleted when it gets |
| 566 // swapped out. | 568 // swapped out. |
| 567 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount(); | 569 pending_rfh->GetSiteInstance()->IncrementActiveFrameCount(); |
| 568 | 570 |
| 569 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 571 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 570 EXPECT_EQ(pending_rfh, main_test_rfh()); | 572 EXPECT_EQ(pending_rfh, main_test_rfh()); |
| 571 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 573 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 588 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 590 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 589 | 591 |
| 590 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. | 592 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. |
| 591 if (!IsBrowserSideNavigationEnabled()) { | 593 if (!IsBrowserSideNavigationEnabled()) { |
| 592 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); | 594 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); |
| 593 pending_rfh->SendBeforeUnloadACK(true); | 595 pending_rfh->SendBeforeUnloadACK(true); |
| 594 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); | 596 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); |
| 595 } | 597 } |
| 596 | 598 |
| 597 // DidNavigate from the back action | 599 // DidNavigate from the back action |
| 598 contents()->TestDidNavigate(goback_rfh, entry_id, false, url2, | 600 contents()->TestDidNavigateWithSequenceNumber( |
| 599 ui::PAGE_TRANSITION_TYPED); | 601 goback_rfh, entry_id, false, url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 602 false, 2, 0); |
| 600 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 603 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 601 EXPECT_EQ(goback_rfh, main_test_rfh()); | 604 EXPECT_EQ(goback_rfh, main_test_rfh()); |
| 602 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 605 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
| 603 // There should be a proxy for the pending RFH SiteInstance. | 606 // There should be a proxy for the pending RFH SiteInstance. |
| 604 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 607 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
| 605 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance())); | 608 GetRenderFrameProxyHost(pending_rfh->GetSiteInstance())); |
| 606 EXPECT_EQ(pending_rvh_delete_count, 0); | 609 EXPECT_EQ(pending_rvh_delete_count, 0); |
| 607 pending_rfh->OnSwappedOut(); | 610 pending_rfh->OnSwappedOut(); |
| 608 | 611 |
| 609 // Close contents and ensure RVHs are deleted. | 612 // Close contents and ensure RVHs are deleted. |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 // intent. | 1137 // intent. |
| 1135 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { | 1138 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
| 1136 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 1139 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
| 1137 GURL url1(std::string(kChromeUIScheme) + "://" + | 1140 GURL url1(std::string(kChromeUIScheme) + "://" + |
| 1138 std::string(kChromeUIGpuHost)); | 1141 std::string(kChromeUIGpuHost)); |
| 1139 controller().LoadURL( | 1142 controller().LoadURL( |
| 1140 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1143 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1141 int entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1144 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 1142 TestRenderFrameHost* webui_rfh = main_test_rfh(); | 1145 TestRenderFrameHost* webui_rfh = main_test_rfh(); |
| 1143 webui_rfh->PrepareForCommit(); | 1146 webui_rfh->PrepareForCommit(); |
| 1144 contents()->TestDidNavigate(webui_rfh, entry_id, true, url1, | 1147 contents()->TestDidNavigateWithSequenceNumber( |
| 1145 ui::PAGE_TRANSITION_TYPED); | 1148 webui_rfh, entry_id, true, url1, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 1149 false, 0, 0); |
| 1146 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 1150 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
| 1147 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1151 SiteInstance* instance1 = contents()->GetSiteInstance(); |
| 1148 | 1152 |
| 1149 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1153 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1150 EXPECT_EQ(webui_rfh, main_test_rfh()); | 1154 EXPECT_EQ(webui_rfh, main_test_rfh()); |
| 1151 EXPECT_EQ(url1, entry1->GetURL()); | 1155 EXPECT_EQ(url1, entry1->GetURL()); |
| 1152 EXPECT_EQ(instance1, | 1156 EXPECT_EQ(instance1, |
| 1153 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 1157 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
| 1154 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1158 EXPECT_TRUE(webui_rfh->GetEnabledBindings() & 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->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1186 EXPECT_FALSE(google_rfh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 1182 | 1187 |
| 1183 // Navigate to third page on same site. | 1188 // Navigate to third page on same site. |
| 1184 const GURL url3("http://news.google.com"); | 1189 const GURL url3("http://news.google.com"); |
| 1185 controller().LoadURL( | 1190 controller().LoadURL( |
| 1186 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1191 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1187 entry_id = controller().GetPendingEntry()->GetUniqueID(); | 1192 entry_id = controller().GetPendingEntry()->GetUniqueID(); |
| 1188 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1193 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1189 main_test_rfh()->PrepareForCommit(); | 1194 main_test_rfh()->PrepareForCommit(); |
| 1190 contents()->TestDidNavigate(google_rfh, entry_id, true, url3, | 1195 contents()->TestDidNavigateWithSequenceNumber( |
| 1191 ui::PAGE_TRANSITION_TYPED); | 1196 google_rfh, entry_id, true, url3, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 1197 false, 2, 2); |
| 1192 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 1198 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
| 1193 SiteInstance* instance3 = contents()->GetSiteInstance(); | 1199 SiteInstance* instance3 = contents()->GetSiteInstance(); |
| 1194 | 1200 |
| 1195 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1201 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1196 EXPECT_EQ(google_rfh, main_test_rfh()); | 1202 EXPECT_EQ(google_rfh, main_test_rfh()); |
| 1197 EXPECT_EQ(instance2, instance3); | 1203 EXPECT_EQ(instance2, instance3); |
| 1198 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 1204 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
| 1199 EXPECT_EQ(url3, entry3->GetURL()); | 1205 EXPECT_EQ(url3, entry3->GetURL()); |
| 1200 EXPECT_EQ(instance3, | 1206 EXPECT_EQ(instance3, |
| 1201 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 1207 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1213 EXPECT_EQ(entry1, controller().GetPendingEntry()); | 1219 EXPECT_EQ(entry1, controller().GetPendingEntry()); |
| 1214 | 1220 |
| 1215 // Simulate beforeunload approval. | 1221 // Simulate beforeunload approval. |
| 1216 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); | 1222 EXPECT_TRUE(google_rfh->is_waiting_for_beforeunload_ack()); |
| 1217 base::TimeTicks now = base::TimeTicks::Now(); | 1223 base::TimeTicks now = base::TimeTicks::Now(); |
| 1218 google_rfh->PrepareForCommit(); | 1224 google_rfh->PrepareForCommit(); |
| 1219 google_rfh->OnMessageReceived( | 1225 google_rfh->OnMessageReceived( |
| 1220 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1226 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
| 1221 | 1227 |
| 1222 // DidNavigate from the first back. This aborts the second back's pending RFH. | 1228 // DidNavigate from the first back. This aborts the second back's pending RFH. |
| 1223 contents()->TestDidNavigate(google_rfh, goback_entry->GetUniqueID(), false, | 1229 contents()->TestDidNavigateWithSequenceNumber( |
| 1224 url2, ui::PAGE_TRANSITION_TYPED); | 1230 google_rfh, goback_entry->GetUniqueID(), false, url2, Referrer(), |
| 1231 ui::PAGE_TRANSITION_TYPED, false, 1, 1); |
| 1225 | 1232 |
| 1226 // We should commit this page and forget about the second back. | 1233 // We should commit this page and forget about the second back. |
| 1227 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 1234 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 1228 EXPECT_FALSE(controller().GetPendingEntry()); | 1235 EXPECT_FALSE(controller().GetPendingEntry()); |
| 1229 EXPECT_EQ(google_rfh, main_test_rfh()); | 1236 EXPECT_EQ(google_rfh, main_test_rfh()); |
| 1230 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); | 1237 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); |
| 1231 | 1238 |
| 1232 // We should not have corrupted the NTP entry. | 1239 // We should not have corrupted the NTP entry. |
| 1233 EXPECT_EQ(instance3, | 1240 EXPECT_EQ(instance3, |
| 1234 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 1241 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
| (...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3436 // An automatic navigation. | 3443 // An automatic navigation. |
| 3437 main_test_rfh()->SendNavigateWithModificationCallback( | 3444 main_test_rfh()->SendNavigateWithModificationCallback( |
| 3438 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3445 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
| 3439 | 3446 |
| 3440 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3447 EXPECT_EQ(1u, dialog_manager.reset_count()); |
| 3441 | 3448 |
| 3442 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3449 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
| 3443 } | 3450 } |
| 3444 | 3451 |
| 3445 } // namespace content | 3452 } // namespace content |
| OLD | NEW |