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/navigator.h" |
12 #include "content/browser/frame_host/render_frame_proxy_host.h" | 12 #include "content/browser/frame_host/render_frame_proxy_host.h" |
13 #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" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 #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" | 25 #include "content/test/test_frame_navigation_observer.h" |
27 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
28 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
29 | 28 |
30 namespace content { | 29 namespace content { |
31 | 30 |
32 class SitePerProcessWebContentsObserver: public WebContentsObserver { | |
33 public: | |
34 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | |
35 : WebContentsObserver(web_contents), | |
36 navigation_succeeded_(false) {} | |
37 ~SitePerProcessWebContentsObserver() override {} | |
38 | |
39 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, | |
40 const GURL& validated_url, | |
41 bool is_error_page, | |
42 bool is_iframe_srcdoc) override { | |
43 navigation_succeeded_ = false; | |
44 } | |
45 | |
46 void DidFailProvisionalLoad( | |
47 RenderFrameHost* render_frame_host, | |
48 const GURL& validated_url, | |
49 int error_code, | |
50 const base::string16& error_description) override { | |
51 navigation_url_ = validated_url; | |
52 navigation_succeeded_ = false; | |
53 } | |
54 | |
55 void DidCommitProvisionalLoadForFrame( | |
56 RenderFrameHost* render_frame_host, | |
57 const GURL& url, | |
58 ui::PageTransition transition_type) override { | |
59 navigation_url_ = url; | |
60 navigation_succeeded_ = true; | |
61 } | |
62 | |
63 const GURL& navigation_url() const { | |
64 return navigation_url_; | |
65 } | |
66 | |
67 int navigation_succeeded() const { return navigation_succeeded_; } | |
68 | |
69 private: | |
70 GURL navigation_url_; | |
71 bool navigation_succeeded_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(SitePerProcessWebContentsObserver); | |
74 }; | |
75 | |
76 class RedirectNotificationObserver : public NotificationObserver { | 31 class RedirectNotificationObserver : public NotificationObserver { |
77 public: | 32 public: |
78 // Register to listen for notifications of the given type from either a | 33 // Register to listen for notifications of the given type from either a |
79 // specific source, or from all sources if |source| is | 34 // specific source, or from all sources if |source| is |
80 // NotificationService::AllSources(). | 35 // NotificationService::AllSources(). |
81 RedirectNotificationObserver(int notification_type, | 36 RedirectNotificationObserver(int notification_type, |
82 const NotificationSource& source); | 37 const NotificationSource& source); |
83 ~RedirectNotificationObserver() override; | 38 ~RedirectNotificationObserver() override; |
84 | 39 |
85 // Wait until the specified notification occurs. If the notification was | 40 // Wait until the specified notification occurs. If the notification was |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // correct documents are committed. | 156 // correct documents are committed. |
202 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { | 157 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
203 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 158 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
204 NavigateToURL(shell(), main_url); | 159 NavigateToURL(shell(), main_url); |
205 | 160 |
206 // It is safe to obtain the root frame tree node here, as it doesn't change. | 161 // It is safe to obtain the root frame tree node here, as it doesn't change. |
207 FrameTreeNode* root = | 162 FrameTreeNode* root = |
208 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 163 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
209 GetFrameTree()->root(); | 164 GetFrameTree()->root(); |
210 | 165 |
211 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 166 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
212 | 167 |
213 // Load same-site page into iframe. | 168 // Load same-site page into iframe. |
214 FrameTreeNode* child = root->child_at(0); | 169 FrameTreeNode* child = root->child_at(0); |
215 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 170 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
216 NavigateFrameToURL(child, http_url); | 171 NavigateFrameToURL(child, http_url); |
217 EXPECT_EQ(http_url, observer.navigation_url()); | 172 EXPECT_EQ(http_url, observer.navigation_url()); |
218 EXPECT_TRUE(observer.navigation_succeeded()); | 173 EXPECT_TRUE(observer.navigation_succeeded()); |
219 { | 174 { |
220 // There should be only one RenderWidgetHost when there are no | 175 // There should be only one RenderWidgetHost when there are no |
221 // cross-process iframes. | 176 // cross-process iframes. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 249 |
295 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { | 250 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { |
296 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 251 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
297 NavigateToURL(shell(), main_url); | 252 NavigateToURL(shell(), main_url); |
298 | 253 |
299 // It is safe to obtain the root frame tree node here, as it doesn't change. | 254 // It is safe to obtain the root frame tree node here, as it doesn't change. |
300 FrameTreeNode* root = | 255 FrameTreeNode* root = |
301 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 256 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
302 GetFrameTree()->root(); | 257 GetFrameTree()->root(); |
303 | 258 |
304 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 259 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
305 | 260 |
306 // Load same-site page into iframe. | 261 // Load same-site page into iframe. |
307 FrameTreeNode* child = root->child_at(0); | 262 FrameTreeNode* child = root->child_at(0); |
308 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 263 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
309 NavigateFrameToURL(child, http_url); | 264 NavigateFrameToURL(child, http_url); |
310 EXPECT_EQ(http_url, observer.navigation_url()); | 265 EXPECT_EQ(http_url, observer.navigation_url()); |
311 EXPECT_TRUE(observer.navigation_succeeded()); | 266 EXPECT_TRUE(observer.navigation_succeeded()); |
312 | 267 |
313 // Load cross-site page into iframe. | 268 // Load cross-site page into iframe. |
314 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 269 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 net::SpawnedTestServer::kLocalhost, | 380 net::SpawnedTestServer::kLocalhost, |
426 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 381 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
427 ASSERT_TRUE(https_server.Start()); | 382 ASSERT_TRUE(https_server.Start()); |
428 | 383 |
429 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 384 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
430 GURL http_url(test_server()->GetURL("files/title1.html")); | 385 GURL http_url(test_server()->GetURL("files/title1.html")); |
431 GURL https_url(https_server.GetURL("files/title1.html")); | 386 GURL https_url(https_server.GetURL("files/title1.html")); |
432 | 387 |
433 NavigateToURL(shell(), main_url); | 388 NavigateToURL(shell(), main_url); |
434 | 389 |
435 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 390 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
436 { | 391 { |
437 // Load cross-site client-redirect page into Iframe. | 392 // Load cross-site client-redirect page into Iframe. |
438 // Should be blocked. | 393 // Should be blocked. |
439 GURL client_redirect_https_url(https_server.GetURL( | 394 GURL client_redirect_https_url(https_server.GetURL( |
440 "client-redirect?files/title1.html")); | 395 "client-redirect?files/title1.html")); |
441 EXPECT_TRUE(NavigateIframeToURL(shell(), | 396 EXPECT_TRUE(NavigateIframeToURL(shell(), |
442 client_redirect_https_url, "test")); | 397 client_redirect_https_url, "test")); |
443 // DidFailProvisionalLoad when navigating to client_redirect_https_url. | 398 // DidFailProvisionalLoad when navigating to client_redirect_https_url. |
444 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); | 399 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); |
445 EXPECT_FALSE(observer.navigation_succeeded()); | 400 EXPECT_FALSE(observer.navigation_succeeded()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 net::SpawnedTestServer::kLocalhost, | 506 net::SpawnedTestServer::kLocalhost, |
552 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 507 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
553 ASSERT_TRUE(https_server.Start()); | 508 ASSERT_TRUE(https_server.Start()); |
554 | 509 |
555 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 510 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
556 GURL http_url(test_server()->GetURL("files/title1.html")); | 511 GURL http_url(test_server()->GetURL("files/title1.html")); |
557 GURL https_url(https_server.GetURL("files/title1.html")); | 512 GURL https_url(https_server.GetURL("files/title1.html")); |
558 | 513 |
559 NavigateToURL(shell(), main_url); | 514 NavigateToURL(shell(), main_url); |
560 | 515 |
561 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 516 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
562 { | 517 { |
563 // Load client-redirect page pointing to a cross-site client-redirect page, | 518 // Load client-redirect page pointing to a cross-site client-redirect page, |
564 // which eventually redirects back to same-site page. | 519 // which eventually redirects back to same-site page. |
565 GURL client_redirect_https_url(https_server.GetURL( | 520 GURL client_redirect_https_url(https_server.GetURL( |
566 "client-redirect?" + http_url.spec())); | 521 "client-redirect?" + http_url.spec())); |
567 GURL client_redirect_http_url(test_server()->GetURL( | 522 GURL client_redirect_http_url(test_server()->GetURL( |
568 "client-redirect?" + client_redirect_https_url.spec())); | 523 "client-redirect?" + client_redirect_https_url.spec())); |
569 | 524 |
570 // We should wait until second client redirect get cancelled. | 525 // We should wait until second client redirect get cancelled. |
571 RedirectNotificationObserver load_observer2( | 526 RedirectNotificationObserver load_observer2( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // It is safe to obtain the root frame tree node here, as it doesn't change. | 595 // It is safe to obtain the root frame tree node here, as it doesn't change. |
641 FrameTreeNode* root = | 596 FrameTreeNode* root = |
642 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 597 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
643 GetFrameTree()->root(); | 598 GetFrameTree()->root(); |
644 | 599 |
645 EXPECT_TRUE(root->child_at(1) != NULL); | 600 EXPECT_TRUE(root->child_at(1) != NULL); |
646 EXPECT_EQ(2U, root->child_at(1)->child_count()); | 601 EXPECT_EQ(2U, root->child_at(1)->child_count()); |
647 | 602 |
648 { | 603 { |
649 // Load same-site page into iframe. | 604 // Load same-site page into iframe. |
650 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 605 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
651 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 606 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
652 NavigateFrameToURL(root->child_at(0), http_url); | 607 NavigateFrameToURL(root->child_at(0), http_url); |
653 EXPECT_EQ(http_url, observer.navigation_url()); | 608 EXPECT_EQ(http_url, observer.navigation_url()); |
654 EXPECT_TRUE(observer.navigation_succeeded()); | 609 EXPECT_TRUE(observer.navigation_succeeded()); |
655 RenderFrameProxyHost* proxy_to_parent = | 610 RenderFrameProxyHost* proxy_to_parent = |
656 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( | 611 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
657 shell()->web_contents()->GetSiteInstance()); | 612 shell()->web_contents()->GetSiteInstance()); |
658 EXPECT_FALSE(proxy_to_parent); | 613 EXPECT_FALSE(proxy_to_parent); |
659 } | 614 } |
660 | 615 |
661 // Create the cross-site URL to navigate to. | 616 // Create the cross-site URL to navigate to. |
662 GURL cross_site_url = | 617 GURL cross_site_url = |
663 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); | 618 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); |
664 | 619 |
665 // Load cross-site page into the second iframe without waiting for the | 620 // Load cross-site page into the second iframe without waiting for the |
666 // navigation to complete. Once LoadURLWithParams returns, we would expect | 621 // navigation to complete. Once LoadURLWithParams returns, we would expect |
667 // proxies to have been created in the frame tree, but children of the | 622 // proxies to have been created in the frame tree, but children of the |
668 // navigating frame to still be present. The reason is that we don't run the | 623 // navigating frame to still be present. The reason is that we don't run the |
669 // message loop, so no IPCs that alter the frame tree can be processed. | 624 // message loop, so no IPCs that alter the frame tree can be processed. |
670 FrameTreeNode* child = root->child_at(1); | 625 FrameTreeNode* child = root->child_at(1); |
671 SiteInstance* site = NULL; | 626 SiteInstance* site = NULL; |
672 { | 627 { |
673 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 628 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
674 TestFrameNavigationObserver navigation_observer(child); | 629 TestFrameNavigationObserver navigation_observer(child); |
675 NavigationController::LoadURLParams params(cross_site_url); | 630 NavigationController::LoadURLParams params(cross_site_url); |
676 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 631 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
677 params.frame_tree_node_id = child->frame_tree_node_id(); | 632 params.frame_tree_node_id = child->frame_tree_node_id(); |
678 child->navigator()->GetController()->LoadURLWithParams(params); | 633 child->navigator()->GetController()->LoadURLWithParams(params); |
679 EXPECT_TRUE(child->render_manager()->pending_frame_host()); | 634 EXPECT_TRUE(child->render_manager()->pending_frame_host()); |
680 | 635 |
681 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); | 636 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); |
682 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | 637 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); |
683 | 638 |
(...skipping 15 matching lines...) Expand all Loading... |
699 | 654 |
700 // Load another cross-site page into the same iframe. | 655 // Load another cross-site page into the same iframe. |
701 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); | 656 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); |
702 { | 657 { |
703 // Perform the same checks as the first cross-site navigation, since | 658 // Perform the same checks as the first cross-site navigation, since |
704 // there have been issues in subsequent cross-site navigations. Also ensure | 659 // there have been issues in subsequent cross-site navigations. Also ensure |
705 // that the SiteInstance has properly changed. | 660 // that the SiteInstance has properly changed. |
706 // TODO(nasko): Once we have proper cleanup of resources, add code to | 661 // TODO(nasko): Once we have proper cleanup of resources, add code to |
707 // verify that the intermediate SiteInstance/RenderFrameHost have been | 662 // verify that the intermediate SiteInstance/RenderFrameHost have been |
708 // properly cleaned up. | 663 // properly cleaned up. |
709 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 664 TestNavigationWebContentsObserver observer(shell()->web_contents()); |
710 TestFrameNavigationObserver navigation_observer(child); | 665 TestFrameNavigationObserver navigation_observer(child); |
711 NavigationController::LoadURLParams params(cross_site_url); | 666 NavigationController::LoadURLParams params(cross_site_url); |
712 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 667 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
713 params.frame_tree_node_id = child->frame_tree_node_id(); | 668 params.frame_tree_node_id = child->frame_tree_node_id(); |
714 child->navigator()->GetController()->LoadURLWithParams(params); | 669 child->navigator()->GetController()->LoadURLWithParams(params); |
715 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); | 670 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); |
716 | 671 |
717 SiteInstance* site2 = | 672 SiteInstance* site2 = |
718 child->render_manager()->pending_frame_host()->GetSiteInstance(); | 673 child->render_manager()->pending_frame_host()->GetSiteInstance(); |
719 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | 674 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); |
720 EXPECT_NE(site, site2); | 675 EXPECT_NE(site, site2); |
721 | 676 |
722 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); | 677 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); |
723 EXPECT_TRUE( | 678 EXPECT_TRUE( |
724 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); | 679 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); |
725 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); | 680 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); |
726 for (size_t i = 0; i < child->child_count(); ++i) { | 681 for (size_t i = 0; i < child->child_count(); ++i) { |
727 EXPECT_FALSE( | 682 EXPECT_FALSE( |
728 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); | 683 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); |
729 } | 684 } |
730 | 685 |
731 navigation_observer.Wait(); | 686 navigation_observer.Wait(); |
732 EXPECT_TRUE(observer.navigation_succeeded()); | 687 EXPECT_TRUE(observer.navigation_succeeded()); |
733 EXPECT_EQ(cross_site_url, observer.navigation_url()); | 688 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
734 EXPECT_EQ(0U, child->child_count()); | 689 EXPECT_EQ(0U, child->child_count()); |
735 } | 690 } |
736 } | 691 } |
737 | 692 |
738 } // namespace content | 693 } // namespace content |
OLD | NEW |