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

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

Issue 789273006: Make ContentSettingsObserver security checks work with OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 6 years 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"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { 207 SitePerProcessBrowserTest::SitePerProcessBrowserTest() {
208 }; 208 };
209 209
210 void SitePerProcessBrowserTest::StartFrameAtDataURL() { 210 void SitePerProcessBrowserTest::StartFrameAtDataURL() {
211 std::string data_url_script = 211 std::string data_url_script =
212 "var iframes = document.getElementById('test');iframes.src=" 212 "var iframes = document.getElementById('test');iframes.src="
213 "'data:text/html,dataurl';"; 213 "'data:text/html,dataurl';";
214 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); 214 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script));
215 } 215 }
216 216
217 bool SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window,
218 const GURL& url,
219 std::string iframe_id) {
220 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe
221 // navigations generate extra DidStartLoading and DidStopLoading messages.
222 // Until we replace swappedout:// with frame proxies, we need to listen for
223 // something else. For now, we trigger NEW_SUBFRAME navigations and listen
224 // for commit.
225 std::string script = base::StringPrintf(
226 "setTimeout(\""
227 "var iframes = document.getElementById('%s');iframes.src='%s';"
228 "\",0)",
229 iframe_id.c_str(), url.spec().c_str());
230 WindowedNotificationObserver load_observer(
231 NOTIFICATION_NAV_ENTRY_COMMITTED,
232 Source<NavigationController>(
233 &window->web_contents()->GetController()));
234 bool result = ExecuteScript(window->web_contents(), script);
235 load_observer.Wait();
236 return result;
237 }
238
239 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { 217 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) {
240 command_line->AppendSwitch(switches::kSitePerProcess); 218 command_line->AppendSwitch(switches::kSitePerProcess);
241 }; 219 };
242 220
243 void SitePerProcessBrowserTest::SetUpOnMainThread() { 221 void SitePerProcessBrowserTest::SetUpOnMainThread() {
244 host_resolver()->AddRule("*", "127.0.0.1"); 222 host_resolver()->AddRule("*", "127.0.0.1");
245 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 223 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
246 SetupCrossSiteRedirector(embedded_test_server()); 224 SetupCrossSiteRedirector(embedded_test_server());
247 } 225 }
248 226
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 EXPECT_EQ(url, observer.navigation_url()); 344 EXPECT_EQ(url, observer.navigation_url());
367 345
368 // Ensure that we have created a new process for the subframe. 346 // Ensure that we have created a new process for the subframe.
369 ASSERT_EQ(2U, root->child_count()); 347 ASSERT_EQ(2U, root->child_count());
370 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); 348 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
371 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); 349 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
372 350
373 // Emulate the main frame changing the src of the iframe such that it 351 // Emulate the main frame changing the src of the iframe such that it
374 // navigates cross-site. 352 // navigates cross-site.
375 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); 353 url = embedded_test_server()->GetURL("bar.com", "/title3.html");
376 NavigateIframeToURL(shell(), url, "test"); 354 NavigateIframeToURL(shell()->web_contents(), "test", url);
377 EXPECT_TRUE(observer.navigation_succeeded()); 355 EXPECT_TRUE(observer.navigation_succeeded());
378 EXPECT_EQ(url, observer.navigation_url()); 356 EXPECT_EQ(url, observer.navigation_url());
379 357
380 // Check again that a new process is created and is different from the 358 // Check again that a new process is created and is different from the
381 // top level one and the previous one. 359 // top level one and the previous one.
382 ASSERT_EQ(2U, root->child_count()); 360 ASSERT_EQ(2U, root->child_count());
383 child = root->child_at(0); 361 child = root->child_at(0);
384 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 362 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
385 child->current_frame_host()->GetSiteInstance()); 363 child->current_frame_host()->GetSiteInstance());
386 EXPECT_NE(site_instance, 364 EXPECT_NE(site_instance,
(...skipping 15 matching lines...) Expand all
402 NavigateToURL(shell(), main_url); 380 NavigateToURL(shell(), main_url);
403 381
404 StartFrameAtDataURL(); 382 StartFrameAtDataURL();
405 383
406 // These must stay in scope with replace_host. 384 // These must stay in scope with replace_host.
407 GURL::Replacements replace_host; 385 GURL::Replacements replace_host;
408 std::string foo_com("foo.com"); 386 std::string foo_com("foo.com");
409 387
410 // Load cross-site page into iframe. 388 // Load cross-site page into iframe.
411 EXPECT_TRUE(NavigateIframeToURL( 389 EXPECT_TRUE(NavigateIframeToURL(
412 shell(), 390 shell()->web_contents(), "test",
413 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"), 391 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html")));
414 "test"));
415 392
416 // Check the subframe process. 393 // Check the subframe process.
417 FrameTreeNode* root = 394 FrameTreeNode* root =
418 static_cast<WebContentsImpl*>(shell()->web_contents())-> 395 static_cast<WebContentsImpl*>(shell()->web_contents())->
419 GetFrameTree()->root(); 396 GetFrameTree()->root();
420 ASSERT_EQ(2U, root->child_count()); 397 ASSERT_EQ(2U, root->child_count());
421 FrameTreeNode* child = root->child_at(0); 398 FrameTreeNode* child = root->child_at(0);
422 EXPECT_EQ(main_url, root->current_url()); 399 EXPECT_EQ(main_url, root->current_url());
423 EXPECT_EQ("foo.com", child->current_url().host()); 400 EXPECT_EQ("foo.com", child->current_url().host());
424 EXPECT_EQ("/title2.html", child->current_url().path()); 401 EXPECT_EQ("/title2.html", child->current_url().path());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 GURL https_url(https_server.GetURL("files/title1.html")); 455 GURL https_url(https_server.GetURL("files/title1.html"));
479 456
480 NavigateToURL(shell(), main_url); 457 NavigateToURL(shell(), main_url);
481 458
482 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 459 SitePerProcessWebContentsObserver observer(shell()->web_contents());
483 { 460 {
484 // Load cross-site client-redirect page into Iframe. 461 // Load cross-site client-redirect page into Iframe.
485 // Should be blocked. 462 // Should be blocked.
486 GURL client_redirect_https_url(https_server.GetURL( 463 GURL client_redirect_https_url(https_server.GetURL(
487 "client-redirect?files/title1.html")); 464 "client-redirect?files/title1.html"));
488 EXPECT_TRUE(NavigateIframeToURL(shell(), 465 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
489 client_redirect_https_url, "test")); 466 client_redirect_https_url));
490 // DidFailProvisionalLoad when navigating to client_redirect_https_url. 467 // DidFailProvisionalLoad when navigating to client_redirect_https_url.
491 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); 468 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url);
492 EXPECT_FALSE(observer.navigation_succeeded()); 469 EXPECT_FALSE(observer.navigation_succeeded());
493 } 470 }
494 471
495 { 472 {
496 // Load cross-site server-redirect page into Iframe, 473 // Load cross-site server-redirect page into Iframe,
497 // which redirects to same-site page. 474 // which redirects to same-site page.
498 GURL server_redirect_http_url(https_server.GetURL( 475 GURL server_redirect_http_url(https_server.GetURL(
499 "server-redirect?" + http_url.spec())); 476 "server-redirect?" + http_url.spec()));
500 EXPECT_TRUE(NavigateIframeToURL(shell(), 477 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
501 server_redirect_http_url, "test")); 478 server_redirect_http_url));
502 EXPECT_EQ(observer.navigation_url(), http_url); 479 EXPECT_EQ(observer.navigation_url(), http_url);
503 EXPECT_TRUE(observer.navigation_succeeded()); 480 EXPECT_TRUE(observer.navigation_succeeded());
504 } 481 }
505 482
506 { 483 {
507 // Load cross-site server-redirect page into Iframe, 484 // Load cross-site server-redirect page into Iframe,
508 // which redirects to cross-site page. 485 // which redirects to cross-site page.
509 GURL server_redirect_http_url(https_server.GetURL( 486 GURL server_redirect_http_url(https_server.GetURL(
510 "server-redirect?files/title1.html")); 487 "server-redirect?files/title1.html"));
511 EXPECT_TRUE(NavigateIframeToURL(shell(), 488 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
512 server_redirect_http_url, "test")); 489 server_redirect_http_url));
513 // DidFailProvisionalLoad when navigating to https_url. 490 // DidFailProvisionalLoad when navigating to https_url.
514 EXPECT_EQ(observer.navigation_url(), https_url); 491 EXPECT_EQ(observer.navigation_url(), https_url);
515 EXPECT_FALSE(observer.navigation_succeeded()); 492 EXPECT_FALSE(observer.navigation_succeeded());
516 } 493 }
517 494
518 { 495 {
519 // Load same-site server-redirect page into Iframe, 496 // Load same-site server-redirect page into Iframe,
520 // which redirects to cross-site page. 497 // which redirects to cross-site page.
521 GURL server_redirect_http_url(test_server()->GetURL( 498 GURL server_redirect_http_url(test_server()->GetURL(
522 "server-redirect?" + https_url.spec())); 499 "server-redirect?" + https_url.spec()));
523 EXPECT_TRUE(NavigateIframeToURL(shell(), 500 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
524 server_redirect_http_url, "test")); 501 server_redirect_http_url));
525 502
526 EXPECT_EQ(observer.navigation_url(), https_url); 503 EXPECT_EQ(observer.navigation_url(), https_url);
527 EXPECT_FALSE(observer.navigation_succeeded()); 504 EXPECT_FALSE(observer.navigation_succeeded());
528 } 505 }
529 506
530 { 507 {
531 // Load same-site client-redirect page into Iframe, 508 // Load same-site client-redirect page into Iframe,
532 // which redirects to cross-site page. 509 // which redirects to cross-site page.
533 GURL client_redirect_http_url(test_server()->GetURL( 510 GURL client_redirect_http_url(test_server()->GetURL(
534 "client-redirect?" + https_url.spec())); 511 "client-redirect?" + https_url.spec()));
535 512
536 RedirectNotificationObserver load_observer2( 513 RedirectNotificationObserver load_observer2(
537 NOTIFICATION_LOAD_STOP, 514 NOTIFICATION_LOAD_STOP,
538 Source<NavigationController>( 515 Source<NavigationController>(
539 &shell()->web_contents()->GetController())); 516 &shell()->web_contents()->GetController()));
540 517
541 EXPECT_TRUE(NavigateIframeToURL(shell(), 518 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
542 client_redirect_http_url, "test")); 519 client_redirect_http_url));
543 520
544 // Same-site Client-Redirect Page should be loaded successfully. 521 // Same-site Client-Redirect Page should be loaded successfully.
545 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 522 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
546 EXPECT_TRUE(observer.navigation_succeeded()); 523 EXPECT_TRUE(observer.navigation_succeeded());
547 524
548 // Redirecting to Cross-site Page should be blocked. 525 // Redirecting to Cross-site Page should be blocked.
549 load_observer2.Wait(); 526 load_observer2.Wait();
550 EXPECT_EQ(observer.navigation_url(), https_url); 527 EXPECT_EQ(observer.navigation_url(), https_url);
551 EXPECT_FALSE(observer.navigation_succeeded()); 528 EXPECT_FALSE(observer.navigation_succeeded());
552 } 529 }
553 530
554 { 531 {
555 // Load same-site server-redirect page into Iframe, 532 // Load same-site server-redirect page into Iframe,
556 // which redirects to same-site page. 533 // which redirects to same-site page.
557 GURL server_redirect_http_url(test_server()->GetURL( 534 GURL server_redirect_http_url(test_server()->GetURL(
558 "server-redirect?files/title1.html")); 535 "server-redirect?files/title1.html"));
559 EXPECT_TRUE(NavigateIframeToURL(shell(), 536 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
560 server_redirect_http_url, "test")); 537 server_redirect_http_url));
561 EXPECT_EQ(observer.navigation_url(), http_url); 538 EXPECT_EQ(observer.navigation_url(), http_url);
562 EXPECT_TRUE(observer.navigation_succeeded()); 539 EXPECT_TRUE(observer.navigation_succeeded());
563 } 540 }
564 541
565 { 542 {
566 // Load same-site client-redirect page into Iframe, 543 // Load same-site client-redirect page into Iframe,
567 // which redirects to same-site page. 544 // which redirects to same-site page.
568 GURL client_redirect_http_url(test_server()->GetURL( 545 GURL client_redirect_http_url(test_server()->GetURL(
569 "client-redirect?" + http_url.spec())); 546 "client-redirect?" + http_url.spec()));
570 RedirectNotificationObserver load_observer2( 547 RedirectNotificationObserver load_observer2(
571 NOTIFICATION_LOAD_STOP, 548 NOTIFICATION_LOAD_STOP,
572 Source<NavigationController>( 549 Source<NavigationController>(
573 &shell()->web_contents()->GetController())); 550 &shell()->web_contents()->GetController()));
574 551
575 EXPECT_TRUE(NavigateIframeToURL(shell(), 552 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
576 client_redirect_http_url, "test")); 553 client_redirect_http_url));
577 554
578 // Same-site Client-Redirect Page should be loaded successfully. 555 // Same-site Client-Redirect Page should be loaded successfully.
579 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 556 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
580 EXPECT_TRUE(observer.navigation_succeeded()); 557 EXPECT_TRUE(observer.navigation_succeeded());
581 558
582 // Redirecting to Same-site Page should be loaded successfully. 559 // Redirecting to Same-site Page should be loaded successfully.
583 load_observer2.Wait(); 560 load_observer2.Wait();
584 EXPECT_EQ(observer.navigation_url(), http_url); 561 EXPECT_EQ(observer.navigation_url(), http_url);
585 EXPECT_TRUE(observer.navigation_succeeded()); 562 EXPECT_TRUE(observer.navigation_succeeded());
586 } 563 }
(...skipping 26 matching lines...) Expand all
613 "client-redirect?" + http_url.spec())); 590 "client-redirect?" + http_url.spec()));
614 GURL client_redirect_http_url(test_server()->GetURL( 591 GURL client_redirect_http_url(test_server()->GetURL(
615 "client-redirect?" + client_redirect_https_url.spec())); 592 "client-redirect?" + client_redirect_https_url.spec()));
616 593
617 // We should wait until second client redirect get cancelled. 594 // We should wait until second client redirect get cancelled.
618 RedirectNotificationObserver load_observer2( 595 RedirectNotificationObserver load_observer2(
619 NOTIFICATION_LOAD_STOP, 596 NOTIFICATION_LOAD_STOP,
620 Source<NavigationController>( 597 Source<NavigationController>(
621 &shell()->web_contents()->GetController())); 598 &shell()->web_contents()->GetController()));
622 599
623 EXPECT_TRUE(NavigateIframeToURL(shell(), client_redirect_http_url, "test")); 600 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
601 client_redirect_http_url));
624 602
625 // DidFailProvisionalLoad when navigating to client_redirect_https_url. 603 // DidFailProvisionalLoad when navigating to client_redirect_https_url.
626 load_observer2.Wait(); 604 load_observer2.Wait();
627 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); 605 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url);
628 EXPECT_FALSE(observer.navigation_succeeded()); 606 EXPECT_FALSE(observer.navigation_succeeded());
629 } 607 }
630 608
631 { 609 {
632 // Load server-redirect page pointing to a cross-site server-redirect page, 610 // Load server-redirect page pointing to a cross-site server-redirect page,
633 // which eventually redirect back to same-site page. 611 // which eventually redirect back to same-site page.
634 GURL server_redirect_https_url(https_server.GetURL( 612 GURL server_redirect_https_url(https_server.GetURL(
635 "server-redirect?" + http_url.spec())); 613 "server-redirect?" + http_url.spec()));
636 GURL server_redirect_http_url(test_server()->GetURL( 614 GURL server_redirect_http_url(test_server()->GetURL(
637 "server-redirect?" + server_redirect_https_url.spec())); 615 "server-redirect?" + server_redirect_https_url.spec()));
638 EXPECT_TRUE(NavigateIframeToURL(shell(), 616 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
639 server_redirect_http_url, "test")); 617 server_redirect_http_url));
640 EXPECT_EQ(observer.navigation_url(), http_url); 618 EXPECT_EQ(observer.navigation_url(), http_url);
641 EXPECT_TRUE(observer.navigation_succeeded()); 619 EXPECT_TRUE(observer.navigation_succeeded());
642 } 620 }
643 621
644 { 622 {
645 // Load server-redirect page pointing to a cross-site server-redirect page, 623 // Load server-redirect page pointing to a cross-site server-redirect page,
646 // which eventually redirects back to cross-site page. 624 // which eventually redirects back to cross-site page.
647 GURL server_redirect_https_url(https_server.GetURL( 625 GURL server_redirect_https_url(https_server.GetURL(
648 "server-redirect?" + https_url.spec())); 626 "server-redirect?" + https_url.spec()));
649 GURL server_redirect_http_url(test_server()->GetURL( 627 GURL server_redirect_http_url(test_server()->GetURL(
650 "server-redirect?" + server_redirect_https_url.spec())); 628 "server-redirect?" + server_redirect_https_url.spec()));
651 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); 629 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
630 server_redirect_http_url));
652 631
653 // DidFailProvisionalLoad when navigating to https_url. 632 // DidFailProvisionalLoad when navigating to https_url.
654 EXPECT_EQ(observer.navigation_url(), https_url); 633 EXPECT_EQ(observer.navigation_url(), https_url);
655 EXPECT_FALSE(observer.navigation_succeeded()); 634 EXPECT_FALSE(observer.navigation_succeeded());
656 } 635 }
657 636
658 { 637 {
659 // Load server-redirect page pointing to a cross-site client-redirect page, 638 // Load server-redirect page pointing to a cross-site client-redirect page,
660 // which eventually redirects back to same-site page. 639 // which eventually redirects back to same-site page.
661 GURL client_redirect_http_url(https_server.GetURL( 640 GURL client_redirect_http_url(https_server.GetURL(
662 "client-redirect?" + http_url.spec())); 641 "client-redirect?" + http_url.spec()));
663 GURL server_redirect_http_url(test_server()->GetURL( 642 GURL server_redirect_http_url(test_server()->GetURL(
664 "server-redirect?" + client_redirect_http_url.spec())); 643 "server-redirect?" + client_redirect_http_url.spec()));
665 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); 644 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test",
645 server_redirect_http_url));
666 646
667 // DidFailProvisionalLoad when navigating to client_redirect_http_url. 647 // DidFailProvisionalLoad when navigating to client_redirect_http_url.
668 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 648 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
669 EXPECT_FALSE(observer.navigation_succeeded()); 649 EXPECT_FALSE(observer.navigation_succeeded());
670 } 650 }
671 } 651 }
672 652
673 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are 653 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are
674 // created in the FrameTree skipping the subtree of the navigating frame. 654 // created in the FrameTree skipping the subtree of the navigating frame.
675 // 655 //
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 &result)); 842 &result));
863 EXPECT_EQ(result + "/", foo_url.GetOrigin().spec()); 843 EXPECT_EQ(result + "/", foo_url.GetOrigin().spec());
864 EXPECT_TRUE(ExecuteScriptAndExtractString( 844 EXPECT_TRUE(ExecuteScriptAndExtractString(
865 bottom_child->current_frame_host(), 845 bottom_child->current_frame_host(),
866 "window.domAutomationController.send(location.ancestorOrigins[1]);", 846 "window.domAutomationController.send(location.ancestorOrigins[1]);",
867 &result)); 847 &result));
868 EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); 848 EXPECT_EQ(result + "/", main_url.GetOrigin().spec());
869 } 849 }
870 850
871 } // namespace content 851 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698