Index: content/browser/site_per_process_browsertest.cc |
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc |
index 80c95ff99ac5d34d5842621b0052d0d123cde54d..9fb0be8d73d6b87248d4ce2e89a4ca29fd0025e2 100644 |
--- a/content/browser/site_per_process_browsertest.cc |
+++ b/content/browser/site_per_process_browsertest.cc |
@@ -574,6 +574,10 @@ class SitePerProcessHighDPIBrowserTest : public SitePerProcessBrowserTest { |
command_line->AppendSwitchASCII( |
switches::kForceDeviceScaleFactor, |
base::StringPrintf("%f", kDeviceScaleFactor)); |
+ // TODO(amalika): Remove this switch when |
+ // the EmbedderCSPEnforcement becomes stable |
alexmos
2016/09/30 06:20:42
nit: wrap comments at 80 chars (this is fewer than
|
+ command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
alexmos
2016/09/30 06:20:42
Instead of doing this here, let's define a new cla
|
+ "EmbedderCSPEnforcement"); |
} |
}; |
@@ -3031,7 +3035,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
FrameOwnerPropertiesPropagationMargin) { |
GURL main_url(embedded_test_server()->GetURL( |
- "a.com", "/frame_owner_properties_margin.html")); |
+ "a.com", "/frame_owner_properties_margin_and_csp.html")); |
NavigateToURL(shell(), main_url); |
// It is safe to obtain the root frame tree node here, as it doesn't change. |
@@ -3115,6 +3119,67 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
} |
} |
+// Verify that "csp" property on frame |
+// elements ropagates to child frames correctly. |
alexmos
2016/09/30 06:20:42
nits:
s/ropagates/propagates/
Please fix the wrap
|
+IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
+ FrameOwnerPropertiesPropagationCSP) { |
+ GURL main_url(embedded_test_server()->GetURL( |
+ "a.com", "/frame_owner_properties_margin_and_csp.html")); |
alexmos
2016/09/30 06:20:42
Instead of reusing the file, it might be cleaner t
|
+ NavigateToURL(shell(), main_url); |
alexmos
2016/09/30 06:20:42
nit: EXPECT_TRUE
|
+ |
+ // It is safe to obtain the root frame tree node here, as it doesn't change. |
+ FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
+ ASSERT_EQ(1u, root->child_count()); |
+ |
+ EXPECT_EQ( |
+ " Site A ------------ proxies for B\n" |
+ " +--Site B ------- proxies for A\n" |
+ "Where A = http://a.com/\n" |
+ " B = http://b.com/", |
+ DepictFrameTree(root)); |
+ |
+ FrameTreeNode* child = root->child_at(0); |
+ |
+ std::string csp; |
+ EXPECT_TRUE(ExecuteScriptAndExtractString( |
+ root, |
+ "window.domAutomationController.send(" |
+ "document.getElementById('child-1').getAttribute('csp'));", |
+ &csp)); |
+ EXPECT_EQ("object-src \'none\'", csp); |
+ |
+ // Run the test over variety of parent/child cases. |
+ GURL urls[] = {// Remote to remote. |
+ embedded_test_server()->GetURL("c.com", "/title2.html"), |
+ // Remote to local. |
+ embedded_test_server()->GetURL("a.com", "/title1.html"), |
+ // Local to remote. |
+ embedded_test_server()->GetURL("b.com", "/title2.html")}; |
+ |
+ std::vector<base::string16> csp_values = { |
alexmos
2016/09/30 06:20:42
why not just std::string and avoid all conversions
|
+ base::ASCIIToUTF16("default-src a.com"), |
+ base::ASCIIToUTF16("default-src b.com"), |
+ base::ASCIIToUTF16("img-src c.com")}; |
+ base::string16 current_csp; |
+ |
+ // Before each navigation, we change the csp property of the frame. |
+ // We then check whether that property is applied |
+ // correctly after the navigation has completed. |
+ for (size_t i = 0; i < arraysize(urls); ++i) { |
+ // Change csp before navigating. |
+ current_csp = csp_values[i]; |
+ EXPECT_TRUE(ExecuteScript( |
+ root, |
+ base::StringPrintf("document.getElementById('child-1').setAttribute(" |
+ " 'csp', '%s');", |
+ base::UTF16ToUTF8(current_csp).c_str()))); |
alexmos
2016/09/30 06:20:42
nit: could just use csp_values[i] directly (here a
|
+ |
+ NavigateFrameToURL(child, urls[i]); |
+ |
+ EXPECT_EQ(current_csp, child->frame_owner_properties().csp); |
alexmos
2016/09/30 06:20:42
Is it possible to observe that the passed CSP attr
amalika
2016/09/30 07:48:51
The deserialization and the algorithms have not be
|
+ } |
+} |
+ |
// Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. |
IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
GURL main_url(embedded_test_server()->GetURL( |