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

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

Issue 2655463006: PlzNavigate: Enforce 'frame-src' CSP on the browser. (Closed)
Patch Set: Fix tests. Created 3 years, 10 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 7139 matching lines...) Expand 10 before | Expand all | Expand 10 after
7150 7150
7151 // The blocked frame should still fire a load event in its parent's process. 7151 // The blocked frame should still fire a load event in its parent's process.
7152 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7152 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7153 7153
7154 // Check that the current RenderFrameHost has stopped loading. 7154 // Check that the current RenderFrameHost has stopped loading.
7155 if (root->child_at(0)->current_frame_host()->is_loading()) { 7155 if (root->child_at(0)->current_frame_host()->is_loading()) {
7156 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7156 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7157 load_observer.Wait(); 7157 load_observer.Wait();
7158 } 7158 }
7159 7159
7160 // The blocked frame should stay at the old location. 7160 if (IsBrowserSideNavigationEnabled()) {
alexmos 2017/02/10 22:59:53 I'm not too thrilled that there will be a behavior
7161 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7161 // The blocked frame should go to an error page. Hence its url is the
7162 // blocked page url.
alexmos 2017/02/10 22:59:53 This isn't very intuitive, so perhaps explain why
arthursonzogni 2017/02/13 16:33:20 Done.
7163 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7162 7164
7163 // The blocked frame should keep the old title. 7165 // The page should get the title of an error page (i.e "") and not the
7164 std::string frame_title; 7166 // title of the blocked page.
7165 EXPECT_TRUE(ExecuteScriptAndExtractString( 7167 std::string frame_title;
7166 root->child_at(0), "domAutomationController.send(document.title)", 7168 EXPECT_TRUE(ExecuteScriptAndExtractString(
7167 &frame_title)); 7169 root->child_at(0), "domAutomationController.send(document.title)",
7168 EXPECT_EQ("Title Of Awesomeness", frame_title); 7170 &frame_title));
7171 EXPECT_EQ("", frame_title);
alexmos 2017/02/10 22:59:53 I'd also check RFHI::last_successful_url() to make
arthursonzogni 2017/02/13 16:33:20 RFHI::last_successful_url() returns the empty url
alexmos 2017/02/14 06:57:19 Ah, got it, thanks. That's actually really great;
7172 } else {
7173 // The blocked frame should stay at the old location.
7174 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7175
7176 // The blocked frame should keep the old title.
7177 std::string frame_title;
7178 EXPECT_TRUE(ExecuteScriptAndExtractString(
7179 root->child_at(0), "domAutomationController.send(document.title)",
7180 &frame_title));
7181 EXPECT_EQ("Title Of Awesomeness", frame_title);
7182 }
7169 7183
7170 // Navigate to a URL without CSP. 7184 // Navigate to a URL without CSP.
7171 EXPECT_TRUE(NavigateToURL( 7185 EXPECT_TRUE(NavigateToURL(
7172 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); 7186 shell(), embedded_test_server()->GetURL("a.com", "/title1.html")));
7173 7187
7174 // Verify that the frame's CSP got correctly reset to an empty set. 7188 // Verify that the frame's CSP got correctly reset to an empty set.
7175 EXPECT_EQ(0u, 7189 EXPECT_EQ(0u,
7176 root->current_replication_state().accumulated_csp_headers.size()); 7190 root->current_replication_state().accumulated_csp_headers.size());
7177 } 7191 }
7178 7192
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7225 7239
7226 // The blocked frame should still fire a load event in its parent's process. 7240 // The blocked frame should still fire a load event in its parent's process.
7227 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7241 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7228 7242
7229 // Check that the current RenderFrameHost has stopped loading. 7243 // Check that the current RenderFrameHost has stopped loading.
7230 if (root->child_at(0)->current_frame_host()->is_loading()) { 7244 if (root->child_at(0)->current_frame_host()->is_loading()) {
7231 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7245 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7232 load_observer2.Wait(); 7246 load_observer2.Wait();
7233 } 7247 }
7234 7248
7235 // The blocked frame should stay at the old location. 7249 if (IsBrowserSideNavigationEnabled()) {
7236 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); 7250 // The blocked frame should go an error page. Hence its url is the
7251 // blocked page url.
7252 EXPECT_EQ(blocked_url, root->child_at(0)->current_url());
7237 7253
7238 // The blocked frame should keep the old title. 7254 // The page should get the title of an error page (i.e "") and not the
7239 std::string frame_title; 7255 // title of the blocked page.
7240 EXPECT_TRUE(ExecuteScriptAndExtractString( 7256 std::string frame_title;
7241 root->child_at(0), "domAutomationController.send(document.title)", 7257 EXPECT_TRUE(ExecuteScriptAndExtractString(
7242 &frame_title)); 7258 root->child_at(0), "domAutomationController.send(document.title)",
7243 EXPECT_EQ("Title Of Awesomeness", frame_title); 7259 &frame_title));
7260 EXPECT_EQ("", frame_title);
7261 } else {
7262 // The blocked frame should stay at the old location.
7263 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url());
7264
7265 // The blocked frame should keep the old title.
7266 std::string frame_title;
7267 EXPECT_TRUE(ExecuteScriptAndExtractString(
7268 root->child_at(0), "domAutomationController.send(document.title)",
7269 &frame_title));
7270 EXPECT_EQ("Title Of Awesomeness", frame_title);
7271 }
7244 } 7272 }
7245 7273
7246 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. 7274 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src.
7247 // In this version of a test, CSP is inherited by srcdoc iframe from a parent 7275 // In this version of a test, CSP is inherited by srcdoc iframe from a parent
7248 // that declared CSP via HTTP headers. Cross-origin frame navigating to a 7276 // that declared CSP via HTTP headers. Cross-origin frame navigating to a
7249 // blocked location is a child of the srcdoc iframe. 7277 // blocked location is a child of the srcdoc iframe.
7250 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 7278 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7251 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { 7279 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) {
7252 GURL main_url( 7280 GURL main_url(
7253 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); 7281 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html"));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
7294 7322
7295 // The blocked frame should still fire a load event in its parent's process. 7323 // The blocked frame should still fire a load event in its parent's process.
7296 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 7324 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
7297 7325
7298 // Check that the current RenderFrameHost has stopped loading. 7326 // Check that the current RenderFrameHost has stopped loading.
7299 if (navigating_frame->current_frame_host()->is_loading()) { 7327 if (navigating_frame->current_frame_host()->is_loading()) {
7300 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; 7328 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything";
7301 load_observer2.Wait(); 7329 load_observer2.Wait();
7302 } 7330 }
7303 7331
7304 // The blocked frame should stay at the old location. 7332 if (IsBrowserSideNavigationEnabled()) {
7305 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); 7333 // The blocked frame should go an error page. Hence its url is the
7334 // blocked page url.
7335 EXPECT_EQ(blocked_url, navigating_frame->current_url());
7306 7336
7307 // The blocked frame should keep the old title. 7337 // The page should get the title of an error page (i.e "") and not the
7308 std::string frame_title; 7338 // title of the blocked page.
7309 EXPECT_TRUE(ExecuteScriptAndExtractString( 7339 std::string frame_title;
7310 navigating_frame, "domAutomationController.send(document.title)", 7340 EXPECT_TRUE(ExecuteScriptAndExtractString(
7311 &frame_title)); 7341 navigating_frame, "domAutomationController.send(document.title)",
7312 EXPECT_EQ("Title Of Awesomeness", frame_title); 7342 &frame_title));
7343 EXPECT_EQ("", frame_title);
7344 } else {
7345 // The blocked frame should stay at the old location.
7346 EXPECT_EQ(old_subframe_url, navigating_frame->current_url());
7347
7348 // The blocked frame should keep the old title.
7349 std::string frame_title;
7350 EXPECT_TRUE(ExecuteScriptAndExtractString(
7351 navigating_frame, "domAutomationController.send(document.title)",
7352 &frame_title));
7353 EXPECT_EQ("Title Of Awesomeness", frame_title);
7354 }
7313 7355
7314 // Navigate the subframe to a URL without CSP. 7356 // Navigate the subframe to a URL without CSP.
7315 NavigateFrameToURL(srcdoc_frame, 7357 NavigateFrameToURL(srcdoc_frame,
7316 embedded_test_server()->GetURL("a.com", "/title1.html")); 7358 embedded_test_server()->GetURL("a.com", "/title1.html"));
7317 7359
7318 // Verify that the frame's CSP got correctly reset to an empty set. 7360 // Verify that the frame's CSP got correctly reset to an empty set.
7319 EXPECT_EQ( 7361 EXPECT_EQ(
7320 0u, 7362 0u,
7321 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); 7363 srcdoc_frame->current_replication_state().accumulated_csp_headers.size());
7322 } 7364 }
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
9333 "subframes_with_resources.html?urls=%s,%s&" 9375 "subframes_with_resources.html?urls=%s,%s&"
9334 "numSubresources=3", 9376 "numSubresources=3",
9335 path0.c_str(), path1.c_str()))); 9377 path0.c_str(), path1.c_str())));
9336 EXPECT_TRUE(NavigateToURL(shell(), url)); 9378 EXPECT_TRUE(NavigateToURL(shell(), url));
9337 bool result; 9379 bool result;
9338 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); 9380 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result));
9339 EXPECT_TRUE(result); 9381 EXPECT_TRUE(result);
9340 } 9382 }
9341 9383
9342 } // namespace content 9384 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698