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

Side by Side Diff: third_party/WebKit/Source/platform/feature_policy/FeaturePolicyTest.cpp

Issue 2767983003: Initial Implementation of Iframe Attribute for Feature Policy (Part 4) (Closed)
Patch Set: Codereview: nit + added more unit tests for container policy Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/feature_policy/FeaturePolicy.h" 5 #include "platform/feature_policy/FeaturePolicy.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 // Origin strings used for tests 10 // Origin strings used for tests
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, parsed_policy[2].feature); 120 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, parsed_policy[2].feature);
121 EXPECT_FALSE(parsed_policy[2].matches_all_origins); 121 EXPECT_FALSE(parsed_policy[2].matches_all_origins);
122 EXPECT_EQ(1UL, parsed_policy[2].origins.size()); 122 EXPECT_EQ(1UL, parsed_policy[2].origins.size());
123 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( 123 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
124 parsed_policy[2].origins[0].Get())); 124 parsed_policy[2].origins[0].Get()));
125 } 125 }
126 126
127 TEST_F(FeaturePolicyTest, ParseEmptyContainerPolicy) { 127 TEST_F(FeaturePolicyTest, ParseEmptyContainerPolicy) {
128 WebParsedFeaturePolicy container_policy = 128 WebParsedFeaturePolicy container_policy =
129 GetContainerPolicyFromAllowedFeatures( 129 GetContainerPolicyFromAllowedFeatures(
130 std::vector<WebFeaturePolicyFeature>({}), origin_a_.Get()); 130 std::vector<WebFeaturePolicyFeature>({}), false, false,
131 origin_a_.Get());
131 EXPECT_EQ(0UL, container_policy.size()); 132 EXPECT_EQ(0UL, container_policy.size());
132 } 133 }
133 134
134 TEST_F(FeaturePolicyTest, ParseContainerPolicy) { 135 TEST_F(FeaturePolicyTest, ParseContainerPolicy) {
135 WebParsedFeaturePolicy container_policy = 136 WebParsedFeaturePolicy container_policy =
136 GetContainerPolicyFromAllowedFeatures( 137 GetContainerPolicyFromAllowedFeatures(
137 std::vector<WebFeaturePolicyFeature>( 138 std::vector<WebFeaturePolicyFeature>(
138 {WebFeaturePolicyFeature::kVibrate, 139 {WebFeaturePolicyFeature::kVibrate,
139 WebFeaturePolicyFeature::kPayment}), 140 WebFeaturePolicyFeature::kPayment}),
140 origin_a_.Get()); 141 false, false, origin_a_.Get());
141 EXPECT_EQ(2UL, container_policy.size()); 142 EXPECT_EQ(2UL, container_policy.size());
142 EXPECT_EQ(WebFeaturePolicyFeature::kVibrate, container_policy[0].feature); 143 EXPECT_EQ(WebFeaturePolicyFeature::kVibrate, container_policy[0].feature);
143 EXPECT_FALSE(container_policy[0].matches_all_origins); 144 EXPECT_FALSE(container_policy[0].matches_all_origins);
145 EXPECT_EQ(1UL, container_policy[0].origins.size());
146 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
147 container_policy[0].origins[0].Get()));
148 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature);
149 EXPECT_FALSE(container_policy[1].matches_all_origins);
150 EXPECT_EQ(1UL, container_policy[1].origins.size());
151 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
152 container_policy[1].origins[0].Get()));
153 }
154
155 TEST_F(FeaturePolicyTest, ParseContainerPolicyWithAllowFullscreen) {
156 WebParsedFeaturePolicy container_policy =
157 GetContainerPolicyFromAllowedFeatures(
158 std::vector<WebFeaturePolicyFeature>({}), true, false,
159 origin_a_.Get());
160 EXPECT_EQ(1UL, container_policy.size());
161 EXPECT_EQ(WebFeaturePolicyFeature::kFullscreen, container_policy[0].feature);
162 EXPECT_TRUE(container_policy[0].matches_all_origins);
163 }
164
165 TEST_F(FeaturePolicyTest, ParseContainerPolicyWithAllowPaymentRequest) {
166 WebParsedFeaturePolicy container_policy =
167 GetContainerPolicyFromAllowedFeatures(
168 std::vector<WebFeaturePolicyFeature>(
169 {WebFeaturePolicyFeature::kVibrate}),
170 false, true, origin_a_.Get());
171 EXPECT_EQ(2UL, container_policy.size());
172 EXPECT_EQ(WebFeaturePolicyFeature::kVibrate, container_policy[0].feature);
173 EXPECT_FALSE(container_policy[0].matches_all_origins);
144 EXPECT_EQ(1UL, container_policy[0].origins.size()); 174 EXPECT_EQ(1UL, container_policy[0].origins.size());
145 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( 175 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
146 container_policy[0].origins[0].Get())); 176 container_policy[0].origins[0].Get()));
147 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature); 177 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature);
178 EXPECT_TRUE(container_policy[1].matches_all_origins);
179 }
180
181 TEST_F(FeaturePolicyTest, ParseContainerPolicyWithAllowAttributes) {
182 WebParsedFeaturePolicy container_policy =
183 GetContainerPolicyFromAllowedFeatures(
184 std::vector<WebFeaturePolicyFeature>(
185 {WebFeaturePolicyFeature::kVibrate,
186 WebFeaturePolicyFeature::kPayment}),
187 true, true, origin_a_.Get());
188 EXPECT_EQ(3UL, container_policy.size());
189 EXPECT_EQ(WebFeaturePolicyFeature::kVibrate, container_policy[0].feature);
190 EXPECT_FALSE(container_policy[0].matches_all_origins);
191 EXPECT_EQ(1UL, container_policy[0].origins.size());
192 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
193 container_policy[0].origins[0].Get()));
194 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature);
148 EXPECT_FALSE(container_policy[1].matches_all_origins); 195 EXPECT_FALSE(container_policy[1].matches_all_origins);
149 EXPECT_EQ(1UL, container_policy[1].origins.size()); 196 EXPECT_EQ(1UL, container_policy[1].origins.size());
150 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( 197 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin(
151 container_policy[1].origins[0].Get())); 198 container_policy[1].origins[0].Get()));
199 EXPECT_EQ(WebFeaturePolicyFeature::kFullscreen, container_policy[2].feature);
200 EXPECT_TRUE(container_policy[2].matches_all_origins);
152 } 201 }
153 202
154 } // namespace blink 203 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698