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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(false); |
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_NE(static_cast<SiteInstanceImpl*>(active_rvh()->GetSiteInstance())-> | 236 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( |
237 browsing_instance_, | 237 dest_rvh2->GetSiteInstance())); |
238 static_cast<SiteInstanceImpl*>(dest_rvh2->GetSiteInstance())-> | |
239 browsing_instance_); | |
240 | 238 |
241 // 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 |
242 // SiteInstance. | 240 // SiteInstance. |
243 NavigateActiveAndCommit(kNtpUrl); | 241 NavigateActiveAndCommit(kNtpUrl); |
244 | 242 |
245 contents2.GetController().LoadURL( | 243 contents2.GetController().LoadURL( |
246 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 244 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
247 std::string()); | 245 std::string()); |
248 dest_rvh2->SendShouldCloseACK(true); | 246 dest_rvh2->SendShouldCloseACK(true); |
249 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> | 247 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 | 763 |
766 // We should be able to navigate forward. | 764 // We should be able to navigate forward. |
767 contents()->GetController().GoForward(); | 765 contents()->GetController().GoForward(); |
768 contents()->ProceedWithCrossSiteNavigation(); | 766 contents()->ProceedWithCrossSiteNavigation(); |
769 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 767 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
770 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 768 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
771 EXPECT_EQ(rvh2, rvh()); | 769 EXPECT_EQ(rvh2, rvh()); |
772 EXPECT_FALSE(rvh2->is_swapped_out()); | 770 EXPECT_FALSE(rvh2->is_swapped_out()); |
773 EXPECT_TRUE(rvh1->is_swapped_out()); | 771 EXPECT_TRUE(rvh1->is_swapped_out()); |
774 } | 772 } |
| 773 |
| 774 // Test that we create swapped out RVHs for the opener chain when navigating an |
| 775 // opened tab cross-process. This allows us to support certain cross-process |
| 776 // JavaScript calls (http://crbug.com/99202). |
| 777 TEST_F(RenderViewHostManagerTest, CreateSwappedOutOpenerRVHs) { |
| 778 const GURL kUrl1("http://www.google.com/"); |
| 779 const GURL kUrl2("http://www.chromium.org/"); |
| 780 const GURL kNtpUrl(chrome::kTestNewTabURL); |
| 781 |
| 782 // Navigate to an initial URL. |
| 783 contents()->NavigateAndCommit(kUrl1); |
| 784 RenderViewHostManager* manager = contents()->GetRenderManagerForTesting(); |
| 785 |
| 786 // Pretend the RVH is alive so it doesn't go away. |
| 787 TestRenderViewHost* rvh1 = test_rvh(); |
| 788 |
| 789 // Create 2 new tabs and simulate them being the opener chain for the main |
| 790 // tab. They should be in the same SiteInstance. |
| 791 TestWebContents opener1(browser_context(), rvh1->GetSiteInstance()); |
| 792 RenderViewHostManager* opener1_manager = opener1.GetRenderManagerForTesting(); |
| 793 contents()->SetOpener(&opener1); |
| 794 |
| 795 TestWebContents opener2(browser_context(), rvh1->GetSiteInstance()); |
| 796 RenderViewHostManager* opener2_manager = opener2.GetRenderManagerForTesting(); |
| 797 opener1.SetOpener(&opener2); |
| 798 |
| 799 // Navigate to a cross-site URL (different SiteInstance but same |
| 800 // BrowsingInstance). |
| 801 contents()->NavigateAndCommit(kUrl2); |
| 802 TestRenderViewHost* rvh2 = test_rvh(); |
| 803 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
| 804 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 805 rvh2->GetSiteInstance())); |
| 806 |
| 807 // Ensure rvh1 is placed on swapped out list of the current tab. |
| 808 EXPECT_TRUE(manager->IsSwappedOut(rvh1)); |
| 809 EXPECT_EQ(rvh1, |
| 810 manager->GetSwappedOutRenderViewHost(rvh1->GetSiteInstance())); |
| 811 |
| 812 // Ensure a swapped out RVH is created in the first opener tab. |
| 813 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
| 814 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 815 EXPECT_TRUE(opener1_manager->IsSwappedOut(opener1_rvh)); |
| 816 EXPECT_TRUE(opener1_rvh->is_swapped_out()); |
| 817 |
| 818 // Ensure a swapped out RVH is created in the second opener tab. |
| 819 TestRenderViewHost* opener2_rvh = static_cast<TestRenderViewHost*>( |
| 820 opener2_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 821 EXPECT_TRUE(opener2_manager->IsSwappedOut(opener2_rvh)); |
| 822 EXPECT_TRUE(opener2_rvh->is_swapped_out()); |
| 823 |
| 824 // Navigate to a cross-BrowsingInstance URL. |
| 825 contents()->NavigateAndCommit(kNtpUrl); |
| 826 TestRenderViewHost* rvh3 = test_rvh(); |
| 827 EXPECT_NE(rvh1->GetSiteInstance(), rvh3->GetSiteInstance()); |
| 828 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 829 rvh3->GetSiteInstance())); |
| 830 |
| 831 // No scripting is allowed across BrowsingInstances, so we should not create |
| 832 // swapped out RVHs for the opener chain in this case. |
| 833 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
| 834 rvh3->GetSiteInstance())); |
| 835 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( |
| 836 rvh3->GetSiteInstance())); |
| 837 } |
OLD | NEW |