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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 103633002: Add RenderFrameHostDelegate and plumb it through all the necessary classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/frame_host/navigation_controller_impl.h" 6 #include "content/browser/frame_host/navigation_controller_impl.h"
7 #include "content/browser/frame_host/navigation_entry_impl.h" 7 #include "content/browser/frame_host/navigation_entry_impl.h"
8 #include "content/browser/frame_host/render_frame_host_manager.h" 8 #include "content/browser/frame_host/render_frame_host_manager.h"
9 #include "content/browser/renderer_host/test_render_view_host.h" 9 #include "content/browser/renderer_host/test_render_view_host.h"
10 #include "content/browser/site_instance_impl.h" 10 #include "content/browser/site_instance_impl.h"
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // Tests the Init function by checking the initial RenderViewHost. 561 // Tests the Init function by checking the initial RenderViewHost.
562 TEST_F(RenderFrameHostManagerTest, Init) { 562 TEST_F(RenderFrameHostManagerTest, Init) {
563 // Using TestBrowserContext. 563 // Using TestBrowserContext.
564 SiteInstanceImpl* instance = 564 SiteInstanceImpl* instance =
565 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); 565 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
566 EXPECT_FALSE(instance->HasSite()); 566 EXPECT_FALSE(instance->HasSite());
567 567
568 scoped_ptr<TestWebContents> web_contents( 568 scoped_ptr<TestWebContents> web_contents(
569 TestWebContents::Create(browser_context(), instance)); 569 TestWebContents::Create(browser_context(), instance));
570 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 570 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
571 web_contents.get()); 571 web_contents.get(), web_contents.get());
572 572
573 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 573 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
574 574
575 RenderViewHost* host = manager.current_host(); 575 RenderViewHost* host = manager.current_host();
576 ASSERT_TRUE(host); 576 ASSERT_TRUE(host);
577 EXPECT_EQ(instance, host->GetSiteInstance()); 577 EXPECT_EQ(instance, host->GetSiteInstance());
578 EXPECT_EQ(web_contents.get(), host->GetDelegate()); 578 EXPECT_EQ(web_contents.get(), host->GetDelegate());
579 EXPECT_TRUE(manager.GetRenderWidgetHostView()); 579 EXPECT_TRUE(manager.GetRenderWidgetHostView());
580 EXPECT_FALSE(manager.pending_render_view_host()); 580 EXPECT_FALSE(manager.pending_render_view_host());
581 } 581 }
582 582
583 // Tests the Navigate function. We navigate three sites consecutively and check 583 // Tests the Navigate function. We navigate three sites consecutively and check
584 // how the pending/committed RenderViewHost are modified. 584 // how the pending/committed RenderViewHost are modified.
585 TEST_F(RenderFrameHostManagerTest, Navigate) { 585 TEST_F(RenderFrameHostManagerTest, Navigate) {
586 TestNotificationTracker notifications; 586 TestNotificationTracker notifications;
587 587
588 SiteInstance* instance = SiteInstance::Create(browser_context()); 588 SiteInstance* instance = SiteInstance::Create(browser_context());
589 589
590 scoped_ptr<TestWebContents> web_contents( 590 scoped_ptr<TestWebContents> web_contents(
591 TestWebContents::Create(browser_context(), instance)); 591 TestWebContents::Create(browser_context(), instance));
592 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 592 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
593 Source<WebContents>(web_contents.get())); 593 Source<WebContents>(web_contents.get()));
594 594
595 // Create. 595 // Create.
596 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 596 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
597 web_contents.get()); 597 web_contents.get(), web_contents.get());
598 598
599 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 599 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
600 600
601 RenderViewHost* host; 601 RenderViewHost* host;
602 602
603 // 1) The first navigation. -------------------------- 603 // 1) The first navigation. --------------------------
604 const GURL kUrl1("http://www.google.com/"); 604 const GURL kUrl1("http://www.google.com/");
605 NavigationEntryImpl entry1( 605 NavigationEntryImpl entry1(
606 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 606 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
607 base::string16() /* title */, PAGE_TRANSITION_TYPED, 607 base::string16() /* title */, PAGE_TRANSITION_TYPED,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 679
680 SiteInstance* instance = SiteInstance::Create(browser_context()); 680 SiteInstance* instance = SiteInstance::Create(browser_context());
681 681
682 scoped_ptr<TestWebContents> web_contents( 682 scoped_ptr<TestWebContents> web_contents(
683 TestWebContents::Create(browser_context(), instance)); 683 TestWebContents::Create(browser_context(), instance));
684 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 684 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
685 Source<WebContents>(web_contents.get())); 685 Source<WebContents>(web_contents.get()));
686 686
687 // Create. 687 // Create.
688 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 688 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
689 web_contents.get()); 689 web_contents.get(), web_contents.get());
690 690
691 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 691 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
692 692
693 // 1) The first navigation. -------------------------- 693 // 1) The first navigation. --------------------------
694 const GURL kUrl1("http://www.google.com/"); 694 const GURL kUrl1("http://www.google.com/");
695 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 695 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
696 Referrer(), base::string16() /* title */, 696 Referrer(), base::string16() /* title */,
697 PAGE_TRANSITION_TYPED, 697 PAGE_TRANSITION_TYPED,
698 false /* is_renderer_init */); 698 false /* is_renderer_init */);
699 RenderViewHost* host = manager.Navigate(entry1); 699 RenderViewHost* host = manager.Navigate(entry1);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 822 }
823 823
824 // Tests WebUI creation. 824 // Tests WebUI creation.
825 TEST_F(RenderFrameHostManagerTest, WebUI) { 825 TEST_F(RenderFrameHostManagerTest, WebUI) {
826 set_should_create_webui(true); 826 set_should_create_webui(true);
827 SiteInstance* instance = SiteInstance::Create(browser_context()); 827 SiteInstance* instance = SiteInstance::Create(browser_context());
828 828
829 scoped_ptr<TestWebContents> web_contents( 829 scoped_ptr<TestWebContents> web_contents(
830 TestWebContents::Create(browser_context(), instance)); 830 TestWebContents::Create(browser_context(), instance));
831 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 831 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
832 web_contents.get()); 832 web_contents.get(), web_contents.get());
833 833
834 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 834 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
835 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); 835 EXPECT_FALSE(manager.current_host()->IsRenderViewLive());
836 836
837 const GURL kUrl("chrome://foo"); 837 const GURL kUrl("chrome://foo");
838 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 838 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
839 Referrer(), base::string16() /* title */, 839 Referrer(), base::string16() /* title */,
840 PAGE_TRANSITION_TYPED, 840 PAGE_TRANSITION_TYPED,
841 false /* is_renderer_init */); 841 false /* is_renderer_init */);
842 RenderViewHost* host = manager.Navigate(entry); 842 RenderViewHost* host = manager.Navigate(entry);
(...skipping 26 matching lines...) Expand all
869 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 869 // Tests that we can open a WebUI link in a new tab from a WebUI page and still
870 // grant the correct bindings. http://crbug.com/189101. 870 // grant the correct bindings. http://crbug.com/189101.
871 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { 871 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) {
872 set_should_create_webui(true); 872 set_should_create_webui(true);
873 SiteInstance* blank_instance = SiteInstance::Create(browser_context()); 873 SiteInstance* blank_instance = SiteInstance::Create(browser_context());
874 874
875 // Create a blank tab. 875 // Create a blank tab.
876 scoped_ptr<TestWebContents> web_contents1( 876 scoped_ptr<TestWebContents> web_contents1(
877 TestWebContents::Create(browser_context(), blank_instance)); 877 TestWebContents::Create(browser_context(), blank_instance));
878 RenderFrameHostManager manager1(web_contents1.get(), web_contents1.get(), 878 RenderFrameHostManager manager1(web_contents1.get(), web_contents1.get(),
879 web_contents1.get()); 879 web_contents1.get(), web_contents1.get());
880 manager1.Init( 880 manager1.Init(
881 browser_context(), blank_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 881 browser_context(), blank_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
882 // Test the case that new RVH is considered live. 882 // Test the case that new RVH is considered live.
883 manager1.current_host()->CreateRenderView(base::string16(), -1, -1); 883 manager1.current_host()->CreateRenderView(base::string16(), -1, -1);
884 884
885 // Navigate to a WebUI page. 885 // Navigate to a WebUI page.
886 const GURL kUrl1("chrome://foo"); 886 const GURL kUrl1("chrome://foo");
887 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 887 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
888 Referrer(), base::string16() /* title */, 888 Referrer(), base::string16() /* title */,
889 PAGE_TRANSITION_TYPED, 889 PAGE_TRANSITION_TYPED,
890 false /* is_renderer_init */); 890 false /* is_renderer_init */);
891 RenderViewHost* host1 = manager1.Navigate(entry1); 891 RenderViewHost* host1 = manager1.Navigate(entry1);
892 892
893 // We should have a pending navigation to the WebUI RenderViewHost. 893 // We should have a pending navigation to the WebUI RenderViewHost.
894 // It should already have bindings. 894 // It should already have bindings.
895 EXPECT_EQ(host1, manager1.pending_render_view_host()); 895 EXPECT_EQ(host1, manager1.pending_render_view_host());
896 EXPECT_NE(host1, manager1.current_host()); 896 EXPECT_NE(host1, manager1.current_host());
897 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 897 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
898 898
899 // Commit and ensure we still have bindings. 899 // Commit and ensure we still have bindings.
900 manager1.DidNavigateMainFrame(host1); 900 manager1.DidNavigateMainFrame(host1);
901 SiteInstance* webui_instance = host1->GetSiteInstance(); 901 SiteInstance* webui_instance = host1->GetSiteInstance();
902 EXPECT_EQ(host1, manager1.current_host()); 902 EXPECT_EQ(host1, manager1.current_host());
903 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 903 EXPECT_TRUE(host1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
904 904
905 // Now simulate clicking a link that opens in a new tab. 905 // Now simulate clicking a link that opens in a new tab.
906 scoped_ptr<TestWebContents> web_contents2( 906 scoped_ptr<TestWebContents> web_contents2(
907 TestWebContents::Create(browser_context(), webui_instance)); 907 TestWebContents::Create(browser_context(), webui_instance));
908 RenderFrameHostManager manager2(web_contents2.get(), web_contents2.get(), 908 RenderFrameHostManager manager2(web_contents2.get(), web_contents2.get(),
909 web_contents2.get()); 909 web_contents2.get(), web_contents2.get());
910 manager2.Init( 910 manager2.Init(
911 browser_context(), webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 911 browser_context(), webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
912 // Make sure the new RVH is considered live. This is usually done in 912 // Make sure the new RVH is considered live. This is usually done in
913 // RenderWidgetHost::Init when opening a new tab from a link. 913 // RenderWidgetHost::Init when opening a new tab from a link.
914 manager2.current_host()->CreateRenderView(base::string16(), -1, -1); 914 manager2.current_host()->CreateRenderView(base::string16(), -1, -1);
915 915
916 const GURL kUrl2("chrome://foo/bar"); 916 const GURL kUrl2("chrome://foo/bar");
917 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 917 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
918 Referrer(), base::string16() /* title */, 918 Referrer(), base::string16() /* title */,
919 PAGE_TRANSITION_LINK, 919 PAGE_TRANSITION_LINK,
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 TestNotificationTracker notifications; 1185 TestNotificationTracker notifications;
1186 1186
1187 GURL guest_url(std::string(kGuestScheme).append("://abc123")); 1187 GURL guest_url(std::string(kGuestScheme).append("://abc123"));
1188 SiteInstance* instance = 1188 SiteInstance* instance =
1189 SiteInstance::CreateForURL(browser_context(), guest_url); 1189 SiteInstance::CreateForURL(browser_context(), guest_url);
1190 scoped_ptr<TestWebContents> web_contents( 1190 scoped_ptr<TestWebContents> web_contents(
1191 TestWebContents::Create(browser_context(), instance)); 1191 TestWebContents::Create(browser_context(), instance));
1192 1192
1193 // Create. 1193 // Create.
1194 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 1194 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
1195 web_contents.get()); 1195 web_contents.get(), web_contents.get());
1196 1196
1197 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 1197 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
1198 1198
1199 RenderViewHost* host; 1199 RenderViewHost* host;
1200 1200
1201 // 1) The first navigation. -------------------------- 1201 // 1) The first navigation. --------------------------
1202 const GURL kUrl1("http://www.google.com/"); 1202 const GURL kUrl1("http://www.google.com/");
1203 NavigationEntryImpl entry1( 1203 NavigationEntryImpl entry1(
1204 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 1204 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
1205 base::string16() /* title */, PAGE_TRANSITION_TYPED, 1205 base::string16() /* title */, PAGE_TRANSITION_TYPED,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 1250
1251 BeforeUnloadFiredWebContentsDelegate delegate; 1251 BeforeUnloadFiredWebContentsDelegate delegate;
1252 scoped_ptr<TestWebContents> web_contents( 1252 scoped_ptr<TestWebContents> web_contents(
1253 TestWebContents::Create(browser_context(), instance)); 1253 TestWebContents::Create(browser_context(), instance));
1254 web_contents->SetDelegate(&delegate); 1254 web_contents->SetDelegate(&delegate);
1255 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 1255 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
1256 Source<WebContents>(web_contents.get())); 1256 Source<WebContents>(web_contents.get()));
1257 1257
1258 // Create. 1258 // Create.
1259 RenderFrameHostManager manager(web_contents.get(), web_contents.get(), 1259 RenderFrameHostManager manager(web_contents.get(), web_contents.get(),
1260 web_contents.get()); 1260 web_contents.get(), web_contents.get());
1261 1261
1262 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 1262 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
1263 1263
1264 // 1) The first navigation. -------------------------- 1264 // 1) The first navigation. --------------------------
1265 const GURL kUrl1("http://www.google.com/"); 1265 const GURL kUrl1("http://www.google.com/");
1266 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1266 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1267 Referrer(), base::string16() /* title */, 1267 Referrer(), base::string16() /* title */,
1268 PAGE_TRANSITION_TYPED, 1268 PAGE_TRANSITION_TYPED,
1269 false /* is_renderer_init */); 1269 false /* is_renderer_init */);
1270 RenderViewHost* host = manager.Navigate(entry1); 1270 RenderViewHost* host = manager.Navigate(entry1);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 Source<RenderWidgetHost>(host2)); 1310 Source<RenderWidgetHost>(host2));
1311 manager.ShouldClosePage(false, true, base::TimeTicks()); 1311 manager.ShouldClosePage(false, true, base::TimeTicks());
1312 1312
1313 EXPECT_TRUE( 1313 EXPECT_TRUE(
1314 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1314 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1315 EXPECT_FALSE(manager.pending_render_view_host()); 1315 EXPECT_FALSE(manager.pending_render_view_host());
1316 EXPECT_EQ(host, manager.current_host()); 1316 EXPECT_EQ(host, manager.current_host());
1317 } 1317 }
1318 1318
1319 } // namespace content 1319 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.cc ('k') | content/browser/frame_host/test_render_frame_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698