Chromium Code Reviews| 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..cb8752a1e1192b5607ff35654118d5d0ad7363c6 100644 |
| --- a/content/browser/site_per_process_browsertest.cc |
| +++ b/content/browser/site_per_process_browsertest.cc |
| @@ -591,6 +591,23 @@ class SitePerProcessIgnoreCertErrorsBrowserTest |
| } |
| }; |
| +// SitePerProcessEmbedderCSPEnforcementBrowserTest |
| + |
| +class SitePerProcessEmbedderCSPEnforcementBrowserTest |
| + : public SitePerProcessBrowserTest { |
| + public: |
| + SitePerProcessEmbedderCSPEnforcementBrowserTest() {} |
| + |
| + protected: |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| + // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes |
| + // stable |
| + command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| + "EmbedderCSPEnforcement"); |
| + } |
| +}; |
| + |
| double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
| double device_scale_factor; |
| const char kGetFrameDeviceScaleFactor[] = |
| @@ -3115,6 +3132,63 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| } |
| } |
| +// Verify that "csp" property on frame elements propogates to child frames |
|
alexmos
2016/10/04 23:50:20
nit: s/propogates/propagates/
|
| +// correctly. See https://crbug.com/647588 |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessEmbedderCSPEnforcementBrowserTest, |
| + FrameOwnerPropertiesPropagationCSP) { |
| + GURL main_url(embedded_test_server()->GetURL( |
| + "a.com", "/frame_owner_properties_csp.html")); |
| + EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| + |
| + // 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<std::string> csp_values = {"default-src a.com", |
| + "default-src b.com", "img-src c.com"}; |
| + |
| + // 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. |
| + EXPECT_TRUE(ExecuteScript( |
| + root, |
| + base::StringPrintf("document.getElementById('child-1').setAttribute(" |
| + " 'csp', '%s');", |
| + csp_values[i].c_str()))); |
| + |
| + NavigateFrameToURL(child, urls[i]); |
| + EXPECT_EQ(csp_values[i], child->frame_owner_properties().csp); |
| + // TODO(amalika): add checks that the CSP replication takes effect |
| + } |
| +} |
| + |
| // 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( |