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

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

Issue 2520223002: Replicate a parsed feature policy representation so it doesn't need to be parsed in the browser pro… (Closed)
Patch Set: Fp2 Created 4 years 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // have at least one of each kind of default behaviour represented. 82 // have at least one of each kind of default behaviour represented.
83 FeaturePolicy::FeatureList m_featureList; 83 FeaturePolicy::FeatureList m_featureList;
84 }; 84 };
85 85
86 TEST_F(FeaturePolicyTest, ParseValidPolicy) { 86 TEST_F(FeaturePolicyTest, ParseValidPolicy) {
87 Vector<String> messages; 87 Vector<String> messages;
88 for (const char* policyString : kValidPolicies) { 88 for (const char* policyString : kValidPolicies) {
89 messages.clear(); 89 messages.clear();
90 std::unique_ptr<FeaturePolicy> policy = 90 std::unique_ptr<FeaturePolicy> policy =
91 createFromParentPolicy(nullptr, m_originA); 91 createFromParentPolicy(nullptr, m_originA);
92 policy->setHeaderPolicy(policyString, &messages); 92 policy->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
93 policyString, m_originA.get(), &messages));
93 EXPECT_EQ(0UL, messages.size()); 94 EXPECT_EQ(0UL, messages.size());
94 } 95 }
95 } 96 }
96 97
97 TEST_F(FeaturePolicyTest, ParseInvalidPolicy) { 98 TEST_F(FeaturePolicyTest, ParseInvalidPolicy) {
98 Vector<String> messages; 99 Vector<String> messages;
99 for (const char* policyString : kInvalidPolicies) { 100 for (const char* policyString : kInvalidPolicies) {
100 messages.clear(); 101 messages.clear();
101 std::unique_ptr<FeaturePolicy> policy = 102 std::unique_ptr<FeaturePolicy> policy =
102 createFromParentPolicy(nullptr, m_originA); 103 createFromParentPolicy(nullptr, m_originA);
103 policy->setHeaderPolicy(policyString, &messages); 104 policy->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
105 policyString, m_originA.get(), &messages));
104 EXPECT_NE(0UL, messages.size()); 106 EXPECT_NE(0UL, messages.size());
105 } 107 }
106 } 108 }
107 109
108 TEST_F(FeaturePolicyTest, TestInitialPolicy) { 110 TEST_F(FeaturePolicyTest, TestInitialPolicy) {
109 // +-------------+ 111 // +-------------+
110 // |(1)Origin A | 112 // |(1)Origin A |
111 // |No Policy | 113 // |No Policy |
112 // +-------------+ 114 // +-------------+
113 // Default-on and top-level-only features should be enabled in top-level 115 // Default-on and top-level-only features should be enabled in top-level
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // | |Policy: {"default-self": ["self"]} | | 170 // | |Policy: {"default-self": ["self"]} | |
169 // | +-----------------------------------+ | 171 // | +-----------------------------------+ |
170 // +---------------------------------------+ 172 // +---------------------------------------+
171 // Default-self feature should be disabled in cross origin frame, even if no 173 // Default-self feature should be disabled in cross origin frame, even if no
172 // policy was specified in the parent frame. 174 // policy was specified in the parent frame.
173 Vector<String> messages; 175 Vector<String> messages;
174 std::unique_ptr<FeaturePolicy> policy1 = 176 std::unique_ptr<FeaturePolicy> policy1 =
175 createFromParentPolicy(nullptr, m_originA); 177 createFromParentPolicy(nullptr, m_originA);
176 std::unique_ptr<FeaturePolicy> policy2 = 178 std::unique_ptr<FeaturePolicy> policy2 =
177 createFromParentPolicy(policy1.get(), m_originB); 179 createFromParentPolicy(policy1.get(), m_originB);
178 policy2->setHeaderPolicy("{\"default-self\": [\"self\"]}", &messages); 180 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
181 "{\"default-self\": [\"self\"]}", m_originB.get(), &messages));
179 EXPECT_EQ(0UL, messages.size()); 182 EXPECT_EQ(0UL, messages.size());
180 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 183 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature));
181 } 184 }
182 185
183 TEST_F(FeaturePolicyTest, TestFrameSelfInheritance) { 186 TEST_F(FeaturePolicyTest, TestFrameSelfInheritance) {
184 // +------------------------------------------+ 187 // +------------------------------------------+
185 // |(1) Origin A | 188 // |(1) Origin A |
186 // |Policy: {"default-self": ["self"]} | 189 // |Policy: {"default-self": ["self"]} |
187 // | +-----------------+ +-----------------+ | 190 // | +-----------------+ +-----------------+ |
188 // | |(2) Origin A | |(4) Origin B | | 191 // | |(2) Origin A | |(4) Origin B | |
189 // | |No Policy | |No Policy | | 192 // | |No Policy | |No Policy | |
190 // | | +-------------+ | | +-------------+ | | 193 // | | +-------------+ | | +-------------+ | |
191 // | | |(3)Origin A | | | |(5)Origin B | | | 194 // | | |(3)Origin A | | | |(5)Origin B | | |
192 // | | |No Policy | | | |No Policy | | | 195 // | | |No Policy | | | |No Policy | | |
193 // | | +-------------+ | | +-------------+ | | 196 // | | +-------------+ | | +-------------+ | |
194 // | +-----------------+ +-----------------+ | 197 // | +-----------------+ +-----------------+ |
195 // +------------------------------------------+ 198 // +------------------------------------------+
196 // Feature should be enabled at the top-level, and through the chain of 199 // Feature should be enabled at the top-level, and through the chain of
197 // same-origin frames 2 and 3. It should be disabled in frames 4 and 5, as 200 // same-origin frames 2 and 3. It should be disabled in frames 4 and 5, as
198 // they are at a different origin. 201 // they are at a different origin.
199 Vector<String> messages; 202 Vector<String> messages;
200 std::unique_ptr<FeaturePolicy> policy1 = 203 std::unique_ptr<FeaturePolicy> policy1 =
201 createFromParentPolicy(nullptr, m_originA); 204 createFromParentPolicy(nullptr, m_originA);
202 policy1->setHeaderPolicy("{\"default-self\": [\"self\"]}", &messages); 205 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
206 "{\"default-self\": [\"self\"]}", m_originA.get(), &messages));
203 EXPECT_EQ(0UL, messages.size()); 207 EXPECT_EQ(0UL, messages.size());
204 std::unique_ptr<FeaturePolicy> policy2 = 208 std::unique_ptr<FeaturePolicy> policy2 =
205 createFromParentPolicy(policy1.get(), m_originA); 209 createFromParentPolicy(policy1.get(), m_originA);
206 std::unique_ptr<FeaturePolicy> policy3 = 210 std::unique_ptr<FeaturePolicy> policy3 =
207 createFromParentPolicy(policy2.get(), m_originA); 211 createFromParentPolicy(policy2.get(), m_originA);
208 std::unique_ptr<FeaturePolicy> policy4 = 212 std::unique_ptr<FeaturePolicy> policy4 =
209 createFromParentPolicy(policy1.get(), m_originB); 213 createFromParentPolicy(policy1.get(), m_originB);
210 std::unique_ptr<FeaturePolicy> policy5 = 214 std::unique_ptr<FeaturePolicy> policy5 =
211 createFromParentPolicy(policy4.get(), m_originB); 215 createFromParentPolicy(policy4.get(), m_originB);
212 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 216 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
(...skipping 13 matching lines...) Expand all
226 // | | |(3)Origin A | | | 230 // | | |(3)Origin A | | |
227 // | | |No Policy | | | 231 // | | |No Policy | | |
228 // | | +-------------+ | | 232 // | | +-------------+ | |
229 // | +-----------------+ | 233 // | +-----------------+ |
230 // +-----------------------------------+ 234 // +-----------------------------------+
231 // Feature which is enabled at top-level should be disabled in frame 3, as 235 // Feature which is enabled at top-level should be disabled in frame 3, as
232 // it is embedded by frame 2, for which the feature is not enabled. 236 // it is embedded by frame 2, for which the feature is not enabled.
233 Vector<String> messages; 237 Vector<String> messages;
234 std::unique_ptr<FeaturePolicy> policy1 = 238 std::unique_ptr<FeaturePolicy> policy1 =
235 createFromParentPolicy(nullptr, m_originA); 239 createFromParentPolicy(nullptr, m_originA);
236 policy1->setHeaderPolicy("{\"default-self\": [\"self\"]}", &messages); 240 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
241 "{\"default-self\": [\"self\"]}", m_originA.get(), &messages));
237 EXPECT_EQ(0UL, messages.size()); 242 EXPECT_EQ(0UL, messages.size());
238 std::unique_ptr<FeaturePolicy> policy2 = 243 std::unique_ptr<FeaturePolicy> policy2 =
239 createFromParentPolicy(policy1.get(), m_originB); 244 createFromParentPolicy(policy1.get(), m_originB);
240 std::unique_ptr<FeaturePolicy> policy3 = 245 std::unique_ptr<FeaturePolicy> policy3 =
241 createFromParentPolicy(policy2.get(), m_originA); 246 createFromParentPolicy(policy2.get(), m_originA);
242 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 247 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature));
243 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 248 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature));
244 } 249 }
245 250
246 TEST_F(FeaturePolicyTest, TestSelectiveFrameInheritance) { 251 TEST_F(FeaturePolicyTest, TestSelectiveFrameInheritance) {
247 // +------------------------------------------+ 252 // +------------------------------------------+
248 // |(1) Origin A | 253 // |(1) Origin A |
249 // |Policy: {"default-self": ["Origin B"]} | 254 // |Policy: {"default-self": ["Origin B"]} |
250 // | +-----------------+ +-----------------+ | 255 // | +-----------------+ +-----------------+ |
251 // | |(2) Origin B | |(3) Origin C | | 256 // | |(2) Origin B | |(3) Origin C | |
252 // | |No Policy | |No Policy | | 257 // | |No Policy | |No Policy | |
253 // | | | | +-------------+ | | 258 // | | | | +-------------+ | |
254 // | | | | |(4)Origin B | | | 259 // | | | | |(4)Origin B | | |
255 // | | | | |No Policy | | | 260 // | | | | |No Policy | | |
256 // | | | | +-------------+ | | 261 // | | | | +-------------+ | |
257 // | +-----------------+ +-----------------+ | 262 // | +-----------------+ +-----------------+ |
258 // +------------------------------------------+ 263 // +------------------------------------------+
259 // Feature should be enabled in second level Origin B frame, but disabled in 264 // Feature should be enabled in second level Origin B frame, but disabled in
260 // Frame 4, because it is embedded by frame 3, where the feature is not 265 // Frame 4, because it is embedded by frame 3, where the feature is not
261 // enabled. 266 // enabled.
262 Vector<String> messages; 267 Vector<String> messages;
263 std::unique_ptr<FeaturePolicy> policy1 = 268 std::unique_ptr<FeaturePolicy> policy1 =
264 createFromParentPolicy(nullptr, m_originA); 269 createFromParentPolicy(nullptr, m_originA);
265 policy1->setHeaderPolicy("{\"default-self\": [\"" ORIGIN_B "\"]}", &messages); 270 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
271 "{\"default-self\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages));
266 EXPECT_EQ(0UL, messages.size()); 272 EXPECT_EQ(0UL, messages.size());
267 std::unique_ptr<FeaturePolicy> policy2 = 273 std::unique_ptr<FeaturePolicy> policy2 =
268 createFromParentPolicy(policy1.get(), m_originB); 274 createFromParentPolicy(policy1.get(), m_originB);
269 std::unique_ptr<FeaturePolicy> policy3 = 275 std::unique_ptr<FeaturePolicy> policy3 =
270 createFromParentPolicy(policy1.get(), m_originC); 276 createFromParentPolicy(policy1.get(), m_originC);
271 std::unique_ptr<FeaturePolicy> policy4 = 277 std::unique_ptr<FeaturePolicy> policy4 =
272 createFromParentPolicy(policy3.get(), m_originB); 278 createFromParentPolicy(policy3.get(), m_originB);
273 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 279 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
274 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 280 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature));
275 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); 281 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature));
276 } 282 }
277 283
278 TEST_F(FeaturePolicyTest, TestPolicyCanBlockSelf) { 284 TEST_F(FeaturePolicyTest, TestPolicyCanBlockSelf) {
279 // +----------------------------+ 285 // +----------------------------+
280 // |(1)Origin A | 286 // |(1)Origin A |
281 // |Policy: {"default-on": []} | 287 // |Policy: {"default-on": []} |
282 // +----------------------------+ 288 // +----------------------------+
283 // Default-on feature should be disabled in top-level frame. 289 // Default-on feature should be disabled in top-level frame.
284 Vector<String> messages; 290 Vector<String> messages;
285 std::unique_ptr<FeaturePolicy> policy1 = 291 std::unique_ptr<FeaturePolicy> policy1 =
286 createFromParentPolicy(nullptr, m_originA); 292 createFromParentPolicy(nullptr, m_originA);
287 policy1->setHeaderPolicy("{\"default-on\": []}", &messages); 293 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
294 "{\"default-on\": []}", m_originA.get(), &messages));
288 EXPECT_EQ(0UL, messages.size()); 295 EXPECT_EQ(0UL, messages.size());
289 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature)); 296 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature));
290 } 297 }
291 298
292 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksSameOriginChildPolicy) { 299 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksSameOriginChildPolicy) {
293 // +----------------------------+ 300 // +----------------------------+
294 // |(1)Origin A | 301 // |(1)Origin A |
295 // |Policy: {"default-on": []} | 302 // |Policy: {"default-on": []} |
296 // | +-------------+ | 303 // | +-------------+ |
297 // | |(2)Origin A | | 304 // | |(2)Origin A | |
298 // | |No Policy | | 305 // | |No Policy | |
299 // | +-------------+ | 306 // | +-------------+ |
300 // +----------------------------+ 307 // +----------------------------+
301 // Feature should be disabled in child frame. 308 // Feature should be disabled in child frame.
302 Vector<String> messages; 309 Vector<String> messages;
303 std::unique_ptr<FeaturePolicy> policy1 = 310 std::unique_ptr<FeaturePolicy> policy1 =
304 createFromParentPolicy(nullptr, m_originA); 311 createFromParentPolicy(nullptr, m_originA);
305 policy1->setHeaderPolicy("{\"default-on\": []}", &messages); 312 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
313 "{\"default-on\": []}", m_originA.get(), &messages));
306 EXPECT_EQ(0UL, messages.size()); 314 EXPECT_EQ(0UL, messages.size());
307 std::unique_ptr<FeaturePolicy> policy2 = 315 std::unique_ptr<FeaturePolicy> policy2 =
308 createFromParentPolicy(policy1.get(), m_originA); 316 createFromParentPolicy(policy1.get(), m_originA);
309 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); 317 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature));
310 } 318 }
311 319
312 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockSelf) { 320 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockSelf) {
313 // +--------------------------------+ 321 // +--------------------------------+
314 // |(1)Origin A | 322 // |(1)Origin A |
315 // |No Policy | 323 // |No Policy |
316 // | +----------------------------+ | 324 // | +----------------------------+ |
317 // | |(2)Origin B | | 325 // | |(2)Origin B | |
318 // | |Policy: {"default-on": []} | | 326 // | |Policy: {"default-on": []} | |
319 // | +----------------------------+ | 327 // | +----------------------------+ |
320 // +--------------------------------+ 328 // +--------------------------------+
321 // Default-on feature should be disabled by cross-origin child frame. 329 // Default-on feature should be disabled by cross-origin child frame.
322 Vector<String> messages; 330 Vector<String> messages;
323 std::unique_ptr<FeaturePolicy> policy1 = 331 std::unique_ptr<FeaturePolicy> policy1 =
324 createFromParentPolicy(nullptr, m_originA); 332 createFromParentPolicy(nullptr, m_originA);
325 std::unique_ptr<FeaturePolicy> policy2 = 333 std::unique_ptr<FeaturePolicy> policy2 =
326 createFromParentPolicy(policy1.get(), m_originB); 334 createFromParentPolicy(policy1.get(), m_originB);
327 policy2->setHeaderPolicy("{\"default-on\": []}", &messages); 335 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
336 "{\"default-on\": []}", m_originB.get(), &messages));
328 EXPECT_EQ(0UL, messages.size()); 337 EXPECT_EQ(0UL, messages.size());
329 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); 338 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature));
330 } 339 }
331 340
332 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockChildren) { 341 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockChildren) {
333 // +--------------------------------------+ 342 // +--------------------------------------+
334 // |(1)Origin A | 343 // |(1)Origin A |
335 // |No Policy | 344 // |No Policy |
336 // | +----------------------------------+ | 345 // | +----------------------------------+ |
337 // | |(2)Origin B | | 346 // | |(2)Origin B | |
338 // | |Policy: {"default-on": ["self"]} | | 347 // | |Policy: {"default-on": ["self"]} | |
339 // | | +-------------+ | | 348 // | | +-------------+ | |
340 // | | |(3)Origin C | | | 349 // | | |(3)Origin C | | |
341 // | | |No Policy | | | 350 // | | |No Policy | | |
342 // | | +-------------+ | | 351 // | | +-------------+ | |
343 // | +----------------------------------+ | 352 // | +----------------------------------+ |
344 // +--------------------------------------+ 353 // +--------------------------------------+
345 // Default-on feature should be enabled in frames 1 and 2; disabled in frame 354 // Default-on feature should be enabled in frames 1 and 2; disabled in frame
346 // 3 by child frame policy. 355 // 3 by child frame policy.
347 Vector<String> messages; 356 Vector<String> messages;
348 std::unique_ptr<FeaturePolicy> policy1 = 357 std::unique_ptr<FeaturePolicy> policy1 =
349 createFromParentPolicy(nullptr, m_originA); 358 createFromParentPolicy(nullptr, m_originA);
350 std::unique_ptr<FeaturePolicy> policy2 = 359 std::unique_ptr<FeaturePolicy> policy2 =
351 createFromParentPolicy(policy1.get(), m_originB); 360 createFromParentPolicy(policy1.get(), m_originB);
352 policy2->setHeaderPolicy("{\"default-on\": [\"self\"]}", &messages); 361 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
362 "{\"default-on\": [\"self\"]}", m_originB.get(), &messages));
353 EXPECT_EQ(0UL, messages.size()); 363 EXPECT_EQ(0UL, messages.size());
354 std::unique_ptr<FeaturePolicy> policy3 = 364 std::unique_ptr<FeaturePolicy> policy3 =
355 createFromParentPolicy(policy2.get(), m_originC); 365 createFromParentPolicy(policy2.get(), m_originC);
356 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); 366 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature));
357 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature)); 367 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature));
358 } 368 }
359 369
360 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksCrossOriginChildPolicy) { 370 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksCrossOriginChildPolicy) {
361 // +----------------------------+ 371 // +----------------------------+
362 // |(1)Origin A | 372 // |(1)Origin A |
363 // |Policy: {"default-on": []} | 373 // |Policy: {"default-on": []} |
364 // | +-------------+ | 374 // | +-------------+ |
365 // | |(2)Origin B | | 375 // | |(2)Origin B | |
366 // | |No Policy | | 376 // | |No Policy | |
367 // | +-------------+ | 377 // | +-------------+ |
368 // +----------------------------+ 378 // +----------------------------+
369 // Default-on feature should be disabled in cross-origin child frame. 379 // Default-on feature should be disabled in cross-origin child frame.
370 Vector<String> messages; 380 Vector<String> messages;
371 std::unique_ptr<FeaturePolicy> policy1 = 381 std::unique_ptr<FeaturePolicy> policy1 =
372 createFromParentPolicy(nullptr, m_originA); 382 createFromParentPolicy(nullptr, m_originA);
373 policy1->setHeaderPolicy("{\"default-on\": []}", &messages); 383 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
384 "{\"default-on\": []}", m_originA.get(), &messages));
374 EXPECT_EQ(0UL, messages.size()); 385 EXPECT_EQ(0UL, messages.size());
375 std::unique_ptr<FeaturePolicy> policy2 = 386 std::unique_ptr<FeaturePolicy> policy2 =
376 createFromParentPolicy(policy1.get(), m_originB); 387 createFromParentPolicy(policy1.get(), m_originB);
377 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); 388 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature));
378 } 389 }
379 390
380 TEST_F(FeaturePolicyTest, TestEnableForAllOrigins) { 391 TEST_F(FeaturePolicyTest, TestEnableForAllOrigins) {
381 // +--------------------------------+ 392 // +--------------------------------+
382 // |(1) Origin A | 393 // |(1) Origin A |
383 // |Policy: {"default-self": ["*"]} | 394 // |Policy: {"default-self": ["*"]} |
384 // | +-----------------+ | 395 // | +-----------------+ |
385 // | |(2) Origin B | | 396 // | |(2) Origin B | |
386 // | |No Policy | | 397 // | |No Policy | |
387 // | | +-------------+ | | 398 // | | +-------------+ | |
388 // | | |(3)Origin A | | | 399 // | | |(3)Origin A | | |
389 // | | |No Policy | | | 400 // | | |No Policy | | |
390 // | | +-------------+ | | 401 // | | +-------------+ | |
391 // | +-----------------+ | 402 // | +-----------------+ |
392 // +--------------------------------+ 403 // +--------------------------------+
393 // Feature should be enabled in top and second level; disabled in frame 3. 404 // Feature should be enabled in top and second level; disabled in frame 3.
394 Vector<String> messages; 405 Vector<String> messages;
395 std::unique_ptr<FeaturePolicy> policy1 = 406 std::unique_ptr<FeaturePolicy> policy1 =
396 createFromParentPolicy(nullptr, m_originA); 407 createFromParentPolicy(nullptr, m_originA);
397 policy1->setHeaderPolicy("{\"default-self\": [\"*\"]}", &messages); 408 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
409 "{\"default-self\": [\"*\"]}", m_originA.get(), &messages));
398 EXPECT_EQ(0UL, messages.size()); 410 EXPECT_EQ(0UL, messages.size());
399 std::unique_ptr<FeaturePolicy> policy2 = 411 std::unique_ptr<FeaturePolicy> policy2 =
400 createFromParentPolicy(policy1.get(), m_originB); 412 createFromParentPolicy(policy1.get(), m_originB);
401 std::unique_ptr<FeaturePolicy> policy3 = 413 std::unique_ptr<FeaturePolicy> policy3 =
402 createFromParentPolicy(policy2.get(), m_originA); 414 createFromParentPolicy(policy2.get(), m_originA);
403 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 415 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
404 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 416 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
405 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 417 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature));
406 } 418 }
407 419
408 TEST_F(FeaturePolicyTest, TestDefaultOnEnablesForAllAncestors) { 420 TEST_F(FeaturePolicyTest, TestDefaultOnEnablesForAllAncestors) {
409 // +---------------------------------------+ 421 // +---------------------------------------+
410 // |(1) Origin A | 422 // |(1) Origin A |
411 // |Policy: {"default-on": ["Origin B"]} | 423 // |Policy: {"default-on": ["Origin B"]} |
412 // | +-----------------------------------+ | 424 // | +-----------------------------------+ |
413 // | |(2) Origin B | | 425 // | |(2) Origin B | |
414 // | |No Policy | | 426 // | |No Policy | |
415 // | | +-------------+ +-------------+ | | 427 // | | +-------------+ +-------------+ | |
416 // | | |(3)Origin B | |(4)Origin C | | | 428 // | | |(3)Origin B | |(4)Origin C | | |
417 // | | |No Policy | |No Policy | | | 429 // | | |No Policy | |No Policy | | |
418 // | | +-------------+ +-------------+ | | 430 // | | +-------------+ +-------------+ | |
419 // | +-----------------------------------+ | 431 // | +-----------------------------------+ |
420 // +---------------------------------------+ 432 // +---------------------------------------+
421 // Feature should be disabled in frame 1; enabled in frames 2, 3 and 4. 433 // Feature should be disabled in frame 1; enabled in frames 2, 3 and 4.
422 Vector<String> messages; 434 Vector<String> messages;
423 std::unique_ptr<FeaturePolicy> policy1 = 435 std::unique_ptr<FeaturePolicy> policy1 =
424 createFromParentPolicy(nullptr, m_originA); 436 createFromParentPolicy(nullptr, m_originA);
425 policy1->setHeaderPolicy("{\"default-on\": [\"" ORIGIN_B "\"]}", &messages); 437 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
438 "{\"default-on\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages));
426 EXPECT_EQ(0UL, messages.size()); 439 EXPECT_EQ(0UL, messages.size());
427 std::unique_ptr<FeaturePolicy> policy2 = 440 std::unique_ptr<FeaturePolicy> policy2 =
428 createFromParentPolicy(policy1.get(), m_originB); 441 createFromParentPolicy(policy1.get(), m_originB);
429 std::unique_ptr<FeaturePolicy> policy3 = 442 std::unique_ptr<FeaturePolicy> policy3 =
430 createFromParentPolicy(policy2.get(), m_originB); 443 createFromParentPolicy(policy2.get(), m_originB);
431 std::unique_ptr<FeaturePolicy> policy4 = 444 std::unique_ptr<FeaturePolicy> policy4 =
432 createFromParentPolicy(policy2.get(), m_originC); 445 createFromParentPolicy(policy2.get(), m_originC);
433 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature)); 446 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature));
434 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); 447 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature));
435 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature)); 448 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature));
(...skipping 10 matching lines...) Expand all
446 // | | +-------------+ +-------------+ | | 459 // | | +-------------+ +-------------+ | |
447 // | | |(3)Origin B | |(4)Origin C | | | 460 // | | |(3)Origin B | |(4)Origin C | | |
448 // | | |No Policy | |No Policy | | | 461 // | | |No Policy | |No Policy | | |
449 // | | +-------------+ +-------------+ | | 462 // | | +-------------+ +-------------+ | |
450 // | +-----------------------------------+ | 463 // | +-----------------------------------+ |
451 // +---------------------------------------+ 464 // +---------------------------------------+
452 // Feature should be disabled in frames 1 and 4; enabled in frames 2 and 3. 465 // Feature should be disabled in frames 1 and 4; enabled in frames 2 and 3.
453 Vector<String> messages; 466 Vector<String> messages;
454 std::unique_ptr<FeaturePolicy> policy1 = 467 std::unique_ptr<FeaturePolicy> policy1 =
455 createFromParentPolicy(nullptr, m_originA); 468 createFromParentPolicy(nullptr, m_originA);
456 policy1->setHeaderPolicy("{\"default-self\": [\"" ORIGIN_B "\"]}", &messages); 469 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
470 "{\"default-self\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages));
457 EXPECT_EQ(0UL, messages.size()); 471 EXPECT_EQ(0UL, messages.size());
458 std::unique_ptr<FeaturePolicy> policy2 = 472 std::unique_ptr<FeaturePolicy> policy2 =
459 createFromParentPolicy(policy1.get(), m_originB); 473 createFromParentPolicy(policy1.get(), m_originB);
460 std::unique_ptr<FeaturePolicy> policy3 = 474 std::unique_ptr<FeaturePolicy> policy3 =
461 createFromParentPolicy(policy2.get(), m_originB); 475 createFromParentPolicy(policy2.get(), m_originB);
462 std::unique_ptr<FeaturePolicy> policy4 = 476 std::unique_ptr<FeaturePolicy> policy4 =
463 createFromParentPolicy(policy2.get(), m_originC); 477 createFromParentPolicy(policy2.get(), m_originC);
464 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 478 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultSelfFeature));
465 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 479 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
466 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 480 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature));
(...skipping 10 matching lines...) Expand all
477 // | | +-------------+ +----------------------------------+ | | 491 // | | +-------------+ +----------------------------------+ | |
478 // | | |(3)Origin B | |(4)Origin C | | | 492 // | | |(3)Origin B | |(4)Origin C | | |
479 // | | |No Policy | |Policy: {"default-off": ["self"]} | | | 493 // | | |No Policy | |Policy: {"default-off": ["self"]} | | |
480 // | | +-------------+ +----------------------------------+ | | 494 // | | +-------------+ +----------------------------------+ | |
481 // | +--------------------------------------------------------+ | 495 // | +--------------------------------------------------------+ |
482 // +------------------------------------------------------------+ 496 // +------------------------------------------------------------+
483 // Feature should be disabled in frames 1, 3 and 4; enabled in frame 2 only. 497 // Feature should be disabled in frames 1, 3 and 4; enabled in frame 2 only.
484 Vector<String> messages; 498 Vector<String> messages;
485 std::unique_ptr<FeaturePolicy> policy1 = 499 std::unique_ptr<FeaturePolicy> policy1 =
486 createFromParentPolicy(nullptr, m_originA); 500 createFromParentPolicy(nullptr, m_originA);
487 policy1->setHeaderPolicy("{\"default-off\": [\"" ORIGIN_B "\"]}", &messages); 501 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
502 "{\"default-off\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages));
488 EXPECT_EQ(0UL, messages.size()); 503 EXPECT_EQ(0UL, messages.size());
489 std::unique_ptr<FeaturePolicy> policy2 = 504 std::unique_ptr<FeaturePolicy> policy2 =
490 createFromParentPolicy(policy1.get(), m_originB); 505 createFromParentPolicy(policy1.get(), m_originB);
491 policy2->setHeaderPolicy("{\"default-off\": [\"self\"]}", &messages); 506 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
507 "{\"default-off\": [\"self\"]}", m_originB.get(), &messages));
492 std::unique_ptr<FeaturePolicy> policy3 = 508 std::unique_ptr<FeaturePolicy> policy3 =
493 createFromParentPolicy(policy2.get(), m_originB); 509 createFromParentPolicy(policy2.get(), m_originB);
494 std::unique_ptr<FeaturePolicy> policy4 = 510 std::unique_ptr<FeaturePolicy> policy4 =
495 createFromParentPolicy(policy2.get(), m_originC); 511 createFromParentPolicy(policy2.get(), m_originC);
496 policy4->setHeaderPolicy("{\"default-off\": [\"self\"]}", &messages); 512 policy4->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
513 "{\"default-off\": [\"self\"]}", m_originC.get(), &messages));
497 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOffFeature)); 514 EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOffFeature));
498 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOffFeature)); 515 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOffFeature));
499 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOffFeature)); 516 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOffFeature));
500 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultOffFeature)); 517 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultOffFeature));
501 } 518 }
502 519
503 TEST_F(FeaturePolicyTest, TestReenableForAllOrigins) { 520 TEST_F(FeaturePolicyTest, TestReenableForAllOrigins) {
504 // +------------------------------------+ 521 // +------------------------------------+
505 // |(1) Origin A | 522 // |(1) Origin A |
506 // |Policy: {"default-self": ["*"]} | 523 // |Policy: {"default-self": ["*"]} |
507 // | +--------------------------------+ | 524 // | +--------------------------------+ |
508 // | |(2) Origin B | | 525 // | |(2) Origin B | |
509 // | |Policy: {"default-self": ["*"]} | | 526 // | |Policy: {"default-self": ["*"]} | |
510 // | | +-------------+ | | 527 // | | +-------------+ | |
511 // | | |(3)Origin A | | | 528 // | | |(3)Origin A | | |
512 // | | |No Policy | | | 529 // | | |No Policy | | |
513 // | | +-------------+ | | 530 // | | +-------------+ | |
514 // | +--------------------------------+ | 531 // | +--------------------------------+ |
515 // +------------------------------------+ 532 // +------------------------------------+
516 // Feature should be enabled in all frames. 533 // Feature should be enabled in all frames.
517 Vector<String> messages; 534 Vector<String> messages;
518 std::unique_ptr<FeaturePolicy> policy1 = 535 std::unique_ptr<FeaturePolicy> policy1 =
519 createFromParentPolicy(nullptr, m_originA); 536 createFromParentPolicy(nullptr, m_originA);
520 policy1->setHeaderPolicy("{\"default-self\": [\"*\"]}", &messages); 537 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
538 "{\"default-self\": [\"*\"]}", m_originA.get(), &messages));
521 EXPECT_EQ(0UL, messages.size()); 539 EXPECT_EQ(0UL, messages.size());
522 std::unique_ptr<FeaturePolicy> policy2 = 540 std::unique_ptr<FeaturePolicy> policy2 =
523 createFromParentPolicy(policy1.get(), m_originB); 541 createFromParentPolicy(policy1.get(), m_originB);
524 policy2->setHeaderPolicy("{\"default-self\": [\"*\"]}", &messages); 542 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
543 "{\"default-self\": [\"*\"]}", m_originB.get(), &messages));
525 EXPECT_EQ(0UL, messages.size()); 544 EXPECT_EQ(0UL, messages.size());
526 std::unique_ptr<FeaturePolicy> policy3 = 545 std::unique_ptr<FeaturePolicy> policy3 =
527 createFromParentPolicy(policy2.get(), m_originA); 546 createFromParentPolicy(policy2.get(), m_originA);
528 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 547 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
529 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 548 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
530 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 549 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature));
531 } 550 }
532 551
533 TEST_F(FeaturePolicyTest, TestBlockedFrameCannotReenable) { 552 TEST_F(FeaturePolicyTest, TestBlockedFrameCannotReenable) {
534 // +--------------------------------------+ 553 // +--------------------------------------+
535 // |(1)Origin A | 554 // |(1)Origin A |
536 // |Policy: {"default-self": ["self"]} | 555 // |Policy: {"default-self": ["self"]} |
537 // | +----------------------------------+ | 556 // | +----------------------------------+ |
538 // | |(2)Origin B | | 557 // | |(2)Origin B | |
539 // | |Policy: {"default-self": ["*"]} | | 558 // | |Policy: {"default-self": ["*"]} | |
540 // | | +-------------+ +-------------+ | | 559 // | | +-------------+ +-------------+ | |
541 // | | |(3)Origin A | |(4)Origin C | | | 560 // | | |(3)Origin A | |(4)Origin C | | |
542 // | | |No Policy | |No Policy | | | 561 // | | |No Policy | |No Policy | | |
543 // | | +-------------+ +-------------+ | | 562 // | | +-------------+ +-------------+ | |
544 // | +----------------------------------+ | 563 // | +----------------------------------+ |
545 // +--------------------------------------+ 564 // +--------------------------------------+
546 // Feature should be enabled at the top level; disabled in all other frames. 565 // Feature should be enabled at the top level; disabled in all other frames.
547 Vector<String> messages; 566 Vector<String> messages;
548 std::unique_ptr<FeaturePolicy> policy1 = 567 std::unique_ptr<FeaturePolicy> policy1 =
549 createFromParentPolicy(nullptr, m_originA); 568 createFromParentPolicy(nullptr, m_originA);
550 policy1->setHeaderPolicy("{\"default-self\": [\"self\"]}", &messages); 569 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
570 "{\"default-self\": [\"self\"]}", m_originA.get(), &messages));
551 EXPECT_EQ(0UL, messages.size()); 571 EXPECT_EQ(0UL, messages.size());
552 std::unique_ptr<FeaturePolicy> policy2 = 572 std::unique_ptr<FeaturePolicy> policy2 =
553 createFromParentPolicy(policy1.get(), m_originB); 573 createFromParentPolicy(policy1.get(), m_originB);
554 policy2->setHeaderPolicy("{\"default-self\": [\"*\"]}", &messages); 574 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
575 "{\"default-self\": [\"*\"]}", m_originB.get(), &messages));
555 EXPECT_EQ(0UL, messages.size()); 576 EXPECT_EQ(0UL, messages.size());
556 std::unique_ptr<FeaturePolicy> policy3 = 577 std::unique_ptr<FeaturePolicy> policy3 =
557 createFromParentPolicy(policy2.get(), m_originA); 578 createFromParentPolicy(policy2.get(), m_originA);
558 std::unique_ptr<FeaturePolicy> policy4 = 579 std::unique_ptr<FeaturePolicy> policy4 =
559 createFromParentPolicy(policy2.get(), m_originC); 580 createFromParentPolicy(policy2.get(), m_originC);
560 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 581 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
561 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 582 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature));
562 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 583 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature));
563 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); 584 EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature));
564 } 585 }
565 586
566 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegate) { 587 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegate) {
567 // +---------------------------------------------------+ 588 // +---------------------------------------------------+
568 // |(1) Origin A | 589 // |(1) Origin A |
569 // |Policy: {"default-self": ["self", "Origin B"]} | 590 // |Policy: {"default-self": ["self", "Origin B"]} |
570 // | +-----------------------------------------------+ | 591 // | +-----------------------------------------------+ |
571 // | |(2) Origin B | | 592 // | |(2) Origin B | |
572 // | |Policy: {"default-self": ["self", "Origin C"]} | | 593 // | |Policy: {"default-self": ["self", "Origin C"]} | |
573 // | | +-------------+ | | 594 // | | +-------------+ | |
574 // | | |(3)Origin C | | | 595 // | | |(3)Origin C | | |
575 // | | |No Policy | | | 596 // | | |No Policy | | |
576 // | | +-------------+ | | 597 // | | +-------------+ | |
577 // | +-----------------------------------------------+ | 598 // | +-----------------------------------------------+ |
578 // +---------------------------------------------------+ 599 // +---------------------------------------------------+
579 // Feature should be enabled in all frames. 600 // Feature should be enabled in all frames.
580 Vector<String> messages; 601 Vector<String> messages;
581 std::unique_ptr<FeaturePolicy> policy1 = 602 std::unique_ptr<FeaturePolicy> policy1 =
582 createFromParentPolicy(nullptr, m_originA); 603 createFromParentPolicy(nullptr, m_originA);
583 policy1->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", 604 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
584 &messages); 605 "{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(),
606 &messages));
585 EXPECT_EQ(0UL, messages.size()); 607 EXPECT_EQ(0UL, messages.size());
586 std::unique_ptr<FeaturePolicy> policy2 = 608 std::unique_ptr<FeaturePolicy> policy2 =
587 createFromParentPolicy(policy1.get(), m_originB); 609 createFromParentPolicy(policy1.get(), m_originB);
588 policy2->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_C "\"]}", 610 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
589 &messages); 611 "{\"default-self\": [\"self\", \"" ORIGIN_C "\"]}", m_originB.get(),
612 &messages));
590 EXPECT_EQ(0UL, messages.size()); 613 EXPECT_EQ(0UL, messages.size());
591 std::unique_ptr<FeaturePolicy> policy3 = 614 std::unique_ptr<FeaturePolicy> policy3 =
592 createFromParentPolicy(policy2.get(), m_originC); 615 createFromParentPolicy(policy2.get(), m_originC);
593 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 616 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
594 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 617 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
595 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 618 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature));
596 } 619 }
597 620
598 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegateByDefault) { 621 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegateByDefault) {
599 // +-----------------------------------------------+ 622 // +-----------------------------------------------+
600 // |(1) Origin A | 623 // |(1) Origin A |
601 // |Policy: {"default-on": ["self", "Origin B"]} | 624 // |Policy: {"default-on": ["self", "Origin B"]} |
602 // | +--------------------+ +--------------------+ | 625 // | +--------------------+ +--------------------+ |
603 // | |(2) Origin B | | (4) Origin C | | 626 // | |(2) Origin B | | (4) Origin C | |
604 // | |No Policy | | No Policy | | 627 // | |No Policy | | No Policy | |
605 // | | +-------------+ | | | | 628 // | | +-------------+ | | | |
606 // | | |(3)Origin C | | | | | 629 // | | |(3)Origin C | | | | |
607 // | | |No Policy | | | | | 630 // | | |No Policy | | | | |
608 // | | +-------------+ | | | | 631 // | | +-------------+ | | | |
609 // | +--------------------+ +--------------------+ | 632 // | +--------------------+ +--------------------+ |
610 // +-----------------------------------------------+ 633 // +-----------------------------------------------+
611 // Feature should be enabled in frames 1, 2, and 3, and disabled in frame 4. 634 // Feature should be enabled in frames 1, 2, and 3, and disabled in frame 4.
612 Vector<String> messages; 635 Vector<String> messages;
613 std::unique_ptr<FeaturePolicy> policy1 = 636 std::unique_ptr<FeaturePolicy> policy1 =
614 createFromParentPolicy(nullptr, m_originA); 637 createFromParentPolicy(nullptr, m_originA);
615 policy1->setHeaderPolicy("{\"default-on\": [\"self\", \"" ORIGIN_B "\"]}", 638 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
616 &messages); 639 "{\"default-on\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(),
640 &messages));
617 EXPECT_EQ(0UL, messages.size()); 641 EXPECT_EQ(0UL, messages.size());
618 std::unique_ptr<FeaturePolicy> policy2 = 642 std::unique_ptr<FeaturePolicy> policy2 =
619 createFromParentPolicy(policy1.get(), m_originB); 643 createFromParentPolicy(policy1.get(), m_originB);
620 std::unique_ptr<FeaturePolicy> policy3 = 644 std::unique_ptr<FeaturePolicy> policy3 =
621 createFromParentPolicy(policy2.get(), m_originC); 645 createFromParentPolicy(policy2.get(), m_originC);
622 std::unique_ptr<FeaturePolicy> policy4 = 646 std::unique_ptr<FeaturePolicy> policy4 =
623 createFromParentPolicy(policy1.get(), m_originC); 647 createFromParentPolicy(policy1.get(), m_originC);
624 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); 648 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature));
625 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); 649 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature));
626 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature)); 650 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature));
(...skipping 11 matching lines...) Expand all
638 // | | |(3)Origin C | | | | | 662 // | | |(3)Origin C | | | | |
639 // | | |No Policy | | | | | 663 // | | |No Policy | | | | |
640 // | | +-------------+ | | | | 664 // | | +-------------+ | | | |
641 // | +--------------------+ +--------------------+ | 665 // | +--------------------+ +--------------------+ |
642 // +-----------------------------------------------+ 666 // +-----------------------------------------------+
643 // Feature should be enabled in frames 1 and 2, and disabled in frames 3 and 667 // Feature should be enabled in frames 1 and 2, and disabled in frames 3 and
644 // 4. 668 // 4.
645 Vector<String> messages; 669 Vector<String> messages;
646 std::unique_ptr<FeaturePolicy> policy1 = 670 std::unique_ptr<FeaturePolicy> policy1 =
647 createFromParentPolicy(nullptr, m_originA); 671 createFromParentPolicy(nullptr, m_originA);
648 policy1->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", 672 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
649 &messages); 673 "{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(),
674 &messages));
650 EXPECT_EQ(0UL, messages.size()); 675 EXPECT_EQ(0UL, messages.size());
651 std::unique_ptr<FeaturePolicy> policy2 = 676 std::unique_ptr<FeaturePolicy> policy2 =
652 createFromParentPolicy(policy1.get(), m_originB); 677 createFromParentPolicy(policy1.get(), m_originB);
653 std::unique_ptr<FeaturePolicy> policy3 = 678 std::unique_ptr<FeaturePolicy> policy3 =
654 createFromParentPolicy(policy2.get(), m_originC); 679 createFromParentPolicy(policy2.get(), m_originC);
655 std::unique_ptr<FeaturePolicy> policy4 = 680 std::unique_ptr<FeaturePolicy> policy4 =
656 createFromParentPolicy(policy1.get(), m_originC); 681 createFromParentPolicy(policy1.get(), m_originC);
657 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 682 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
658 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 683 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
659 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 684 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature));
(...skipping 13 matching lines...) Expand all
673 // | | |(3)Origin C | | | 698 // | | |(3)Origin C | | |
674 // | | |No Policy | | | 699 // | | |No Policy | | |
675 // | | +-------------+ | | 700 // | | +-------------+ | |
676 // | +-------------------------------------------+ | 701 // | +-------------------------------------------+ |
677 // +-----------------------------------------------+ 702 // +-----------------------------------------------+
678 // Default-self feature should be enabled in all frames; Default-on feature 703 // Default-self feature should be enabled in all frames; Default-on feature
679 // should be enabled in frame 1, and disabled in frames 2 and 3. 704 // should be enabled in frame 1, and disabled in frames 2 and 3.
680 Vector<String> messages; 705 Vector<String> messages;
681 std::unique_ptr<FeaturePolicy> policy1 = 706 std::unique_ptr<FeaturePolicy> policy1 =
682 createFromParentPolicy(nullptr, m_originA); 707 createFromParentPolicy(nullptr, m_originA);
683 policy1->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_B 708 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
684 "\"], \"default-on\": [\"self\"]}", 709 "{\"default-self\": [\"self\", \"" ORIGIN_B
685 &messages); 710 "\"], \"default-on\": [\"self\"]}",
711 m_originA.get(), &messages));
686 EXPECT_EQ(0UL, messages.size()); 712 EXPECT_EQ(0UL, messages.size());
687 std::unique_ptr<FeaturePolicy> policy2 = 713 std::unique_ptr<FeaturePolicy> policy2 =
688 createFromParentPolicy(policy1.get(), m_originB); 714 createFromParentPolicy(policy1.get(), m_originB);
689 policy2->setHeaderPolicy( 715 policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
690 "{\"default-self\": [\"*\"], \"default-on\": [\"*\"]}", &messages); 716 "{\"default-self\": [\"*\"], \"default-on\": [\"*\"]}", m_originB.get(),
717 &messages));
691 EXPECT_EQ(0UL, messages.size()); 718 EXPECT_EQ(0UL, messages.size());
692 std::unique_ptr<FeaturePolicy> policy3 = 719 std::unique_ptr<FeaturePolicy> policy3 =
693 createFromParentPolicy(policy2.get(), m_originC); 720 createFromParentPolicy(policy2.get(), m_originC);
694 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 721 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
695 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); 722 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature));
696 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 723 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
697 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); 724 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature));
698 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 725 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature));
699 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature)); 726 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature));
700 } 727 }
701 728
702 TEST_F(FeaturePolicyTest, TestFeatureEnabledForOrigin) { 729 TEST_F(FeaturePolicyTest, TestFeatureEnabledForOrigin) {
703 // +-----------------------------------------------+ 730 // +-----------------------------------------------+
704 // |(1) Origin A | 731 // |(1) Origin A |
705 // |Policy: {"default-off": ["self", "Origin B"]} | 732 // |Policy: {"default-off": ["self", "Origin B"]} |
706 // +-----------------------------------------------+ 733 // +-----------------------------------------------+
707 // Features should be enabled by the policy in frame 1 for origins A and B, 734 // Features should be enabled by the policy in frame 1 for origins A and B,
708 // and disabled for origin C. 735 // and disabled for origin C.
709 Vector<String> messages; 736 Vector<String> messages;
710 std::unique_ptr<FeaturePolicy> policy1 = 737 std::unique_ptr<FeaturePolicy> policy1 =
711 createFromParentPolicy(nullptr, m_originA); 738 createFromParentPolicy(nullptr, m_originA);
712 policy1->setHeaderPolicy("{\"default-off\": [\"self\", \"" ORIGIN_B "\"]}", 739 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
713 &messages); 740 "{\"default-off\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(),
741 &messages));
714 EXPECT_EQ(0UL, messages.size()); 742 EXPECT_EQ(0UL, messages.size());
715 EXPECT_TRUE( 743 EXPECT_TRUE(
716 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originA)); 744 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originA));
717 EXPECT_TRUE( 745 EXPECT_TRUE(
718 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originB)); 746 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originB));
719 EXPECT_FALSE( 747 EXPECT_FALSE(
720 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originC)); 748 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originC));
721 } 749 }
722 750
723 } // namespace blink 751 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698