| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // Using TestBrowserContext. | 325 // Using TestBrowserContext. |
| 326 SiteInstanceImpl* instance = | 326 SiteInstanceImpl* instance = |
| 327 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); | 327 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); |
| 328 EXPECT_FALSE(instance->HasSite()); | 328 EXPECT_FALSE(instance->HasSite()); |
| 329 | 329 |
| 330 scoped_ptr<TestWebContents> web_contents( | 330 scoped_ptr<TestWebContents> web_contents( |
| 331 TestWebContents::Create(browser_context(), instance)); | 331 TestWebContents::Create(browser_context(), instance)); |
| 332 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 332 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 333 web_contents.get()); | 333 web_contents.get()); |
| 334 | 334 |
| 335 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 335 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 336 | 336 |
| 337 RenderViewHost* host = manager.current_host(); | 337 RenderViewHost* host = manager.current_host(); |
| 338 ASSERT_TRUE(host); | 338 ASSERT_TRUE(host); |
| 339 EXPECT_EQ(instance, host->GetSiteInstance()); | 339 EXPECT_EQ(instance, host->GetSiteInstance()); |
| 340 EXPECT_EQ(web_contents.get(), host->GetDelegate()); | 340 EXPECT_EQ(web_contents.get(), host->GetDelegate()); |
| 341 EXPECT_TRUE(manager.GetRenderWidgetHostView()); | 341 EXPECT_TRUE(manager.GetRenderWidgetHostView()); |
| 342 EXPECT_FALSE(manager.pending_render_view_host()); | 342 EXPECT_FALSE(manager.pending_render_view_host()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Tests the Navigate function. We navigate three sites consecutively and check | 345 // Tests the Navigate function. We navigate three sites consecutively and check |
| 346 // how the pending/committed RenderViewHost are modified. | 346 // how the pending/committed RenderViewHost are modified. |
| 347 TEST_F(RenderViewHostManagerTest, Navigate) { | 347 TEST_F(RenderViewHostManagerTest, Navigate) { |
| 348 TestNotificationTracker notifications; | 348 TestNotificationTracker notifications; |
| 349 | 349 |
| 350 SiteInstance* instance = SiteInstance::Create(browser_context()); | 350 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 351 | 351 |
| 352 scoped_ptr<TestWebContents> web_contents( | 352 scoped_ptr<TestWebContents> web_contents( |
| 353 TestWebContents::Create(browser_context(), instance)); | 353 TestWebContents::Create(browser_context(), instance)); |
| 354 notifications.ListenFor( | 354 notifications.ListenFor( |
| 355 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 355 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 356 Source<NavigationController>(&web_contents->GetController())); | 356 Source<NavigationController>(&web_contents->GetController())); |
| 357 | 357 |
| 358 // Create. | 358 // Create. |
| 359 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 359 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 360 web_contents.get()); | 360 web_contents.get()); |
| 361 | 361 |
| 362 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 362 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 363 | 363 |
| 364 RenderViewHost* host; | 364 RenderViewHost* host; |
| 365 | 365 |
| 366 // 1) The first navigation. -------------------------- | 366 // 1) The first navigation. -------------------------- |
| 367 const GURL kUrl1("http://www.google.com/"); | 367 const GURL kUrl1("http://www.google.com/"); |
| 368 NavigationEntryImpl entry1( | 368 NavigationEntryImpl entry1( |
| 369 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 369 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 370 string16() /* title */, PAGE_TRANSITION_TYPED, | 370 string16() /* title */, PAGE_TRANSITION_TYPED, |
| 371 false /* is_renderer_init */); | 371 false /* is_renderer_init */); |
| 372 host = manager.Navigate(entry1); | 372 host = manager.Navigate(entry1); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 scoped_ptr<TestWebContents> web_contents( | 445 scoped_ptr<TestWebContents> web_contents( |
| 446 TestWebContents::Create(browser_context(), instance)); | 446 TestWebContents::Create(browser_context(), instance)); |
| 447 notifications.ListenFor( | 447 notifications.ListenFor( |
| 448 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 448 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 449 Source<NavigationController>(&web_contents->GetController())); | 449 Source<NavigationController>(&web_contents->GetController())); |
| 450 | 450 |
| 451 // Create. | 451 // Create. |
| 452 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 452 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 453 web_contents.get()); | 453 web_contents.get()); |
| 454 | 454 |
| 455 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 455 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 456 | 456 |
| 457 // 1) The first navigation. -------------------------- | 457 // 1) The first navigation. -------------------------- |
| 458 const GURL kUrl1("http://www.google.com/"); | 458 const GURL kUrl1("http://www.google.com/"); |
| 459 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 459 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 460 Referrer(), string16() /* title */, | 460 Referrer(), string16() /* title */, |
| 461 PAGE_TRANSITION_TYPED, | 461 PAGE_TRANSITION_TYPED, |
| 462 false /* is_renderer_init */); | 462 false /* is_renderer_init */); |
| 463 RenderViewHost* host = manager.Navigate(entry1); | 463 RenderViewHost* host = manager.Navigate(entry1); |
| 464 | 464 |
| 465 // The RenderViewHost created in Init will be reused. | 465 // The RenderViewHost created in Init will be reused. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 TEST_F(RenderViewHostManagerTest, WebUI) { | 592 TEST_F(RenderViewHostManagerTest, WebUI) { |
| 593 set_should_create_webui(true); | 593 set_should_create_webui(true); |
| 594 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | 594 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); |
| 595 SiteInstance* instance = SiteInstance::Create(browser_context()); | 595 SiteInstance* instance = SiteInstance::Create(browser_context()); |
| 596 | 596 |
| 597 scoped_ptr<TestWebContents> web_contents( | 597 scoped_ptr<TestWebContents> web_contents( |
| 598 TestWebContents::Create(browser_context(), instance)); | 598 TestWebContents::Create(browser_context(), instance)); |
| 599 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 599 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 600 web_contents.get()); | 600 web_contents.get()); |
| 601 | 601 |
| 602 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 602 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 603 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); | 603 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); |
| 604 | 604 |
| 605 const GURL kUrl("chrome://foo"); | 605 const GURL kUrl("chrome://foo"); |
| 606 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, | 606 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, |
| 607 Referrer(), string16() /* title */, | 607 Referrer(), string16() /* title */, |
| 608 PAGE_TRANSITION_TYPED, | 608 PAGE_TRANSITION_TYPED, |
| 609 false /* is_renderer_init */); | 609 false /* is_renderer_init */); |
| 610 RenderViewHost* host = manager.Navigate(entry); | 610 RenderViewHost* host = manager.Navigate(entry); |
| 611 | 611 |
| 612 // We commit the pending RenderViewHost immediately because the previous | 612 // We commit the pending RenderViewHost immediately because the previous |
| (...skipping 25 matching lines...) Expand all Loading... |
| 638 // grant the correct bindings. http://crbug.com/189101. | 638 // grant the correct bindings. http://crbug.com/189101. |
| 639 TEST_F(RenderViewHostManagerTest, WebUIInNewTab) { | 639 TEST_F(RenderViewHostManagerTest, WebUIInNewTab) { |
| 640 set_should_create_webui(true); | 640 set_should_create_webui(true); |
| 641 SiteInstance* blank_instance = SiteInstance::Create(browser_context()); | 641 SiteInstance* blank_instance = SiteInstance::Create(browser_context()); |
| 642 | 642 |
| 643 // Create a blank tab. | 643 // Create a blank tab. |
| 644 scoped_ptr<TestWebContents> web_contents1( | 644 scoped_ptr<TestWebContents> web_contents1( |
| 645 TestWebContents::Create(browser_context(), blank_instance)); | 645 TestWebContents::Create(browser_context(), blank_instance)); |
| 646 RenderViewHostManager manager1(web_contents1.get(), web_contents1.get(), | 646 RenderViewHostManager manager1(web_contents1.get(), web_contents1.get(), |
| 647 web_contents1.get()); | 647 web_contents1.get()); |
| 648 manager1.Init(browser_context(), blank_instance, MSG_ROUTING_NONE); | 648 manager1.Init( |
| 649 browser_context(), blank_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 649 // Test the case that new RVH is considered live. | 650 // Test the case that new RVH is considered live. |
| 650 manager1.current_host()->CreateRenderView(string16(), -1, -1); | 651 manager1.current_host()->CreateRenderView(string16(), -1, -1); |
| 651 | 652 |
| 652 // Navigate to a WebUI page. | 653 // Navigate to a WebUI page. |
| 653 const GURL kUrl1("chrome://foo"); | 654 const GURL kUrl1("chrome://foo"); |
| 654 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 655 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
| 655 Referrer(), string16() /* title */, | 656 Referrer(), string16() /* title */, |
| 656 PAGE_TRANSITION_TYPED, | 657 PAGE_TRANSITION_TYPED, |
| 657 false /* is_renderer_init */); | 658 false /* is_renderer_init */); |
| 658 RenderViewHost* host1 = manager1.Navigate(entry1); | 659 RenderViewHost* host1 = manager1.Navigate(entry1); |
| 659 | 660 |
| 660 // We should have a pending navigation to the WebUI RenderViewHost. | 661 // We should have a pending navigation to the WebUI RenderViewHost. |
| 661 // It should already have bindings. | 662 // It should already have bindings. |
| 662 EXPECT_EQ(host1, manager1.pending_render_view_host()); | 663 EXPECT_EQ(host1, manager1.pending_render_view_host()); |
| 663 EXPECT_NE(host1, manager1.current_host()); | 664 EXPECT_NE(host1, manager1.current_host()); |
| 664 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 665 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 665 | 666 |
| 666 // Commit and ensure we still have bindings. | 667 // Commit and ensure we still have bindings. |
| 667 manager1.DidNavigateMainFrame(host1); | 668 manager1.DidNavigateMainFrame(host1); |
| 668 SiteInstance* webui_instance = host1->GetSiteInstance(); | 669 SiteInstance* webui_instance = host1->GetSiteInstance(); |
| 669 EXPECT_EQ(host1, manager1.current_host()); | 670 EXPECT_EQ(host1, manager1.current_host()); |
| 670 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 671 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
| 671 | 672 |
| 672 // Now simulate clicking a link that opens in a new tab. | 673 // Now simulate clicking a link that opens in a new tab. |
| 673 scoped_ptr<TestWebContents> web_contents2( | 674 scoped_ptr<TestWebContents> web_contents2( |
| 674 TestWebContents::Create(browser_context(), webui_instance)); | 675 TestWebContents::Create(browser_context(), webui_instance)); |
| 675 RenderViewHostManager manager2(web_contents2.get(), web_contents2.get(), | 676 RenderViewHostManager manager2(web_contents2.get(), web_contents2.get(), |
| 676 web_contents2.get()); | 677 web_contents2.get()); |
| 677 manager2.Init(browser_context(), webui_instance, MSG_ROUTING_NONE); | 678 manager2.Init( |
| 679 browser_context(), webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 678 // Make sure the new RVH is considered live. This is usually done in | 680 // Make sure the new RVH is considered live. This is usually done in |
| 679 // RenderWidgetHost::Init when opening a new tab from a link. | 681 // RenderWidgetHost::Init when opening a new tab from a link. |
| 680 manager2.current_host()->CreateRenderView(string16(), -1, -1); | 682 manager2.current_host()->CreateRenderView(string16(), -1, -1); |
| 681 | 683 |
| 682 const GURL kUrl2("chrome://foo/bar"); | 684 const GURL kUrl2("chrome://foo/bar"); |
| 683 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, | 685 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, |
| 684 Referrer(), string16() /* title */, | 686 Referrer(), string16() /* title */, |
| 685 PAGE_TRANSITION_LINK, | 687 PAGE_TRANSITION_LINK, |
| 686 true /* is_renderer_init */); | 688 true /* is_renderer_init */); |
| 687 RenderViewHost* host2 = manager2.Navigate(entry2); | 689 RenderViewHost* host2 = manager2.Navigate(entry2); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 GURL guest_url(std::string(chrome::kGuestScheme).append("://abc123")); | 896 GURL guest_url(std::string(chrome::kGuestScheme).append("://abc123")); |
| 895 SiteInstance* instance = | 897 SiteInstance* instance = |
| 896 SiteInstance::CreateForURL(browser_context(), guest_url); | 898 SiteInstance::CreateForURL(browser_context(), guest_url); |
| 897 scoped_ptr<TestWebContents> web_contents( | 899 scoped_ptr<TestWebContents> web_contents( |
| 898 TestWebContents::Create(browser_context(), instance)); | 900 TestWebContents::Create(browser_context(), instance)); |
| 899 | 901 |
| 900 // Create. | 902 // Create. |
| 901 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 903 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
| 902 web_contents.get()); | 904 web_contents.get()); |
| 903 | 905 |
| 904 manager.Init(browser_context(), instance, MSG_ROUTING_NONE); | 906 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
| 905 | 907 |
| 906 RenderViewHost* host; | 908 RenderViewHost* host; |
| 907 | 909 |
| 908 // 1) The first navigation. -------------------------- | 910 // 1) The first navigation. -------------------------- |
| 909 const GURL kUrl1("http://www.google.com/"); | 911 const GURL kUrl1("http://www.google.com/"); |
| 910 NavigationEntryImpl entry1( | 912 NavigationEntryImpl entry1( |
| 911 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 913 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
| 912 string16() /* title */, PAGE_TRANSITION_TYPED, | 914 string16() /* title */, PAGE_TRANSITION_TYPED, |
| 913 false /* is_renderer_init */); | 915 false /* is_renderer_init */); |
| 914 host = manager.Navigate(entry1); | 916 host = manager.Navigate(entry1); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 942 | 944 |
| 943 // Commit. | 945 // Commit. |
| 944 manager.DidNavigateMainFrame(host); | 946 manager.DidNavigateMainFrame(host); |
| 945 EXPECT_EQ(host, manager.current_host()); | 947 EXPECT_EQ(host, manager.current_host()); |
| 946 ASSERT_TRUE(host); | 948 ASSERT_TRUE(host); |
| 947 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), | 949 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), |
| 948 instance); | 950 instance); |
| 949 } | 951 } |
| 950 | 952 |
| 951 } // namespace content | 953 } // namespace content |
| OLD | NEW |