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

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

Issue 688363002: Convert tests to use GetURL(host, path) instead of redirector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 static_cast<WebContentsImpl*>(shell()->web_contents()) 223 static_cast<WebContentsImpl*>(shell()->web_contents())
224 ->GetRenderWidgetHostViewsInTree(); 224 ->GetRenderWidgetHostViewsInTree();
225 EXPECT_EQ(1U, views_set.size()); 225 EXPECT_EQ(1U, views_set.size());
226 } 226 }
227 RenderFrameProxyHost* proxy_to_parent = 227 RenderFrameProxyHost* proxy_to_parent =
228 child->render_manager()->GetRenderFrameProxyHost( 228 child->render_manager()->GetRenderFrameProxyHost(
229 shell()->web_contents()->GetSiteInstance()); 229 shell()->web_contents()->GetSiteInstance());
230 EXPECT_FALSE(proxy_to_parent); 230 EXPECT_FALSE(proxy_to_parent);
231 231
232 // Load cross-site page into iframe. 232 // Load cross-site page into iframe.
233 NavigateFrameToURL( 233 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html");
234 root->child_at(0), 234 NavigateFrameToURL(root->child_at(0), url);
235 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"));
236 // Verify that the navigation succeeded and the expected URL was loaded. 235 // Verify that the navigation succeeded and the expected URL was loaded.
237 EXPECT_TRUE(observer.navigation_succeeded()); 236 EXPECT_TRUE(observer.navigation_succeeded());
238 EXPECT_EQ(embedded_test_server()->base_url().scheme(), 237 EXPECT_EQ(url, observer.navigation_url());
239 observer.navigation_url().scheme());
240 EXPECT_EQ("foo.com", observer.navigation_url().host());
241 EXPECT_EQ("/title2.html", observer.navigation_url().path());
242 238
243 // Ensure that we have created a new process for the subframe. 239 // Ensure that we have created a new process for the subframe.
244 ASSERT_EQ(2U, root->child_count()); 240 ASSERT_EQ(2U, root->child_count());
245 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); 241 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
246 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); 242 RenderViewHost* rvh = child->current_frame_host()->render_view_host();
247 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); 243 RenderProcessHost* rph = child->current_frame_host()->GetProcess();
248 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); 244 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh);
249 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); 245 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
250 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); 246 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph);
251 { 247 {
252 // There should be now two RenderWidgetHosts, one for each process 248 // There should be now two RenderWidgetHosts, one for each process
253 // rendering a frame. 249 // rendering a frame.
254 std::set<RenderWidgetHostView*> views_set = 250 std::set<RenderWidgetHostView*> views_set =
255 static_cast<WebContentsImpl*>(shell()->web_contents()) 251 static_cast<WebContentsImpl*>(shell()->web_contents())
256 ->GetRenderWidgetHostViewsInTree(); 252 ->GetRenderWidgetHostViewsInTree();
257 EXPECT_EQ(2U, views_set.size()); 253 EXPECT_EQ(2U, views_set.size());
258 } 254 }
259 proxy_to_parent = child->render_manager()->GetProxyToParent(); 255 proxy_to_parent = child->render_manager()->GetProxyToParent();
260 EXPECT_TRUE(proxy_to_parent); 256 EXPECT_TRUE(proxy_to_parent);
261 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector()); 257 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector());
262 EXPECT_EQ( 258 EXPECT_EQ(
263 rvh->GetView(), 259 rvh->GetView(),
264 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); 260 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing());
265 261
266 // Load another cross-site page into the same iframe. 262 // Load another cross-site page into the same iframe.
267 NavigateFrameToURL( 263 url = embedded_test_server()->GetURL("bar.com", "/title3.html");
268 root->child_at(0), 264 NavigateFrameToURL(root->child_at(0), url);
269 embedded_test_server()->GetURL("/cross-site/bar.com/title3.html"));
270 EXPECT_TRUE(observer.navigation_succeeded()); 265 EXPECT_TRUE(observer.navigation_succeeded());
271 EXPECT_EQ(embedded_test_server()->base_url().scheme(), 266 EXPECT_EQ(url, observer.navigation_url());
272 observer.navigation_url().scheme());
273 EXPECT_EQ("bar.com", observer.navigation_url().host());
274 EXPECT_EQ("/title3.html", observer.navigation_url().path());
275 267
276 // Check again that a new process is created and is different from the 268 // Check again that a new process is created and is different from the
277 // top level one and the previous one. 269 // top level one and the previous one.
278 ASSERT_EQ(2U, root->child_count()); 270 ASSERT_EQ(2U, root->child_count());
279 child = root->child_at(0); 271 child = root->child_at(0);
280 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), 272 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(),
281 child->current_frame_host()->render_view_host()); 273 child->current_frame_host()->render_view_host());
282 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); 274 EXPECT_NE(rvh, child->current_frame_host()->render_view_host());
283 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 275 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
284 child->current_frame_host()->GetSiteInstance()); 276 child->current_frame_host()->GetSiteInstance());
(...skipping 27 matching lines...) Expand all
312 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 304 SitePerProcessWebContentsObserver observer(shell()->web_contents());
313 305
314 // Load same-site page into iframe. 306 // Load same-site page into iframe.
315 FrameTreeNode* child = root->child_at(0); 307 FrameTreeNode* child = root->child_at(0);
316 GURL http_url(embedded_test_server()->GetURL("/title1.html")); 308 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
317 NavigateFrameToURL(child, http_url); 309 NavigateFrameToURL(child, http_url);
318 EXPECT_EQ(http_url, observer.navigation_url()); 310 EXPECT_EQ(http_url, observer.navigation_url());
319 EXPECT_TRUE(observer.navigation_succeeded()); 311 EXPECT_TRUE(observer.navigation_succeeded());
320 312
321 // Load cross-site page into iframe. 313 // Load cross-site page into iframe.
322 NavigateFrameToURL( 314 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html");
323 root->child_at(0), 315 NavigateFrameToURL(root->child_at(0), url);
324 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"));
325 EXPECT_TRUE(observer.navigation_succeeded()); 316 EXPECT_TRUE(observer.navigation_succeeded());
326 EXPECT_EQ("foo.com", observer.navigation_url().host()); 317 EXPECT_EQ(url, observer.navigation_url());
327 EXPECT_EQ("/title2.html", observer.navigation_url().path());
328 318
329 // Ensure that we have created a new process for the subframe. 319 // Ensure that we have created a new process for the subframe.
330 ASSERT_EQ(2U, root->child_count()); 320 ASSERT_EQ(2U, root->child_count());
331 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); 321 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
332 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); 322 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
333 323
334 // Emulate the main frame changing the src of the iframe such that it 324 // Emulate the main frame changing the src of the iframe such that it
335 // navigates cross-site. 325 // navigates cross-site.
336 NavigateIframeToURL( 326 url = embedded_test_server()->GetURL("bar.com", "/title3.html");
337 shell(), 327 NavigateIframeToURL(shell(), url, "test");
338 embedded_test_server()->GetURL("/cross-site/bar.com/title3.html"),
339 "test");
340 EXPECT_TRUE(observer.navigation_succeeded()); 328 EXPECT_TRUE(observer.navigation_succeeded());
341 EXPECT_EQ("bar.com", observer.navigation_url().host()); 329 EXPECT_EQ(url, observer.navigation_url());
342 EXPECT_EQ("/title3.html", observer.navigation_url().path());
343 330
344 // Check again that a new process is created and is different from the 331 // Check again that a new process is created and is different from the
345 // top level one and the previous one. 332 // top level one and the previous one.
346 ASSERT_EQ(2U, root->child_count()); 333 ASSERT_EQ(2U, root->child_count());
347 child = root->child_at(0); 334 child = root->child_at(0);
348 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 335 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
349 child->current_frame_host()->GetSiteInstance()); 336 child->current_frame_host()->GetSiteInstance());
350 EXPECT_NE(site_instance, 337 EXPECT_NE(site_instance,
351 child->current_frame_host()->GetSiteInstance()); 338 child->current_frame_host()->GetSiteInstance());
352 339
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 NavigateFrameToURL(root->child_at(0), http_url); 652 NavigateFrameToURL(root->child_at(0), http_url);
666 EXPECT_EQ(http_url, observer.navigation_url()); 653 EXPECT_EQ(http_url, observer.navigation_url());
667 EXPECT_TRUE(observer.navigation_succeeded()); 654 EXPECT_TRUE(observer.navigation_succeeded());
668 RenderFrameProxyHost* proxy_to_parent = 655 RenderFrameProxyHost* proxy_to_parent =
669 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( 656 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(
670 shell()->web_contents()->GetSiteInstance()); 657 shell()->web_contents()->GetSiteInstance());
671 EXPECT_FALSE(proxy_to_parent); 658 EXPECT_FALSE(proxy_to_parent);
672 } 659 }
673 660
674 // Create the cross-site URL to navigate to. 661 // Create the cross-site URL to navigate to.
675 GURL::Replacements replace_host; 662 GURL cross_site_url =
676 std::string foo_com("foo.com"); 663 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html");
677 GURL cross_site_url(embedded_test_server()->GetURL("/frame_tree/1-1.html"));
678 replace_host.SetHostStr(foo_com);
679 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
680 664
681 // Load cross-site page into the second iframe without waiting for the 665 // Load cross-site page into the second iframe without waiting for the
682 // navigation to complete. Once LoadURLWithParams returns, we would expect 666 // navigation to complete. Once LoadURLWithParams returns, we would expect
683 // proxies to have been created in the frame tree, but children of the 667 // proxies to have been created in the frame tree, but children of the
684 // navigating frame to still be present. The reason is that we don't run the 668 // navigating frame to still be present. The reason is that we don't run the
685 // message loop, so no IPCs that alter the frame tree can be processed. 669 // message loop, so no IPCs that alter the frame tree can be processed.
686 FrameTreeNode* child = root->child_at(1); 670 FrameTreeNode* child = root->child_at(1);
687 SiteInstance* site = NULL; 671 SiteInstance* site = NULL;
688 { 672 {
689 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 673 SitePerProcessWebContentsObserver observer(shell()->web_contents());
(...skipping 12 matching lines...) Expand all
702 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); 686 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site));
703 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); 687 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site));
704 for (size_t i = 0; i < child->child_count(); ++i) { 688 for (size_t i = 0; i < child->child_count(); ++i) {
705 EXPECT_FALSE( 689 EXPECT_FALSE(
706 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); 690 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site));
707 } 691 }
708 // Now that the verification is done, run the message loop and wait for the 692 // Now that the verification is done, run the message loop and wait for the
709 // navigation to complete. 693 // navigation to complete.
710 navigation_observer.Wait(); 694 navigation_observer.Wait();
711 EXPECT_FALSE(child->render_manager()->pending_frame_host()); 695 EXPECT_FALSE(child->render_manager()->pending_frame_host());
696 EXPECT_TRUE(observer.navigation_succeeded());
712 EXPECT_EQ(cross_site_url, observer.navigation_url()); 697 EXPECT_EQ(cross_site_url, observer.navigation_url());
713 EXPECT_TRUE(observer.navigation_succeeded());
714 } 698 }
715 699
716 // Load another cross-site page into the same iframe. 700 // Load another cross-site page into the same iframe.
717 cross_site_url = embedded_test_server()->GetURL("/title2.html"); 701 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html");
718 std::string bar_com("bar.com");
719 replace_host.SetHostStr(bar_com);
720 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
721
722 { 702 {
723 // Perform the same checks as the first cross-site navigation, since 703 // Perform the same checks as the first cross-site navigation, since
724 // there have been issues in subsequent cross-site navigations. Also ensure 704 // there have been issues in subsequent cross-site navigations. Also ensure
725 // that the SiteInstance has properly changed. 705 // that the SiteInstance has properly changed.
726 // TODO(nasko): Once we have proper cleanup of resources, add code to 706 // TODO(nasko): Once we have proper cleanup of resources, add code to
727 // verify that the intermediate SiteInstance/RenderFrameHost have been 707 // verify that the intermediate SiteInstance/RenderFrameHost have been
728 // properly cleaned up. 708 // properly cleaned up.
729 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 709 SitePerProcessWebContentsObserver observer(shell()->web_contents());
730 TestFrameNavigationObserver navigation_observer(child); 710 TestFrameNavigationObserver navigation_observer(child);
731 NavigationController::LoadURLParams params(cross_site_url); 711 NavigationController::LoadURLParams params(cross_site_url);
(...skipping 10 matching lines...) Expand all
742 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); 722 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2));
743 EXPECT_TRUE( 723 EXPECT_TRUE(
744 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); 724 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2));
745 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); 725 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2));
746 for (size_t i = 0; i < child->child_count(); ++i) { 726 for (size_t i = 0; i < child->child_count(); ++i) {
747 EXPECT_FALSE( 727 EXPECT_FALSE(
748 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); 728 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2));
749 } 729 }
750 730
751 navigation_observer.Wait(); 731 navigation_observer.Wait();
732 EXPECT_TRUE(observer.navigation_succeeded());
752 EXPECT_EQ(cross_site_url, observer.navigation_url()); 733 EXPECT_EQ(cross_site_url, observer.navigation_url());
753 EXPECT_TRUE(observer.navigation_succeeded());
754 EXPECT_EQ(0U, child->child_count()); 734 EXPECT_EQ(0U, child->child_count());
755 } 735 }
756 } 736 }
757 737
758 } // namespace content 738 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698