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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "content/browser/frame_host/cross_process_frame_connector.h" | 7 #include "content/browser/frame_host/cross_process_frame_connector.h" |
8 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/frame_host/navigator.h" |
9 #include "content/browser/frame_host/render_frame_proxy_host.h" | 10 #include "content/browser/frame_host/render_frame_proxy_host.h" |
10 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 11 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
19 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
20 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
23 #include "content/test/content_browser_test_utils_internal.h" | 24 #include "content/test/content_browser_test_utils_internal.h" |
| 25 #include "content/test/test_frame_navigation_observer.h" |
24 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
25 #include "url/gurl.h" | 27 #include "url/gurl.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) {} |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 GURL server_redirect_http_url(test_server()->GetURL( | 561 GURL server_redirect_http_url(test_server()->GetURL( |
560 "server-redirect?" + client_redirect_http_url.spec())); | 562 "server-redirect?" + client_redirect_http_url.spec())); |
561 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 563 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
562 | 564 |
563 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 565 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
564 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 566 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
565 EXPECT_FALSE(observer.navigation_succeeded()); | 567 EXPECT_FALSE(observer.navigation_succeeded()); |
566 } | 568 } |
567 } | 569 } |
568 | 570 |
| 571 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are |
| 572 // created in the FrameTree skipping the subtree of the navigating frame. |
| 573 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ProxiesCreationSkipsSubtree) { |
| 574 host_resolver()->AddRule("*", "127.0.0.1"); |
| 575 ASSERT_TRUE(test_server()->Start()); |
| 576 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 577 NavigateToURL(shell(), main_url); |
| 578 |
| 579 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 580 FrameTreeNode* root = |
| 581 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 582 GetFrameTree()->root(); |
| 583 |
| 584 SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
| 585 |
| 586 EXPECT_TRUE(root->child_at(1) != NULL); |
| 587 EXPECT_EQ(2U, root->child_at(1)->child_count()); |
| 588 |
| 589 // Load same-site page into iframe. |
| 590 GURL http_url(test_server()->GetURL("files/title1.html")); |
| 591 NavigateFrameToURL(root->child_at(0), http_url); |
| 592 EXPECT_EQ(http_url, observer.navigation_url()); |
| 593 EXPECT_TRUE(observer.navigation_succeeded()); |
| 594 RenderFrameProxyHost* proxy_to_parent = |
| 595 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
| 596 shell()->web_contents()->GetSiteInstance()); |
| 597 EXPECT_FALSE(proxy_to_parent); |
| 598 |
| 599 // Create the cross-site URL to navigate to. |
| 600 GURL::Replacements replace_host; |
| 601 std::string foo_com("foo.com"); |
| 602 GURL cross_site_url(test_server()->GetURL("files/frame_tree/1-1.html")); |
| 603 replace_host.SetHostStr(foo_com); |
| 604 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 605 |
| 606 // Load cross-site page into the second iframe without waiting for the |
| 607 // navigation to complete. Once LoadURLWithParams returns, we would expect |
| 608 // proxies to have been created in the frame tree, but children of the |
| 609 // navigating frame to still be present. The reason is that we don't run the |
| 610 // message loop, so no IPCs that alter the frame tree can be processed. |
| 611 FrameTreeNode* child = root->child_at(1); |
| 612 TestFrameNavigationObserver navigation_observer(child); |
| 613 { |
| 614 NavigationController::LoadURLParams params(cross_site_url); |
| 615 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); |
| 616 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 617 child->navigator()->GetController()->LoadURLWithParams(params); |
| 618 EXPECT_TRUE(child->render_manager()->pending_frame_host()); |
| 619 } |
| 620 |
| 621 SiteInstance* site = |
| 622 child->render_manager()->pending_frame_host()->GetSiteInstance(); |
| 623 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); |
| 624 |
| 625 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); |
| 626 EXPECT_TRUE( |
| 627 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); |
| 628 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); |
| 629 for (size_t i = 0; i < child->child_count(); ++i) { |
| 630 EXPECT_FALSE( |
| 631 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); |
| 632 } |
| 633 |
| 634 // Now that the verification is done, run the message loop and wait for the |
| 635 // navigation to complete. |
| 636 navigation_observer.Wait(); |
| 637 EXPECT_FALSE(child->render_manager()->pending_frame_host()); |
| 638 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| 639 EXPECT_TRUE(observer.navigation_succeeded()); |
| 640 |
| 641 // Load another cross-site page into the same iframe. |
| 642 cross_site_url = test_server()->GetURL("files/title1.html"); |
| 643 std::string bar_com("bar.com"); |
| 644 replace_host.SetHostStr(bar_com); |
| 645 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 646 |
| 647 { |
| 648 NavigationController::LoadURLParams params(cross_site_url); |
| 649 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); |
| 650 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 651 child->navigator()->GetController()->LoadURLWithParams(params); |
| 652 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); |
| 653 } |
| 654 |
| 655 SiteInstance* site2 = |
| 656 child->render_manager()->pending_frame_host()->GetSiteInstance(); |
| 657 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); |
| 658 EXPECT_NE(site, site2); |
| 659 |
| 660 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); |
| 661 EXPECT_TRUE( |
| 662 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); |
| 663 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); |
| 664 for (size_t i=0; i < child->child_count(); ++i) { |
| 665 EXPECT_FALSE( |
| 666 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); |
| 667 } |
| 668 |
| 669 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| 670 EXPECT_TRUE(observer.navigation_succeeded()); |
| 671 } |
| 672 |
569 } // namespace content | 673 } // namespace content |
OLD | NEW |