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

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

Issue 2655463006: PlzNavigate: Enforce 'frame-src' CSP on the browser. (Closed)
Patch Set: Rebase. Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 " B = http://b.com/", 2400 " B = http://b.com/",
2401 DepictFrameTree(root)); 2401 DepictFrameTree(root));
2402 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 2402 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
2403 child->current_frame_host()->GetSiteInstance()); 2403 child->current_frame_host()->GetSiteInstance());
2404 } 2404 }
2405 2405
2406 // The FrameTreeNode should update its URL (so that we don't affect other uses 2406 // The FrameTreeNode should update its URL (so that we don't affect other uses
2407 // of the API), but the frame's last_successful_url shouldn't change and the 2407 // of the API), but the frame's last_successful_url shouldn't change and the
2408 // origin should be empty. 2408 // origin should be empty.
2409 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the 2409 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the
2410 // last succesful url should be empty (since the frame only loaded an error 2410 // last successful url should be empty (since the frame only loaded an error
2411 // page). 2411 // page).
2412 if (IsBrowserSideNavigationEnabled()) 2412 if (IsBrowserSideNavigationEnabled())
2413 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); 2413 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url());
2414 else 2414 else
2415 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); 2415 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url());
2416 EXPECT_EQ(url_b, child->current_url()); 2416 EXPECT_EQ(url_b, child->current_url());
2417 EXPECT_EQ("null", child->current_origin().Serialize()); 2417 EXPECT_EQ("null", child->current_origin().Serialize());
2418 2418
2419 // Try again after re-enabling host resolution. 2419 // Try again after re-enabling host resolution.
2420 host_resolver()->AddRule("*", "127.0.0.1"); 2420 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 4996 matching lines...) Expand 10 before | Expand all | Expand 10 after
7417 // The blocked frame should still fire a load event in its parent's process. 7417 // The blocked frame should still fire a load event in its parent's process.
7418 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7418 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7419 7419
7420 // Check that the current RenderFrameHost has stopped loading. 7420 // Check that the current RenderFrameHost has stopped loading.
7421 if (root->child_at(0)->current_frame_host()->is_loading()) { 7421 if (root->child_at(0)->current_frame_host()->is_loading()) {
7422 if (!IsBrowserSideNavigationEnabled()) 7422 if (!IsBrowserSideNavigationEnabled())
7423 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7423 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7424 load_observer.Wait(); 7424 load_observer.Wait();
7425 } 7425 }
7426 7426
7427 // The blocked frame should stay at the old location. 7427 // The last successful url shouldn't be the blocked url.
7428 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7428 EXPECT_EQ(old_subframe_url,
7429 root->child_at(0)->current_frame_host()->last_successful_url());
7429 7430
7430 // The blocked frame should keep the old title. 7431 if (IsBrowserSideNavigationEnabled()) {
7431 std::string frame_title; 7432 // The blocked frame should go to an error page. Errors currently commit
7432 EXPECT_TRUE(ExecuteScriptAndExtractString( 7433 // with the URL of the blocked page.
7433 root->child_at(0), "domAutomationController.send(document.title)", 7434 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7434 &frame_title)); 7435
7435 EXPECT_EQ("Title Of Awesomeness", frame_title); 7436 // The page should get the title of an error page (i.e "") and not the
7437 // title of the blocked page.
7438 std::string frame_title;
7439 EXPECT_TRUE(ExecuteScriptAndExtractString(
7440 root->child_at(0), "domAutomationController.send(document.title)",
7441 &frame_title));
7442 EXPECT_EQ("", frame_title);
7443 } else {
7444 // The blocked frame should stay at the old location.
7445 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7446
7447 // The blocked frame should keep the old title.
7448 std::string frame_title;
7449 EXPECT_TRUE(ExecuteScriptAndExtractString(
7450 root->child_at(0), "domAutomationController.send(document.title)",
7451 &frame_title));
7452 EXPECT_EQ("Title Of Awesomeness", frame_title);
7453 }
7436 7454
7437 // Navigate to a URL without CSP. 7455 // Navigate to a URL without CSP.
7438 EXPECT_TRUE(NavigateToURL( 7456 EXPECT_TRUE(NavigateToURL(
7439 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); 7457 shell(), embedded_test_server()->GetURL("a.com", "/title1.html")));
7440 7458
7441 // Verify that the frame's CSP got correctly reset to an empty set. 7459 // Verify that the frame's CSP got correctly reset to an empty set.
7442 EXPECT_EQ(0u, 7460 EXPECT_EQ(0u,
7443 root->current_replication_state().accumulated_csp_headers.size()); 7461 root->current_replication_state().accumulated_csp_headers.size());
7444 } 7462 }
7445 7463
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7493 // The blocked frame should still fire a load event in its parent's process. 7511 // The blocked frame should still fire a load event in its parent's process.
7494 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7512 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7495 7513
7496 // Check that the current RenderFrameHost has stopped loading. 7514 // Check that the current RenderFrameHost has stopped loading.
7497 if (root->child_at(0)->current_frame_host()->is_loading()) { 7515 if (root->child_at(0)->current_frame_host()->is_loading()) {
7498 if (!IsBrowserSideNavigationEnabled()) 7516 if (!IsBrowserSideNavigationEnabled())
7499 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7517 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7500 load_observer2.Wait(); 7518 load_observer2.Wait();
7501 } 7519 }
7502 7520
7503 // The blocked frame should stay at the old location. 7521 // The last successful url shouldn't be the blocked url.
7504 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7522 EXPECT_EQ(old_subframe_url,
7523 root->child_at(0)->current_frame_host()->last_successful_url());
7505 7524
7506 // The blocked frame should keep the old title. 7525 if (IsBrowserSideNavigationEnabled()) {
7507 std::string frame_title; 7526 // The blocked frame should go to an error page. Errors currently commit
7508 EXPECT_TRUE(ExecuteScriptAndExtractString( 7527 // with the URL of the blocked page.
7509 root->child_at(0), "domAutomationController.send(document.title)", 7528 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7510 &frame_title)); 7529
7511 EXPECT_EQ("Title Of Awesomeness", frame_title); 7530 // The page should get the title of an error page (i.e "") and not the
7531 // title of the blocked page.
7532 std::string frame_title;
7533 EXPECT_TRUE(ExecuteScriptAndExtractString(
7534 root->child_at(0), "domAutomationController.send(document.title)",
7535 &frame_title));
7536 EXPECT_EQ("", frame_title);
7537 } else {
7538 // The blocked frame should stay at the old location.
7539 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7540
7541 // The blocked frame should keep the old title.
7542 std::string frame_title;
7543 EXPECT_TRUE(ExecuteScriptAndExtractString(
7544 root->child_at(0), "domAutomationController.send(document.title)",
7545 &frame_title));
7546 EXPECT_EQ("Title Of Awesomeness", frame_title);
7547 }
7512 } 7548 }
7513 7549
7514 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. 7550 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src.
7515 // In this version of a test, CSP is inherited by srcdoc iframe from a parent 7551 // In this version of a test, CSP is inherited by srcdoc iframe from a parent
7516 // that declared CSP via HTTP headers. Cross-origin frame navigating to a 7552 // that declared CSP via HTTP headers. Cross-origin frame navigating to a
7517 // blocked location is a child of the srcdoc iframe. 7553 // blocked location is a child of the srcdoc iframe.
7518 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 7554 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7519 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { 7555 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) {
7520 GURL main_url( 7556 GURL main_url(
7521 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); 7557 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html"));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
7563 // The blocked frame should still fire a load event in its parent's process. 7599 // The blocked frame should still fire a load event in its parent's process.
7564 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7600 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7565 7601
7566 // Check that the current RenderFrameHost has stopped loading. 7602 // Check that the current RenderFrameHost has stopped loading.
7567 if (navigating_frame->current_frame_host()->is_loading()) { 7603 if (navigating_frame->current_frame_host()->is_loading()) {
7568 if (!IsBrowserSideNavigationEnabled()) 7604 if (!IsBrowserSideNavigationEnabled())
7569 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7605 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7570 load_observer2.Wait(); 7606 load_observer2.Wait();
7571 } 7607 }
7572 7608
7573 // The blocked frame should stay at the old location. 7609 // The last successful url shouldn't be the blocked url.
7574 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); 7610 EXPECT_EQ(old_subframe_url,
7611 navigating_frame->current_frame_host()->last_successful_url());
7575 7612
7576 // The blocked frame should keep the old title. 7613 if (IsBrowserSideNavigationEnabled()) {
7577 std::string frame_title; 7614 // The blocked frame should go to an error page. Errors currently commit
7578 EXPECT_TRUE(ExecuteScriptAndExtractString( 7615 // with the URL of the blocked page.
7579 navigating_frame, "domAutomationController.send(document.title)", 7616 EXPECT_EQ(blocked_url, navigating_frame->current_url());
7580 &frame_title)); 7617
7581 EXPECT_EQ("Title Of Awesomeness", frame_title); 7618 // The page should get the title of an error page (i.e "") and not the
7619 // title of the blocked page.
7620 std::string frame_title;
7621 EXPECT_TRUE(ExecuteScriptAndExtractString(
7622 navigating_frame, "domAutomationController.send(document.title)",
7623 &frame_title));
7624 EXPECT_EQ("", frame_title);
7625 } else {
7626 // The blocked frame should stay at the old location.
7627 EXPECT_EQ(old_subframe_url, navigating_frame->current_url());
7628
7629 // The blocked frame should keep the old title.
7630 std::string frame_title;
7631 EXPECT_TRUE(ExecuteScriptAndExtractString(
7632 navigating_frame, "domAutomationController.send(document.title)",
7633 &frame_title));
7634 EXPECT_EQ("Title Of Awesomeness", frame_title);
7635 }
7582 7636
7583 // Navigate the subframe to a URL without CSP. 7637 // Navigate the subframe to a URL without CSP.
7584 NavigateFrameToURL(srcdoc_frame, 7638 NavigateFrameToURL(srcdoc_frame,
7585 embedded_test_server()->GetURL("a.com", "/title1.html")); 7639 embedded_test_server()->GetURL("a.com", "/title1.html"));
7586 7640
7587 // Verify that the frame's CSP got correctly reset to an empty set. 7641 // Verify that the frame's CSP got correctly reset to an empty set.
7588 EXPECT_EQ( 7642 EXPECT_EQ(
7589 0u, 7643 0u,
7590 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); 7644 srcdoc_frame->current_replication_state().accumulated_csp_headers.size());
7591 } 7645 }
(...skipping 2254 matching lines...) Expand 10 before | Expand all | Expand 10 after
9846 9900
9847 // Try the same navigation, but use the browser-initiated path. 9901 // Try the same navigation, but use the browser-initiated path.
9848 NavigateFrameToURL(root->child_at(0), frame_url); 9902 NavigateFrameToURL(root->child_at(0), frame_url);
9849 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); 9903 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host());
9850 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); 9904 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url);
9851 EXPECT_EQ(b_site_instance, 9905 EXPECT_EQ(b_site_instance,
9852 root->child_at(0)->current_frame_host()->GetSiteInstance()); 9906 root->child_at(0)->current_frame_host()->GetSiteInstance());
9853 } 9907 }
9854 9908
9855 } // namespace content 9909 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698