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 EXPECT_TRUE(root->child_at(1) != NULL); | |
585 EXPECT_EQ(2U, root->child_at(1)->child_count()); | |
586 | |
587 { | |
588 // Load same-site page into iframe. | |
589 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
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 | |
600 // Create the cross-site URL to navigate to. | |
601 GURL::Replacements replace_host; | |
602 std::string foo_com("foo.com"); | |
603 GURL cross_site_url(test_server()->GetURL("files/frame_tree/1-1.html")); | |
604 replace_host.SetHostStr(foo_com); | |
605 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
606 | |
607 // Load cross-site page into the second iframe without waiting for the | |
608 // navigation to complete. Once LoadURLWithParams returns, we would expect | |
609 // proxies to have been created in the frame tree, but children of the | |
610 // navigating frame to still be present. The reason is that we don't run the | |
611 // message loop, so no IPCs that alter the frame tree can be processed. | |
612 FrameTreeNode* child = root->child_at(1); | |
613 SiteInstance* site; | |
614 { | |
615 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
616 TestFrameNavigationObserver navigation_observer(child); | |
617 NavigationController::LoadURLParams params(cross_site_url); | |
618 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); | |
619 params.frame_tree_node_id = child->frame_tree_node_id(); | |
620 child->navigator()->GetController()->LoadURLWithParams(params); | |
621 EXPECT_TRUE(child->render_manager()->pending_frame_host()); | |
622 | |
623 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
624 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | |
625 | |
626 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); | |
627 EXPECT_TRUE( | |
628 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); | |
629 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); | |
630 for (size_t i = 0; i < child->child_count(); ++i){ | |
631 EXPECT_FALSE( | |
632 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); | |
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 | |
642 // Load another cross-site page into the same iframe. | |
643 cross_site_url = test_server()->GetURL("files/title2.html"); | |
644 std::string bar_com("bar.com"); | |
645 replace_host.SetHostStr(bar_com); | |
646 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
647 | |
648 { | |
kenrb
2014/09/05 17:23:38
This section probably warrants another comment. It
| |
649 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
650 TestFrameNavigationObserver navigation_observer(child); | |
651 NavigationController::LoadURLParams params(cross_site_url); | |
652 params.transition_type = PageTransitionFromInt(PAGE_TRANSITION_LINK); | |
653 params.frame_tree_node_id = child->frame_tree_node_id(); | |
654 child->navigator()->GetController()->LoadURLWithParams(params); | |
655 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); | |
656 | |
657 SiteInstance* site2 = | |
658 child->render_manager()->pending_frame_host()->GetSiteInstance(); | |
659 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | |
660 EXPECT_NE(site, site2); | |
661 | |
662 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); | |
663 EXPECT_TRUE( | |
664 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); | |
665 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); | |
666 for (size_t i = 0; i < child->child_count(); ++i) { | |
667 EXPECT_FALSE( | |
668 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); | |
669 } | |
670 | |
671 navigation_observer.Wait(); | |
672 EXPECT_EQ(cross_site_url, observer.navigation_url()); | |
673 EXPECT_TRUE(observer.navigation_succeeded()); | |
674 } | |
675 } | |
676 | |
569 } // namespace content | 677 } // namespace content |
OLD | NEW |