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 10 matching lines...) Expand all Loading... | |
21 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 21 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
22 #include "content/browser/gpu/compositor_util.h" | 22 #include "content/browser/gpu/compositor_util.h" |
23 #include "content/browser/renderer_host/render_view_host_impl.h" | 23 #include "content/browser/renderer_host/render_view_host_impl.h" |
24 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 24 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
25 #include "content/browser/web_contents/web_contents_impl.h" | 25 #include "content/browser/web_contents/web_contents_impl.h" |
26 #include "content/common/frame_messages.h" | 26 #include "content/common/frame_messages.h" |
27 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
28 #include "content/public/browser/notification_observer.h" | 28 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
31 #include "content/public/browser/resource_dispatcher_host.h" | |
31 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
32 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
33 #include "content/public/test/content_browser_test_utils.h" | 34 #include "content/public/test/content_browser_test_utils.h" |
34 #include "content/public/test/test_navigation_observer.h" | 35 #include "content/public/test/test_navigation_observer.h" |
35 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
36 #include "content/shell/browser/shell.h" | 37 #include "content/shell/browser/shell.h" |
37 #include "content/test/content_browser_test_utils_internal.h" | 38 #include "content/test/content_browser_test_utils_internal.h" |
38 #include "content/test/test_frame_navigation_observer.h" | 39 #include "content/test/test_frame_navigation_observer.h" |
39 #include "ipc/ipc_security_test_util.h" | 40 #include "ipc/ipc_security_test_util.h" |
40 #include "net/dns/mock_host_resolver.h" | 41 #include "net/dns/mock_host_resolver.h" |
(...skipping 3578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3619 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 3620 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
3620 | 3621 |
3621 // Use new window to navigate main window. | 3622 // Use new window to navigate main window. |
3622 std::string script = | 3623 std::string script = |
3623 "window.opener.location.href = '" + cross_url.spec() + "'"; | 3624 "window.opener.location.href = '" + cross_url.spec() + "'"; |
3624 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 3625 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); |
3625 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 3626 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
3626 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 3627 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
3627 } | 3628 } |
3628 | 3629 |
3630 // This test ensures that RenderFrame isn't leaked in the renderer process if | |
Charlie Reis
2015/10/29 17:28:58
nit: that the
nasko
2015/10/29 19:09:45
Done.
| |
3631 // a pending cross-process navigation is cancelled. The test works by by trying | |
3632 // to create a new RenderFrame with the same routing id. If there is an | |
3633 // entry with the same routing ID, a CHECK is hit and the process crashes. | |
3634 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
3635 SubframePendingAndBackToSameSiteInstance) { | |
3636 GURL main_url(embedded_test_server()->GetURL( | |
3637 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
3638 NavigateToURL(shell(), main_url); | |
3639 | |
3640 // Capture the FrameTreeNode this test will be navigating. | |
3641 FrameTreeNode* node = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
3642 ->GetFrameTree() | |
3643 ->root() | |
3644 ->child_at(0); | |
3645 EXPECT_TRUE(node); | |
3646 EXPECT_NE(node->current_frame_host()->GetSiteInstance(), | |
3647 node->parent()->current_frame_host()->GetSiteInstance()); | |
3648 | |
3649 // Navigate to the site of the parent, but to a page that will not commit. | |
3650 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
3651 NavigationStallDelegate stall_delegate(same_site_url); | |
3652 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); | |
3653 { | |
3654 NavigationController::LoadURLParams params(same_site_url); | |
3655 params.transition_type = ui::PAGE_TRANSITION_LINK; | |
3656 params.frame_tree_node_id = node->frame_tree_node_id(); | |
3657 node->navigator()->GetController()->LoadURLWithParams(params); | |
3658 } | |
3659 | |
3660 // Grab the routing id of the pending RenderFrameHost and setup a process | |
Charlie Reis
2015/10/29 17:28:58
nit: set up
nasko
2015/10/29 19:09:45
Done.
| |
3661 // observer to ensure there is no crash when a new RenderFrame creation is | |
3662 // attempted. | |
3663 RenderProcessHost* process = | |
3664 node->render_manager()->pending_frame_host()->GetProcess(); | |
3665 RenderProcessHostWatcher watcher( | |
3666 process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
3667 int frame_routing_id = | |
3668 node->render_manager()->pending_frame_host()->GetRoutingID(); | |
3669 int proxy_routing_id = | |
3670 node->render_manager()->GetProxyToParent()->GetRoutingID(); | |
3671 | |
3672 // Now go to c.com so the navigation to a.com is cancelled and send an IPC | |
3673 // to create a new RenderFrame with the routing id of the previously pending | |
3674 // one. | |
3675 NavigateFrameToURL(node, | |
3676 embedded_test_server()->GetURL("c.com", "/title2.html")); | |
3677 { | |
3678 FrameMsg_NewFrame_Params params; | |
3679 params.routing_id = frame_routing_id; | |
3680 params.proxy_routing_id = proxy_routing_id; | |
3681 params.opener_routing_id = MSG_ROUTING_NONE; | |
3682 params.parent_routing_id = | |
3683 shell()->web_contents()->GetMainFrame()->GetRoutingID(); | |
3684 params.previous_sibling_routing_id = MSG_ROUTING_NONE; | |
3685 params.widget_params.routing_id = MSG_ROUTING_NONE; | |
3686 params.widget_params.hidden = true; | |
3687 | |
3688 process->Send(new FrameMsg_NewFrame(params)); | |
Charlie Reis
2015/10/29 17:28:58
I'm a bit surprised this works cleanly. I guess w
nasko
2015/10/29 19:09:45
Yes, we don't have any checks for possible reuse.
| |
3689 } | |
3690 | |
3691 // The test must wait for a process to exit, but if there is no leak, the | |
3692 // RenderFrame will be properly created and there will be no crash. | |
3693 // Therefore, navigate the main frame to completely different site, which | |
3694 // will cause the original process to exit cleanly. | |
3695 EXPECT_TRUE(NavigateToURL( | |
3696 shell(), embedded_test_server()->GetURL("d.com", "/title3.html"))); | |
3697 watcher.Wait(); | |
3698 EXPECT_TRUE(watcher.did_exit_normally()); | |
3699 | |
3700 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | |
3701 } | |
3702 | |
3629 } // namespace content | 3703 } // namespace content |
OLD | NEW |