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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 public: | 584 public: |
585 SitePerProcessIgnoreCertErrorsBrowserTest() {} | 585 SitePerProcessIgnoreCertErrorsBrowserTest() {} |
586 | 586 |
587 protected: | 587 protected: |
588 void SetUpCommandLine(base::CommandLine* command_line) override { | 588 void SetUpCommandLine(base::CommandLine* command_line) override { |
589 SitePerProcessBrowserTest::SetUpCommandLine(command_line); | 589 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
590 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); | 590 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
591 } | 591 } |
592 }; | 592 }; |
593 | 593 |
| 594 // SitePerProcessEmbedderCSPEnforcementBrowserTest |
| 595 |
| 596 class SitePerProcessEmbedderCSPEnforcementBrowserTest |
| 597 : public SitePerProcessBrowserTest { |
| 598 public: |
| 599 SitePerProcessEmbedderCSPEnforcementBrowserTest() {} |
| 600 |
| 601 protected: |
| 602 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 603 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| 604 // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes |
| 605 // stable |
| 606 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 607 "EmbedderCSPEnforcement"); |
| 608 } |
| 609 }; |
| 610 |
594 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { | 611 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
595 double device_scale_factor; | 612 double device_scale_factor; |
596 const char kGetFrameDeviceScaleFactor[] = | 613 const char kGetFrameDeviceScaleFactor[] = |
597 "window.domAutomationController.send(window.devicePixelRatio);"; | 614 "window.domAutomationController.send(window.devicePixelRatio);"; |
598 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, | 615 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, |
599 &device_scale_factor)); | 616 &device_scale_factor)); |
600 return device_scale_factor; | 617 return device_scale_factor; |
601 } | 618 } |
602 | 619 |
603 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, | 620 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3108 "window.domAutomationController.send(" | 3125 "window.domAutomationController.send(" |
3109 "document.body.getAttribute('marginheight'));", | 3126 "document.body.getAttribute('marginheight'));", |
3110 &actual_margin_height)); | 3127 &actual_margin_height)); |
3111 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); | 3128 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); |
3112 | 3129 |
3113 current_margin_width += 5; | 3130 current_margin_width += 5; |
3114 current_margin_height += 10; | 3131 current_margin_height += 10; |
3115 } | 3132 } |
3116 } | 3133 } |
3117 | 3134 |
| 3135 // Verify that "csp" property on frame elements propogates to child frames |
| 3136 // correctly. See https://crbug.com/647588 |
| 3137 IN_PROC_BROWSER_TEST_F(SitePerProcessEmbedderCSPEnforcementBrowserTest, |
| 3138 FrameOwnerPropertiesPropagationCSP) { |
| 3139 GURL main_url(embedded_test_server()->GetURL( |
| 3140 "a.com", "/frame_owner_properties_csp.html")); |
| 3141 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3142 |
| 3143 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3144 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3145 ASSERT_EQ(1u, root->child_count()); |
| 3146 |
| 3147 EXPECT_EQ( |
| 3148 " Site A ------------ proxies for B\n" |
| 3149 " +--Site B ------- proxies for A\n" |
| 3150 "Where A = http://a.com/\n" |
| 3151 " B = http://b.com/", |
| 3152 DepictFrameTree(root)); |
| 3153 |
| 3154 FrameTreeNode* child = root->child_at(0); |
| 3155 |
| 3156 std::string csp; |
| 3157 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3158 root, |
| 3159 "window.domAutomationController.send(" |
| 3160 "document.getElementById('child-1').getAttribute('csp'));", |
| 3161 &csp)); |
| 3162 EXPECT_EQ("object-src \'none\'", csp); |
| 3163 |
| 3164 // Run the test over variety of parent/child cases. |
| 3165 GURL urls[] = {// Remote to remote. |
| 3166 embedded_test_server()->GetURL("c.com", "/title2.html"), |
| 3167 // Remote to local. |
| 3168 embedded_test_server()->GetURL("a.com", "/title1.html"), |
| 3169 // Local to remote. |
| 3170 embedded_test_server()->GetURL("b.com", "/title2.html")}; |
| 3171 |
| 3172 std::vector<std::string> csp_values = {"default-src a.com", |
| 3173 "default-src b.com", "img-src c.com"}; |
| 3174 |
| 3175 // Before each navigation, we change the csp property of the frame. |
| 3176 // We then check whether that property is applied |
| 3177 // correctly after the navigation has completed. |
| 3178 for (size_t i = 0; i < arraysize(urls); ++i) { |
| 3179 // Change csp before navigating. |
| 3180 EXPECT_TRUE(ExecuteScript( |
| 3181 root, |
| 3182 base::StringPrintf("document.getElementById('child-1').setAttribute(" |
| 3183 " 'csp', '%s');", |
| 3184 csp_values[i].c_str()))); |
| 3185 |
| 3186 NavigateFrameToURL(child, urls[i]); |
| 3187 EXPECT_EQ(csp_values[i], child->frame_owner_properties().csp); |
| 3188 // TODO(amalika): add checks that the CSP replication takes effect |
| 3189 } |
| 3190 } |
| 3191 |
3118 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. | 3192 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. |
3119 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { | 3193 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
3120 GURL main_url(embedded_test_server()->GetURL( | 3194 GURL main_url(embedded_test_server()->GetURL( |
3121 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); | 3195 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); |
3122 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3196 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
3123 | 3197 |
3124 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3198 // It is safe to obtain the root frame tree node here, as it doesn't change. |
3125 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3199 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
3126 | 3200 |
3127 EXPECT_EQ( | 3201 EXPECT_EQ( |
(...skipping 5096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8224 " Site A ------------ proxies for B C\n" | 8298 " Site A ------------ proxies for B C\n" |
8225 " +--Site B ------- proxies for A C\n" | 8299 " +--Site B ------- proxies for A C\n" |
8226 " +--Site C -- proxies for A B\n" | 8300 " +--Site C -- proxies for A B\n" |
8227 "Where A = http://a.com/\n" | 8301 "Where A = http://a.com/\n" |
8228 " B = http://b.com/\n" | 8302 " B = http://b.com/\n" |
8229 " C = http://c.com/", | 8303 " C = http://c.com/", |
8230 DepictFrameTree(root)); | 8304 DepictFrameTree(root)); |
8231 } | 8305 } |
8232 | 8306 |
8233 } // namespace content | 8307 } // namespace content |
OLD | NEW |