| 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/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
| 8 #include "content/browser/site_instance_impl.h" | 8 #include "content/browser/site_instance_impl.h" |
| 9 #include "content/browser/web_contents/navigation_controller_impl.h" | 9 #include "content/browser/web_contents/navigation_controller_impl.h" |
| 10 #include "content/browser/web_contents/navigation_entry_impl.h" | 10 #include "content/browser/web_contents/navigation_entry_impl.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 198 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
| 199 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 199 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 200 const GURL kNtpUrl(content::kTestNewTabURL); | 200 const GURL kNtpUrl(content::kTestNewTabURL); |
| 201 const GURL kDestUrl("http://www.google.com/"); | 201 const GURL kDestUrl("http://www.google.com/"); |
| 202 | 202 |
| 203 // Navigate our first tab to the new tab page and then to the destination. | 203 // Navigate our first tab to the new tab page and then to the destination. |
| 204 NavigateActiveAndCommit(kNtpUrl); | 204 NavigateActiveAndCommit(kNtpUrl); |
| 205 NavigateActiveAndCommit(kDestUrl); | 205 NavigateActiveAndCommit(kDestUrl); |
| 206 | 206 |
| 207 // Make a second tab. | 207 // Make a second tab. |
| 208 TestWebContents contents2(browser_context(), NULL); | 208 scoped_ptr<TestWebContents> contents2( |
| 209 TestWebContents::Create(browser_context(), NULL)); |
| 209 | 210 |
| 210 // Load the two URLs in the second tab. Note that the first navigation creates | 211 // Load the two URLs in the second tab. Note that the first navigation creates |
| 211 // a RVH that's not pending (since there is no cross-site transition), so | 212 // a RVH that's not pending (since there is no cross-site transition), so |
| 212 // we use the committed one. | 213 // we use the committed one. |
| 213 contents2.GetController().LoadURL( | 214 contents2->GetController().LoadURL( |
| 214 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 215 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 215 std::string()); | 216 std::string()); |
| 216 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( | 217 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( |
| 217 contents2.GetRenderManagerForTesting()->current_host()); | 218 contents2->GetRenderManagerForTesting()->current_host()); |
| 218 EXPECT_FALSE(contents2.cross_navigation_pending()); | 219 EXPECT_FALSE(contents2->cross_navigation_pending()); |
| 219 ntp_rvh2->SendNavigate(100, kNtpUrl); | 220 ntp_rvh2->SendNavigate(100, kNtpUrl); |
| 220 | 221 |
| 221 // The second one is the opposite, creating a cross-site transition and | 222 // The second one is the opposite, creating a cross-site transition and |
| 222 // requiring a beforeunload ack. | 223 // requiring a beforeunload ack. |
| 223 contents2.GetController().LoadURL( | 224 contents2->GetController().LoadURL( |
| 224 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 225 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 225 std::string()); | 226 std::string()); |
| 226 EXPECT_TRUE(contents2.cross_navigation_pending()); | 227 EXPECT_TRUE(contents2->cross_navigation_pending()); |
| 227 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( | 228 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( |
| 228 contents2.GetRenderManagerForTesting()->pending_render_view_host()); | 229 contents2->GetRenderManagerForTesting()->pending_render_view_host()); |
| 229 ASSERT_TRUE(dest_rvh2); | 230 ASSERT_TRUE(dest_rvh2); |
| 230 ntp_rvh2->SendShouldCloseACK(true); | 231 ntp_rvh2->SendShouldCloseACK(true); |
| 231 dest_rvh2->SendNavigate(101, kDestUrl); | 232 dest_rvh2->SendNavigate(101, kDestUrl); |
| 232 ntp_rvh2->OnSwapOutACK(); | 233 ntp_rvh2->OnSwapOutACK(); |
| 233 | 234 |
| 234 // The two RVH's should be different in every way. | 235 // The two RVH's should be different in every way. |
| 235 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); | 236 EXPECT_NE(active_rvh()->GetProcess(), dest_rvh2->GetProcess()); |
| 236 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); | 237 EXPECT_NE(active_rvh()->GetSiteInstance(), dest_rvh2->GetSiteInstance()); |
| 237 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( | 238 EXPECT_FALSE(active_rvh()->GetSiteInstance()->IsRelatedSiteInstance( |
| 238 dest_rvh2->GetSiteInstance())); | 239 dest_rvh2->GetSiteInstance())); |
| 239 | 240 |
| 240 // Navigate both to the new tab page, and verify that they share a | 241 // Navigate both to the new tab page, and verify that they share a |
| 241 // RenderProcessHost (not a SiteInstance). | 242 // RenderProcessHost (not a SiteInstance). |
| 242 NavigateActiveAndCommit(kNtpUrl); | 243 NavigateActiveAndCommit(kNtpUrl); |
| 243 | 244 |
| 244 contents2.GetController().LoadURL( | 245 contents2->GetController().LoadURL( |
| 245 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 246 kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 246 std::string()); | 247 std::string()); |
| 247 dest_rvh2->SendShouldCloseACK(true); | 248 dest_rvh2->SendShouldCloseACK(true); |
| 248 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> | 249 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> |
| 249 pending_render_view_host())->SendNavigate(102, kNtpUrl); | 250 pending_render_view_host())->SendNavigate(102, kNtpUrl); |
| 250 dest_rvh2->OnSwapOutACK(); | 251 dest_rvh2->OnSwapOutACK(); |
| 251 | 252 |
| 252 EXPECT_NE(active_rvh()->GetSiteInstance(), | 253 EXPECT_NE(active_rvh()->GetSiteInstance(), |
| 253 contents2.GetRenderViewHost()->GetSiteInstance()); | 254 contents2->GetRenderViewHost()->GetSiteInstance()); |
| 254 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), | 255 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), |
| 255 contents2.GetRenderViewHost()->GetSiteInstance()->GetProcess()); | 256 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); |
| 256 } | 257 } |
| 257 | 258 |
| 258 // Ensure that the browser ignores most IPC messages that arrive from a | 259 // Ensure that the browser ignores most IPC messages that arrive from a |
| 259 // RenderViewHost that has been swapped out. We do not want to take | 260 // RenderViewHost that has been swapped out. We do not want to take |
| 260 // action on requests from a non-active renderer. The main exception is | 261 // action on requests from a non-active renderer. The main exception is |
| 261 // for synchronous messages, which cannot be ignored without leaving the | 262 // for synchronous messages, which cannot be ignored without leaving the |
| 262 // renderer in a stuck state. See http://crbug.com/93427. | 263 // renderer in a stuck state. See http://crbug.com/93427. |
| 263 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { | 264 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { |
| 264 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 265 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 265 const GURL kNtpUrl(content::kTestNewTabURL); | 266 const GURL kNtpUrl(content::kTestNewTabURL); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 ViewMsg_EnableViewSourceMode::ID)); | 387 ViewMsg_EnableViewSourceMode::ID)); |
| 387 } | 388 } |
| 388 | 389 |
| 389 // Tests the Init function by checking the initial RenderViewHost. | 390 // Tests the Init function by checking the initial RenderViewHost. |
| 390 TEST_F(RenderViewHostManagerTest, Init) { | 391 TEST_F(RenderViewHostManagerTest, Init) { |
| 391 // Using TestBrowserContext. | 392 // Using TestBrowserContext. |
| 392 SiteInstanceImpl* instance = | 393 SiteInstanceImpl* instance = |
| 393 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); | 394 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); |
| 394 EXPECT_FALSE(instance->HasSite()); | 395 EXPECT_FALSE(instance->HasSite()); |
| 395 | 396 |
| 396 TestWebContents web_contents(browser_context(), instance); | 397 scoped_ptr<TestWebContents> web_contents( |
| 397 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 398 TestWebContents::Create(browser_context(), instance)); |
| 399 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 400 web_contents.get()); |
| 398 | 401 |
| 399 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 402 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 400 | 403 |
| 401 RenderViewHost* host = manager.current_host(); | 404 RenderViewHost* host = manager.current_host(); |
| 402 ASSERT_TRUE(host); | 405 ASSERT_TRUE(host); |
| 403 EXPECT_TRUE(instance == host->GetSiteInstance()); | 406 EXPECT_EQ(instance, host->GetSiteInstance()); |
| 404 EXPECT_TRUE(&web_contents == host->GetDelegate()); | 407 EXPECT_EQ(web_contents.get(), host->GetDelegate()); |
| 405 EXPECT_TRUE(manager.GetRenderWidgetHostView()); | 408 EXPECT_TRUE(manager.GetRenderWidgetHostView()); |
| 406 EXPECT_FALSE(manager.pending_render_view_host()); | 409 EXPECT_FALSE(manager.pending_render_view_host()); |
| 407 } | 410 } |
| 408 | 411 |
| 409 // Tests the Navigate function. We navigate three sites consecutively and check | 412 // Tests the Navigate function. We navigate three sites consecutively and check |
| 410 // how the pending/committed RenderViewHost are modified. | 413 // how the pending/committed RenderViewHost are modified. |
| 411 TEST_F(RenderViewHostManagerTest, Navigate) { | 414 TEST_F(RenderViewHostManagerTest, Navigate) { |
| 412 content::TestNotificationTracker notifications; | 415 content::TestNotificationTracker notifications; |
| 413 | 416 |
| 414 SiteInstance* instance = SiteInstance::Create(browser_context()); | 417 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 415 | 418 |
| 416 TestWebContents web_contents(browser_context(), instance); | 419 scoped_ptr<TestWebContents> web_contents( |
| 420 TestWebContents::Create(browser_context(), instance)); |
| 417 notifications.ListenFor( | 421 notifications.ListenFor( |
| 418 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 422 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 419 content::Source<NavigationController>( | 423 content::Source<NavigationController>( |
| 420 &web_contents.GetController())); | 424 &web_contents->GetController())); |
| 421 | 425 |
| 422 // Create. | 426 // Create. |
| 423 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 427 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 428 web_contents.get()); |
| 424 | 429 |
| 425 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 430 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 426 | 431 |
| 427 RenderViewHost* host; | 432 RenderViewHost* host; |
| 428 | 433 |
| 429 // 1) The first navigation. -------------------------- | 434 // 1) The first navigation. -------------------------- |
| 430 const GURL kUrl1("http://www.google.com/"); | 435 const GURL kUrl1("http://www.google.com/"); |
| 431 NavigationEntryImpl entry1( | 436 NavigationEntryImpl entry1( |
| 432 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), | 437 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), |
| 433 string16() /* title */, content::PAGE_TRANSITION_TYPED, | 438 string16() /* title */, content::PAGE_TRANSITION_TYPED, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 503 |
| 499 // Tests the Navigate function. In this unit test we verify that the Navigate | 504 // Tests the Navigate function. In this unit test we verify that the Navigate |
| 500 // function can handle a new navigation event before the previous navigation | 505 // function can handle a new navigation event before the previous navigation |
| 501 // has been committed. This is also a regression test for | 506 // has been committed. This is also a regression test for |
| 502 // http://crbug.com/104600. | 507 // http://crbug.com/104600. |
| 503 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { | 508 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { |
| 504 content::TestNotificationTracker notifications; | 509 content::TestNotificationTracker notifications; |
| 505 | 510 |
| 506 SiteInstance* instance = SiteInstance::Create(browser_context()); | 511 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 507 | 512 |
| 508 TestWebContents web_contents(browser_context(), instance); | 513 scoped_ptr<TestWebContents> web_contents( |
| 514 TestWebContents::Create(browser_context(), instance)); |
| 509 notifications.ListenFor( | 515 notifications.ListenFor( |
| 510 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 516 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 511 content::Source<NavigationController>( | 517 content::Source<NavigationController>( |
| 512 &web_contents.GetController())); | 518 &web_contents->GetController())); |
| 513 | 519 |
| 514 // Create. | 520 // Create. |
| 515 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 521 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 522 web_contents.get()); |
| 516 | 523 |
| 517 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 524 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 518 | 525 |
| 519 // 1) The first navigation. -------------------------- | 526 // 1) The first navigation. -------------------------- |
| 520 const GURL kUrl1("http://www.google.com/"); | 527 const GURL kUrl1("http://www.google.com/"); |
| 521 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 528 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 522 content::Referrer(), string16() /* title */, | 529 content::Referrer(), string16() /* title */, |
| 523 content::PAGE_TRANSITION_TYPED, | 530 content::PAGE_TRANSITION_TYPED, |
| 524 false /* is_renderer_init */); | 531 false /* is_renderer_init */); |
| 525 RenderViewHost* host = manager.Navigate(entry1); | 532 RenderViewHost* host = manager.Navigate(entry1); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 EXPECT_TRUE(notifications.Check1AndReset( | 656 EXPECT_TRUE(notifications.Check1AndReset( |
| 650 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 657 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 651 } | 658 } |
| 652 | 659 |
| 653 // Tests WebUI creation. | 660 // Tests WebUI creation. |
| 654 TEST_F(RenderViewHostManagerTest, WebUI) { | 661 TEST_F(RenderViewHostManagerTest, WebUI) { |
| 655 set_should_create_webui(true); | 662 set_should_create_webui(true); |
| 656 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 663 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 657 SiteInstance* instance = SiteInstance::Create(browser_context()); | 664 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 658 | 665 |
| 659 TestWebContents web_contents(browser_context(), instance); | 666 scoped_ptr<TestWebContents> web_contents( |
| 660 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 667 TestWebContents::Create(browser_context(), instance)); |
| 668 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 669 web_contents.get()); |
| 661 | 670 |
| 662 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 671 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 663 | 672 |
| 664 const GURL kUrl(content::kTestNewTabURL); | 673 const GURL kUrl(content::kTestNewTabURL); |
| 665 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 674 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 666 content::Referrer(), string16() /* title */, | 675 content::Referrer(), string16() /* title */, |
| 667 content::PAGE_TRANSITION_TYPED, | 676 content::PAGE_TRANSITION_TYPED, |
| 668 false /* is_renderer_init */); | 677 false /* is_renderer_init */); |
| 669 RenderViewHost* host = manager.Navigate(entry); | 678 RenderViewHost* host = manager.Navigate(entry); |
| 670 | 679 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 const GURL kUrl2("http://www.chromium.org/"); | 792 const GURL kUrl2("http://www.chromium.org/"); |
| 784 const GURL kNtpUrl(content::kTestNewTabURL); | 793 const GURL kNtpUrl(content::kTestNewTabURL); |
| 785 | 794 |
| 786 // Navigate to an initial URL. | 795 // Navigate to an initial URL. |
| 787 contents()->NavigateAndCommit(kUrl1); | 796 contents()->NavigateAndCommit(kUrl1); |
| 788 RenderViewHostManager* manager = contents()->GetRenderManagerForTesting(); | 797 RenderViewHostManager* manager = contents()->GetRenderManagerForTesting(); |
| 789 TestRenderViewHost* rvh1 = test_rvh(); | 798 TestRenderViewHost* rvh1 = test_rvh(); |
| 790 | 799 |
| 791 // Create 2 new tabs and simulate them being the opener chain for the main | 800 // Create 2 new tabs and simulate them being the opener chain for the main |
| 792 // tab. They should be in the same SiteInstance. | 801 // tab. They should be in the same SiteInstance. |
| 793 TestWebContents opener1(browser_context(), rvh1->GetSiteInstance()); | 802 scoped_ptr<TestWebContents> opener1( |
| 794 RenderViewHostManager* opener1_manager = opener1.GetRenderManagerForTesting(); | 803 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); |
| 795 contents()->SetOpener(&opener1); | 804 RenderViewHostManager* opener1_manager = |
| 805 opener1->GetRenderManagerForTesting(); |
| 806 contents()->SetOpener(opener1.get()); |
| 796 | 807 |
| 797 TestWebContents opener2(browser_context(), rvh1->GetSiteInstance()); | 808 scoped_ptr<TestWebContents> opener2( |
| 798 RenderViewHostManager* opener2_manager = opener2.GetRenderManagerForTesting(); | 809 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); |
| 799 opener1.SetOpener(&opener2); | 810 RenderViewHostManager* opener2_manager = |
| 811 opener2->GetRenderManagerForTesting(); |
| 812 opener1->SetOpener(opener2.get()); |
| 800 | 813 |
| 801 // Navigate to a cross-site URL (different SiteInstance but same | 814 // Navigate to a cross-site URL (different SiteInstance but same |
| 802 // BrowsingInstance). | 815 // BrowsingInstance). |
| 803 contents()->NavigateAndCommit(kUrl2); | 816 contents()->NavigateAndCommit(kUrl2); |
| 804 TestRenderViewHost* rvh2 = test_rvh(); | 817 TestRenderViewHost* rvh2 = test_rvh(); |
| 805 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 818 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
| 806 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 819 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 807 rvh2->GetSiteInstance())); | 820 rvh2->GetSiteInstance())); |
| 808 | 821 |
| 809 // Ensure rvh1 is placed on swapped out list of the current tab. | 822 // Ensure rvh1 is placed on swapped out list of the current tab. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 861 |
| 849 // Navigate to an initial WebUI URL. | 862 // Navigate to an initial WebUI URL. |
| 850 contents()->NavigateAndCommit(kSettingsUrl); | 863 contents()->NavigateAndCommit(kSettingsUrl); |
| 851 | 864 |
| 852 // Ensure the RVH has WebUI bindings. | 865 // Ensure the RVH has WebUI bindings. |
| 853 TestRenderViewHost* rvh1 = test_rvh(); | 866 TestRenderViewHost* rvh1 = test_rvh(); |
| 854 EXPECT_TRUE(rvh1->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); | 867 EXPECT_TRUE(rvh1->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); |
| 855 | 868 |
| 856 // Create a new tab and simulate it being the opener for the main | 869 // Create a new tab and simulate it being the opener for the main |
| 857 // tab. It should be in the same SiteInstance. | 870 // tab. It should be in the same SiteInstance. |
| 858 TestWebContents opener1(browser_context(), rvh1->GetSiteInstance()); | 871 scoped_ptr<TestWebContents> opener1( |
| 859 RenderViewHostManager* opener1_manager = opener1.GetRenderManagerForTesting(); | 872 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); |
| 860 contents()->SetOpener(&opener1); | 873 RenderViewHostManager* opener1_manager = |
| 874 opener1->GetRenderManagerForTesting(); |
| 875 contents()->SetOpener(opener1.get()); |
| 861 | 876 |
| 862 // Navigate to a different WebUI URL (different SiteInstance, same | 877 // Navigate to a different WebUI URL (different SiteInstance, same |
| 863 // BrowsingInstance). | 878 // BrowsingInstance). |
| 864 contents()->NavigateAndCommit(kPluginUrl); | 879 contents()->NavigateAndCommit(kPluginUrl); |
| 865 TestRenderViewHost* rvh2 = test_rvh(); | 880 TestRenderViewHost* rvh2 = test_rvh(); |
| 866 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); | 881 EXPECT_NE(rvh1->GetSiteInstance(), rvh2->GetSiteInstance()); |
| 867 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 882 EXPECT_TRUE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
| 868 rvh2->GetSiteInstance())); | 883 rvh2->GetSiteInstance())); |
| 869 | 884 |
| 870 // Ensure a swapped out RVH is created in the first opener tab. | 885 // Ensure a swapped out RVH is created in the first opener tab. |
| 871 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( | 886 TestRenderViewHost* opener1_rvh = static_cast<TestRenderViewHost*>( |
| 872 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); | 887 opener1_manager->GetSwappedOutRenderViewHost(rvh2->GetSiteInstance())); |
| 873 EXPECT_TRUE(opener1_manager->IsSwappedOut(opener1_rvh)); | 888 EXPECT_TRUE(opener1_manager->IsSwappedOut(opener1_rvh)); |
| 874 EXPECT_TRUE(opener1_rvh->is_swapped_out()); | 889 EXPECT_TRUE(opener1_rvh->is_swapped_out()); |
| 875 | 890 |
| 876 // Ensure the new RVH has WebUI bindings. | 891 // Ensure the new RVH has WebUI bindings. |
| 877 EXPECT_TRUE(rvh2->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); | 892 EXPECT_TRUE(rvh2->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); |
| 878 } | 893 } |
| 879 | 894 |
| 880 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 895 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
| 881 TEST_F(RenderViewHostManagerTest, NoSwapOnGuestNavigations) { | 896 TEST_F(RenderViewHostManagerTest, NoSwapOnGuestNavigations) { |
| 882 content::TestNotificationTracker notifications; | 897 content::TestNotificationTracker notifications; |
| 883 | 898 |
| 884 GURL guest_url("guest://abc123"); | 899 GURL guest_url("guest://abc123"); |
| 885 SiteInstance* instance = | 900 SiteInstance* instance = |
| 886 SiteInstance::CreateForURL(browser_context(), guest_url); | 901 SiteInstance::CreateForURL(browser_context(), guest_url); |
| 887 TestWebContents web_contents(browser_context(), instance); | 902 scoped_ptr<TestWebContents> web_contents( |
| 903 TestWebContents::Create(browser_context(), instance)); |
| 888 | 904 |
| 889 // Create. | 905 // Create. |
| 890 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); | 906 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 907 web_contents.get()); |
| 891 | 908 |
| 892 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 909 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 893 | 910 |
| 894 RenderViewHost* host; | 911 RenderViewHost* host; |
| 895 | 912 |
| 896 // 1) The first navigation. -------------------------- | 913 // 1) The first navigation. -------------------------- |
| 897 const GURL kUrl1("http://www.google.com/"); | 914 const GURL kUrl1("http://www.google.com/"); |
| 898 NavigationEntryImpl entry1( | 915 NavigationEntryImpl entry1( |
| 899 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), | 916 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), |
| 900 string16() /* title */, content::PAGE_TRANSITION_TYPED, | 917 string16() /* title */, content::PAGE_TRANSITION_TYPED, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 929 EXPECT_FALSE(manager.pending_render_view_host()); | 946 EXPECT_FALSE(manager.pending_render_view_host()); |
| 930 | 947 |
| 931 // Commit. | 948 // Commit. |
| 932 manager.DidNavigateMainFrame(host); | 949 manager.DidNavigateMainFrame(host); |
| 933 EXPECT_EQ(host, manager.current_host()); | 950 EXPECT_EQ(host, manager.current_host()); |
| 934 ASSERT_TRUE(host); | 951 ASSERT_TRUE(host); |
| 935 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), | 952 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), |
| 936 instance); | 953 instance); |
| 937 | 954 |
| 938 } | 955 } |
| OLD | NEW |