Chromium Code Reviews| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "content/browser/frame_host/cross_process_frame_connector.h" | 9 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
| 11 #include "content/browser/frame_host/navigator.h" | |
| 11 #include "content/browser/frame_host/render_frame_proxy_host.h" | 12 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 12 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 13 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 23 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
| 24 #include "content/test/content_browser_test_utils_internal.h" | 25 #include "content/test/content_browser_test_utils_internal.h" |
| 26 #include "content/test/test_frame_navigation_observer.h" | |
| 25 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 class SitePerProcessWebContentsObserver: public WebContentsObserver { | 31 class SitePerProcessWebContentsObserver: public WebContentsObserver { |
| 30 public: | 32 public: |
| 31 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | 33 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
| 32 : WebContentsObserver(web_contents), | 34 : WebContentsObserver(web_contents), |
| 33 navigation_succeeded_(false) {} | 35 navigation_succeeded_(false) {} |
| 34 virtual ~SitePerProcessWebContentsObserver() {} | 36 virtual ~SitePerProcessWebContentsObserver() {} |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 236 |
| 235 // Load cross-site page into iframe. | 237 // Load cross-site page into iframe. |
| 236 GURL cross_site_url(test_server()->GetURL("files/title2.html")); | 238 GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| 237 replace_host.SetHostStr(foo_com); | 239 replace_host.SetHostStr(foo_com); |
| 238 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | 240 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 239 NavigateFrameToURL(root->child_at(0), cross_site_url); | 241 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 240 EXPECT_EQ(cross_site_url, observer.navigation_url()); | 242 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| 241 EXPECT_TRUE(observer.navigation_succeeded()); | 243 EXPECT_TRUE(observer.navigation_succeeded()); |
| 242 | 244 |
| 243 // Ensure that we have created a new process for the subframe. | 245 // Ensure that we have created a new process for the subframe. |
| 244 ASSERT_EQ(1U, root->child_count()); | 246 ASSERT_EQ(2U, root->child_count()); |
| 245 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); | 247 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); |
| 246 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); | 248 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); |
| 247 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); | 249 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); |
| 248 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); | 250 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); |
| 249 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); | 251 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); |
| 250 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); | 252 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); |
| 251 { | 253 { |
| 252 // There should be now two RenderWidgetHosts, one for each process | 254 // There should be now two RenderWidgetHosts, one for each process |
| 253 // rendering a frame. | 255 // rendering a frame. |
| 254 std::set<RenderWidgetHostView*> views_set = | 256 std::set<RenderWidgetHostView*> views_set = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 267 cross_site_url = test_server()->GetURL("files/title3.html"); | 269 cross_site_url = test_server()->GetURL("files/title3.html"); |
| 268 std::string bar_com("bar.com"); | 270 std::string bar_com("bar.com"); |
| 269 replace_host.SetHostStr(bar_com); | 271 replace_host.SetHostStr(bar_com); |
| 270 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | 272 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 271 NavigateFrameToURL(root->child_at(0), cross_site_url); | 273 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 272 EXPECT_EQ(cross_site_url, observer.navigation_url()); | 274 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| 273 EXPECT_TRUE(observer.navigation_succeeded()); | 275 EXPECT_TRUE(observer.navigation_succeeded()); |
| 274 | 276 |
| 275 // Check again that a new process is created and is different from the | 277 // Check again that a new process is created and is different from the |
| 276 // top level one and the previous one. | 278 // top level one and the previous one. |
| 277 ASSERT_EQ(1U, root->child_count()); | 279 ASSERT_EQ(2U, root->child_count()); |
| 278 child = root->child_at(0); | 280 child = root->child_at(0); |
| 279 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), | 281 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), |
| 280 child->current_frame_host()->render_view_host()); | 282 child->current_frame_host()->render_view_host()); |
| 281 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); | 283 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); |
| 282 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 284 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 283 child->current_frame_host()->GetSiteInstance()); | 285 child->current_frame_host()->GetSiteInstance()); |
| 284 EXPECT_NE(site_instance, | 286 EXPECT_NE(site_instance, |
| 285 child->current_frame_host()->GetSiteInstance()); | 287 child->current_frame_host()->GetSiteInstance()); |
| 286 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), | 288 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), |
| 287 child->current_frame_host()->GetProcess()); | 289 child->current_frame_host()->GetProcess()); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 GURL server_redirect_http_url(test_server()->GetURL( | 572 GURL server_redirect_http_url(test_server()->GetURL( |
| 571 "server-redirect?" + client_redirect_http_url.spec())); | 573 "server-redirect?" + client_redirect_http_url.spec())); |
| 572 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 574 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| 573 | 575 |
| 574 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 576 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 575 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 577 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| 576 EXPECT_FALSE(observer.navigation_succeeded()); | 578 EXPECT_FALSE(observer.navigation_succeeded()); |
| 577 } | 579 } |
| 578 } | 580 } |
| 579 | 581 |
| 582 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are | |
| 583 // created in the FrameTree skipping the subtree of the navigating frame. | |
| 584 // TODO(nasko): Test is disabled on Android, because it times out. It should | |
| 585 // be fixed together with CrossSiteIframe on that platform. | |
| 586 #if defined(OS_ANDROID) | |
| 587 #define MAYBE_ProxyCreationSkipsSubtree DISABLED_ProxyCreationSkipsSubtree | |
| 588 #else | |
| 589 #define MAYBE_ProxyCreationSkipsSubtree ProxyCreationSkipsSubtree | |
| 590 #endif | |
| 591 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 592 MAYBE_ProxyCreationSkipsSubtree) { | |
| 593 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 594 ASSERT_TRUE(test_server()->Start()); | |
| 595 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | |
| 596 NavigateToURL(shell(), main_url); | |
| 597 | |
| 598 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
| 599 FrameTreeNode* root = | |
| 600 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 601 GetFrameTree()->root(); | |
| 602 | |
| 603 EXPECT_TRUE(root->child_at(1) != NULL); | |
| 604 EXPECT_EQ(2U, root->child_at(1)->child_count()); | |
| 605 | |
| 606 { | |
| 607 // Load same-site page into iframe. | |
| 608 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 609 GURL http_url(test_server()->GetURL("files/title1.html")); | |
| 610 NavigateFrameToURL(root->child_at(0), http_url); | |
| 611 EXPECT_EQ(http_url, observer.navigation_url()); | |
| 612 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 613 RenderFrameProxyHost* proxy_to_parent = | |
| 614 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( | |
| 615 shell()->web_contents()->GetSiteInstance()); | |
| 616 EXPECT_FALSE(proxy_to_parent); | |
| 617 } | |
| 618 | |
| 619 // Create the cross-site URL to navigate to. | |
| 620 GURL::Replacements replace_host; | |
| 621 std::string foo_com("foo.com"); | |
| 622 GURL cross_site_url(test_server()->GetURL("files/frame_tree/1-1.html")); | |
| 623 replace_host.SetHostStr(foo_com); | |
| 624 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
| 625 | |
| 626 // Load cross-site page into the second iframe without waiting for the | |
| 627 // navigation to complete. Once LoadURLWithParams returns, we would expect | |
| 628 // proxies to have been created in the frame tree, but children of the | |
| 629 // navigating frame to still be present. The reason is that we don't run the | |
| 630 // message loop, so no IPCs that alter the frame tree can be processed. | |
| 631 FrameTreeNode* child = root->child_at(1); | |
| 632 SiteInstance* site; | |
|
Charlie Reis
2014/09/24 21:59:36
nit: Please initialize this to null.
nasko
2014/09/25 16:20:27
Done.
| |
| 633 { | |
| 634 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 635 TestFrameNavigationObserver navigation_observer(child); | |
| 636 NavigationController::LoadURLParams params(cross_site_url); | |
| 637 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | |
| 638 params.frame_tree_node_id = child->frame_tree_node_id(); | |
| 639 child->navigator()->GetController()->LoadURLWithParams(params); | |
| 640 EXPECT_TRUE(child->render_manager()->pending_frame_host()); | |
| 641 | |
| 642 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
| 643 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | |
| 644 | |
| 645 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); | |
| 646 EXPECT_TRUE( | |
| 647 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); | |
| 648 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); | |
| 649 for (size_t i = 0; i < child->child_count(); ++i) { | |
| 650 EXPECT_FALSE( | |
| 651 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); | |
| 652 } | |
| 653 // Now that the verification is done, run the message loop and wait for the | |
| 654 // navigation to complete. | |
| 655 navigation_observer.Wait(); | |
| 656 EXPECT_FALSE(child->render_manager()->pending_frame_host()); | |
| 657 EXPECT_EQ(cross_site_url, observer.navigation_url()); | |
| 658 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 659 } | |
| 660 | |
| 661 // Load another cross-site page into the same iframe. | |
| 662 cross_site_url = test_server()->GetURL("files/title2.html"); | |
| 663 std::string bar_com("bar.com"); | |
| 664 replace_host.SetHostStr(bar_com); | |
| 665 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
| 666 | |
| 667 { | |
| 668 // Perform the same checks as the first cross-site navigation, since | |
| 669 // there have been issues in subsequent cross-site navigations. Also ensure | |
| 670 // that the SiteInstance has properly changed. | |
| 671 // TODO(nasko): Once we have proper cleanup of resources, add code to | |
| 672 // verify that the intermediate SiteInstance/RenderFrameHost have been | |
| 673 // properly cleaned up. | |
| 674 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 675 TestFrameNavigationObserver navigation_observer(child); | |
| 676 NavigationController::LoadURLParams params(cross_site_url); | |
| 677 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | |
| 678 params.frame_tree_node_id = child->frame_tree_node_id(); | |
| 679 child->navigator()->GetController()->LoadURLWithParams(params); | |
| 680 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); | |
| 681 | |
| 682 SiteInstance* site2 = | |
| 683 child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
| 684 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | |
| 685 EXPECT_NE(site, site2); | |
| 686 | |
| 687 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 688 EXPECT_TRUE( | |
| 689 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 690 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 691 for (size_t i = 0; i < child->child_count(); ++i) { | |
| 692 EXPECT_FALSE( | |
| 693 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 694 } | |
| 695 | |
| 696 navigation_observer.Wait(); | |
| 697 EXPECT_EQ(cross_site_url, observer.navigation_url()); | |
| 698 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 699 EXPECT_EQ(0U, child->child_count()); | |
| 700 } | |
| 701 } | |
| 702 | |
| 580 } // namespace content | 703 } // namespace content |
| OLD | NEW |