| 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "content/browser/browser_thread_impl.h" | 6 #include "content/browser/browser_thread_impl.h" |
| 7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.h" |
| 8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
| 9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
| 10 #include "content/browser/web_contents/navigation_entry_impl.h" | 10 #include "content/browser/web_contents/navigation_entry_impl.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 old_rvh->SendShouldCloseACK(true); | 167 old_rvh->SendShouldCloseACK(true); |
| 168 | 168 |
| 169 // Commit the navigation with a new page ID. | 169 // Commit the navigation with a new page ID. |
| 170 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 170 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
| 171 active_rvh()->GetSiteInstance()); | 171 active_rvh()->GetSiteInstance()); |
| 172 active_test_rvh()->SendNavigate(max_page_id + 1, url); | 172 active_test_rvh()->SendNavigate(max_page_id + 1, url); |
| 173 | 173 |
| 174 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation | 174 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation |
| 175 // without making any network requests. | 175 // without making any network requests. |
| 176 if (old_rvh != active_rvh()) | 176 if (old_rvh != active_rvh()) |
| 177 old_rvh->OnSwapOutACK(false); | 177 old_rvh->OnSwapOutACK(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool ShouldSwapProcesses(RenderViewHostManager* manager, | 180 bool ShouldSwapProcesses(RenderViewHostManager* manager, |
| 181 const NavigationEntryImpl* cur_entry, | 181 const NavigationEntryImpl* cur_entry, |
| 182 const NavigationEntryImpl* new_entry) const { | 182 const NavigationEntryImpl* new_entry) const { |
| 183 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); | 183 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); |
| 184 } | 184 } |
| 185 | 185 |
| 186 private: | 186 private: |
| 187 RenderViewHostManagerTestClient client_; | 187 RenderViewHostManagerTestClient client_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // requiring a beforeunload ack. | 221 // requiring a beforeunload ack. |
| 222 contents2.GetController().LoadURL( | 222 contents2.GetController().LoadURL( |
| 223 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 223 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 224 std::string()); | 224 std::string()); |
| 225 EXPECT_TRUE(contents2.cross_navigation_pending()); | 225 EXPECT_TRUE(contents2.cross_navigation_pending()); |
| 226 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( | 226 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
| 227 contents2.GetRenderManagerForTesting()->pending_render_view_host()); | 227 contents2.GetRenderManagerForTesting()->pending_render_view_host()); |
| 228 ASSERT_TRUE(dest_rvh2); | 228 ASSERT_TRUE(dest_rvh2); |
| 229 ntp_rvh2->SendShouldCloseACK(true); | 229 ntp_rvh2->SendShouldCloseACK(true); |
| 230 dest_rvh2->SendNavigate(101, kDestUrl); | 230 dest_rvh2->SendNavigate(101, kDestUrl); |
| 231 ntp_rvh2->OnSwapOutACK(false); | 231 ntp_rvh2->OnSwapOutACK(); |
| 232 | 232 |
| 233 // The two RVH's should be different in every way. | 233 // The two RVH's should be different in every way. |
| 234 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); | 234 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); |
| 235 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); | 235 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); |
| 236 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( | 236 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( |
| 237 dest_rvh2->GetSiteInstance())); | 237 dest_rvh2->GetSiteInstance())); |
| 238 | 238 |
| 239 // Navigate both to the new tab page, and verify that they share a | 239 // Navigate both to the new tab page, and verify that they share a |
| 240 // SiteInstance. | 240 // SiteInstance. |
| 241 NavigateActiveAndCommit(kNtpUrl); | 241 NavigateActiveAndCommit(kNtpUrl); |
| 242 | 242 |
| 243 contents2.GetController().LoadURL( | 243 contents2.GetController().LoadURL( |
| 244 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 244 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 245 std::string()); | 245 std::string()); |
| 246 dest_rvh2->SendShouldCloseACK(true); | 246 dest_rvh2->SendShouldCloseACK(true); |
| 247 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> | 247 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> |
| 248 pending_render_view_host())->SendNavigate(102, kNtpUrl); | 248 pending_render_view_host())->SendNavigate(102, kNtpUrl); |
| 249 dest_rvh2->OnSwapOutACK(false); | 249 dest_rvh2->OnSwapOutACK(); |
| 250 | 250 |
| 251 EXPECT_EQ(active_rvh()->GetSiteInstance(), | 251 EXPECT_EQ(active_rvh()->GetSiteInstance(), |
| 252 contents2.GetRenderViewHost()->GetSiteInstance()); | 252 contents2.GetRenderViewHost()->GetSiteInstance()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Ensure that the browser ignores most IPC messages that arrive from a | 255 // Ensure that the browser ignores most IPC messages that arrive from a |
| 256 // RenderViewHost that has been swapped out. We do not want to take | 256 // RenderViewHost that has been swapped out. We do not want to take |
| 257 // action on requests from a non-active renderer. The main exception is | 257 // action on requests from a non-active renderer. The main exception is |
| 258 // for synchronous messages, which cannot be ignored without leaving the | 258 // for synchronous messages, which cannot be ignored without leaving the |
| 259 // renderer in a stuck state. See http://crbug.com/93427. | 259 // renderer in a stuck state. See http://crbug.com/93427. |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 test_host->SendShouldCloseACK(true); | 576 test_host->SendShouldCloseACK(true); |
| 577 | 577 |
| 578 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a | 578 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a |
| 579 // call of RenderViewHostManager::OnCrossSiteResponse before | 579 // call of RenderViewHostManager::OnCrossSiteResponse before |
| 580 // RenderViewHostManager::DidNavigateMainFrame is called. | 580 // RenderViewHostManager::DidNavigateMainFrame is called. |
| 581 // The RVH is not swapped out until the commit. | 581 // The RVH is not swapped out until the commit. |
| 582 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), | 582 manager.OnCrossSiteResponse(host2->GetProcess()->GetID(), |
| 583 host2->GetPendingRequestId()); | 583 host2->GetPendingRequestId()); |
| 584 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( | 584 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( |
| 585 ViewMsg_SwapOut::ID)); | 585 ViewMsg_SwapOut::ID)); |
| 586 test_host->OnSwapOutACK(false); | 586 test_host->OnSwapOutACK(); |
| 587 | 587 |
| 588 EXPECT_EQ(host, manager.current_host()); | 588 EXPECT_EQ(host, manager.current_host()); |
| 589 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( | 589 EXPECT_FALSE(static_cast<RenderViewHostImpl*>( |
| 590 manager.current_host())->is_swapped_out()); | 590 manager.current_host())->is_swapped_out()); |
| 591 EXPECT_EQ(host2, manager.pending_render_view_host()); | 591 EXPECT_EQ(host2, manager.pending_render_view_host()); |
| 592 // There should be still no navigation messages being sent. | 592 // There should be still no navigation messages being sent. |
| 593 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( | 593 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( |
| 594 ViewMsg_Navigate::ID)); | 594 ViewMsg_Navigate::ID)); |
| 595 | 595 |
| 596 // 3) Cross-site navigate to next site before 2) has committed. -------------- | 596 // 3) Cross-site navigate to next site before 2) has committed. -------------- |
| (...skipping 27 matching lines...) Expand all Loading... |
| 624 | 624 |
| 625 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a | 625 // CrossSiteResourceHandler::StartCrossSiteTransition triggers a |
| 626 // call of RenderViewHostManager::OnCrossSiteResponse before | 626 // call of RenderViewHostManager::OnCrossSiteResponse before |
| 627 // RenderViewHostManager::DidNavigateMainFrame is called. | 627 // RenderViewHostManager::DidNavigateMainFrame is called. |
| 628 // The RVH is not swapped out until the commit. | 628 // The RVH is not swapped out until the commit. |
| 629 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), | 629 manager.OnCrossSiteResponse(host3->GetProcess()->GetID(), |
| 630 static_cast<RenderViewHostImpl*>( | 630 static_cast<RenderViewHostImpl*>( |
| 631 host3)->GetPendingRequestId()); | 631 host3)->GetPendingRequestId()); |
| 632 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( | 632 EXPECT_TRUE(test_process_host->sink().GetUniqueMessageMatching( |
| 633 ViewMsg_SwapOut::ID)); | 633 ViewMsg_SwapOut::ID)); |
| 634 test_host->OnSwapOutACK(false); | 634 test_host->OnSwapOutACK(); |
| 635 | 635 |
| 636 // Commit. | 636 // Commit. |
| 637 manager.DidNavigateMainFrame(host3); | 637 manager.DidNavigateMainFrame(host3); |
| 638 EXPECT_TRUE(host3 == manager.current_host()); | 638 EXPECT_TRUE(host3 == manager.current_host()); |
| 639 ASSERT_TRUE(host3); | 639 ASSERT_TRUE(host3); |
| 640 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> | 640 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> |
| 641 HasSite()); | 641 HasSite()); |
| 642 // Check the pending RenderViewHost has been committed. | 642 // Check the pending RenderViewHost has been committed. |
| 643 EXPECT_FALSE(manager.pending_render_view_host()); | 643 EXPECT_FALSE(manager.pending_render_view_host()); |
| 644 | 644 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 828 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 829 rvh3->GetSiteInstance())); | 829 rvh3->GetSiteInstance())); |
| 830 | 830 |
| 831 // No scripting is allowed across BrowsingInstances, so we should not create | 831 // No scripting is allowed across BrowsingInstances, so we should not create |
| 832 // swapped out RVHs for the opener chain in this case. | 832 // swapped out RVHs for the opener chain in this case. |
| 833 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 833 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
| 834 rvh3->GetSiteInstance())); | 834 rvh3->GetSiteInstance())); |
| 835 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( | 835 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( |
| 836 rvh3->GetSiteInstance())); | 836 rvh3->GetSiteInstance())); |
| 837 } | 837 } |
| OLD | NEW |