OLD | NEW |
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 Loading... |
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 Loading... |
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 the process to exit, but if there is no leak, the |
| 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 |
| 4343 // This test ensures that the RenderFrame isn't leaked in the renderer process |
| 4344 // when a remote parent detaches a child frame. The test works by trying |
| 4345 // to create a new RenderFrame with the same routing id. If there is an |
| 4346 // entry with the same routing ID, a CHECK is hit and the process crashes. |
| 4347 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ParentDetachRemoteChild) { |
| 4348 GURL main_url(embedded_test_server()->GetURL( |
| 4349 "a.com", "/cross_site_iframe_factory.html?a(b,b)")); |
| 4350 NavigateToURL(shell(), main_url); |
| 4351 |
| 4352 WebContentsImpl* web_contents = |
| 4353 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 4354 EXPECT_EQ(2U, web_contents->GetFrameTree()->root()->child_count()); |
| 4355 |
| 4356 // Capture the FrameTreeNode this test will be navigating. |
| 4357 FrameTreeNode* node = web_contents->GetFrameTree()->root()->child_at(0); |
| 4358 EXPECT_TRUE(node); |
| 4359 EXPECT_NE(node->current_frame_host()->GetSiteInstance(), |
| 4360 node->parent()->current_frame_host()->GetSiteInstance()); |
| 4361 |
| 4362 // Grab the routing id of the first child RenderFrameHost and set up a process |
| 4363 // observer to ensure there is no crash when a new RenderFrame creation is |
| 4364 // attempted. |
| 4365 RenderProcessHost* process = node->current_frame_host()->GetProcess(); |
| 4366 RenderProcessHostWatcher watcher( |
| 4367 process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 4368 int frame_routing_id = node->current_frame_host()->GetRoutingID(); |
| 4369 int widget_routing_id = |
| 4370 node->current_frame_host()->GetRenderWidgetHost()->GetRoutingID(); |
| 4371 int parent_routing_id = |
| 4372 node->parent()->render_manager()->GetRoutingIdForSiteInstance( |
| 4373 node->current_frame_host()->GetSiteInstance()); |
| 4374 |
| 4375 // Have the parent frame remove the child frame from its DOM. This should |
| 4376 // result in the child RenderFrame being deleted in the remote process. |
| 4377 EXPECT_TRUE(ExecuteScript(web_contents, |
| 4378 "document.body.removeChild(" |
| 4379 "document.querySelectorAll('iframe')[0])")); |
| 4380 EXPECT_EQ(1U, web_contents->GetFrameTree()->root()->child_count()); |
| 4381 |
| 4382 { |
| 4383 FrameMsg_NewFrame_Params params; |
| 4384 params.routing_id = frame_routing_id; |
| 4385 params.proxy_routing_id = MSG_ROUTING_NONE; |
| 4386 params.opener_routing_id = MSG_ROUTING_NONE; |
| 4387 params.parent_routing_id = parent_routing_id; |
| 4388 params.previous_sibling_routing_id = MSG_ROUTING_NONE; |
| 4389 params.widget_params.routing_id = widget_routing_id; |
| 4390 params.widget_params.hidden = true; |
| 4391 |
| 4392 process->Send(new FrameMsg_NewFrame(params)); |
| 4393 } |
| 4394 |
| 4395 // The test must wait for the process to exit, but if there is no leak, the |
| 4396 // RenderFrame will be properly created and there will be no crash. |
| 4397 // Therefore, navigate the remaining subframe to completely different site, |
| 4398 // which will cause the original process to exit cleanly. |
| 4399 NavigateFrameToURL( |
| 4400 web_contents->GetFrameTree()->root()->child_at(0), |
| 4401 embedded_test_server()->GetURL("d.com", "/title3.html")); |
| 4402 watcher.Wait(); |
| 4403 EXPECT_TRUE(watcher.did_exit_normally()); |
| 4404 } |
| 4405 |
4269 } // namespace content | 4406 } // namespace content |
OLD | NEW |