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

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

Issue 2655463006: PlzNavigate: Enforce 'frame-src' CSP on the browser. (Closed)
Patch Set: Addressed comments 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 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 " B = http://b.com/", 2393 " B = http://b.com/",
2394 DepictFrameTree(root)); 2394 DepictFrameTree(root));
2395 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 2395 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
2396 child->current_frame_host()->GetSiteInstance()); 2396 child->current_frame_host()->GetSiteInstance());
2397 } 2397 }
2398 2398
2399 // The FrameTreeNode should update its URL (so that we don't affect other uses 2399 // The FrameTreeNode should update its URL (so that we don't affect other uses
2400 // of the API), but the frame's last_successful_url shouldn't change and the 2400 // of the API), but the frame's last_successful_url shouldn't change and the
2401 // origin should be empty. 2401 // origin should be empty.
2402 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the 2402 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the
2403 // last succesful url should be empty (since the frame only loaded an error 2403 // last successful url should be empty (since the frame only loaded an error
2404 // page). 2404 // page).
2405 if (IsBrowserSideNavigationEnabled()) 2405 if (IsBrowserSideNavigationEnabled())
2406 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); 2406 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url());
2407 else 2407 else
2408 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); 2408 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url());
2409 EXPECT_EQ(url_b, child->current_url()); 2409 EXPECT_EQ(url_b, child->current_url());
2410 EXPECT_EQ("null", child->current_origin().Serialize()); 2410 EXPECT_EQ("null", child->current_origin().Serialize());
2411 2411
2412 // Try again after re-enabling host resolution. 2412 // Try again after re-enabling host resolution.
2413 host_resolver()->AddRule("*", "127.0.0.1"); 2413 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 4967 matching lines...) Expand 10 before | Expand all | Expand 10 after
7381 7381
7382 // The blocked frame should still fire a load event in its parent's process. 7382 // The blocked frame should still fire a load event in its parent's process.
7383 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7383 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7384 7384
7385 // Check that the current RenderFrameHost has stopped loading. 7385 // Check that the current RenderFrameHost has stopped loading.
7386 if (root->child_at(0)->current_frame_host()->is_loading()) { 7386 if (root->child_at(0)->current_frame_host()->is_loading()) {
7387 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7387 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7388 load_observer.Wait(); 7388 load_observer.Wait();
7389 } 7389 }
7390 7390
7391 // The blocked frame should stay at the old location. 7391 if (IsBrowserSideNavigationEnabled()) {
7392 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7392 // We have switched RenderFrameHosts for the subframe, so the last
7393 // successful url should be empty (since the frame only loaded an error
7394 // page).
7395 EXPECT_EQ(GURL(),
7396 root->child_at(0)->current_frame_host()->last_successful_url());
7393 7397
7394 // The blocked frame should keep the old title. 7398 // The blocked frame should go to an error page. Errors currently commit
7395 std::string frame_title; 7399 // with the URL of the blocked page.
7396 EXPECT_TRUE(ExecuteScriptAndExtractString( 7400 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7397 root->child_at(0), "domAutomationController.send(document.title)", 7401
7398 &frame_title)); 7402 // The page should get the title of an error page (i.e "") and not the
7399 EXPECT_EQ("Title Of Awesomeness", frame_title); 7403 // title of the blocked page.
7404 std::string frame_title;
7405 EXPECT_TRUE(ExecuteScriptAndExtractString(
7406 root->child_at(0), "domAutomationController.send(document.title)",
7407 &frame_title));
7408 EXPECT_EQ("", frame_title);
7409 } else {
7410 // The last successful url shouldn't be the blocked url.
7411 EXPECT_EQ(old_subframe_url,
7412 root->child_at(0)->current_frame_host()->last_successful_url());
7413
7414 // The blocked frame should stay at the old location.
7415 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7416
7417 // The blocked frame should keep the old title.
7418 std::string frame_title;
7419 EXPECT_TRUE(ExecuteScriptAndExtractString(
7420 root->child_at(0), "domAutomationController.send(document.title)",
7421 &frame_title));
7422 EXPECT_EQ("Title Of Awesomeness", frame_title);
7423 }
7400 7424
7401 // Navigate to a URL without CSP. 7425 // Navigate to a URL without CSP.
7402 EXPECT_TRUE(NavigateToURL( 7426 EXPECT_TRUE(NavigateToURL(
7403 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); 7427 shell(), embedded_test_server()->GetURL("a.com", "/title1.html")));
7404 7428
7405 // Verify that the frame's CSP got correctly reset to an empty set. 7429 // Verify that the frame's CSP got correctly reset to an empty set.
7406 EXPECT_EQ(0u, 7430 EXPECT_EQ(0u,
7407 root->current_replication_state().accumulated_csp_headers.size()); 7431 root->current_replication_state().accumulated_csp_headers.size());
7408 } 7432 }
7409 7433
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7456 7480
7457 // The blocked frame should still fire a load event in its parent's process. 7481 // The blocked frame should still fire a load event in its parent's process.
7458 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7482 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7459 7483
7460 // Check that the current RenderFrameHost has stopped loading. 7484 // Check that the current RenderFrameHost has stopped loading.
7461 if (root->child_at(0)->current_frame_host()->is_loading()) { 7485 if (root->child_at(0)->current_frame_host()->is_loading()) {
7462 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7486 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7463 load_observer2.Wait(); 7487 load_observer2.Wait();
7464 } 7488 }
7465 7489
7466 // The blocked frame should stay at the old location. 7490 if (IsBrowserSideNavigationEnabled()) {
7467 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7491 // We have switched RenderFrameHosts for the subframe, so the last
7492 // successful url should be empty (since the frame only loaded an error
7493 // page).
7494 EXPECT_EQ(GURL(),
7495 root->child_at(0)->current_frame_host()->last_successful_url());
7468 7496
7469 // The blocked frame should keep the old title. 7497 // The blocked frame should go to an error page. Errors currently commit
7470 std::string frame_title; 7498 // with the URL of the blocked page.
7471 EXPECT_TRUE(ExecuteScriptAndExtractString( 7499 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7472 root->child_at(0), "domAutomationController.send(document.title)", 7500
7473 &frame_title)); 7501 // The page should get the title of an error page (i.e "") and not the
7474 EXPECT_EQ("Title Of Awesomeness", frame_title); 7502 // title of the blocked page.
7503 std::string frame_title;
7504 EXPECT_TRUE(ExecuteScriptAndExtractString(
7505 root->child_at(0), "domAutomationController.send(document.title)",
7506 &frame_title));
7507 EXPECT_EQ("", frame_title);
7508 } else {
7509 // The last successful url shouldn't be the blocked url.
7510 EXPECT_EQ(old_subframe_url,
7511 root->child_at(0)->current_frame_host()->last_successful_url());
7512
7513 // The blocked frame should stay at the old location.
7514 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7515
7516 // The blocked frame should keep the old title.
7517 std::string frame_title;
7518 EXPECT_TRUE(ExecuteScriptAndExtractString(
7519 root->child_at(0), "domAutomationController.send(document.title)",
7520 &frame_title));
7521 EXPECT_EQ("Title Of Awesomeness", frame_title);
7522 }
7475 } 7523 }
7476 7524
7477 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. 7525 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src.
7478 // In this version of a test, CSP is inherited by srcdoc iframe from a parent 7526 // In this version of a test, CSP is inherited by srcdoc iframe from a parent
7479 // that declared CSP via HTTP headers. Cross-origin frame navigating to a 7527 // that declared CSP via HTTP headers. Cross-origin frame navigating to a
7480 // blocked location is a child of the srcdoc iframe. 7528 // blocked location is a child of the srcdoc iframe.
7481 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 7529 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7482 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { 7530 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) {
7483 GURL main_url( 7531 GURL main_url(
7484 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); 7532 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html"));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
7525 7573
7526 // The blocked frame should still fire a load event in its parent's process. 7574 // The blocked frame should still fire a load event in its parent's process.
7527 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7575 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7528 7576
7529 // Check that the current RenderFrameHost has stopped loading. 7577 // Check that the current RenderFrameHost has stopped loading.
7530 if (navigating_frame->current_frame_host()->is_loading()) { 7578 if (navigating_frame->current_frame_host()->is_loading()) {
7531 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7579 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7532 load_observer2.Wait(); 7580 load_observer2.Wait();
7533 } 7581 }
7534 7582
7535 // The blocked frame should stay at the old location. 7583 if (IsBrowserSideNavigationEnabled()) {
7536 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); 7584 // We have switched RenderFrameHosts for the subframe, so the last
7585 // successful url should be empty (since the frame only loaded an error
7586 // page).
7587 EXPECT_EQ(GURL(),
7588 navigating_frame->current_frame_host()->last_successful_url());
7537 7589
7538 // The blocked frame should keep the old title. 7590 // The blocked frame should go to an error page. Errors currently commit
7539 std::string frame_title; 7591 // with the URL of the blocked page.
7540 EXPECT_TRUE(ExecuteScriptAndExtractString( 7592 EXPECT_EQ(blocked_url, navigating_frame->current_url());
7541 navigating_frame, "domAutomationController.send(document.title)", 7593
7542 &frame_title)); 7594 // The page should get the title of an error page (i.e "") and not the
7543 EXPECT_EQ("Title Of Awesomeness", frame_title); 7595 // title of the blocked page.
7596 std::string frame_title;
7597 EXPECT_TRUE(ExecuteScriptAndExtractString(
7598 navigating_frame, "domAutomationController.send(document.title)",
7599 &frame_title));
7600 EXPECT_EQ("", frame_title);
7601 } else {
7602 // The last successful url shouldn't be the blocked url.
7603 EXPECT_EQ(old_subframe_url,
7604 navigating_frame->current_frame_host()->last_successful_url());
7605
7606 // The blocked frame should stay at the old location.
7607 EXPECT_EQ(old_subframe_url, navigating_frame->current_url());
7608
7609 // The blocked frame should keep the old title.
7610 std::string frame_title;
7611 EXPECT_TRUE(ExecuteScriptAndExtractString(
7612 navigating_frame, "domAutomationController.send(document.title)",
7613 &frame_title));
7614 EXPECT_EQ("Title Of Awesomeness", frame_title);
7615 }
7544 7616
7545 // Navigate the subframe to a URL without CSP. 7617 // Navigate the subframe to a URL without CSP.
7546 NavigateFrameToURL(srcdoc_frame, 7618 NavigateFrameToURL(srcdoc_frame,
7547 embedded_test_server()->GetURL("a.com", "/title1.html")); 7619 embedded_test_server()->GetURL("a.com", "/title1.html"));
7548 7620
7549 // Verify that the frame's CSP got correctly reset to an empty set. 7621 // Verify that the frame's CSP got correctly reset to an empty set.
7550 EXPECT_EQ( 7622 EXPECT_EQ(
7551 0u, 7623 0u,
7552 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); 7624 srcdoc_frame->current_replication_state().accumulated_csp_headers.size());
7553 } 7625 }
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
9795 9867
9796 // Try the same navigation, but use the browser-initiated path. 9868 // Try the same navigation, but use the browser-initiated path.
9797 NavigateFrameToURL(root->child_at(0), frame_url); 9869 NavigateFrameToURL(root->child_at(0), frame_url);
9798 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); 9870 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host());
9799 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); 9871 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url);
9800 EXPECT_EQ(b_site_instance, 9872 EXPECT_EQ(b_site_instance,
9801 root->child_at(0)->current_frame_host()->GetSiteInstance()); 9873 root->child_at(0)->current_frame_host()->GetSiteInstance());
9802 } 9874 }
9803 9875
9804 } // namespace content 9876 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698