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

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

Issue 257083002: Check BrowsingInstance before swapping prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 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/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/frame_host/cross_site_transferring_request.h" 7 #include "content/browser/frame_host/cross_site_transferring_request.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigator.h" 10 #include "content/browser/frame_host/navigator.h"
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 710
711 // Tests the Init function by checking the initial RenderViewHost. 711 // Tests the Init function by checking the initial RenderViewHost.
712 TEST_F(RenderFrameHostManagerTest, Init) { 712 TEST_F(RenderFrameHostManagerTest, Init) {
713 // Using TestBrowserContext. 713 // Using TestBrowserContext.
714 SiteInstanceImpl* instance = 714 SiteInstanceImpl* instance =
715 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context())); 715 static_cast<SiteInstanceImpl*>(SiteInstance::Create(browser_context()));
716 EXPECT_FALSE(instance->HasSite()); 716 EXPECT_FALSE(instance->HasSite());
717 717
718 scoped_ptr<TestWebContents> web_contents( 718 scoped_ptr<TestWebContents> web_contents(
719 TestWebContents::Create(browser_context(), instance)); 719 TestWebContents::Create(browser_context(), instance));
720 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(),
721 web_contents.get(), web_contents.get(),
722 web_contents.get(), web_contents.get());
723 RenderFrameHostManager* manager = tree.root()->render_manager();
724 720
725 manager->Init(browser_context(), instance, MSG_ROUTING_NONE, 721 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
726 MSG_ROUTING_NONE);
727
728 RenderViewHostImpl* rvh = manager->current_host(); 722 RenderViewHostImpl* rvh = manager->current_host();
729 RenderFrameHostImpl* rfh = manager->current_frame_host(); 723 RenderFrameHostImpl* rfh = manager->current_frame_host();
730 ASSERT_TRUE(rvh); 724 ASSERT_TRUE(rvh);
731 ASSERT_TRUE(rfh); 725 ASSERT_TRUE(rfh);
732 EXPECT_EQ(rvh, rfh->render_view_host()); 726 EXPECT_EQ(rvh, rfh->render_view_host());
733 EXPECT_EQ(instance, rvh->GetSiteInstance()); 727 EXPECT_EQ(instance, rvh->GetSiteInstance());
734 EXPECT_EQ(web_contents.get(), rvh->GetDelegate()); 728 EXPECT_EQ(web_contents.get(), rvh->GetDelegate());
735 EXPECT_EQ(web_contents.get(), rfh->delegate()); 729 EXPECT_EQ(web_contents.get(), rfh->delegate());
736 EXPECT_TRUE(manager->GetRenderWidgetHostView()); 730 EXPECT_TRUE(manager->GetRenderWidgetHostView());
737 EXPECT_FALSE(manager->pending_render_view_host()); 731 EXPECT_FALSE(manager->pending_render_view_host());
738 } 732 }
739 733
740 // Tests the Navigate function. We navigate three sites consecutively and check 734 // Tests the Navigate function. We navigate three sites consecutively and check
741 // how the pending/committed RenderViewHost are modified. 735 // how the pending/committed RenderViewHost are modified.
742 TEST_F(RenderFrameHostManagerTest, Navigate) { 736 TEST_F(RenderFrameHostManagerTest, Navigate) {
743 TestNotificationTracker notifications; 737 TestNotificationTracker notifications;
744 738
745 SiteInstance* instance = SiteInstance::Create(browser_context()); 739 SiteInstance* instance = SiteInstance::Create(browser_context());
746 740
747 scoped_ptr<TestWebContents> web_contents( 741 scoped_ptr<TestWebContents> web_contents(
748 TestWebContents::Create(browser_context(), instance)); 742 TestWebContents::Create(browser_context(), instance));
749 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 743 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
750 Source<WebContents>(web_contents.get())); 744 Source<WebContents>(web_contents.get()));
751 745
752 // Create. 746 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
753 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(),
754 web_contents.get(), web_contents.get(),
755 web_contents.get(), web_contents.get());
756 RenderFrameHostManager* manager = tree.root()->render_manager();
757
758 manager->Init(browser_context(), instance, MSG_ROUTING_NONE,
759 MSG_ROUTING_NONE);
760
761 RenderFrameHostImpl* host; 747 RenderFrameHostImpl* host;
762 748
763 // 1) The first navigation. -------------------------- 749 // 1) The first navigation. --------------------------
764 const GURL kUrl1("http://www.google.com/"); 750 const GURL kUrl1("http://www.google.com/");
765 NavigationEntryImpl entry1( 751 NavigationEntryImpl entry1(
766 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 752 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
767 base::string16() /* title */, PAGE_TRANSITION_TYPED, 753 base::string16() /* title */, PAGE_TRANSITION_TYPED,
768 false /* is_renderer_init */); 754 false /* is_renderer_init */);
769 host = manager->Navigate(entry1); 755 host = manager->Navigate(entry1);
770 756
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyReNavigation) { 823 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyReNavigation) {
838 TestNotificationTracker notifications; 824 TestNotificationTracker notifications;
839 825
840 SiteInstance* instance = SiteInstance::Create(browser_context()); 826 SiteInstance* instance = SiteInstance::Create(browser_context());
841 827
842 scoped_ptr<TestWebContents> web_contents( 828 scoped_ptr<TestWebContents> web_contents(
843 TestWebContents::Create(browser_context(), instance)); 829 TestWebContents::Create(browser_context(), instance));
844 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 830 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
845 Source<WebContents>(web_contents.get())); 831 Source<WebContents>(web_contents.get()));
846 832
847 // Create. 833 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
848 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(),
849 web_contents.get(), web_contents.get(),
850 web_contents.get(), web_contents.get());
851 RenderFrameHostManager* manager = tree.root()->render_manager();
852
853 manager->Init(browser_context(), instance, MSG_ROUTING_NONE,
854 MSG_ROUTING_NONE);
855 834
856 // 1) The first navigation. -------------------------- 835 // 1) The first navigation. --------------------------
857 const GURL kUrl1("http://www.google.com/"); 836 const GURL kUrl1("http://www.google.com/");
858 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 837 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
859 Referrer(), base::string16() /* title */, 838 Referrer(), base::string16() /* title */,
860 PAGE_TRANSITION_TYPED, 839 PAGE_TRANSITION_TYPED,
861 false /* is_renderer_init */); 840 false /* is_renderer_init */);
862 RenderFrameHostImpl* host = manager->Navigate(entry1); 841 RenderFrameHostImpl* host = manager->Navigate(entry1);
863 842
864 // The RenderFrameHost created in Init will be reused. 843 // The RenderFrameHost created in Init will be reused.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 EXPECT_FALSE(rvh3->are_navigations_suspended()); 1004 EXPECT_FALSE(rvh3->are_navigations_suspended());
1026 } 1005 }
1027 1006
1028 // Tests WebUI creation. 1007 // Tests WebUI creation.
1029 TEST_F(RenderFrameHostManagerTest, WebUI) { 1008 TEST_F(RenderFrameHostManagerTest, WebUI) {
1030 set_should_create_webui(true); 1009 set_should_create_webui(true);
1031 SiteInstance* instance = SiteInstance::Create(browser_context()); 1010 SiteInstance* instance = SiteInstance::Create(browser_context());
1032 1011
1033 scoped_ptr<TestWebContents> web_contents( 1012 scoped_ptr<TestWebContents> web_contents(
1034 TestWebContents::Create(browser_context(), instance)); 1013 TestWebContents::Create(browser_context(), instance));
1035 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(), 1014 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1036 web_contents.get(), web_contents.get(),
1037 web_contents.get(), web_contents.get());
1038 RenderFrameHostManager* manager = tree.root()->render_manager();
1039 1015
1040 manager->Init(browser_context(), instance, MSG_ROUTING_NONE,
1041 MSG_ROUTING_NONE);
1042 EXPECT_FALSE(manager->current_host()->IsRenderViewLive()); 1016 EXPECT_FALSE(manager->current_host()->IsRenderViewLive());
1043 1017
1044 const GURL kUrl("chrome://foo"); 1018 const GURL kUrl("chrome://foo");
1045 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl, 1019 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
1046 Referrer(), base::string16() /* title */, 1020 Referrer(), base::string16() /* title */,
1047 PAGE_TRANSITION_TYPED, 1021 PAGE_TRANSITION_TYPED,
1048 false /* is_renderer_init */); 1022 false /* is_renderer_init */);
1049 RenderFrameHostImpl* host = manager->Navigate(entry); 1023 RenderFrameHostImpl* host = manager->Navigate(entry);
1050 1024
1051 // We commit the pending RenderFrameHost immediately because the previous 1025 // We commit the pending RenderFrameHost immediately because the previous
(...skipping 24 matching lines...) Expand all
1076 1050
1077 // Tests that we can open a WebUI link in a new tab from a WebUI page and still 1051 // Tests that we can open a WebUI link in a new tab from a WebUI page and still
1078 // grant the correct bindings. http://crbug.com/189101. 1052 // grant the correct bindings. http://crbug.com/189101.
1079 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) { 1053 TEST_F(RenderFrameHostManagerTest, WebUIInNewTab) {
1080 set_should_create_webui(true); 1054 set_should_create_webui(true);
1081 SiteInstance* blank_instance = SiteInstance::Create(browser_context()); 1055 SiteInstance* blank_instance = SiteInstance::Create(browser_context());
1082 1056
1083 // Create a blank tab. 1057 // Create a blank tab.
1084 scoped_ptr<TestWebContents> web_contents1( 1058 scoped_ptr<TestWebContents> web_contents1(
1085 TestWebContents::Create(browser_context(), blank_instance)); 1059 TestWebContents::Create(browser_context(), blank_instance));
1086 FrameTree tree1(web_contents1->GetFrameTree()->root()->navigator(), 1060 RenderFrameHostManager* manager1 =
1087 web_contents1.get(), web_contents1.get(), 1061 web_contents1->GetRenderManagerForTesting();
1088 web_contents1.get(), web_contents1.get());
1089 RenderFrameHostManager* manager1 = tree1.root()->render_manager();
1090 manager1->Init(
1091 browser_context(), blank_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
1092 // Test the case that new RVH is considered live. 1062 // Test the case that new RVH is considered live.
1093 manager1->current_host()->CreateRenderView(base::string16(), -1, -1, false); 1063 manager1->current_host()->CreateRenderView(base::string16(), -1, -1, false);
1094 1064
1095 // Navigate to a WebUI page. 1065 // Navigate to a WebUI page.
1096 const GURL kUrl1("chrome://foo"); 1066 const GURL kUrl1("chrome://foo");
1097 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1067 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1098 Referrer(), base::string16() /* title */, 1068 Referrer(), base::string16() /* title */,
1099 PAGE_TRANSITION_TYPED, 1069 PAGE_TRANSITION_TYPED,
1100 false /* is_renderer_init */); 1070 false /* is_renderer_init */);
1101 RenderFrameHostImpl* host1 = manager1->Navigate(entry1); 1071 RenderFrameHostImpl* host1 = manager1->Navigate(entry1);
1102 1072
1103 // We should have a pending navigation to the WebUI RenderViewHost. 1073 // We should have a pending navigation to the WebUI RenderViewHost.
1104 // It should already have bindings. 1074 // It should already have bindings.
1105 EXPECT_EQ(host1, manager1->pending_frame_host()); 1075 EXPECT_EQ(host1, manager1->pending_frame_host());
1106 EXPECT_NE(host1, manager1->current_frame_host()); 1076 EXPECT_NE(host1, manager1->current_frame_host());
1107 EXPECT_TRUE( 1077 EXPECT_TRUE(
1108 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1078 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1109 1079
1110 // Commit and ensure we still have bindings. 1080 // Commit and ensure we still have bindings.
1111 manager1->DidNavigateFrame(host1); 1081 manager1->DidNavigateFrame(host1);
1112 SiteInstance* webui_instance = host1->GetSiteInstance(); 1082 SiteInstance* webui_instance = host1->GetSiteInstance();
1113 EXPECT_EQ(host1, manager1->current_frame_host()); 1083 EXPECT_EQ(host1, manager1->current_frame_host());
1114 EXPECT_TRUE( 1084 EXPECT_TRUE(
1115 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); 1085 host1->render_view_host()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
1116 1086
1117 // Now simulate clicking a link that opens in a new tab. 1087 // Now simulate clicking a link that opens in a new tab.
1118 scoped_ptr<TestWebContents> web_contents2( 1088 scoped_ptr<TestWebContents> web_contents2(
1119 TestWebContents::Create(browser_context(), webui_instance)); 1089 TestWebContents::Create(browser_context(), webui_instance));
1120 FrameTree tree2(web_contents2->GetFrameTree()->root()->navigator(), 1090 RenderFrameHostManager* manager2 =
1121 web_contents2.get(), web_contents2.get(), 1091 web_contents2->GetRenderManagerForTesting();
1122 web_contents2.get(), web_contents2.get());
1123 RenderFrameHostManager* manager2 = tree2.root()->render_manager();
1124 manager2->Init(
1125 browser_context(), webui_instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
1126 // Make sure the new RVH is considered live. This is usually done in 1092 // Make sure the new RVH is considered live. This is usually done in
1127 // RenderWidgetHost::Init when opening a new tab from a link. 1093 // RenderWidgetHost::Init when opening a new tab from a link.
1128 manager2->current_host()->CreateRenderView(base::string16(), -1, -1, false); 1094 manager2->current_host()->CreateRenderView(base::string16(), -1, -1, false);
1129 1095
1130 const GURL kUrl2("chrome://foo/bar"); 1096 const GURL kUrl2("chrome://foo/bar");
1131 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 1097 NavigationEntryImpl entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
1132 Referrer(), base::string16() /* title */, 1098 Referrer(), base::string16() /* title */,
1133 PAGE_TRANSITION_LINK, 1099 PAGE_TRANSITION_LINK,
1134 true /* is_renderer_init */); 1100 true /* is_renderer_init */);
1135 RenderFrameHostImpl* host2 = manager2->Navigate(entry2); 1101 RenderFrameHostImpl* host2 = manager2->Navigate(entry2);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 // Test that we reuse the same guest SiteInstance if we navigate across sites. 1370 // Test that we reuse the same guest SiteInstance if we navigate across sites.
1405 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { 1371 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) {
1406 TestNotificationTracker notifications; 1372 TestNotificationTracker notifications;
1407 1373
1408 GURL guest_url(std::string(kGuestScheme).append("://abc123")); 1374 GURL guest_url(std::string(kGuestScheme).append("://abc123"));
1409 SiteInstance* instance = 1375 SiteInstance* instance =
1410 SiteInstance::CreateForURL(browser_context(), guest_url); 1376 SiteInstance::CreateForURL(browser_context(), guest_url);
1411 scoped_ptr<TestWebContents> web_contents( 1377 scoped_ptr<TestWebContents> web_contents(
1412 TestWebContents::Create(browser_context(), instance)); 1378 TestWebContents::Create(browser_context(), instance));
1413 1379
1414 // Create. 1380 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1415 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(),
1416 web_contents.get(), web_contents.get(),
1417 web_contents.get(), web_contents.get());
1418 RenderFrameHostManager* manager = tree.root()->render_manager();
1419
1420 manager->Init(browser_context(), instance, MSG_ROUTING_NONE,
1421 MSG_ROUTING_NONE);
1422 1381
1423 RenderFrameHostImpl* host; 1382 RenderFrameHostImpl* host;
1424 1383
1425 // 1) The first navigation. -------------------------- 1384 // 1) The first navigation. --------------------------
1426 const GURL kUrl1("http://www.google.com/"); 1385 const GURL kUrl1("http://www.google.com/");
1427 NavigationEntryImpl entry1( 1386 NavigationEntryImpl entry1(
1428 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), 1387 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
1429 base::string16() /* title */, PAGE_TRANSITION_TYPED, 1388 base::string16() /* title */, PAGE_TRANSITION_TYPED,
1430 false /* is_renderer_init */); 1389 false /* is_renderer_init */);
1431 host = manager->Navigate(entry1); 1390 host = manager->Navigate(entry1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 1431
1473 SiteInstance* instance = SiteInstance::Create(browser_context()); 1432 SiteInstance* instance = SiteInstance::Create(browser_context());
1474 1433
1475 BeforeUnloadFiredWebContentsDelegate delegate; 1434 BeforeUnloadFiredWebContentsDelegate delegate;
1476 scoped_ptr<TestWebContents> web_contents( 1435 scoped_ptr<TestWebContents> web_contents(
1477 TestWebContents::Create(browser_context(), instance)); 1436 TestWebContents::Create(browser_context(), instance));
1478 web_contents->SetDelegate(&delegate); 1437 web_contents->SetDelegate(&delegate);
1479 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 1438 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
1480 Source<WebContents>(web_contents.get())); 1439 Source<WebContents>(web_contents.get()));
1481 1440
1482 // Create. 1441 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting();
1483 FrameTree tree(web_contents->GetFrameTree()->root()->navigator(),
1484 web_contents.get(), web_contents.get(),
1485 web_contents.get(), web_contents.get());
1486 RenderFrameHostManager* manager = tree.root()->render_manager();
1487
1488 manager->Init(browser_context(), instance, MSG_ROUTING_NONE,
1489 MSG_ROUTING_NONE);
1490 1442
1491 // 1) The first navigation. -------------------------- 1443 // 1) The first navigation. --------------------------
1492 const GURL kUrl1("http://www.google.com/"); 1444 const GURL kUrl1("http://www.google.com/");
1493 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1445 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1494 Referrer(), base::string16() /* title */, 1446 Referrer(), base::string16() /* title */,
1495 PAGE_TRANSITION_TYPED, 1447 PAGE_TRANSITION_TYPED,
1496 false /* is_renderer_init */); 1448 false /* is_renderer_init */);
1497 RenderFrameHostImpl* host = manager->Navigate(entry1); 1449 RenderFrameHostImpl* host = manager->Navigate(entry1);
1498 1450
1499 // The RenderFrameHost created in Init will be reused. 1451 // The RenderFrameHost created in Init will be reused.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 pending_rfh->GetSiteInstance())->increment_active_view_count(); 1792 pending_rfh->GetSiteInstance())->increment_active_view_count();
1841 1793
1842 main_test_rfh()->OnMessageReceived( 1794 main_test_rfh()->OnMessageReceived(
1843 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1795 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1844 EXPECT_FALSE(contents()->cross_navigation_pending()); 1796 EXPECT_FALSE(contents()->cross_navigation_pending());
1845 EXPECT_FALSE(rvh_deleted_observer.deleted()); 1797 EXPECT_FALSE(rvh_deleted_observer.deleted());
1846 } 1798 }
1847 } 1799 }
1848 1800
1849 } // namespace content 1801 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.cc ('k') | content/browser/site_instance_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698