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

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

Issue 2378643002: Propagating csp attribute changes on frameOwnerPropertiesChanged() (Closed)
Patch Set: Enable Experimental switch Created 4 years, 2 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
« no previous file with comments | « no previous file | content/common/frame_messages.h » ('j') | content/common/frame_owner_properties.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->AppendSwitch(
556 switches::kEnableExperimentalWebPlatformFeatures);
Mike West 2016/09/29 08:58:53 Hrm. This might be an argument for pushing the CSP
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 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 for (size_t i = 0; i < arraysize(scrolling_values); ++i) { 3024 for (size_t i = 0; i < arraysize(scrolling_values); ++i) {
3020 bool expect_scrollbar = scrolling_values[i] != "no"; 3025 bool expect_scrollbar = scrolling_values[i] != "no";
3021 set_scrolling_property(root->current_frame_host(), scrolling_values[i]); 3026 set_scrolling_property(root->current_frame_host(), scrolling_values[i]);
3022 for (size_t j = 0; j < arraysize(urls); ++j) { 3027 for (size_t j = 0; j < arraysize(urls); ++j) {
3023 NavigateFrameToURL(child, urls[j]); 3028 NavigateFrameToURL(child, urls[j]);
3024 EXPECT_EQ(expect_scrollbar, has_scrollbar(child->current_frame_host())); 3029 EXPECT_EQ(expect_scrollbar, has_scrollbar(child->current_frame_host()));
3025 } 3030 }
3026 } 3031 }
3027 } 3032 }
3028 3033
3029 // Verify that "marginwidth" and "marginheight" properties on frame elements 3034 // Verify that "marginwidth","marginheight" and "csp" properties on frame
3035 // elements
3030 // propagate to child frames correctly. 3036 // propagate to child frames correctly.
3031 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 3037 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
3032 FrameOwnerPropertiesPropagationMargin) { 3038 FrameOwnerPropertiesPropagationMarginAndCSP) {
3033 GURL main_url(embedded_test_server()->GetURL( 3039 GURL main_url(embedded_test_server()->GetURL(
3034 "a.com", "/frame_owner_properties_margin.html")); 3040 "a.com", "/frame_owner_properties_margin_and_csp.html"));
3035 NavigateToURL(shell(), main_url); 3041 NavigateToURL(shell(), main_url);
3036 3042
3037 // It is safe to obtain the root frame tree node here, as it doesn't change. 3043 // It is safe to obtain the root frame tree node here, as it doesn't change.
3038 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 3044 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
3039 ASSERT_EQ(1u, root->child_count()); 3045 ASSERT_EQ(1u, root->child_count());
3040 3046
3041 EXPECT_EQ( 3047 EXPECT_EQ(
3042 " Site A ------------ proxies for B\n" 3048 " Site A ------------ proxies for B\n"
3043 " +--Site B ------- proxies for A\n" 3049 " +--Site B ------- proxies for A\n"
3044 "Where A = http://a.com/\n" 3050 "Where A = http://a.com/\n"
(...skipping 11 matching lines...) Expand all
3056 EXPECT_EQ("10", margin_width); 3062 EXPECT_EQ("10", margin_width);
3057 3063
3058 std::string margin_height; 3064 std::string margin_height;
3059 EXPECT_TRUE(ExecuteScriptAndExtractString( 3065 EXPECT_TRUE(ExecuteScriptAndExtractString(
3060 child, 3066 child,
3061 "window.domAutomationController.send(" 3067 "window.domAutomationController.send("
3062 "document.body.getAttribute('marginheight'));", 3068 "document.body.getAttribute('marginheight'));",
3063 &margin_height)); 3069 &margin_height));
3064 EXPECT_EQ("50", margin_height); 3070 EXPECT_EQ("50", margin_height);
3065 3071
3072 std::string csp;
3073 EXPECT_TRUE(ExecuteScriptAndExtractString(
3074 root,
3075 "window.domAutomationController.send("
3076 "document.getElementById('child-1').getAttribute('csp'));",
3077 &csp));
3078 EXPECT_EQ("object-src none", csp);
3079
3066 // Run the test over variety of parent/child cases. 3080 // Run the test over variety of parent/child cases.
3067 GURL urls[] = { 3081 GURL urls[] = {
3068 // Remote to remote. 3082 // Remote to remote.
3069 embedded_test_server()->GetURL("c.com", "/title2.html"), 3083 embedded_test_server()->GetURL("c.com", "/title2.html"),
3070 // Remote to local. 3084 // Remote to local.
3071 embedded_test_server()->GetURL("a.com", "/title1.html"), 3085 embedded_test_server()->GetURL("a.com", "/title1.html"),
3072 // Local to remote. 3086 // Local to remote.
3073 embedded_test_server()->GetURL("b.com", "/title2.html") 3087 embedded_test_server()->GetURL("b.com", "/title2.html")
3074 }; 3088 };
3075 3089
3076 int current_margin_width = 15; 3090 std::vector<std::string> csp_values = {"default-src a.com",
3077 int current_margin_height = 25; 3091 "default-src b.com", "img-src none"};
3092 std::string current_csp;
3093 int current_margin_width = 10;
3094 int current_margin_height = 50;
Mike West 2016/09/29 08:58:53 Why did the margins change?
3078 3095
3079 // Before each navigation, we change the marginwidth and marginheight 3096 // Before each navigation, we change the marginwidth, marginheight and csp
Mike West 2016/09/29 08:58:53 Nit: Oxford comma (e.g. "x, y, and z")
3080 // properties of the frame. We then check whether those properties are applied 3097 // properties of the frame. We then check whether those properties are applied
3081 // correctly after the navigation has completed. 3098 // correctly after the navigation has completed.
3082 for (size_t i = 0; i < arraysize(urls); ++i) { 3099 for (size_t i = 0; i < arraysize(urls); ++i) {
3083 // Change marginwidth and marginheight before navigating. 3100 current_csp = csp_values[i];
3101 current_margin_width += 5;
3102 current_margin_height += 10;
3103
3104 // Change marginwidth, marginheight, and csp before navigating.
Mike West 2016/09/29 08:58:53 Nit: Move this before the assignments above.
3084 EXPECT_TRUE(ExecuteScript( 3105 EXPECT_TRUE(ExecuteScript(
3085 root, 3106 root,
3086 base::StringPrintf("document.getElementById('child-1').setAttribute(" 3107 base::StringPrintf("document.getElementById('child-1').setAttribute("
3108 " 'csp', '%s');",
3109 current_csp.c_str())));
3110 EXPECT_TRUE(ExecuteScript(
3111 root,
3112 base::StringPrintf("document.getElementById('child-1').setAttribute("
3087 " 'marginwidth', '%d');", 3113 " 'marginwidth', '%d');",
3088 current_margin_width))); 3114 current_margin_width)));
3089 EXPECT_TRUE(ExecuteScript( 3115 EXPECT_TRUE(ExecuteScript(
3090 root, 3116 root,
3091 base::StringPrintf("document.getElementById('child-1').setAttribute(" 3117 base::StringPrintf("document.getElementById('child-1').setAttribute("
3092 " 'marginheight', '%d');", 3118 " 'marginheight', '%d');",
3093 current_margin_height))); 3119 current_margin_height)));
3094 3120
3095 NavigateFrameToURL(child, urls[i]); 3121 NavigateFrameToURL(child, urls[i]);
3096 3122
3123 EXPECT_EQ(current_csp, child->frame_owner_properties().csp);
3124
3097 std::string actual_margin_width; 3125 std::string actual_margin_width;
3098 EXPECT_TRUE(ExecuteScriptAndExtractString( 3126 EXPECT_TRUE(ExecuteScriptAndExtractString(
3099 child, 3127 child,
3100 "window.domAutomationController.send(" 3128 "window.domAutomationController.send("
3101 "document.body.getAttribute('marginwidth'));", 3129 "document.body.getAttribute('marginwidth'));",
3102 &actual_margin_width)); 3130 &actual_margin_width));
3103 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width); 3131 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width);
3104 3132
3105 std::string actual_margin_height; 3133 std::string actual_margin_height;
3106 EXPECT_TRUE(ExecuteScriptAndExtractString( 3134 EXPECT_TRUE(ExecuteScriptAndExtractString(
3107 child, 3135 child,
3108 "window.domAutomationController.send(" 3136 "window.domAutomationController.send("
3109 "document.body.getAttribute('marginheight'));", 3137 "document.body.getAttribute('marginheight'));",
3110 &actual_margin_height)); 3138 &actual_margin_height));
3111 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); 3139 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height);
3112
3113 current_margin_width += 5;
3114 current_margin_height += 10;
3115 } 3140 }
3116 } 3141 }
3117 3142
3118 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. 3143 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy.
3119 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { 3144 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) {
3120 GURL main_url(embedded_test_server()->GetURL( 3145 GURL main_url(embedded_test_server()->GetURL(
3121 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); 3146 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)"));
3122 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 3147 EXPECT_TRUE(NavigateToURL(shell(), main_url));
3123 3148
3124 // It is safe to obtain the root frame tree node here, as it doesn't change. 3149 // It is safe to obtain the root frame tree node here, as it doesn't change.
(...skipping 5099 matching lines...) Expand 10 before | Expand all | Expand 10 after
8224 " Site A ------------ proxies for B C\n" 8249 " Site A ------------ proxies for B C\n"
8225 " +--Site B ------- proxies for A C\n" 8250 " +--Site B ------- proxies for A C\n"
8226 " +--Site C -- proxies for A B\n" 8251 " +--Site C -- proxies for A B\n"
8227 "Where A = http://a.com/\n" 8252 "Where A = http://a.com/\n"
8228 " B = http://b.com/\n" 8253 " B = http://b.com/\n"
8229 " C = http://c.com/", 8254 " C = http://c.com/",
8230 DepictFrameTree(root)); 8255 DepictFrameTree(root));
8231 } 8256 }
8232 8257
8233 } // namespace content 8258 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/frame_messages.h » ('j') | content/common/frame_owner_properties.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698