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

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

Powered by Google App Engine
This is Rietveld 408576698