Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 #if defined(OS_MACOSX) | 71 #if defined(OS_MACOSX) |
| 72 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" | 72 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 namespace content { | 75 namespace content { |
| 76 | 76 |
| 77 namespace { | 77 namespace { |
| 78 | 78 |
| 79 const GURL kBlockedURL("data:,"); | |
| 80 | |
| 79 // Helper function to send a postMessage and wait for a reply message. The | 81 // Helper function to send a postMessage and wait for a reply message. The |
| 80 // |post_message_script| is executed on the |sender_ftn| frame, and the sender | 82 // |post_message_script| is executed on the |sender_ftn| frame, and the sender |
| 81 // frame is expected to post |reply_status| from the DOMAutomationController | 83 // frame is expected to post |reply_status| from the DOMAutomationController |
| 82 // when it receives a reply. | 84 // when it receives a reply. |
| 83 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, | 85 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, |
| 84 const std::string& post_message_script, | 86 const std::string& post_message_script, |
| 85 const std::string& reply_status) { | 87 const std::string& reply_status) { |
| 86 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or | 88 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or |
| 87 // else it might miss the message of interest. See https://crbug.com/518729. | 89 // else it might miss the message of interest. See https://crbug.com/518729. |
| 88 DOMMessageQueue msg_queue; | 90 DOMMessageQueue msg_queue; |
| (...skipping 6066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6155 ASSERT_TRUE(https_server.Start()); | 6157 ASSERT_TRUE(https_server.Start()); |
| 6156 SetupCrossSiteRedirector(&https_server); | 6158 SetupCrossSiteRedirector(&https_server); |
| 6157 | 6159 |
| 6158 GURL iframe_url( | 6160 GURL iframe_url( |
| 6159 https_server.GetURL("/mixed-content/basic-active-in-iframe.html")); | 6161 https_server.GetURL("/mixed-content/basic-active-in-iframe.html")); |
| 6160 EXPECT_TRUE(NavigateToURL(shell(), iframe_url)); | 6162 EXPECT_TRUE(NavigateToURL(shell(), iframe_url)); |
| 6161 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 6163 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6162 ASSERT_EQ(1U, root->child_count()); | 6164 ASSERT_EQ(1U, root->child_count()); |
| 6163 FrameTreeNode* mixed_child = root->child_at(0)->child_at(0); | 6165 FrameTreeNode* mixed_child = root->child_at(0)->child_at(0); |
| 6164 ASSERT_TRUE(mixed_child); | 6166 ASSERT_TRUE(mixed_child); |
| 6165 // The child iframe attempted to create a mixed iframe; this should | 6167 // The child iframe attempted to create a mixed iframe; this will commit |
| 6166 // have been blocked, so the mixed iframe should not have committed a | 6168 // a load to 'data:,' (so that it ends up in a unique origin). |
| 6167 // load. | 6169 EXPECT_TRUE(mixed_child->has_committed_real_load()); |
| 6168 EXPECT_FALSE(mixed_child->has_committed_real_load()); | 6170 EXPECT_EQ(kBlockedURL, mixed_child->current_url()); |
| 6169 } | 6171 } |
| 6170 | 6172 |
| 6171 // Test that subresources with certificate errors that are redundant | 6173 // Test that subresources with certificate errors that are redundant |
| 6172 // with the main page do not get reported to the browser. That is, if | 6174 // with the main page do not get reported to the browser. That is, if |
| 6173 // https://redundant.test frames https://a.com which frames | 6175 // https://redundant.test frames https://a.com which frames |
| 6174 // https://redundant.test which loads an image with certificate errors, | 6176 // https://redundant.test which loads an image with certificate errors, |
| 6175 // the browser doesn't care and doesn't need to know about the image's | 6177 // the browser doesn't care and doesn't need to know about the image's |
| 6176 // certificate errors because they are redundant with the main page | 6178 // certificate errors because they are redundant with the main page |
| 6177 // load. | 6179 // load. |
| 6178 IN_PROC_BROWSER_TEST_F(SitePerProcessIgnoreCertErrorsBrowserTest, | 6180 IN_PROC_BROWSER_TEST_F(SitePerProcessIgnoreCertErrorsBrowserTest, |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6372 | 6374 |
| 6373 // The blocked frame should still fire a load event in its parent's process. | 6375 // The blocked frame should still fire a load event in its parent's process. |
| 6374 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6376 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6375 | 6377 |
| 6376 // Check that the current RenderFrameHost has stopped loading. | 6378 // Check that the current RenderFrameHost has stopped loading. |
| 6377 if (root->child_at(0)->current_frame_host()->is_loading()) { | 6379 if (root->child_at(0)->current_frame_host()->is_loading()) { |
| 6378 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6380 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6379 load_observer.Wait(); | 6381 load_observer.Wait(); |
| 6380 } | 6382 } |
| 6381 | 6383 |
| 6382 // The blocked frame should stay at the old location. | 6384 // The blocked frame should commit to |kBlockedURL| |
| 6383 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 6385 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); |
| 6384 | 6386 |
| 6385 // The blocked frame should keep the old title. | |
| 6386 std::string frame_title; | 6387 std::string frame_title; |
| 6387 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6388 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6388 root->child_at(0)->current_frame_host(), | 6389 root->child_at(0)->current_frame_host(), |
| 6389 "domAutomationController.send(document.title)", &frame_title)); | 6390 "domAutomationController.send(document.title)", &frame_title)); |
| 6390 EXPECT_EQ("Title Of Awesomeness", frame_title); | 6391 EXPECT_EQ("", frame_title); |
| 6391 | 6392 |
| 6392 // Navigate to a URL without CSP. | 6393 // Navigate to a URL without CSP. |
| 6393 EXPECT_TRUE(NavigateToURL( | 6394 EXPECT_TRUE(NavigateToURL( |
| 6394 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 6395 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
| 6395 | 6396 |
| 6396 // Verify that the frame's CSP got correctly reset to an empty set. | 6397 // Verify that the frame's CSP got correctly reset to an empty set. |
| 6397 EXPECT_EQ(0u, | 6398 EXPECT_EQ(0u, |
| 6398 root->current_replication_state().accumulated_csp_headers.size()); | 6399 root->current_replication_state().accumulated_csp_headers.size()); |
| 6399 } | 6400 } |
| 6400 | 6401 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6449 | 6450 |
| 6450 // The blocked frame should still fire a load event in its parent's process. | 6451 // The blocked frame should still fire a load event in its parent's process. |
| 6451 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6452 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6452 | 6453 |
| 6453 // Check that the current RenderFrameHost has stopped loading. | 6454 // Check that the current RenderFrameHost has stopped loading. |
| 6454 if (root->child_at(0)->current_frame_host()->is_loading()) { | 6455 if (root->child_at(0)->current_frame_host()->is_loading()) { |
| 6455 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6456 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6456 load_observer2.Wait(); | 6457 load_observer2.Wait(); |
| 6457 } | 6458 } |
| 6458 | 6459 |
| 6459 // The blocked frame should stay at the old location. | 6460 // The blocked frame should commit to |kBlockedURL| |
| 6460 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 6461 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); |
| 6461 | 6462 |
| 6462 // The blocked frame should keep the old title. | |
| 6463 std::string frame_title; | 6463 std::string frame_title; |
| 6464 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6464 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6465 root->child_at(0)->current_frame_host(), | 6465 root->child_at(0)->current_frame_host(), |
| 6466 "domAutomationController.send(document.title)", &frame_title)); | 6466 "domAutomationController.send(document.title)", &frame_title)); |
| 6467 EXPECT_EQ("Title Of Awesomeness", frame_title); | 6467 EXPECT_EQ("", frame_title); |
| 6468 } | 6468 } |
| 6469 | 6469 |
| 6470 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. | 6470 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. |
| 6471 // In this version of a test, CSP is inherited by srcdoc iframe from a parent | 6471 // In this version of a test, CSP is inherited by srcdoc iframe from a parent |
| 6472 // that declared CSP via HTTP headers. Cross-origin frame navigating to a | 6472 // that declared CSP via HTTP headers. Cross-origin frame navigating to a |
| 6473 // blocked location is a child of the srcdoc iframe. | 6473 // blocked location is a child of the srcdoc iframe. |
| 6474 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 6474 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 6475 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { | 6475 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { |
| 6476 GURL main_url( | 6476 GURL main_url( |
| 6477 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); | 6477 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6520 | 6520 |
| 6521 // The blocked frame should still fire a load event in its parent's process. | 6521 // The blocked frame should still fire a load event in its parent's process. |
| 6522 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6522 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6523 | 6523 |
| 6524 // Check that the current RenderFrameHost has stopped loading. | 6524 // Check that the current RenderFrameHost has stopped loading. |
| 6525 if (navigating_frame->current_frame_host()->is_loading()) { | 6525 if (navigating_frame->current_frame_host()->is_loading()) { |
| 6526 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6526 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6527 load_observer2.Wait(); | 6527 load_observer2.Wait(); |
| 6528 } | 6528 } |
| 6529 | 6529 |
| 6530 // The blocked frame should stay at the old location. | 6530 // The blocked frame should commit to |kBlockedURL| |
|
Charlie Reis
2016/06/06 20:43:07
nit: Keep the period. (Same above.)
| |
| 6531 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); | 6531 EXPECT_EQ(kBlockedURL, navigating_frame->current_url()); |
| 6532 | 6532 |
| 6533 // The blocked frame should keep the old title. | |
| 6534 std::string frame_title; | 6533 std::string frame_title; |
| 6535 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6534 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6536 navigating_frame->current_frame_host(), | 6535 navigating_frame->current_frame_host(), |
| 6537 "domAutomationController.send(document.title)", &frame_title)); | 6536 "domAutomationController.send(document.title)", &frame_title)); |
| 6538 EXPECT_EQ("Title Of Awesomeness", frame_title); | 6537 EXPECT_EQ("", frame_title); |
| 6539 | 6538 |
| 6540 // Navigate the subframe to a URL without CSP. | 6539 // Navigate the subframe to a URL without CSP. |
| 6541 NavigateFrameToURL(srcdoc_frame, | 6540 NavigateFrameToURL(srcdoc_frame, |
| 6542 embedded_test_server()->GetURL("a.com", "/title1.html")); | 6541 embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 6543 | 6542 |
| 6544 // Verify that the frame's CSP got correctly reset to an empty set. | 6543 // Verify that the frame's CSP got correctly reset to an empty set. |
| 6545 EXPECT_EQ( | 6544 EXPECT_EQ( |
| 6546 0u, | 6545 0u, |
| 6547 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); | 6546 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); |
| 6548 } | 6547 } |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7209 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); | 7208 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); |
| 7210 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7209 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7211 | 7210 |
| 7212 // Cross-site navigation should preserve the fullscreen flags. | 7211 // Cross-site navigation should preserve the fullscreen flags. |
| 7213 NavigateFrameToURL(root->child_at(0)->child_at(0), | 7212 NavigateFrameToURL(root->child_at(0)->child_at(0), |
| 7214 embedded_test_server()->GetURL("d.com", "/title1.html")); | 7213 embedded_test_server()->GetURL("d.com", "/title1.html")); |
| 7215 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7214 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7216 } | 7215 } |
| 7217 | 7216 |
| 7218 } // namespace content | 7217 } // namespace content |
| OLD | NEW |