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