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

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

Issue 2727803004: Replace string by enum in WebParsedFeaturePolicyDeclaration#feature (Closed)
Patch Set: Codereview: nit -- add comments to introduce features Created 3 years, 9 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/child/feature_policy/feature_policy_platform.cc » ('j') | no next file with comments »
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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 709
710 protected: 710 protected:
711 void SetUpCommandLine(base::CommandLine* command_line) override { 711 void SetUpCommandLine(base::CommandLine* command_line) override {
712 SitePerProcessBrowserTest::SetUpCommandLine(command_line); 712 SitePerProcessBrowserTest::SetUpCommandLine(command_line);
713 // TODO(iclelland): Remove this switch when Feature Policy ships. 713 // TODO(iclelland): Remove this switch when Feature Policy ships.
714 // https://crbug.com/623682 714 // https://crbug.com/623682
715 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, 715 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
716 "FeaturePolicy"); 716 "FeaturePolicy");
717 } 717 }
718 718
719 ParsedFeaturePolicyHeader CreateFPHeader(const std::string& feature_name, 719 ParsedFeaturePolicyHeader CreateFPHeader(
720 const std::vector<GURL>& origins) { 720 blink::WebFeaturePolicyFeature feature,
721 const std::vector<GURL>& origins) {
721 ParsedFeaturePolicyHeader result(1); 722 ParsedFeaturePolicyHeader result(1);
722 result[0].feature_name = feature_name; 723 result[0].feature = feature;
723 result[0].matches_all_origins = false; 724 result[0].matches_all_origins = false;
724 DCHECK(!origins.empty()); 725 DCHECK(!origins.empty());
725 for (const GURL& origin : origins) 726 for (const GURL& origin : origins)
726 result[0].origins.push_back(url::Origin(origin)); 727 result[0].origins.push_back(url::Origin(origin));
727 return result; 728 return result;
728 } 729 }
729 730
730 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( 731 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll(
731 const std::string& feature_name) { 732 blink::WebFeaturePolicyFeature feature) {
732 ParsedFeaturePolicyHeader result(1); 733 ParsedFeaturePolicyHeader result(1);
733 result[0].feature_name = feature_name; 734 result[0].feature = feature;
734 result[0].matches_all_origins = true; 735 result[0].matches_all_origins = true;
735 return result; 736 return result;
736 } 737 }
737 }; 738 };
738 739
739 bool operator==(const ParsedFeaturePolicyDeclaration& first, 740 bool operator==(const ParsedFeaturePolicyDeclaration& first,
740 const ParsedFeaturePolicyDeclaration& second) { 741 const ParsedFeaturePolicyDeclaration& second) {
741 return std::tie(first.feature_name, first.matches_all_origins, 742 return std::tie(first.feature, first.matches_all_origins, first.origins) ==
742 first.origins) == std::tie(second.feature_name, 743 std::tie(second.feature, second.matches_all_origins, second.origins);
743 second.matches_all_origins,
744 second.origins);
745 } 744 }
746 745
747 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, 746 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest,
748 SubframeLoadsWithCorrectDeviceScaleFactor) { 747 SubframeLoadsWithCorrectDeviceScaleFactor) {
749 GURL main_url(embedded_test_server()->GetURL( 748 GURL main_url(embedded_test_server()->GetURL(
750 "a.com", "/cross_site_iframe_factory.html?a(b)")); 749 "a.com", "/cross_site_iframe_factory.html?a(b)"));
751 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 750 EXPECT_TRUE(NavigateToURL(shell(), main_url));
752 751
753 // On Android forcing device scale factor does not work for tests, therefore 752 // On Android forcing device scale factor does not work for tests, therefore
754 // we ensure that make frame and iframe have the same DIP scale there, but 753 // we ensure that make frame and iframe have the same DIP scale there, but
(...skipping 8428 matching lines...) Expand 10 before | Expand all | Expand 10 after
9183 TestFeaturePolicyReplicationOnSameOriginNavigation) { 9182 TestFeaturePolicyReplicationOnSameOriginNavigation) {
9184 GURL start_url( 9183 GURL start_url(
9185 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 9184 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
9186 GURL first_nav_url( 9185 GURL first_nav_url(
9187 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); 9186 embedded_test_server()->GetURL("a.com", "/feature-policy2.html"));
9188 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); 9187 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html"));
9189 9188
9190 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 9189 EXPECT_TRUE(NavigateToURL(shell(), start_url));
9191 9190
9192 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9191 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9193 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), 9192 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9193 {start_url.GetOrigin()}),
9194 root->current_replication_state().feature_policy_header); 9194 root->current_replication_state().feature_policy_header);
9195 9195
9196 // When the main frame navigates to a page with a new policy, it should 9196 // When the main frame navigates to a page with a new policy, it should
9197 // overwrite the old one. 9197 // overwrite the old one.
9198 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 9198 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
9199 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), 9199 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9200 root->current_replication_state().feature_policy_header); 9200 root->current_replication_state().feature_policy_header);
9201 9201
9202 // When the main frame navigates to a page without a policy, the replicated 9202 // When the main frame navigates to a page without a policy, the replicated
9203 // policy header should be cleared. 9203 // policy header should be cleared.
9204 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 9204 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
9205 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); 9205 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
9206 } 9206 }
9207 9207
9208 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 9208 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9209 TestFeaturePolicyReplicationOnCrossOriginNavigation) { 9209 TestFeaturePolicyReplicationOnCrossOriginNavigation) {
9210 GURL start_url( 9210 GURL start_url(
9211 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 9211 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
9212 GURL first_nav_url( 9212 GURL first_nav_url(
9213 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 9213 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9214 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 9214 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
9215 9215
9216 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 9216 EXPECT_TRUE(NavigateToURL(shell(), start_url));
9217 9217
9218 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9218 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9219 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), 9219 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9220 {start_url.GetOrigin()}),
9220 root->current_replication_state().feature_policy_header); 9221 root->current_replication_state().feature_policy_header);
9221 9222
9222 // When the main frame navigates to a page with a new policy, it should 9223 // When the main frame navigates to a page with a new policy, it should
9223 // overwrite the old one. 9224 // overwrite the old one.
9224 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 9225 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
9225 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), 9226 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9226 root->current_replication_state().feature_policy_header); 9227 root->current_replication_state().feature_policy_header);
9227 9228
9228 // When the main frame navigates to a page without a policy, the replicated 9229 // When the main frame navigates to a page without a policy, the replicated
9229 // policy header should be cleared. 9230 // policy header should be cleared.
9230 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 9231 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
9231 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); 9232 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
9232 } 9233 }
9233 9234
9234 // Test that the replicated feature policy header is correct in subframes as 9235 // Test that the replicated feature policy header is correct in subframes as
9235 // they navigate. 9236 // they navigate.
9236 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 9237 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9237 TestFeaturePolicyReplicationFromRemoteFrames) { 9238 TestFeaturePolicyReplicationFromRemoteFrames) {
9238 GURL main_url( 9239 GURL main_url(
9239 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); 9240 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html"));
9240 GURL first_nav_url( 9241 GURL first_nav_url(
9241 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 9242 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9242 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 9243 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
9243 9244
9244 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 9245 EXPECT_TRUE(NavigateToURL(shell(), main_url));
9245 9246
9246 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9247 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9247 EXPECT_EQ(CreateFPHeader("vibrate", 9248 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9248 {main_url.GetOrigin(), GURL("http://example.com/")}), 9249 {main_url.GetOrigin(), GURL("http://example.com/")}),
9249 root->current_replication_state().feature_policy_header); 9250 root->current_replication_state().feature_policy_header);
9250 EXPECT_EQ(1UL, root->child_count()); 9251 EXPECT_EQ(1UL, root->child_count());
9251 EXPECT_EQ( 9252 EXPECT_EQ(
9252 CreateFPHeader("vibrate", {main_url.GetOrigin()}), 9253 CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9254 {main_url.GetOrigin()}),
9253 root->child_at(0)->current_replication_state().feature_policy_header); 9255 root->child_at(0)->current_replication_state().feature_policy_header);
9254 9256
9255 // Navigate the iframe cross-site. 9257 // Navigate the iframe cross-site.
9256 NavigateFrameToURL(root->child_at(0), first_nav_url); 9258 NavigateFrameToURL(root->child_at(0), first_nav_url);
9257 EXPECT_EQ( 9259 EXPECT_EQ(
9258 CreateFPHeaderMatchesAll("vibrate"), 9260 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9259 root->child_at(0)->current_replication_state().feature_policy_header); 9261 root->child_at(0)->current_replication_state().feature_policy_header);
9260 9262
9261 // Navigate the iframe to another location, this one with no policy header 9263 // Navigate the iframe to another location, this one with no policy header
9262 NavigateFrameToURL(root->child_at(0), second_nav_url); 9264 NavigateFrameToURL(root->child_at(0), second_nav_url);
9263 EXPECT_TRUE(root->child_at(0) 9265 EXPECT_TRUE(root->child_at(0)
9264 ->current_replication_state() 9266 ->current_replication_state()
9265 .feature_policy_header.empty()); 9267 .feature_policy_header.empty());
9266 9268
9267 // Navigate the iframe back to a page with a policy 9269 // Navigate the iframe back to a page with a policy
9268 NavigateFrameToURL(root->child_at(0), first_nav_url); 9270 NavigateFrameToURL(root->child_at(0), first_nav_url);
9269 EXPECT_EQ( 9271 EXPECT_EQ(
9270 CreateFPHeaderMatchesAll("vibrate"), 9272 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9271 root->child_at(0)->current_replication_state().feature_policy_header); 9273 root->child_at(0)->current_replication_state().feature_policy_header);
9272 } 9274 }
9273 9275
9274 // Ensure that an iframe that navigates cross-site doesn't use the same process 9276 // Ensure that an iframe that navigates cross-site doesn't use the same process
9275 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, 9277 // as its parent. Then when its parent navigates it via the "srcdoc" attribute,
9276 // it must reuse its parent's process. 9278 // it must reuse its parent's process.
9277 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 9279 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
9278 IframeSrcdocAfterCrossSiteNavigation) { 9280 IframeSrcdocAfterCrossSiteNavigation) {
9279 GURL parent_url(embedded_test_server()->GetURL( 9281 GURL parent_url(embedded_test_server()->GetURL(
9280 "a.com", "/cross_site_iframe_factory.html?a(b)")); 9282 "a.com", "/cross_site_iframe_factory.html?a(b)"));
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
9895 9897
9896 // Try the same navigation, but use the browser-initiated path. 9898 // Try the same navigation, but use the browser-initiated path.
9897 NavigateFrameToURL(root->child_at(0), frame_url); 9899 NavigateFrameToURL(root->child_at(0), frame_url);
9898 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); 9900 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host());
9899 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); 9901 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url);
9900 EXPECT_EQ(b_site_instance, 9902 EXPECT_EQ(b_site_instance,
9901 root->child_at(0)->current_frame_host()->GetSiteInstance()); 9903 root->child_at(0)->current_frame_host()->GetSiteInstance());
9902 } 9904 }
9903 9905
9904 } // namespace content 9906 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/feature_policy/feature_policy_platform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698