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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1409693009: Fix leaking of RenderFrames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on ToT and a small change. Created 5 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
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 "content/browser/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 22 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
23 #include "content/browser/gpu/compositor_util.h" 23 #include "content/browser/gpu/compositor_util.h"
24 #include "content/browser/renderer_host/render_view_host_impl.h" 24 #include "content/browser/renderer_host/render_view_host_impl.h"
25 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 25 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
26 #include "content/browser/web_contents/web_contents_impl.h" 26 #include "content/browser/web_contents/web_contents_impl.h"
27 #include "content/common/frame_messages.h" 27 #include "content/common/frame_messages.h"
28 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
29 #include "content/public/browser/notification_observer.h" 29 #include "content/public/browser/notification_observer.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/resource_dispatcher_host.h"
32 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
33 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
34 #include "content/public/test/content_browser_test_utils.h" 35 #include "content/public/test/content_browser_test_utils.h"
35 #include "content/public/test/test_navigation_observer.h" 36 #include "content/public/test/test_navigation_observer.h"
36 #include "content/public/test/test_utils.h" 37 #include "content/public/test/test_utils.h"
37 #include "content/shell/browser/shell.h" 38 #include "content/shell/browser/shell.h"
38 #include "content/test/content_browser_test_utils_internal.h" 39 #include "content/test/content_browser_test_utils_internal.h"
39 #include "content/test/test_frame_navigation_observer.h" 40 #include "content/test/test_frame_navigation_observer.h"
40 #include "ipc/ipc_security_test_util.h" 41 #include "ipc/ipc_security_test_util.h"
41 #include "net/dns/mock_host_resolver.h" 42 #include "net/dns/mock_host_resolver.h"
(...skipping 4217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4259 router->RouteMouseEvent(root_view, &click_event); 4260 router->RouteMouseEvent(root_view, &click_event);
4260 4261
4261 context_menu_delegate.Wait(); 4262 context_menu_delegate.Wait();
4262 4263
4263 ContextMenuParams params = context_menu_delegate.getParams(); 4264 ContextMenuParams params = context_menu_delegate.getParams();
4264 4265
4265 EXPECT_EQ(point.x(), params.x); 4266 EXPECT_EQ(point.x(), params.x);
4266 EXPECT_EQ(point.y(), params.y); 4267 EXPECT_EQ(point.y(), params.y);
4267 } 4268 }
4268 4269
4270 // This test ensures that the RenderFrame isn't leaked in the renderer process
4271 // if a pending cross-process navigation is cancelled. The test works by trying
4272 // to create a new RenderFrame with the same routing id. If there is an
4273 // entry with the same routing ID, a CHECK is hit and the process crashes.
4274 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
4275 SubframePendingAndBackToSameSiteInstance) {
4276 GURL main_url(embedded_test_server()->GetURL(
4277 "a.com", "/cross_site_iframe_factory.html?a(b)"));
4278 NavigateToURL(shell(), main_url);
4279
4280 // Capture the FrameTreeNode this test will be navigating.
4281 FrameTreeNode* node = static_cast<WebContentsImpl*>(shell()->web_contents())
4282 ->GetFrameTree()
4283 ->root()
4284 ->child_at(0);
4285 EXPECT_TRUE(node);
4286 EXPECT_NE(node->current_frame_host()->GetSiteInstance(),
4287 node->parent()->current_frame_host()->GetSiteInstance());
4288
4289 // Navigate to the site of the parent, but to a page that will not commit.
4290 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
4291 NavigationStallDelegate stall_delegate(same_site_url);
4292 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate);
4293 {
4294 NavigationController::LoadURLParams params(same_site_url);
4295 params.transition_type = ui::PAGE_TRANSITION_LINK;
4296 params.frame_tree_node_id = node->frame_tree_node_id();
4297 node->navigator()->GetController()->LoadURLWithParams(params);
4298 }
4299
4300 // Grab the routing id of the pending RenderFrameHost and set up a process
4301 // observer to ensure there is no crash when a new RenderFrame creation is
4302 // attempted.
4303 RenderProcessHost* process =
4304 node->render_manager()->pending_frame_host()->GetProcess();
4305 RenderProcessHostWatcher watcher(
4306 process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
4307 int frame_routing_id =
4308 node->render_manager()->pending_frame_host()->GetRoutingID();
4309 int proxy_routing_id =
4310 node->render_manager()->GetProxyToParent()->GetRoutingID();
4311
4312 // Now go to c.com so the navigation to a.com is cancelled and send an IPC
4313 // to create a new RenderFrame with the routing id of the previously pending
4314 // one.
4315 NavigateFrameToURL(node,
4316 embedded_test_server()->GetURL("c.com", "/title2.html"));
4317 {
4318 FrameMsg_NewFrame_Params params;
4319 params.routing_id = frame_routing_id;
4320 params.proxy_routing_id = proxy_routing_id;
4321 params.opener_routing_id = MSG_ROUTING_NONE;
4322 params.parent_routing_id =
4323 shell()->web_contents()->GetMainFrame()->GetRoutingID();
4324 params.previous_sibling_routing_id = MSG_ROUTING_NONE;
4325 params.widget_params.routing_id = MSG_ROUTING_NONE;
4326 params.widget_params.hidden = true;
4327
4328 process->Send(new FrameMsg_NewFrame(params));
4329 }
4330
4331 // The test must wait for a process to exit, but if there is no leak, the
Charlie Reis 2015/12/11 00:03:17 nit: s/a/the/
nasko 2015/12/11 00:47:25 Done.
4332 // RenderFrame will be properly created and there will be no crash.
4333 // Therefore, navigate the main frame to completely different site, which
4334 // will cause the original process to exit cleanly.
4335 EXPECT_TRUE(NavigateToURL(
4336 shell(), embedded_test_server()->GetURL("d.com", "/title3.html")));
4337 watcher.Wait();
4338 EXPECT_TRUE(watcher.did_exit_normally());
4339
4340 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
4341 }
4342
4269 } // namespace content 4343 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698