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

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

Issue 57433010: Prevent creating a swapped out RVH in the same SiteInstance as the current one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 7 years, 1 month 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_view_host_manager.h" 8 #include "content/browser/frame_host/render_view_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 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( 1085 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost(
1086 rvh3->GetSiteInstance())); 1086 rvh3->GetSiteInstance()));
1087 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( 1087 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost(
1088 rvh3->GetSiteInstance())); 1088 rvh3->GetSiteInstance()));
1089 } 1089 }
1090 1090
1091 // Test that we clean up swapped out RenderViewHosts when a process hosting 1091 // Test that we clean up swapped out RenderViewHosts when a process hosting
1092 // those associated RenderViews crashes. http://crbug.com/258993 1092 // those associated RenderViews crashes. http://crbug.com/258993
1093 TEST_F(RenderViewHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { 1093 TEST_F(RenderViewHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) {
1094 const GURL kUrl1("http://www.google.com/"); 1094 const GURL kUrl1("http://www.google.com/");
1095 const GURL kUrl2("http://www.chromium.org/");
1095 1096
1096 // Navigate to an initial URL. 1097 // Navigate to an initial URL.
1097 contents()->NavigateAndCommit(kUrl1); 1098 contents()->NavigateAndCommit(kUrl1);
1098 TestRenderViewHost* rvh1 = test_rvh(); 1099 TestRenderViewHost* rvh1 = test_rvh();
1099 1100
1100 // Create a new tab as an opener for the main tab. 1101 // Create a new tab as an opener for the main tab.
1101 scoped_ptr<TestWebContents> opener1( 1102 scoped_ptr<TestWebContents> opener1(
1102 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance())); 1103 TestWebContents::Create(browser_context(), rvh1->GetSiteInstance()));
1103 RenderViewHostManager* opener1_manager = 1104 RenderViewHostManager* opener1_manager =
1104 opener1->GetRenderManagerForTesting(); 1105 opener1->GetRenderManagerForTesting();
1105 contents()->SetOpener(opener1.get()); 1106 contents()->SetOpener(opener1.get());
1106 1107
1108 // Make sure the new opener RVH is considered live.
1109 opener1_manager->current_host()->CreateRenderView(string16(), -1, -1);
1110
1111 // Use a cross-process navigation in the opener to swap out the old RVH.
1107 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( 1112 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost(
1108 rvh1->GetSiteInstance())); 1113 rvh1->GetSiteInstance()));
1109 opener1->CreateSwappedOutRenderView(rvh1->GetSiteInstance()); 1114 opener1->NavigateAndCommit(kUrl2);
1110 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost( 1115 EXPECT_TRUE(opener1_manager->GetSwappedOutRenderViewHost(
1111 rvh1->GetSiteInstance())); 1116 rvh1->GetSiteInstance()));
1112 1117
1113 // Fake a process crash. 1118 // Fake a process crash.
1114 RenderProcessHost::RendererClosedDetails details( 1119 RenderProcessHost::RendererClosedDetails details(
1115 rvh1->GetProcess()->GetHandle(), 1120 rvh1->GetProcess()->GetHandle(),
1116 base::TERMINATION_STATUS_PROCESS_CRASHED, 1121 base::TERMINATION_STATUS_PROCESS_CRASHED,
1117 0); 1122 0);
1118 NotificationService::current()->Notify( 1123 NotificationService::current()->Notify(
1119 NOTIFICATION_RENDERER_PROCESS_CLOSED, 1124 NOTIFICATION_RENDERER_PROCESS_CLOSED,
1120 Source<RenderProcessHost>(rvh1->GetProcess()), 1125 Source<RenderProcessHost>(rvh1->GetProcess()),
1121 Details<RenderProcessHost::RendererClosedDetails>(&details)); 1126 Details<RenderProcessHost::RendererClosedDetails>(&details));
1122 rvh1->set_render_view_created(false); 1127 rvh1->set_render_view_created(false);
1123 1128
1124 // Ensure that the swapped out RenderViewHost has been deleted. 1129 // Ensure that the swapped out RenderViewHost has been deleted.
1125 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( 1130 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost(
1126 rvh1->GetSiteInstance())); 1131 rvh1->GetSiteInstance()));
1127 1132
1128 // Reload the initial tab. This should recreate the opener. 1133 // Reload the initial tab. This should recreate the opener's swapped out RVH
1134 // in the original SiteInstance.
1129 contents()->GetController().Reload(true); 1135 contents()->GetController().Reload(true);
1130 1136 EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost(
1131 EXPECT_EQ(opener1_manager->current_host()->GetRoutingID(), 1137 rvh1->GetSiteInstance())->GetRoutingID(),
1132 test_rvh()->opener_route_id()); 1138 test_rvh()->opener_route_id());
1133 } 1139 }
1134 1140
1135 // Test that RenderViewHosts created for WebUI navigations are properly 1141 // Test that RenderViewHosts created for WebUI navigations are properly
1136 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost 1142 // granted WebUI bindings even if an unprivileged swapped out RenderViewHost
1137 // is in the same process (http://crbug.com/79918). 1143 // is in the same process (http://crbug.com/79918).
1138 TEST_F(RenderViewHostManagerTest, EnableWebUIWithSwappedOutOpener) { 1144 TEST_F(RenderViewHostManagerTest, EnableWebUIWithSwappedOutOpener) {
1139 set_should_create_webui(true); 1145 set_should_create_webui(true);
1140 const GURL kSettingsUrl("chrome://chrome/settings"); 1146 const GURL kSettingsUrl("chrome://chrome/settings");
1141 const GURL kPluginUrl("chrome://plugins"); 1147 const GURL kPluginUrl("chrome://plugins");
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 Source<RenderWidgetHost>(host2)); 1309 Source<RenderWidgetHost>(host2));
1304 manager.ShouldClosePage(false, true, base::TimeTicks()); 1310 manager.ShouldClosePage(false, true, base::TimeTicks());
1305 1311
1306 EXPECT_TRUE( 1312 EXPECT_TRUE(
1307 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1313 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1308 EXPECT_FALSE(manager.pending_render_view_host()); 1314 EXPECT_FALSE(manager.pending_render_view_host());
1309 EXPECT_EQ(host, manager.current_host()); 1315 EXPECT_EQ(host, manager.current_host());
1310 } 1316 }
1311 1317
1312 } // namespace content 1318 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_view_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