| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 // Tests the Init function by checking the initial RenderViewHost. | 386 // Tests the Init function by checking the initial RenderViewHost. |
| 387 TEST_F(RenderViewHostManagerTest, Init) { | 387 TEST_F(RenderViewHostManagerTest, Init) { |
| 388 // Using TestBrowserContext. | 388 // Using TestBrowserContext. |
| 389 SiteInstanceImpl* instance = | 389 SiteInstanceImpl* instance = |
| 390 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); | 390 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); |
| 391 EXPECT_FALSE(instance->HasSite()); | 391 EXPECT_FALSE(instance->HasSite()); |
| 392 | 392 |
| 393 TestWebContents web_contents(browser_context(), instance); | 393 TestWebContents web_contents(browser_context(), instance); |
| 394 RenderViewHostManager manager(&web_contents, &web_contents); | 394 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); |
| 395 | 395 |
| 396 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 396 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 397 | 397 |
| 398 RenderViewHost* host = manager.current_host(); | 398 RenderViewHost* host = manager.current_host(); |
| 399 ASSERT_TRUE(host); | 399 ASSERT_TRUE(host); |
| 400 EXPECT_TRUE(instance == host->GetSiteInstance()); | 400 EXPECT_TRUE(instance == host->GetSiteInstance()); |
| 401 EXPECT_TRUE(&web_contents == host->GetDelegate()); | 401 EXPECT_TRUE(&web_contents == host->GetDelegate()); |
| 402 EXPECT_TRUE(manager.GetRenderWidgetHostView()); | 402 EXPECT_TRUE(manager.GetRenderWidgetHostView()); |
| 403 EXPECT_FALSE(manager.pending_render_view_host()); | 403 EXPECT_FALSE(manager.pending_render_view_host()); |
| 404 } | 404 } |
| 405 | 405 |
| 406 // Tests the Navigate function. We navigate three sites consecutively and check | 406 // Tests the Navigate function. We navigate three sites consecutively and check |
| 407 // how the pending/committed RenderViewHost are modified. | 407 // how the pending/committed RenderViewHost are modified. |
| 408 TEST_F(RenderViewHostManagerTest, Navigate) { | 408 TEST_F(RenderViewHostManagerTest, Navigate) { |
| 409 TestNotificationTracker notifications; | 409 TestNotificationTracker notifications; |
| 410 | 410 |
| 411 SiteInstance* instance = SiteInstance::Create(browser_context()); | 411 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 412 | 412 |
| 413 TestWebContents web_contents(browser_context(), instance); | 413 TestWebContents web_contents(browser_context(), instance); |
| 414 notifications.ListenFor( | 414 notifications.ListenFor( |
| 415 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 415 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 416 content::Source<NavigationController>( | 416 content::Source<NavigationController>( |
| 417 &web_contents.GetController())); | 417 &web_contents.GetController())); |
| 418 | 418 |
| 419 // Create. | 419 // Create. |
| 420 RenderViewHostManager manager(&web_contents, &web_contents); | 420 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); |
| 421 | 421 |
| 422 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 422 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 423 | 423 |
| 424 RenderViewHost* host; | 424 RenderViewHost* host; |
| 425 | 425 |
| 426 // 1) The first navigation. -------------------------- | 426 // 1) The first navigation. -------------------------- |
| 427 const GURL kUrl1("http://www.google.com/"); | 427 const GURL kUrl1("http://www.google.com/"); |
| 428 NavigationEntryImpl entry1( | 428 NavigationEntryImpl entry1( |
| 429 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), | 429 NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(), |
| 430 string16() /* title */, content::PAGE_TRANSITION_TYPED, | 430 string16() /* title */, content::PAGE_TRANSITION_TYPED, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 502 |
| 503 SiteInstance* instance = SiteInstance::Create(browser_context()); | 503 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 504 | 504 |
| 505 TestWebContents web_contents(browser_context(), instance); | 505 TestWebContents web_contents(browser_context(), instance); |
| 506 notifications.ListenFor( | 506 notifications.ListenFor( |
| 507 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 507 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 508 content::Source<NavigationController>( | 508 content::Source<NavigationController>( |
| 509 &web_contents.GetController())); | 509 &web_contents.GetController())); |
| 510 | 510 |
| 511 // Create. | 511 // Create. |
| 512 RenderViewHostManager manager(&web_contents, &web_contents); | 512 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); |
| 513 | 513 |
| 514 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 514 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 515 | 515 |
| 516 // 1) The first navigation. -------------------------- | 516 // 1) The first navigation. -------------------------- |
| 517 const GURL kUrl1("http://www.google.com/"); | 517 const GURL kUrl1("http://www.google.com/"); |
| 518 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 518 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 519 content::Referrer(), string16() /* title */, | 519 content::Referrer(), string16() /* title */, |
| 520 content::PAGE_TRANSITION_TYPED, | 520 content::PAGE_TRANSITION_TYPED, |
| 521 false /* is_renderer_init */); | 521 false /* is_renderer_init */); |
| 522 RenderViewHost* host = manager.Navigate(entry1); | 522 RenderViewHost* host = manager.Navigate(entry1); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 647 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
| 648 } | 648 } |
| 649 | 649 |
| 650 // Tests WebUI creation. | 650 // Tests WebUI creation. |
| 651 TEST_F(RenderViewHostManagerTest, WebUI) { | 651 TEST_F(RenderViewHostManagerTest, WebUI) { |
| 652 set_should_create_webui(true); | 652 set_should_create_webui(true); |
| 653 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 653 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
| 654 SiteInstance* instance = SiteInstance::Create(browser_context()); | 654 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 655 | 655 |
| 656 TestWebContents web_contents(browser_context(), instance); | 656 TestWebContents web_contents(browser_context(), instance); |
| 657 RenderViewHostManager manager(&web_contents, &web_contents); | 657 RenderViewHostManager manager(&web_contents, &web_contents, &web_contents); |
| 658 | 658 |
| 659 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 659 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); |
| 660 | 660 |
| 661 const GURL kUrl(chrome::kTestNewTabURL); | 661 const GURL kUrl(chrome::kTestNewTabURL); |
| 662 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 662 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 663 content::Referrer(), string16() /* title */, | 663 content::Referrer(), string16() /* title */, |
| 664 content::PAGE_TRANSITION_TYPED, | 664 content::PAGE_TRANSITION_TYPED, |
| 665 false /* is_renderer_init */); | 665 false /* is_renderer_init */); |
| 666 RenderViewHost* host = manager.Navigate(entry); | 666 RenderViewHost* host = manager.Navigate(entry); |
| 667 | 667 |
| (...skipping 160 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 |