Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: content/browser/web_contents/render_view_host_manager_unittest.cc

Issue 23129015: Initialize RenderWidget(Host)(View)s with correct visibility state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/renderer_host/test_render_view_host.h" 6 #include "content/browser/renderer_host/test_render_view_host.h"
7 #include "content/browser/site_instance_impl.h" 7 #include "content/browser/site_instance_impl.h"
8 #include "content/browser/web_contents/navigation_controller_impl.h" 8 #include "content/browser/web_contents/navigation_controller_impl.h"
9 #include "content/browser/web_contents/navigation_entry_impl.h" 9 #include "content/browser/web_contents/navigation_entry_impl.h"
10 #include "content/browser/web_contents/render_view_host_manager.h" 10 #include "content/browser/web_contents/render_view_host_manager.h"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // Using TestBrowserContext. 538 // Using TestBrowserContext.
539 SiteInstanceImpl* instance = 539 SiteInstanceImpl* instance =
540 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); 540 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
541 EXPECT_FALSE(instance->HasSite()); 541 EXPECT_FALSE(instance->HasSite());
542 542
543 scoped_ptr<TestWebContents> web_contents( 543 scoped_ptr<TestWebContents> web_contents(
544 TestWebContents::Create(browser_context(), instance)); 544 TestWebContents::Create(browser_context(), instance));
545 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 545 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
546 web_contents.get()); 546 web_contents.get());
547 547
548 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 548 manager.Init(browser_context(),
549 instance,
550 MSG_ROUTING_NONE,
551 MSG_ROUTING_NONE,
552 false);
549 553
550 RenderViewHost* host = manager.current_host(); 554 RenderViewHost* host = manager.current_host();
551 ASSERT_TRUE(host); 555 ASSERT_TRUE(host);
552 EXPECT_EQ(instance, host->GetSiteInstance()); 556 EXPECT_EQ(instance, host->GetSiteInstance());
553 EXPECT_EQ(web_contents.get(), host->GetDelegate()); 557 EXPECT_EQ(web_contents.get(), host->GetDelegate());
554 EXPECT_TRUE(manager.GetRenderWidgetHostView()); 558 EXPECT_TRUE(manager.GetRenderWidgetHostView());
555 EXPECT_FALSE(manager.pending_render_view_host()); 559 EXPECT_FALSE(manager.pending_render_view_host());
556 } 560 }
557 561
558 // Tests the Navigate function. We navigate three sites consecutively and check 562 // Tests the Navigate function. We navigate three sites consecutively and check
559 // how the pending/committed RenderViewHost are modified. 563 // how the pending/committed RenderViewHost are modified.
560 TEST_F(RenderViewHostManagerTest, Navigate) { 564 TEST_F(RenderViewHostManagerTest, Navigate) {
561 TestNotificationTracker notifications; 565 TestNotificationTracker notifications;
562 566
563 SiteInstance* instance = SiteInstance::Create(browser_context()); 567 SiteInstance* instance = SiteInstance::Create(browser_context());
564 568
565 scoped_ptr<TestWebContents> web_contents( 569 scoped_ptr<TestWebContents> web_contents(
566 TestWebContents::Create(browser_context(), instance)); 570 TestWebContents::Create(browser_context(), instance));
567 notifications.ListenFor( 571 notifications.ListenFor(
568 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 572 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
569 Source<NavigationController>(&web_contents->GetController())); 573 Source<NavigationController>(&web_contents->GetController()));
570 574
571 // Create. 575 // Create.
572 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 576 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
573 web_contents.get()); 577 web_contents.get());
574 578
575 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 579 manager.Init(browser_context(),
580 instance,
581 MSG_ROUTING_NONE,
582 MSG_ROUTING_NONE,
583 false);
576 584
577 RenderViewHost* host; 585 RenderViewHost* host;
578 586
579 // 1) The first navigation. -------------------------- 587 // 1) The first navigation. --------------------------
580 const GURL kUrl1("http://www.google.com/"); 588 const GURL kUrl1("http://www.google.com/");
581 NavigationEntryImpl entry1( 589 NavigationEntryImpl entry1(
582 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 590 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
583 string16() /* title */, PAGE_TRANSITION_TYPED, 591 string16() /* title */, PAGE_TRANSITION_TYPED,
584 false /* is_renderer_init */); 592 false /* is_renderer_init */);
585 host = manager.Navigate(entry1); 593 host = manager.Navigate(entry1, false);
586 594
587 // The RenderViewHost created in Init will be reused. 595 // The RenderViewHost created in Init will be reused.
588 EXPECT_TRUE(host == manager.current_host()); 596 EXPECT_TRUE(host == manager.current_host());
589 EXPECT_FALSE(manager.pending_render_view_host()); 597 EXPECT_FALSE(manager.pending_render_view_host());
590 598
591 // Commit. 599 // Commit.
592 manager.DidNavigateMainFrame(host); 600 manager.DidNavigateMainFrame(host);
593 // Commit to SiteInstance should be delayed until RenderView commit. 601 // Commit to SiteInstance should be delayed until RenderView commit.
594 EXPECT_TRUE(host == manager.current_host()); 602 EXPECT_TRUE(host == manager.current_host());
595 ASSERT_TRUE(host); 603 ASSERT_TRUE(host);
596 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 604 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
597 HasSite()); 605 HasSite());
598 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); 606 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1);
599 607
600 // 2) Navigate to next site. ------------------------- 608 // 2) Navigate to next site. -------------------------
601 const GURL kUrl2("http://www.google.com/foo"); 609 const GURL kUrl2("http://www.google.com/foo");
602 NavigationEntryImpl entry2( 610 NavigationEntryImpl entry2(
603 NULL /* instance */, -1 /* page_id */, kUrl2, 611 NULL /* instance */, -1 /* page_id */, kUrl2,
604 Referrer(kUrl1, WebKit::WebReferrerPolicyDefault), 612 Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
605 string16() /* title */, PAGE_TRANSITION_LINK, 613 string16() /* title */, PAGE_TRANSITION_LINK,
606 true /* is_renderer_init */); 614 true /* is_renderer_init */);
607 host = manager.Navigate(entry2); 615 host = manager.Navigate(entry2, false);
608 616
609 // The RenderViewHost created in Init will be reused. 617 // The RenderViewHost created in Init will be reused.
610 EXPECT_TRUE(host == manager.current_host()); 618 EXPECT_TRUE(host == manager.current_host());
611 EXPECT_FALSE(manager.pending_render_view_host()); 619 EXPECT_FALSE(manager.pending_render_view_host());
612 620
613 // Commit. 621 // Commit.
614 manager.DidNavigateMainFrame(host); 622 manager.DidNavigateMainFrame(host);
615 EXPECT_TRUE(host == manager.current_host()); 623 EXPECT_TRUE(host == manager.current_host());
616 ASSERT_TRUE(host); 624 ASSERT_TRUE(host);
617 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 625 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
618 HasSite()); 626 HasSite());
619 627
620 // 3) Cross-site navigate to next site. -------------- 628 // 3) Cross-site navigate to next site. --------------
621 const GURL kUrl3("http://webkit.org/"); 629 const GURL kUrl3("http://webkit.org/");
622 NavigationEntryImpl entry3( 630 NavigationEntryImpl entry3(
623 NULL /* instance */, -1 /* page_id */, kUrl3, 631 NULL /* instance */, -1 /* page_id */, kUrl3,
624 Referrer(kUrl2, WebKit::WebReferrerPolicyDefault), 632 Referrer(kUrl2, WebKit::WebReferrerPolicyDefault),
625 string16() /* title */, PAGE_TRANSITION_LINK, 633 string16() /* title */, PAGE_TRANSITION_LINK,
626 false /* is_renderer_init */); 634 false /* is_renderer_init */);
627 host = manager.Navigate(entry3); 635 host = manager.Navigate(entry3, false);
628 636
629 // A new RenderViewHost should be created. 637 // A new RenderViewHost should be created.
630 EXPECT_TRUE(manager.pending_render_view_host()); 638 EXPECT_TRUE(manager.pending_render_view_host());
631 ASSERT_EQ(host, manager.pending_render_view_host()); 639 ASSERT_EQ(host, manager.pending_render_view_host());
632 640
633 notifications.Reset(); 641 notifications.Reset();
634 642
635 // Commit. 643 // Commit.
636 manager.DidNavigateMainFrame(manager.pending_render_view_host()); 644 manager.DidNavigateMainFrame(manager.pending_render_view_host());
637 EXPECT_TRUE(host == manager.current_host()); 645 EXPECT_TRUE(host == manager.current_host());
(...skipping 20 matching lines...) Expand all
658 scoped_ptr<TestWebContents> web_contents( 666 scoped_ptr<TestWebContents> web_contents(
659 TestWebContents::Create(browser_context(), instance)); 667 TestWebContents::Create(browser_context(), instance));
660 notifications.ListenFor( 668 notifications.ListenFor(
661 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 669 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
662 Source<NavigationController>(&web_contents->GetController())); 670 Source<NavigationController>(&web_contents->GetController()));
663 671
664 // Create. 672 // Create.
665 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 673 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
666 web_contents.get()); 674 web_contents.get());
667 675
668 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 676 manager.Init(browser_context(),
677 instance,
678 MSG_ROUTING_NONE,
679 MSG_ROUTING_NONE,
680 false);
669 681
670 // 1) The first navigation. -------------------------- 682 // 1) The first navigation. --------------------------
671 const GURL kUrl1("http://www.google.com/"); 683 const GURL kUrl1("http://www.google.com/");
672 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 684 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
673 Referrer(), string16() /* title */, 685 Referrer(), string16() /* title */,
674 PAGE_TRANSITION_TYPED, 686 PAGE_TRANSITION_TYPED,
675 false /* is_renderer_init */); 687 false /* is_renderer_init */);
676 RenderViewHost* host = manager.Navigate(entry1); 688 RenderViewHost* host = manager.Navigate(entry1, false);
677 689
678 // The RenderViewHost created in Init will be reused. 690 // The RenderViewHost created in Init will be reused.
679 EXPECT_TRUE(host == manager.current_host()); 691 EXPECT_TRUE(host == manager.current_host());
680 EXPECT_FALSE(manager.pending_render_view_host()); 692 EXPECT_FALSE(manager.pending_render_view_host());
681 693
682 // We should observe a notification. 694 // We should observe a notification.
683 EXPECT_TRUE(notifications.Check1AndReset( 695 EXPECT_TRUE(notifications.Check1AndReset(
684 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 696 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
685 notifications.Reset(); 697 notifications.Reset();
686 698
687 // Commit. 699 // Commit.
688 manager.DidNavigateMainFrame(host); 700 manager.DidNavigateMainFrame(host);
689 701
690 // Commit to SiteInstance should be delayed until RenderView commit. 702 // Commit to SiteInstance should be delayed until RenderView commit.
691 EXPECT_TRUE(host == manager.current_host()); 703 EXPECT_TRUE(host == manager.current_host());
692 ASSERT_TRUE(host); 704 ASSERT_TRUE(host);
693 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 705 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
694 HasSite()); 706 HasSite());
695 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); 707 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1);
696 708
697 // 2) Cross-site navigate to next site. ------------------------- 709 // 2) Cross-site navigate to next site. -------------------------
698 const GURL kUrl2("http://www.example.com"); 710 const GURL kUrl2("http://www.example.com");
699 NavigationEntryImpl entry2( 711 NavigationEntryImpl entry2(
700 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(), 712 NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(),
701 string16() /* title */, PAGE_TRANSITION_TYPED, 713 string16() /* title */, PAGE_TRANSITION_TYPED,
702 false /* is_renderer_init */); 714 false /* is_renderer_init */);
703 RenderViewHostImpl* host2 = static_cast<RenderViewHostImpl*>( 715 RenderViewHostImpl* host2 = static_cast<RenderViewHostImpl*>(
704 manager.Navigate(entry2)); 716 manager.Navigate(entry2, false));
705 int host2_process_id = host2->GetProcess()->GetID(); 717 int host2_process_id = host2->GetProcess()->GetID();
706 718
707 // A new RenderViewHost should be created. 719 // A new RenderViewHost should be created.
708 EXPECT_TRUE(manager.pending_render_view_host()); 720 EXPECT_TRUE(manager.pending_render_view_host());
709 ASSERT_EQ(host2, manager.pending_render_view_host()); 721 ASSERT_EQ(host2, manager.pending_render_view_host());
710 EXPECT_NE(host2, host); 722 EXPECT_NE(host2, host);
711 723
712 // Check that the navigation is still suspended because the old RVH 724 // Check that the navigation is still suspended because the old RVH
713 // is not swapped out, yet. 725 // is not swapped out, yet.
714 EXPECT_TRUE(host2->are_navigations_suspended()); 726 EXPECT_TRUE(host2->are_navigations_suspended());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching( 758 EXPECT_FALSE(test_process_host2->sink().GetUniqueMessageMatching(
747 ViewMsg_Navigate::ID)); 759 ViewMsg_Navigate::ID));
748 760
749 // 3) Cross-site navigate to next site before 2) has committed. -------------- 761 // 3) Cross-site navigate to next site before 2) has committed. --------------
750 const GURL kUrl3("http://webkit.org/"); 762 const GURL kUrl3("http://webkit.org/");
751 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3, 763 NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3,
752 Referrer(), string16() /* title */, 764 Referrer(), string16() /* title */,
753 PAGE_TRANSITION_TYPED, 765 PAGE_TRANSITION_TYPED,
754 false /* is_renderer_init */); 766 false /* is_renderer_init */);
755 test_process_host->sink().ClearMessages(); 767 test_process_host->sink().ClearMessages();
756 RenderViewHost* host3 = manager.Navigate(entry3); 768 RenderViewHost* host3 = manager.Navigate(entry3, false);
757 769
758 // A new RenderViewHost should be created. host2 is now deleted. 770 // A new RenderViewHost should be created. host2 is now deleted.
759 EXPECT_TRUE(manager.pending_render_view_host()); 771 EXPECT_TRUE(manager.pending_render_view_host());
760 ASSERT_EQ(host3, manager.pending_render_view_host()); 772 ASSERT_EQ(host3, manager.pending_render_view_host());
761 EXPECT_NE(host3, host); 773 EXPECT_NE(host3, host);
762 EXPECT_NE(host3->GetProcess()->GetID(), host2_process_id); 774 EXPECT_NE(host3->GetProcess()->GetID(), host2_process_id);
763 775
764 // Navigations in the new RVH should be suspended, which is ok because the 776 // Navigations in the new RVH should be suspended, which is ok because the
765 // old RVH is not yet swapped out and can respond to a second beforeunload 777 // old RVH is not yet swapped out and can respond to a second beforeunload
766 // request. 778 // request.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // Tests WebUI creation. 813 // Tests WebUI creation.
802 TEST_F(RenderViewHostManagerTest, WebUI) { 814 TEST_F(RenderViewHostManagerTest, WebUI) {
803 set_should_create_webui(true); 815 set_should_create_webui(true);
804 SiteInstance* instance = SiteInstance::Create(browser_context()); 816 SiteInstance* instance = SiteInstance::Create(browser_context());
805 817
806 scoped_ptr<TestWebContents> web_contents( 818 scoped_ptr<TestWebContents> web_contents(
807 TestWebContents::Create(browser_context(), instance)); 819 TestWebContents::Create(browser_context(), instance));
808 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 820 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
809 web_contents.get()); 821 web_contents.get());
810 822
811 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 823 manager.Init(browser_context(),
824 instance,
825 MSG_ROUTING_NONE,
826 MSG_ROUTING_NONE,
827 false);
812 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); 828 EXPECT_FALSE(manager.current_host()->IsRenderViewLive());
813 829
814 const GURL kUrl("chrome://foo"); 830 const GURL kUrl("chrome://foo");
815 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 831 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
816 Referrer(), string16() /* title */, 832 Referrer(), string16() /* title */,
817 PAGE_TRANSITION_TYPED, 833 PAGE_TRANSITION_TYPED,
818 false /* is_renderer_init */); 834 false /* is_renderer_init */);
819 RenderViewHost* host = manager.Navigate(entry); 835 RenderViewHost* host = manager.Navigate(entry, false);
820 836
821 // We commit the pending RenderViewHost immediately because the previous 837 // We commit the pending RenderViewHost immediately because the previous
822 // RenderViewHost was not live. We test a case where it is live in 838 // RenderViewHost was not live. We test a case where it is live in
823 // WebUIInNewTab. 839 // WebUIInNewTab.
824 EXPECT_TRUE(host); 840 EXPECT_TRUE(host);
825 EXPECT_EQ(host, manager.current_host()); 841 EXPECT_EQ(host, manager.current_host());
826 EXPECT_FALSE(manager.pending_render_view_host()); 842 EXPECT_FALSE(manager.pending_render_view_host());
827 843
828 // It's important that the site instance get set on the Web UI page as soon 844 // It's important that the site instance get set on the Web UI page as soon
829 // as the navigation starts, rather than lazily after it commits, so we don't 845 // as the navigation starts, rather than lazily after it commits, so we don't
(...skipping 17 matching lines...) Expand all
847 // grant the correct bindings. http://crbug.com/189101. 863 // grant the correct bindings. http://crbug.com/189101.
848 TEST_F(RenderViewHostManagerTest, WebUIInNewTab) { 864 TEST_F(RenderViewHostManagerTest, WebUIInNewTab) {
849 set_should_create_webui(true); 865 set_should_create_webui(true);
850 SiteInstance* blank_instance = SiteInstance::Create(browser_context()); 866 SiteInstance* blank_instance = SiteInstance::Create(browser_context());
851 867
852 // Create a blank tab. 868 // Create a blank tab.
853 scoped_ptr<TestWebContents> web_contents1( 869 scoped_ptr<TestWebContents> web_contents1(
854 TestWebContents::Create(browser_context(), blank_instance)); 870 TestWebContents::Create(browser_context(), blank_instance));
855 RenderViewHostManager manager1(web_contents1.get(), web_contents1.get(), 871 RenderViewHostManager manager1(web_contents1.get(), web_contents1.get(),
856 web_contents1.get()); 872 web_contents1.get());
857 manager1.Init( 873 manager1.Init(browser_context(),
858 browser_context(), blank_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 874 blank_instance,
875 MSG_ROUTING_NONE,
876 MSG_ROUTING_NONE,
877 false);
859 // Test the case that new RVH is considered live. 878 // Test the case that new RVH is considered live.
860 manager1.current_host()->CreateRenderView(string16(), -1, -1); 879 manager1.current_host()->CreateRenderView(string16(), -1, -1);
861 880
862 // Navigate to a WebUI page. 881 // Navigate to a WebUI page.
863 const GURL kUrl1("chrome://foo"); 882 const GURL kUrl1("chrome://foo");
864 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 883 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
865 Referrer(), string16() /* title */, 884 Referrer(), string16() /* title */,
866 PAGE_TRANSITION_TYPED, 885 PAGE_TRANSITION_TYPED,
867 false /* is_renderer_init */); 886 false /* is_renderer_init */);
868 RenderViewHost* host1 = manager1.Navigate(entry1); 887 RenderViewHost* host1 = manager1.Navigate(entry1, false);
869 888
870 // We should have a pending navigation to the WebUI RenderViewHost. 889 // We should have a pending navigation to the WebUI RenderViewHost.
871 // It should already have bindings. 890 // It should already have bindings.
872 EXPECT_EQ(host1, manager1.pending_render_view_host()); 891 EXPECT_EQ(host1, manager1.pending_render_view_host());
873 EXPECT_NE(host1, manager1.current_host()); 892 EXPECT_NE(host1, manager1.current_host());
874 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 893 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
875 894
876 // Commit and ensure we still have bindings. 895 // Commit and ensure we still have bindings.
877 manager1.DidNavigateMainFrame(host1); 896 manager1.DidNavigateMainFrame(host1);
878 SiteInstance* webui_instance = host1->GetSiteInstance(); 897 SiteInstance* webui_instance = host1->GetSiteInstance();
879 EXPECT_EQ(host1, manager1.current_host()); 898 EXPECT_EQ(host1, manager1.current_host());
880 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 899 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
881 900
882 // Now simulate clicking a link that opens in a new tab. 901 // Now simulate clicking a link that opens in a new tab.
883 scoped_ptr<TestWebContents> web_contents2( 902 scoped_ptr<TestWebContents> web_contents2(
884 TestWebContents::Create(browser_context(), webui_instance)); 903 TestWebContents::Create(browser_context(), webui_instance));
885 RenderViewHostManager manager2(web_contents2.get(), web_contents2.get(), 904 RenderViewHostManager manager2(web_contents2.get(), web_contents2.get(),
886 web_contents2.get()); 905 web_contents2.get());
887 manager2.Init( 906 manager2.Init(browser_context(),
888 browser_context(), webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 907 webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, false);
889 // Make sure the new RVH is considered live. This is usually done in 908 // Make sure the new RVH is considered live. This is usually done in
890 // RenderWidgetHost::Init when opening a new tab from a link. 909 // RenderWidgetHost::Init when opening a new tab from a link.
891 manager2.current_host()->CreateRenderView(string16(), -1, -1); 910 manager2.current_host()->CreateRenderView(string16(), -1, -1);
892 911
893 const GURL kUrl2("chrome://foo/bar"); 912 const GURL kUrl2("chrome://foo/bar");
894 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 913 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
895 Referrer(), string16() /* title */, 914 Referrer(), string16() /* title */,
896 PAGE_TRANSITION_LINK, 915 PAGE_TRANSITION_LINK,
897 true /* is_renderer_init */); 916 true /* is_renderer_init */);
898 RenderViewHost* host2 = manager2.Navigate(entry2); 917 RenderViewHost* host2 = manager2.Navigate(entry2, false);
899 918
900 // No cross-process transition happens because we are already in the right 919 // No cross-process transition happens because we are already in the right
901 // SiteInstance. We should grant bindings immediately. 920 // SiteInstance. We should grant bindings immediately.
902 EXPECT_EQ(host2, manager2.current_host()); 921 EXPECT_EQ(host2, manager2.current_host());
903 EXPECT_TRUE(host2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 922 EXPECT_TRUE(host2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
904 923
905 manager2.DidNavigateMainFrame(host2); 924 manager2.DidNavigateMainFrame(host2);
906 } 925 }
907 926
908 // Tests that we don't end up in an inconsistent state if a page does a back and 927 // Tests that we don't end up in an inconsistent state if a page does a back and
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 GURL guest_url(std::string(chrome::kGuestScheme).append("://abc123")); 1176 GURL guest_url(std::string(chrome::kGuestScheme).append("://abc123"));
1158 SiteInstance* instance = 1177 SiteInstance* instance =
1159 SiteInstance::CreateForURL(browser_context(), guest_url); 1178 SiteInstance::CreateForURL(browser_context(), guest_url);
1160 scoped_ptr<TestWebContents> web_contents( 1179 scoped_ptr<TestWebContents> web_contents(
1161 TestWebContents::Create(browser_context(), instance)); 1180 TestWebContents::Create(browser_context(), instance));
1162 1181
1163 // Create. 1182 // Create.
1164 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 1183 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
1165 web_contents.get()); 1184 web_contents.get());
1166 1185
1167 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 1186 manager.Init(browser_context(),
1187 instance,
1188 MSG_ROUTING_NONE,
1189 MSG_ROUTING_NONE,
1190 false);
1168 1191
1169 RenderViewHost* host; 1192 RenderViewHost* host;
1170 1193
1171 // 1) The first navigation. -------------------------- 1194 // 1) The first navigation. --------------------------
1172 const GURL kUrl1("http://www.google.com/"); 1195 const GURL kUrl1("http://www.google.com/");
1173 NavigationEntryImpl entry1( 1196 NavigationEntryImpl entry1(
1174 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 1197 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
1175 string16() /* title */, PAGE_TRANSITION_TYPED, 1198 string16() /* title */, PAGE_TRANSITION_TYPED,
1176 false /* is_renderer_init */); 1199 false /* is_renderer_init */);
1177 host = manager.Navigate(entry1); 1200 host = manager.Navigate(entry1, false);
1178 1201
1179 // The RenderViewHost created in Init will be reused. 1202 // The RenderViewHost created in Init will be reused.
1180 EXPECT_TRUE(host == manager.current_host()); 1203 EXPECT_TRUE(host == manager.current_host());
1181 EXPECT_FALSE(manager.pending_render_view_host()); 1204 EXPECT_FALSE(manager.pending_render_view_host());
1182 EXPECT_EQ(manager.current_host()->GetSiteInstance(), instance); 1205 EXPECT_EQ(manager.current_host()->GetSiteInstance(), instance);
1183 1206
1184 // Commit. 1207 // Commit.
1185 manager.DidNavigateMainFrame(host); 1208 manager.DidNavigateMainFrame(host);
1186 // Commit to SiteInstance should be delayed until RenderView commit. 1209 // Commit to SiteInstance should be delayed until RenderView commit.
1187 EXPECT_EQ(host, manager.current_host()); 1210 EXPECT_EQ(host, manager.current_host());
1188 ASSERT_TRUE(host); 1211 ASSERT_TRUE(host);
1189 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 1212 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
1190 HasSite()); 1213 HasSite());
1191 1214
1192 // 2) Navigate to a different domain. ------------------------- 1215 // 2) Navigate to a different domain. -------------------------
1193 // Guests stay in the same process on navigation. 1216 // Guests stay in the same process on navigation.
1194 const GURL kUrl2("http://www.chromium.org"); 1217 const GURL kUrl2("http://www.chromium.org");
1195 NavigationEntryImpl entry2( 1218 NavigationEntryImpl entry2(
1196 NULL /* instance */, -1 /* page_id */, kUrl2, 1219 NULL /* instance */, -1 /* page_id */, kUrl2,
1197 Referrer(kUrl1, WebKit::WebReferrerPolicyDefault), 1220 Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
1198 string16() /* title */, PAGE_TRANSITION_LINK, 1221 string16() /* title */, PAGE_TRANSITION_LINK,
1199 true /* is_renderer_init */); 1222 true /* is_renderer_init */);
1200 host = manager.Navigate(entry2); 1223 host = manager.Navigate(entry2, false);
1201 1224
1202 // The RenderViewHost created in Init will be reused. 1225 // The RenderViewHost created in Init will be reused.
1203 EXPECT_EQ(host, manager.current_host()); 1226 EXPECT_EQ(host, manager.current_host());
1204 EXPECT_FALSE(manager.pending_render_view_host()); 1227 EXPECT_FALSE(manager.pending_render_view_host());
1205 1228
1206 // Commit. 1229 // Commit.
1207 manager.DidNavigateMainFrame(host); 1230 manager.DidNavigateMainFrame(host);
1208 EXPECT_EQ(host, manager.current_host()); 1231 EXPECT_EQ(host, manager.current_host());
1209 ASSERT_TRUE(host); 1232 ASSERT_TRUE(host);
1210 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 1233 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
1211 instance); 1234 instance);
1212 } 1235 }
1213 1236
1214 } // namespace content 1237 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698