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

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 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
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 8374 matching lines...) Expand 10 before | Expand all | Expand 10 after
9129 TestFeaturePolicyReplicationOnSameOriginNavigation) { 9128 TestFeaturePolicyReplicationOnSameOriginNavigation) {
9130 GURL start_url( 9129 GURL start_url(
9131 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 9130 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
9132 GURL first_nav_url( 9131 GURL first_nav_url(
9133 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); 9132 embedded_test_server()->GetURL("a.com", "/feature-policy2.html"));
9134 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); 9133 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html"));
9135 9134
9136 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 9135 EXPECT_TRUE(NavigateToURL(shell(), start_url));
9137 9136
9138 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9137 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9139 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), 9138 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9139 {start_url.GetOrigin()}),
9140 root->current_replication_state().feature_policy_header); 9140 root->current_replication_state().feature_policy_header);
9141 9141
9142 // When the main frame navigates to a page with a new policy, it should 9142 // When the main frame navigates to a page with a new policy, it should
9143 // overwrite the old one. 9143 // overwrite the old one.
9144 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 9144 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
9145 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), 9145 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9146 root->current_replication_state().feature_policy_header); 9146 root->current_replication_state().feature_policy_header);
9147 9147
9148 // When the main frame navigates to a page without a policy, the replicated 9148 // When the main frame navigates to a page without a policy, the replicated
9149 // policy header should be cleared. 9149 // policy header should be cleared.
9150 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 9150 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
9151 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); 9151 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
9152 } 9152 }
9153 9153
9154 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 9154 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9155 TestFeaturePolicyReplicationOnCrossOriginNavigation) { 9155 TestFeaturePolicyReplicationOnCrossOriginNavigation) {
9156 GURL start_url( 9156 GURL start_url(
9157 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 9157 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
9158 GURL first_nav_url( 9158 GURL first_nav_url(
9159 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 9159 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9160 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 9160 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
9161 9161
9162 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 9162 EXPECT_TRUE(NavigateToURL(shell(), start_url));
9163 9163
9164 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9164 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9165 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), 9165 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9166 {start_url.GetOrigin()}),
9166 root->current_replication_state().feature_policy_header); 9167 root->current_replication_state().feature_policy_header);
9167 9168
9168 // When the main frame navigates to a page with a new policy, it should 9169 // When the main frame navigates to a page with a new policy, it should
9169 // overwrite the old one. 9170 // overwrite the old one.
9170 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 9171 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
9171 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), 9172 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9172 root->current_replication_state().feature_policy_header); 9173 root->current_replication_state().feature_policy_header);
9173 9174
9174 // When the main frame navigates to a page without a policy, the replicated 9175 // When the main frame navigates to a page without a policy, the replicated
9175 // policy header should be cleared. 9176 // policy header should be cleared.
9176 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 9177 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
9177 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); 9178 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
9178 } 9179 }
9179 9180
9180 // Test that the replicated feature policy header is correct in subframes as 9181 // Test that the replicated feature policy header is correct in subframes as
9181 // they navigate. 9182 // they navigate.
9182 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 9183 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9183 TestFeaturePolicyReplicationFromRemoteFrames) { 9184 TestFeaturePolicyReplicationFromRemoteFrames) {
9184 GURL main_url( 9185 GURL main_url(
9185 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); 9186 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html"));
9186 GURL first_nav_url( 9187 GURL first_nav_url(
9187 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 9188 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9188 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 9189 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
9189 9190
9190 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 9191 EXPECT_TRUE(NavigateToURL(shell(), main_url));
9191 9192
9192 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 9193 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9193 EXPECT_EQ(CreateFPHeader("vibrate", 9194 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9194 {main_url.GetOrigin(), GURL("http://example.com/")}), 9195 {main_url.GetOrigin(), GURL("http://example.com/")}),
9195 root->current_replication_state().feature_policy_header); 9196 root->current_replication_state().feature_policy_header);
9196 EXPECT_EQ(1UL, root->child_count()); 9197 EXPECT_EQ(1UL, root->child_count());
9197 EXPECT_EQ( 9198 EXPECT_EQ(
9198 CreateFPHeader("vibrate", {main_url.GetOrigin()}), 9199 CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate,
9200 {main_url.GetOrigin()}),
9199 root->child_at(0)->current_replication_state().feature_policy_header); 9201 root->child_at(0)->current_replication_state().feature_policy_header);
9200 9202
9201 // Navigate the iframe cross-site. 9203 // Navigate the iframe cross-site.
9202 NavigateFrameToURL(root->child_at(0), first_nav_url); 9204 NavigateFrameToURL(root->child_at(0), first_nav_url);
9203 EXPECT_EQ( 9205 EXPECT_EQ(
9204 CreateFPHeaderMatchesAll("vibrate"), 9206 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9205 root->child_at(0)->current_replication_state().feature_policy_header); 9207 root->child_at(0)->current_replication_state().feature_policy_header);
9206 9208
9207 // Navigate the iframe to another location, this one with no policy header 9209 // Navigate the iframe to another location, this one with no policy header
9208 NavigateFrameToURL(root->child_at(0), second_nav_url); 9210 NavigateFrameToURL(root->child_at(0), second_nav_url);
9209 EXPECT_TRUE(root->child_at(0) 9211 EXPECT_TRUE(root->child_at(0)
9210 ->current_replication_state() 9212 ->current_replication_state()
9211 .feature_policy_header.empty()); 9213 .feature_policy_header.empty());
9212 9214
9213 // Navigate the iframe back to a page with a policy 9215 // Navigate the iframe back to a page with a policy
9214 NavigateFrameToURL(root->child_at(0), first_nav_url); 9216 NavigateFrameToURL(root->child_at(0), first_nav_url);
9215 EXPECT_EQ( 9217 EXPECT_EQ(
9216 CreateFPHeaderMatchesAll("vibrate"), 9218 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate),
9217 root->child_at(0)->current_replication_state().feature_policy_header); 9219 root->child_at(0)->current_replication_state().feature_policy_header);
9218 } 9220 }
9219 9221
9220 // Ensure that an iframe that navigates cross-site doesn't use the same process 9222 // Ensure that an iframe that navigates cross-site doesn't use the same process
9221 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, 9223 // as its parent. Then when its parent navigates it via the "srcdoc" attribute,
9222 // it must reuse its parent's process. 9224 // it must reuse its parent's process.
9223 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 9225 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
9224 IframeSrcdocAfterCrossSiteNavigation) { 9226 IframeSrcdocAfterCrossSiteNavigation) {
9225 GURL parent_url(embedded_test_server()->GetURL( 9227 GURL parent_url(embedded_test_server()->GetURL(
9226 "a.com", "/cross_site_iframe_factory.html?a(b)")); 9228 "a.com", "/cross_site_iframe_factory.html?a(b)"));
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
9841 9843
9842 // Try the same navigation, but use the browser-initiated path. 9844 // Try the same navigation, but use the browser-initiated path.
9843 NavigateFrameToURL(root->child_at(0), frame_url); 9845 NavigateFrameToURL(root->child_at(0), frame_url);
9844 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); 9846 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host());
9845 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); 9847 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url);
9846 EXPECT_EQ(b_site_instance, 9848 EXPECT_EQ(b_site_instance,
9847 root->child_at(0)->current_frame_host()->GetSiteInstance()); 9849 root->child_at(0)->current_frame_host()->GetSiteInstance());
9848 } 9850 }
9849 9851
9850 } // namespace content 9852 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/feature_policy/feature_policy_platform.cc » ('j') | content/common/feature_policy/feature_policy.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698