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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 542 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 543 }; | 543 }; |
| 544 | 544 |
| 545 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 545 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| 546 return visualizer_.DepictFrameTree(node); | 546 return visualizer_.DepictFrameTree(node); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void SitePerProcessBrowserTest::SetUpCommandLine( | 549 void SitePerProcessBrowserTest::SetUpCommandLine( |
| 550 base::CommandLine* command_line) { | 550 base::CommandLine* command_line) { |
| 551 IsolateAllSitesForTesting(command_line); | 551 IsolateAllSitesForTesting(command_line); |
| 552 | |
| 553 // TODO(amalika): Remove this switch when | |
| 554 // the EmbedderCSPEnforcement becomes stable | |
| 555 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | |
| 556 "EmbedderCSPEnforcement"); | |
| 552 }; | 557 }; |
| 553 | 558 |
| 554 void SitePerProcessBrowserTest::SetUpOnMainThread() { | 559 void SitePerProcessBrowserTest::SetUpOnMainThread() { |
| 555 host_resolver()->AddRule("*", "127.0.0.1"); | 560 host_resolver()->AddRule("*", "127.0.0.1"); |
| 556 ASSERT_TRUE(embedded_test_server()->Start()); | 561 ASSERT_TRUE(embedded_test_server()->Start()); |
| 557 SetupCrossSiteRedirector(embedded_test_server()); | 562 SetupCrossSiteRedirector(embedded_test_server()); |
| 558 } | 563 } |
| 559 | 564 |
| 560 // | 565 // |
| 561 // SitePerProcessHighDPIBrowserTest | 566 // SitePerProcessHighDPIBrowserTest |
| (...skipping 2546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3108 "window.domAutomationController.send(" | 3113 "window.domAutomationController.send(" |
| 3109 "document.body.getAttribute('marginheight'));", | 3114 "document.body.getAttribute('marginheight'));", |
| 3110 &actual_margin_height)); | 3115 &actual_margin_height)); |
| 3111 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); | 3116 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); |
| 3112 | 3117 |
| 3113 current_margin_width += 5; | 3118 current_margin_width += 5; |
| 3114 current_margin_height += 10; | 3119 current_margin_height += 10; |
| 3115 } | 3120 } |
| 3116 } | 3121 } |
| 3117 | 3122 |
| 3123 // Verify that "csp" property on frame | |
| 3124 // elements ropagates to child frames correctly. | |
| 3125 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
|
Mike West
2016/09/29 11:50:14
If you're going to split this out, I'd suggest mov
| |
| 3126 FrameOwnerPropertiesPropagationCSP) { | |
| 3127 GURL main_url(embedded_test_server()->GetURL( | |
| 3128 "a.com", "/frame_owner_properties_margin_and_csp.html")); | |
| 3129 NavigateToURL(shell(), main_url); | |
| 3130 | |
| 3131 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
| 3132 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
| 3133 ASSERT_EQ(1u, root->child_count()); | |
| 3134 | |
| 3135 EXPECT_EQ( | |
| 3136 " Site A ------------ proxies for B\n" | |
| 3137 " +--Site B ------- proxies for A\n" | |
| 3138 "Where A = http://a.com/\n" | |
| 3139 " B = http://b.com/", | |
| 3140 DepictFrameTree(root)); | |
| 3141 | |
| 3142 FrameTreeNode* child = root->child_at(0); | |
| 3143 | |
| 3144 std::string csp; | |
| 3145 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 3146 root, | |
| 3147 "window.domAutomationController.send(" | |
| 3148 "document.getElementById('child-1').getAttribute('csp'));", | |
| 3149 &csp)); | |
| 3150 EXPECT_EQ("object-src \'none\'", csp); | |
| 3151 | |
| 3152 // Run the test over variety of parent/child cases. | |
| 3153 GURL urls[] = {// Remote to remote. | |
| 3154 embedded_test_server()->GetURL("c.com", "/title2.html"), | |
| 3155 // Remote to local. | |
| 3156 embedded_test_server()->GetURL("a.com", "/title1.html"), | |
| 3157 // Local to remote. | |
| 3158 embedded_test_server()->GetURL("b.com", "/title2.html")}; | |
| 3159 | |
| 3160 std::vector<base::string16> csp_values = { | |
| 3161 base::ASCIIToUTF16("default-src a.com"), | |
| 3162 base::ASCIIToUTF16("default-src b.com"), | |
| 3163 base::ASCIIToUTF16("img-src c.com")}; | |
| 3164 base::string16 current_csp; | |
| 3165 | |
| 3166 // Before each navigation, we change the csp property of the frame. | |
| 3167 // We then check whether that property is applied | |
| 3168 // correctly after the navigation has completed. | |
| 3169 for (size_t i = 0; i < arraysize(urls); ++i) { | |
| 3170 // Change csp before navigating. | |
| 3171 current_csp = csp_values[i]; | |
| 3172 EXPECT_TRUE(ExecuteScript( | |
| 3173 root, | |
| 3174 base::StringPrintf("document.getElementById('child-1').setAttribute(" | |
| 3175 " 'csp', '%s');", | |
| 3176 base::UTF16ToUTF8(current_csp).c_str()))); | |
| 3177 | |
| 3178 NavigateFrameToURL(child, urls[i]); | |
| 3179 | |
| 3180 EXPECT_EQ(current_csp, child->frame_owner_properties().csp); | |
| 3181 } | |
| 3182 } | |
| 3183 | |
| 3118 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. | 3184 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. |
| 3119 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { | 3185 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
| 3120 GURL main_url(embedded_test_server()->GetURL( | 3186 GURL main_url(embedded_test_server()->GetURL( |
| 3121 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); | 3187 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); |
| 3122 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3188 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3123 | 3189 |
| 3124 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3190 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3125 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3191 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3126 | 3192 |
| 3127 EXPECT_EQ( | 3193 EXPECT_EQ( |
| (...skipping 5096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8224 " Site A ------------ proxies for B C\n" | 8290 " Site A ------------ proxies for B C\n" |
| 8225 " +--Site B ------- proxies for A C\n" | 8291 " +--Site B ------- proxies for A C\n" |
| 8226 " +--Site C -- proxies for A B\n" | 8292 " +--Site C -- proxies for A B\n" |
| 8227 "Where A = http://a.com/\n" | 8293 "Where A = http://a.com/\n" |
| 8228 " B = http://b.com/\n" | 8294 " B = http://b.com/\n" |
| 8229 " C = http://c.com/", | 8295 " C = http://c.com/", |
| 8230 DepictFrameTree(root)); | 8296 DepictFrameTree(root)); |
| 8231 } | 8297 } |
| 8232 | 8298 |
| 8233 } // namespace content | 8299 } // namespace content |
| OLD | NEW |