Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 536143002: Do not create proxy hosts in the subtree of navigating frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix CrossSiteIframe asserts. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 232
231 // Load cross-site page into iframe. 233 // Load cross-site page into iframe.
232 GURL cross_site_url(test_server()->GetURL("files/title2.html")); 234 GURL cross_site_url(test_server()->GetURL("files/title2.html"));
233 replace_host.SetHostStr(foo_com); 235 replace_host.SetHostStr(foo_com);
234 cross_site_url = cross_site_url.ReplaceComponents(replace_host); 236 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
235 NavigateFrameToURL(root->child_at(0), cross_site_url); 237 NavigateFrameToURL(root->child_at(0), cross_site_url);
236 EXPECT_EQ(cross_site_url, observer.navigation_url()); 238 EXPECT_EQ(cross_site_url, observer.navigation_url());
237 EXPECT_TRUE(observer.navigation_succeeded()); 239 EXPECT_TRUE(observer.navigation_succeeded());
238 240
239 // Ensure that we have created a new process for the subframe. 241 // Ensure that we have created a new process for the subframe.
240 ASSERT_EQ(1U, root->child_count()); 242 ASSERT_EQ(2U, root->child_count());
241 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); 243 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
242 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); 244 RenderViewHost* rvh = child->current_frame_host()->render_view_host();
243 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); 245 RenderProcessHost* rph = child->current_frame_host()->GetProcess();
244 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); 246 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh);
245 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); 247 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
246 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); 248 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph);
247 { 249 {
248 // There should be now two RenderWidgetHosts, one for each process 250 // There should be now two RenderWidgetHosts, one for each process
249 // rendering a frame. 251 // rendering a frame.
250 std::set<RenderWidgetHostView*> views_set = 252 std::set<RenderWidgetHostView*> views_set =
(...skipping 12 matching lines...) Expand all
263 cross_site_url = test_server()->GetURL("files/title3.html"); 265 cross_site_url = test_server()->GetURL("files/title3.html");
264 std::string bar_com("bar.com"); 266 std::string bar_com("bar.com");
265 replace_host.SetHostStr(bar_com); 267 replace_host.SetHostStr(bar_com);
266 cross_site_url = cross_site_url.ReplaceComponents(replace_host); 268 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
267 NavigateFrameToURL(root->child_at(0), cross_site_url); 269 NavigateFrameToURL(root->child_at(0), cross_site_url);
268 EXPECT_EQ(cross_site_url, observer.navigation_url()); 270 EXPECT_EQ(cross_site_url, observer.navigation_url());
269 EXPECT_TRUE(observer.navigation_succeeded()); 271 EXPECT_TRUE(observer.navigation_succeeded());
270 272
271 // Check again that a new process is created and is different from the 273 // Check again that a new process is created and is different from the
272 // top level one and the previous one. 274 // top level one and the previous one.
273 ASSERT_EQ(1U, root->child_count()); 275 ASSERT_EQ(2U, root->child_count());
274 child = root->child_at(0); 276 child = root->child_at(0);
275 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), 277 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(),
276 child->current_frame_host()->render_view_host()); 278 child->current_frame_host()->render_view_host());
277 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); 279 EXPECT_NE(rvh, child->current_frame_host()->render_view_host());
278 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 280 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
279 child->current_frame_host()->GetSiteInstance()); 281 child->current_frame_host()->GetSiteInstance());
280 EXPECT_NE(site_instance, 282 EXPECT_NE(site_instance,
281 child->current_frame_host()->GetSiteInstance()); 283 child->current_frame_host()->GetSiteInstance());
282 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), 284 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(),
283 child->current_frame_host()->GetProcess()); 285 child->current_frame_host()->GetProcess());
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // 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
567 } // namespace content 690 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.cc ('k') | content/test/data/site_per_process_main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698