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

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: 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(), url, "test");
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(),
413 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"), 391 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"),
414 "test")); 392 "test"));
415 393
416 // Check the subframe process. 394 // Check the subframe process.
417 FrameTreeNode* root = 395 FrameTreeNode* root =
418 static_cast<WebContentsImpl*>(shell()->web_contents())-> 396 static_cast<WebContentsImpl*>(shell()->web_contents())->
419 GetFrameTree()->root(); 397 GetFrameTree()->root();
420 ASSERT_EQ(2U, root->child_count()); 398 ASSERT_EQ(2U, root->child_count());
421 FrameTreeNode* child = root->child_at(0); 399 FrameTreeNode* child = root->child_at(0);
422 EXPECT_EQ(main_url, root->current_url()); 400 EXPECT_EQ(main_url, root->current_url());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 GURL https_url(https_server.GetURL("files/title1.html")); 456 GURL https_url(https_server.GetURL("files/title1.html"));
479 457
480 NavigateToURL(shell(), main_url); 458 NavigateToURL(shell(), main_url);
481 459
482 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 460 SitePerProcessWebContentsObserver observer(shell()->web_contents());
483 { 461 {
484 // Load cross-site client-redirect page into Iframe. 462 // Load cross-site client-redirect page into Iframe.
485 // Should be blocked. 463 // Should be blocked.
486 GURL client_redirect_https_url(https_server.GetURL( 464 GURL client_redirect_https_url(https_server.GetURL(
487 "client-redirect?files/title1.html")); 465 "client-redirect?files/title1.html"));
488 EXPECT_TRUE(NavigateIframeToURL(shell(), 466 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
489 client_redirect_https_url, "test")); 467 client_redirect_https_url, "test"));
490 // DidFailProvisionalLoad when navigating to client_redirect_https_url. 468 // DidFailProvisionalLoad when navigating to client_redirect_https_url.
491 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); 469 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url);
492 EXPECT_FALSE(observer.navigation_succeeded()); 470 EXPECT_FALSE(observer.navigation_succeeded());
493 } 471 }
494 472
495 { 473 {
496 // Load cross-site server-redirect page into Iframe, 474 // Load cross-site server-redirect page into Iframe,
497 // which redirects to same-site page. 475 // which redirects to same-site page.
498 GURL server_redirect_http_url(https_server.GetURL( 476 GURL server_redirect_http_url(https_server.GetURL(
499 "server-redirect?" + http_url.spec())); 477 "server-redirect?" + http_url.spec()));
500 EXPECT_TRUE(NavigateIframeToURL(shell(), 478 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
501 server_redirect_http_url, "test")); 479 server_redirect_http_url, "test"));
502 EXPECT_EQ(observer.navigation_url(), http_url); 480 EXPECT_EQ(observer.navigation_url(), http_url);
503 EXPECT_TRUE(observer.navigation_succeeded()); 481 EXPECT_TRUE(observer.navigation_succeeded());
504 } 482 }
505 483
506 { 484 {
507 // Load cross-site server-redirect page into Iframe, 485 // Load cross-site server-redirect page into Iframe,
508 // which redirects to cross-site page. 486 // which redirects to cross-site page.
509 GURL server_redirect_http_url(https_server.GetURL( 487 GURL server_redirect_http_url(https_server.GetURL(
510 "server-redirect?files/title1.html")); 488 "server-redirect?files/title1.html"));
511 EXPECT_TRUE(NavigateIframeToURL(shell(), 489 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
512 server_redirect_http_url, "test")); 490 server_redirect_http_url, "test"));
513 // DidFailProvisionalLoad when navigating to https_url. 491 // DidFailProvisionalLoad when navigating to https_url.
514 EXPECT_EQ(observer.navigation_url(), https_url); 492 EXPECT_EQ(observer.navigation_url(), https_url);
515 EXPECT_FALSE(observer.navigation_succeeded()); 493 EXPECT_FALSE(observer.navigation_succeeded());
516 } 494 }
517 495
518 { 496 {
519 // Load same-site server-redirect page into Iframe, 497 // Load same-site server-redirect page into Iframe,
520 // which redirects to cross-site page. 498 // which redirects to cross-site page.
521 GURL server_redirect_http_url(test_server()->GetURL( 499 GURL server_redirect_http_url(test_server()->GetURL(
522 "server-redirect?" + https_url.spec())); 500 "server-redirect?" + https_url.spec()));
523 EXPECT_TRUE(NavigateIframeToURL(shell(), 501 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
524 server_redirect_http_url, "test")); 502 server_redirect_http_url, "test"));
525 503
526 EXPECT_EQ(observer.navigation_url(), https_url); 504 EXPECT_EQ(observer.navigation_url(), https_url);
527 EXPECT_FALSE(observer.navigation_succeeded()); 505 EXPECT_FALSE(observer.navigation_succeeded());
528 } 506 }
529 507
530 { 508 {
531 // Load same-site client-redirect page into Iframe, 509 // Load same-site client-redirect page into Iframe,
532 // which redirects to cross-site page. 510 // which redirects to cross-site page.
533 GURL client_redirect_http_url(test_server()->GetURL( 511 GURL client_redirect_http_url(test_server()->GetURL(
534 "client-redirect?" + https_url.spec())); 512 "client-redirect?" + https_url.spec()));
535 513
536 RedirectNotificationObserver load_observer2( 514 RedirectNotificationObserver load_observer2(
537 NOTIFICATION_LOAD_STOP, 515 NOTIFICATION_LOAD_STOP,
538 Source<NavigationController>( 516 Source<NavigationController>(
539 &shell()->web_contents()->GetController())); 517 &shell()->web_contents()->GetController()));
540 518
541 EXPECT_TRUE(NavigateIframeToURL(shell(), 519 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
542 client_redirect_http_url, "test")); 520 client_redirect_http_url, "test"));
543 521
544 // Same-site Client-Redirect Page should be loaded successfully. 522 // Same-site Client-Redirect Page should be loaded successfully.
545 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 523 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
546 EXPECT_TRUE(observer.navigation_succeeded()); 524 EXPECT_TRUE(observer.navigation_succeeded());
547 525
548 // Redirecting to Cross-site Page should be blocked. 526 // Redirecting to Cross-site Page should be blocked.
549 load_observer2.Wait(); 527 load_observer2.Wait();
550 EXPECT_EQ(observer.navigation_url(), https_url); 528 EXPECT_EQ(observer.navigation_url(), https_url);
551 EXPECT_FALSE(observer.navigation_succeeded()); 529 EXPECT_FALSE(observer.navigation_succeeded());
552 } 530 }
553 531
554 { 532 {
555 // Load same-site server-redirect page into Iframe, 533 // Load same-site server-redirect page into Iframe,
556 // which redirects to same-site page. 534 // which redirects to same-site page.
557 GURL server_redirect_http_url(test_server()->GetURL( 535 GURL server_redirect_http_url(test_server()->GetURL(
558 "server-redirect?files/title1.html")); 536 "server-redirect?files/title1.html"));
559 EXPECT_TRUE(NavigateIframeToURL(shell(), 537 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
560 server_redirect_http_url, "test")); 538 server_redirect_http_url, "test"));
561 EXPECT_EQ(observer.navigation_url(), http_url); 539 EXPECT_EQ(observer.navigation_url(), http_url);
562 EXPECT_TRUE(observer.navigation_succeeded()); 540 EXPECT_TRUE(observer.navigation_succeeded());
563 } 541 }
564 542
565 { 543 {
566 // Load same-site client-redirect page into Iframe, 544 // Load same-site client-redirect page into Iframe,
567 // which redirects to same-site page. 545 // which redirects to same-site page.
568 GURL client_redirect_http_url(test_server()->GetURL( 546 GURL client_redirect_http_url(test_server()->GetURL(
569 "client-redirect?" + http_url.spec())); 547 "client-redirect?" + http_url.spec()));
570 RedirectNotificationObserver load_observer2( 548 RedirectNotificationObserver load_observer2(
571 NOTIFICATION_LOAD_STOP, 549 NOTIFICATION_LOAD_STOP,
572 Source<NavigationController>( 550 Source<NavigationController>(
573 &shell()->web_contents()->GetController())); 551 &shell()->web_contents()->GetController()));
574 552
575 EXPECT_TRUE(NavigateIframeToURL(shell(), 553 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
576 client_redirect_http_url, "test")); 554 client_redirect_http_url, "test"));
577 555
578 // Same-site Client-Redirect Page should be loaded successfully. 556 // Same-site Client-Redirect Page should be loaded successfully.
579 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 557 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
580 EXPECT_TRUE(observer.navigation_succeeded()); 558 EXPECT_TRUE(observer.navigation_succeeded());
581 559
582 // Redirecting to Same-site Page should be loaded successfully. 560 // Redirecting to Same-site Page should be loaded successfully.
583 load_observer2.Wait(); 561 load_observer2.Wait();
584 EXPECT_EQ(observer.navigation_url(), http_url); 562 EXPECT_EQ(observer.navigation_url(), http_url);
585 EXPECT_TRUE(observer.navigation_succeeded()); 563 EXPECT_TRUE(observer.navigation_succeeded());
(...skipping 27 matching lines...) Expand all
613 "client-redirect?" + http_url.spec())); 591 "client-redirect?" + http_url.spec()));
614 GURL client_redirect_http_url(test_server()->GetURL( 592 GURL client_redirect_http_url(test_server()->GetURL(
615 "client-redirect?" + client_redirect_https_url.spec())); 593 "client-redirect?" + client_redirect_https_url.spec()));
616 594
617 // We should wait until second client redirect get cancelled. 595 // We should wait until second client redirect get cancelled.
618 RedirectNotificationObserver load_observer2( 596 RedirectNotificationObserver load_observer2(
619 NOTIFICATION_LOAD_STOP, 597 NOTIFICATION_LOAD_STOP,
620 Source<NavigationController>( 598 Source<NavigationController>(
621 &shell()->web_contents()->GetController())); 599 &shell()->web_contents()->GetController()));
622 600
623 EXPECT_TRUE(NavigateIframeToURL(shell(), client_redirect_http_url, "test")); 601 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
602 client_redirect_http_url, "test"));
624 603
625 // DidFailProvisionalLoad when navigating to client_redirect_https_url. 604 // DidFailProvisionalLoad when navigating to client_redirect_https_url.
626 load_observer2.Wait(); 605 load_observer2.Wait();
627 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); 606 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url);
628 EXPECT_FALSE(observer.navigation_succeeded()); 607 EXPECT_FALSE(observer.navigation_succeeded());
629 } 608 }
630 609
631 { 610 {
632 // Load server-redirect page pointing to a cross-site server-redirect page, 611 // Load server-redirect page pointing to a cross-site server-redirect page,
633 // which eventually redirect back to same-site page. 612 // which eventually redirect back to same-site page.
634 GURL server_redirect_https_url(https_server.GetURL( 613 GURL server_redirect_https_url(https_server.GetURL(
635 "server-redirect?" + http_url.spec())); 614 "server-redirect?" + http_url.spec()));
636 GURL server_redirect_http_url(test_server()->GetURL( 615 GURL server_redirect_http_url(test_server()->GetURL(
637 "server-redirect?" + server_redirect_https_url.spec())); 616 "server-redirect?" + server_redirect_https_url.spec()));
638 EXPECT_TRUE(NavigateIframeToURL(shell(), 617 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
639 server_redirect_http_url, "test")); 618 server_redirect_http_url, "test"));
640 EXPECT_EQ(observer.navigation_url(), http_url); 619 EXPECT_EQ(observer.navigation_url(), http_url);
641 EXPECT_TRUE(observer.navigation_succeeded()); 620 EXPECT_TRUE(observer.navigation_succeeded());
642 } 621 }
643 622
644 { 623 {
645 // Load server-redirect page pointing to a cross-site server-redirect page, 624 // Load server-redirect page pointing to a cross-site server-redirect page,
646 // which eventually redirects back to cross-site page. 625 // which eventually redirects back to cross-site page.
647 GURL server_redirect_https_url(https_server.GetURL( 626 GURL server_redirect_https_url(https_server.GetURL(
648 "server-redirect?" + https_url.spec())); 627 "server-redirect?" + https_url.spec()));
649 GURL server_redirect_http_url(test_server()->GetURL( 628 GURL server_redirect_http_url(test_server()->GetURL(
650 "server-redirect?" + server_redirect_https_url.spec())); 629 "server-redirect?" + server_redirect_https_url.spec()));
651 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); 630 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
631 server_redirect_http_url, "test"));
652 632
653 // DidFailProvisionalLoad when navigating to https_url. 633 // DidFailProvisionalLoad when navigating to https_url.
654 EXPECT_EQ(observer.navigation_url(), https_url); 634 EXPECT_EQ(observer.navigation_url(), https_url);
655 EXPECT_FALSE(observer.navigation_succeeded()); 635 EXPECT_FALSE(observer.navigation_succeeded());
656 } 636 }
657 637
658 { 638 {
659 // Load server-redirect page pointing to a cross-site client-redirect page, 639 // Load server-redirect page pointing to a cross-site client-redirect page,
660 // which eventually redirects back to same-site page. 640 // which eventually redirects back to same-site page.
661 GURL client_redirect_http_url(https_server.GetURL( 641 GURL client_redirect_http_url(https_server.GetURL(
662 "client-redirect?" + http_url.spec())); 642 "client-redirect?" + http_url.spec()));
663 GURL server_redirect_http_url(test_server()->GetURL( 643 GURL server_redirect_http_url(test_server()->GetURL(
664 "server-redirect?" + client_redirect_http_url.spec())); 644 "server-redirect?" + client_redirect_http_url.spec()));
665 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); 645 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(),
646 server_redirect_http_url, "test"));
666 647
667 // DidFailProvisionalLoad when navigating to client_redirect_http_url. 648 // DidFailProvisionalLoad when navigating to client_redirect_http_url.
668 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 649 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
669 EXPECT_FALSE(observer.navigation_succeeded()); 650 EXPECT_FALSE(observer.navigation_succeeded());
670 } 651 }
671 } 652 }
672 653
673 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are 654 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are
674 // created in the FrameTree skipping the subtree of the navigating frame. 655 // created in the FrameTree skipping the subtree of the navigating frame.
675 // 656 //
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 &result)); 843 &result));
863 EXPECT_EQ(result + "/", foo_url.GetOrigin().spec()); 844 EXPECT_EQ(result + "/", foo_url.GetOrigin().spec());
864 EXPECT_TRUE(ExecuteScriptAndExtractString( 845 EXPECT_TRUE(ExecuteScriptAndExtractString(
865 bottom_child->current_frame_host(), 846 bottom_child->current_frame_host(),
866 "window.domAutomationController.send(location.ancestorOrigins[1]);", 847 "window.domAutomationController.send(location.ancestorOrigins[1]);",
867 &result)); 848 &result));
868 EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); 849 EXPECT_EQ(result + "/", main_url.GetOrigin().spec());
869 } 850 }
870 851
871 } // namespace content 852 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698