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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 return result; | 187 return result; |
| 186 } | 188 } |
| 187 | 189 |
| 188 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 190 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
| 189 command_line->AppendSwitch(switches::kSitePerProcess); | 191 command_line->AppendSwitch(switches::kSitePerProcess); |
| 190 }; | 192 }; |
| 191 | 193 |
| 192 // Ensure that we can complete a cross-process subframe navigation. | 194 // Ensure that we can complete a cross-process subframe navigation. |
| 193 // Crashes ChromeOS bot, but the bug is probably present on other platforms | 195 // Crashes ChromeOS bot, but the bug is probably present on other platforms |
| 194 // also. http://crbug.com/399775 | 196 // also. http://crbug.com/399775 |
| 195 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { | 197 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { |
|
dmazzoni
2014/09/11 15:10:39
Any chance you could enable this on even one platf
nasko
2014/09/11 17:10:36
Your wish has been granted:
https://crrev.com/bd6
| |
| 196 host_resolver()->AddRule("*", "127.0.0.1"); | 198 host_resolver()->AddRule("*", "127.0.0.1"); |
| 197 ASSERT_TRUE(test_server()->Start()); | 199 ASSERT_TRUE(test_server()->Start()); |
| 198 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 200 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 199 NavigateToURL(shell(), main_url); | 201 NavigateToURL(shell(), main_url); |
| 200 | 202 |
| 201 // It is safe to obtain the root frame tree node here, as it doesn't change. | 203 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 202 FrameTreeNode* root = | 204 FrameTreeNode* root = |
| 203 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 205 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 204 GetFrameTree()->root(); | 206 GetFrameTree()->root(); |
| 205 | 207 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 GURL server_redirect_http_url(test_server()->GetURL( | 559 GURL server_redirect_http_url(test_server()->GetURL( |
| 558 "server-redirect?" + client_redirect_http_url.spec())); | 560 "server-redirect?" + client_redirect_http_url.spec())); |
| 559 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 561 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| 560 | 562 |
| 561 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 563 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 562 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 564 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| 563 EXPECT_FALSE(observer.navigation_succeeded()); | 565 EXPECT_FALSE(observer.navigation_succeeded()); |
| 564 } | 566 } |
| 565 } | 567 } |
| 566 | 568 |
| 569 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are | |
| 570 // created in the FrameTree skipping the subtree of the navigating frame. | |
| 571 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ProxyCreationSkipsSubtree) { | |
| 572 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 573 ASSERT_TRUE(test_server()->Start()); | |
| 574 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | |
| 575 NavigateToURL(shell(), main_url); | |
| 576 | |
| 577 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
| 578 FrameTreeNode* root = | |
| 579 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 580 GetFrameTree()->root(); | |
| 581 | |
| 582 EXPECT_TRUE(root->child_at(1) != NULL); | |
| 583 EXPECT_EQ(2U, root->child_at(1)->child_count()); | |
| 584 | |
| 585 { | |
| 586 // Load same-site page into iframe. | |
| 587 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 588 GURL http_url(test_server()->GetURL("files/title1.html")); | |
| 589 NavigateFrameToURL(root->child_at(0), http_url); | |
| 590 EXPECT_EQ(http_url, observer.navigation_url()); | |
| 591 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 592 RenderFrameProxyHost* proxy_to_parent = | |
| 593 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( | |
| 594 shell()->web_contents()->GetSiteInstance()); | |
| 595 EXPECT_FALSE(proxy_to_parent); | |
| 596 } | |
| 597 | |
| 598 // Create the cross-site URL to navigate to. | |
| 599 GURL::Replacements replace_host; | |
| 600 std::string foo_com("foo.com"); | |
| 601 GURL cross_site_url(test_server()->GetURL("files/frame_tree/1-1.html")); | |
| 602 replace_host.SetHostStr(foo_com); | |
| 603 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
| 604 | |
| 605 // Load cross-site page into the second iframe without waiting for the | |
| 606 // navigation to complete. Once LoadURLWithParams returns, we would expect | |
| 607 // proxies to have been created in the frame tree, but children of the | |
| 608 // navigating frame to still be present. The reason is that we don't run the | |
| 609 // message loop, so no IPCs that alter the frame tree can be processed. | |
| 610 FrameTreeNode* child = root->child_at(1); | |
| 611 SiteInstance* site; | |
| 612 { | |
| 613 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 614 TestFrameNavigationObserver navigation_observer(child); | |
| 615 NavigationController::LoadURLParams params(cross_site_url); | |
| 616 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); | |
| 617 params.frame_tree_node_id = child->frame_tree_node_id(); | |
| 618 child->navigator()->GetController()->LoadURLWithParams(params); | |
| 619 EXPECT_TRUE(child->render_manager()->pending_frame_host()); | |
| 620 | |
| 621 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
| 622 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | |
| 623 | |
| 624 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); | |
| 625 EXPECT_TRUE( | |
| 626 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); | |
| 627 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); | |
| 628 for (size_t i = 0; i < child->child_count(); ++i) { | |
| 629 EXPECT_FALSE( | |
| 630 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); | |
| 631 } | |
| 632 // Now that the verification is done, run the message loop and wait for the | |
| 633 // navigation to complete. | |
| 634 navigation_observer.Wait(); | |
| 635 EXPECT_FALSE(child->render_manager()->pending_frame_host()); | |
| 636 EXPECT_EQ(cross_site_url, observer.navigation_url()); | |
| 637 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 638 } | |
| 639 | |
| 640 // Load another cross-site page into the same iframe. | |
| 641 cross_site_url = test_server()->GetURL("files/title2.html"); | |
| 642 std::string bar_com("bar.com"); | |
| 643 replace_host.SetHostStr(bar_com); | |
| 644 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
| 645 | |
| 646 { | |
| 647 // Perform the same checks as the first cross-site navigation, since | |
| 648 // there have been issues in subsequent cross-site navigations. Also ensure | |
| 649 // that the SiteInstance has properly changed. | |
| 650 // TODO(nasko): Once we have proper cleanup of resources, add code to | |
| 651 // verify that the intermediate SiteInstance/RenderFrameHost have been | |
| 652 // properly cleaned up. | |
| 653 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
| 654 TestFrameNavigationObserver navigation_observer(child); | |
| 655 NavigationController::LoadURLParams params(cross_site_url); | |
| 656 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); | |
| 657 params.frame_tree_node_id = child->frame_tree_node_id(); | |
| 658 child->navigator()->GetController()->LoadURLWithParams(params); | |
| 659 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); | |
| 660 | |
| 661 SiteInstance* site2 = | |
| 662 child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
| 663 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | |
| 664 EXPECT_NE(site, site2); | |
| 665 | |
| 666 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 667 EXPECT_TRUE( | |
| 668 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 669 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 670 for (size_t i = 0; i < child->child_count(); ++i) { | |
| 671 EXPECT_FALSE( | |
| 672 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); | |
| 673 } | |
| 674 | |
| 675 navigation_observer.Wait(); | |
| 676 EXPECT_EQ(cross_site_url, observer.navigation_url()); | |
| 677 EXPECT_TRUE(observer.navigation_succeeded()); | |
| 678 EXPECT_EQ(0U, child->child_count()); | |
| 679 } | |
| 680 } | |
| 681 | |
| 567 } // namespace content | 682 } // namespace content |
| OLD | NEW |