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

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

Issue 2254533002: [FeaturePolicy] Initial implementation of Feature Policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fp-flag
Patch Set: Conform to JFV spec for header format 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/feature_policy/FeaturePolicy.h"
6
7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 // Origin strings used for tests
11 #define ORIGIN_A "https://example.com/"
12 #define ORIGIN_B "https://example.net/"
13 #define ORIGIN_C "https://example.org/"
raymes 2016/10/19 23:47:37 nit: can these just be const char*? I haven't seen
iclelland 2016/10/21 13:38:25 I'm using the macros so that we can do easy string
14
15 namespace blink {
16
17 namespace {
18
19 const char* kInvalidPolicies[] = {"Not A JSON literal", "\"Not a JSON object\"",
20 "[\"Also\", \"Not a JSON object\"]", "1.0"};
21
22 // This is an example of a feature which should be disabled by default, both in
23 // top-level and nested frames.
24 const FeaturePolicyFeature kOffByDeaultFeature{"offbydefault",
25 kDisableFeatureForAllOrigins};
26
27 } // namespace
28
29 class FeaturePolicyTest : public ::testing::Test {
30 protected:
31 FeaturePolicyTest()
32 : m_frameworkWasEnabled(RuntimeEnabledFeatures::featurePolicyEnabled()) {
33 RuntimeEnabledFeatures::setFeaturePolicyEnabled(true);
34 // Set the list of controlled features, so that we are guaranteed to
35 // have at least one of each kind of default behaviour represented.
36 Vector<const FeaturePolicyFeature*> featureRegistry =
37 FeaturePolicy::getFeatureRegistry();
dcheng 2016/10/20 17:41:44 Doesn't this copy the feature registry? So I don't
iclelland 2016/10/21 13:38:25 I had fixed this this afternoon, but you're right
38 featureRegistry.clear();
39 featureRegistry.append(&kDocumentWrite);
40 featureRegistry.append(&kVibrateFeature);
41 featureRegistry.append(&kOffByDeaultFeature);
raymes 2016/10/19 23:47:37 nit (optional): should we just make all of these i
iclelland 2016/10/21 13:38:26 Done. I thought that using the real features would
42 }
43
44 ~FeaturePolicyTest() {
45 RuntimeEnabledFeatures::setFeaturePolicyEnabled(m_frameworkWasEnabled);
46 }
47
48 RefPtr<SecurityOrigin> originA = SecurityOrigin::createFromString(ORIGIN_A);
raymes 2016/10/19 23:47:37 nit: should these be prefixed with m_ (I don't kno
iclelland 2016/10/21 13:38:26 Done.
49 RefPtr<SecurityOrigin> originB = SecurityOrigin::createFromString(ORIGIN_B);
50 RefPtr<SecurityOrigin> originC = SecurityOrigin::createFromString(ORIGIN_C);
51
52 private:
53 const bool m_frameworkWasEnabled;
54 };
55
56 TEST_F(FeaturePolicyTest, ParseInvalidPolicy) {
57 for (const char* invalidPolicy : kInvalidPolicies) {
58 EXPECT_TRUE(invalidPolicy);
raymes 2016/10/19 23:47:37 Hmm, what is this testing?
iclelland 2016/10/21 13:38:26 Ahh, I had implemented that test yesterday, but di
59 }
60 }
61
62 TEST_F(FeaturePolicyTest, TestInitialPolicy) {
63 // +-------------+
64 // |(1)Origin A |
65 // |No Policy |
66 // +-------------+
67 // Default-on and top-level-only features should be enabled in top-level
68 // frame. Default-off features should be disabled.
69 FeaturePolicy* policy1 =
70 FeaturePolicy::createFromParentPolicy(nullptr, originA);
71 EXPECT_TRUE(policy1->isFeatureEnabled(&kDocumentWrite));
72 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
73 EXPECT_FALSE(policy1->isFeatureEnabled(&kOffByDeaultFeature));
74 }
75
76 TEST_F(FeaturePolicyTest, TestInitialSameOriginChildPolicy) {
77 // +-----------------+
78 // |(1)Origin A |
79 // |No Policy |
80 // | +-------------+ |
81 // | |(2)Origin A | |
82 // | |No Policy | |
83 // | +-------------+ |
84 // +-----------------+
85 // Default-on features should be enabled in child frame. Default-off and
86 // top-level-only features should be disabled.
raymes 2016/10/19 23:47:37 nit: I think this comment is slightly out of date?
iclelland 2016/10/21 13:38:25 Thanks, fixed.
87 FeaturePolicy* policy1 =
88 FeaturePolicy::createFromParentPolicy(nullptr, originA);
89 FeaturePolicy* policy2 =
90 FeaturePolicy::createFromParentPolicy(policy1, originA);
91 EXPECT_TRUE(policy2->isFeatureEnabled(&kDocumentWrite));
92 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
93 EXPECT_FALSE(policy2->isFeatureEnabled(&kOffByDeaultFeature));
94 }
95
96 TEST_F(FeaturePolicyTest, TestInitialCrossOriginChildPolicy) {
97 // +-----------------+
98 // |(1)Origin A |
99 // |No Policy |
100 // | +-------------+ |
101 // | |(2)Origin B | |
102 // | |No Policy | |
103 // | +-------------+ |
104 // +-----------------+
105 // Default-on features should be enabled in child frame. Default-off and
106 // top-level-only features should be disabled.
107 FeaturePolicy* policy1 =
108 FeaturePolicy::createFromParentPolicy(nullptr, originA);
109 FeaturePolicy* policy2 =
110 FeaturePolicy::createFromParentPolicy(policy1, originB);
111 EXPECT_TRUE(policy2->isFeatureEnabled(&kDocumentWrite));
112 EXPECT_FALSE(policy2->isFeatureEnabled(&kVibrateFeature));
113 EXPECT_FALSE(policy2->isFeatureEnabled(&kOffByDeaultFeature));
114 }
115
116 TEST_F(FeaturePolicyTest, TestCrossOriginChildCannotEnableFeature) {
117 // +-------------------------------------+
118 // |(1) Origin A |
119 // |No Policy |
120 // | +---------------------------------+ |
121 // | |(2) Origin B | |
122 // | |Policy: {"vibrate": ["self"]} | |
123 // | +---------------------------------+ |
124 // +-------------------------------------+
125 // Feature should be disabled in cross origin frame, even if no policy was
126 // specified in the parent frame.
127 FeaturePolicy* policy1 =
128 FeaturePolicy::createFromParentPolicy(nullptr, originA);
129 FeaturePolicy* policy2 =
130 FeaturePolicy::createFromParentPolicy(policy1, originB);
131 policy2->setHeaderPolicy("{\"vibrate\": [\"self\"]}");
132 EXPECT_FALSE(policy2->isFeatureEnabled(&kVibrateFeature));
133 }
134
135 TEST_F(FeaturePolicyTest, TestFrameSelfInheritance) {
136 // +------------------------------------------+
137 // |(1) Origin A |
138 // |Policy: {"vibrate": ["self"]} |
139 // | +-----------------+ +-----------------+ |
140 // | |(2) Origin A | |(4) Origin B | |
141 // | |No Policy | |No Policy | |
142 // | | +-------------+ | | +-------------+ | |
143 // | | |(3)Origin A | | | |(5)Origin B | | |
144 // | | |No Policy | | | |No Policy | | |
145 // | | +-------------+ | | +-------------+ | |
146 // | +-----------------+ +-----------------+ |
147 // +------------------------------------------+
148 // Feature should be enabled at the top-level, and through the chain of
149 // same-origin frames 2 and 3. It should be disabled in frames 4 and 5, as
150 // they are at a different origin.
151 FeaturePolicy* policy1 =
152 FeaturePolicy::createFromParentPolicy(nullptr, originA);
153 policy1->setHeaderPolicy("{\"vibrate\": [\"self\"]}");
154 FeaturePolicy* policy2 =
155 FeaturePolicy::createFromParentPolicy(policy1, originA);
156 FeaturePolicy* policy3 =
157 FeaturePolicy::createFromParentPolicy(policy2, originA);
158 FeaturePolicy* policy4 =
159 FeaturePolicy::createFromParentPolicy(policy1, originB);
160 FeaturePolicy* policy5 =
161 FeaturePolicy::createFromParentPolicy(policy4, originB);
162 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
163 EXPECT_TRUE(policy3->isFeatureEnabled(&kVibrateFeature));
164 EXPECT_FALSE(policy4->isFeatureEnabled(&kVibrateFeature));
165 EXPECT_FALSE(policy5->isFeatureEnabled(&kVibrateFeature));
166 }
167
168 TEST_F(FeaturePolicyTest, TestReflexiveFrameSelfInheritance) {
169 // +---------------------------------+
170 // |(1) Origin A |
171 // |Policy: {"vibrate": ["self"]} |
172 // | +-----------------+ |
173 // | |(2) Origin B | |
174 // | |No Policy | |
175 // | | +-------------+ | |
176 // | | |(3)Origin A | | |
177 // | | |No Policy | | |
178 // | | +-------------+ | |
179 // | +-----------------+ |
180 // +---------------------------------+
181 // Feature which is enabled at top-level should be disabled in frame 3, as
182 // it is embedded by frame 2, for which the feature is not enabled.
183 FeaturePolicy* policy1 =
184 FeaturePolicy::createFromParentPolicy(nullptr, originA);
185 policy1->setHeaderPolicy("{\"vibrate\": [\"self\"]}");
186 FeaturePolicy* policy2 =
187 FeaturePolicy::createFromParentPolicy(policy1, originB);
188 FeaturePolicy* policy3 =
189 FeaturePolicy::createFromParentPolicy(policy2, originA);
190 EXPECT_FALSE(policy2->isFeatureEnabled(&kVibrateFeature));
191 EXPECT_FALSE(policy3->isFeatureEnabled(&kVibrateFeature));
192 }
193
194 TEST_F(FeaturePolicyTest, TestSelectiveFrameInheritance) {
195 // +------------------------------------------+
196 // |(1) Origin A |
197 // |Policy: {"vibrate": ["Origin B"]} |
198 // | +-----------------+ +-----------------+ |
199 // | |(2) Origin B | |(3) Origin C | |
200 // | |No Policy | |No Policy | |
201 // | | | | +-------------+ | |
202 // | | | | |(4)Origin B | | |
203 // | | | | |No Policy | | |
204 // | | | | +-------------+ | |
205 // | +-----------------+ +-----------------+ |
206 // +------------------------------------------+
207 // Feature should be enabled in second level Origin B frame, but disabled in
208 // Frame 4, because it is embedded by frame 3, where the feature is not
209 // enabled.
210 FeaturePolicy* policy1 =
211 FeaturePolicy::createFromParentPolicy(nullptr, originA);
212 policy1->setHeaderPolicy("{\"vibrate\": [\"" ORIGIN_B "\"]}");
213 FeaturePolicy* policy2 =
214 FeaturePolicy::createFromParentPolicy(policy1, originB);
215 FeaturePolicy* policy3 =
216 FeaturePolicy::createFromParentPolicy(policy1, originC);
217 FeaturePolicy* policy4 =
218 FeaturePolicy::createFromParentPolicy(policy3, originB);
219 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
220 EXPECT_FALSE(policy3->isFeatureEnabled(&kVibrateFeature));
221 EXPECT_FALSE(policy4->isFeatureEnabled(&kVibrateFeature));
222 }
223
224 TEST_F(FeaturePolicyTest, TestPolicyCanBlockSelf) {
225 // +----------------------------+
226 // |(1)Origin A |
227 // |Policy: {"docwrite": []} |
228 // +----------------------------+
229 // Default-on feature should be disabled in top-level frame.
230 FeaturePolicy* policy1 =
231 FeaturePolicy::createFromParentPolicy(nullptr, originA);
232 policy1->setHeaderPolicy("{\"docwrite\": []}");
233 EXPECT_FALSE(policy1->isFeatureEnabled(&kDocumentWrite));
234 }
235
236 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksSameOriginChildPolicy) {
237 // +----------------------------+
238 // |(1)Origin A |
239 // |Policy: {"docwrite": []} |
240 // | +-------------+ |
241 // | |(2)Origin A | |
242 // | |No Policy | |
243 // | +-------------+ |
244 // +----------------------------+
245 // Feature should be disabled in child frame.
246 FeaturePolicy* policy1 =
247 FeaturePolicy::createFromParentPolicy(nullptr, originA);
248 policy1->setHeaderPolicy("{\"docwrite\": []}");
249 FeaturePolicy* policy2 =
250 FeaturePolicy::createFromParentPolicy(policy1, originA);
251 EXPECT_FALSE(policy2->isFeatureEnabled(&kDocumentWrite));
252 }
253
254 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockSelf) {
255 // +--------------------------------+
256 // |(1)Origin A |
257 // |No Policy |
258 // | +----------------------------+ |
259 // | |(2)Origin B | |
260 // | |Policy: {"docwrite": []} | |
261 // | +----------------------------+ |
262 // +--------------------------------+
263 // Default-on feature should be disabled by cross-origin child frame.
264 FeaturePolicy* policy1 =
265 FeaturePolicy::createFromParentPolicy(nullptr, originA);
266 FeaturePolicy* policy2 =
267 FeaturePolicy::createFromParentPolicy(policy1, originB);
268 policy2->setHeaderPolicy("{\"docwrite\": []}");
269 EXPECT_FALSE(policy2->isFeatureEnabled(&kDocumentWrite));
270 }
271
272 TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockChildren) {
273 // +--------------------------------------+
274 // |(1)Origin A |
275 // |No Policy |
276 // | +----------------------------------+ |
277 // | |(2)Origin B | |
278 // | |Policy: {"docwrite": ["self"]} | |
279 // | | +-------------+ | |
280 // | | |(3)Origin C | | |
281 // | | |No Policy | | |
282 // | | +-------------+ | |
283 // | +----------------------------------+ |
284 // +--------------------------------------+
285 // Default-on feature should be enabled in frames 1 and 2; disabled in frame
286 // 3 by child frame policy.
287 FeaturePolicy* policy1 =
288 FeaturePolicy::createFromParentPolicy(nullptr, originA);
289 FeaturePolicy* policy2 =
290 FeaturePolicy::createFromParentPolicy(policy1, originB);
291 policy2->setHeaderPolicy("{\"docwrite\": [\"self\"]}");
292 FeaturePolicy* policy3 =
293 FeaturePolicy::createFromParentPolicy(policy2, originC);
294 EXPECT_TRUE(policy2->isFeatureEnabled(&kDocumentWrite));
295 EXPECT_FALSE(policy3->isFeatureEnabled(&kDocumentWrite));
296 }
297
298 TEST_F(FeaturePolicyTest, TestParentPolicyBlocksCrossOriginChildPolicy) {
299 // +----------------------------+
300 // |(1)Origin A |
301 // |Policy: {"docwrite": []} |
302 // | +-------------+ |
303 // | |(2)Origin B | |
304 // | |No Policy | |
305 // | +-------------+ |
306 // +----------------------------+
307 // Default-on feature should be disabled in cross-origin child frame.
308 FeaturePolicy* policy1 =
309 FeaturePolicy::createFromParentPolicy(nullptr, originA);
310 policy1->setHeaderPolicy("{\"docwrite\": []}");
311 FeaturePolicy* policy2 =
312 FeaturePolicy::createFromParentPolicy(policy1, originB);
313 EXPECT_FALSE(policy2->isFeatureEnabled(&kDocumentWrite));
314 }
315
316 TEST_F(FeaturePolicyTest, TestEnableForAllOrigins) {
317 // +------------------------------+
318 // |(1) Origin A |
319 // |Policy: {"vibrate": ["*"]} |
320 // | +-----------------+ |
321 // | |(2) Origin B | |
322 // | |No Policy | |
323 // | | +-------------+ | |
324 // | | |(3)Origin A | | |
325 // | | |No Policy | | |
326 // | | +-------------+ | |
327 // | +-----------------+ |
328 // +------------------------------+
329 // Feature should be enabled in top and second level; disabled in frame 3.
330 FeaturePolicy* policy1 =
331 FeaturePolicy::createFromParentPolicy(nullptr, originA);
332 policy1->setHeaderPolicy("{\"vibrate\": [\"*\"]}");
333 FeaturePolicy* policy2 =
334 FeaturePolicy::createFromParentPolicy(policy1, originB);
335 FeaturePolicy* policy3 =
336 FeaturePolicy::createFromParentPolicy(policy2, originA);
337 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
338 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
339 EXPECT_FALSE(policy3->isFeatureEnabled(&kVibrateFeature));
340 }
341
342 TEST_F(FeaturePolicyTest, TestReenableForAllOrigins) {
343 // +----------------------------------+
344 // |(1) Origin A |
345 // |Policy: {"vibrate": ["*"]} |
346 // | +------------------------------+ |
347 // | |(2) Origin B | |
348 // | |Policy: {"vibrate": ["*"]} | |
349 // | | +-------------+ | |
350 // | | |(3)Origin A | | |
351 // | | |No Policy | | |
352 // | | +-------------+ | |
353 // | +------------------------------+ |
354 // +----------------------------------+
355 // Feature should be enabled in all frames.
356 FeaturePolicy* policy1 =
357 FeaturePolicy::createFromParentPolicy(nullptr, originA);
358 policy1->setHeaderPolicy("{\"vibrate\": [\"*\"]}");
359 FeaturePolicy* policy2 =
360 FeaturePolicy::createFromParentPolicy(policy1, originB);
361 policy2->setHeaderPolicy("{\"vibrate\": [\"*\"]}");
362 FeaturePolicy* policy3 =
363 FeaturePolicy::createFromParentPolicy(policy2, originA);
364 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
365 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
366 EXPECT_TRUE(policy3->isFeatureEnabled(&kVibrateFeature));
367 }
368
369 TEST_F(FeaturePolicyTest, TestBlockedFrameCannotReenable) {
370 // +--------------------------------------+
371 // |(1)Origin A |
372 // |Policy: {"vibrate": ["self"]} |
373 // | +----------------------------------+ |
374 // | |(2)Origin B | |
375 // | |Policy: {"vibrate": ["*"]} | |
376 // | | +-------------+ +-------------+ | |
377 // | | |(3)Origin A | |(4)Origin C | | |
378 // | | |No Policy | |No Policy | | |
379 // | | +-------------+ +-------------+ | |
380 // | +----------------------------------+ |
381 // +--------------------------------------+
382 // Feature should be enabled at the top level; disabled in all other frames.
383 FeaturePolicy* policy1 =
384 FeaturePolicy::createFromParentPolicy(nullptr, originA);
385 policy1->setHeaderPolicy("{\"vibrate\": [\"self\"]}");
386 FeaturePolicy* policy2 =
387 FeaturePolicy::createFromParentPolicy(policy1, originB);
388 policy2->setHeaderPolicy("{\"vibrate\": [\"*\"]}");
389 FeaturePolicy* policy3 =
390 FeaturePolicy::createFromParentPolicy(policy2, originA);
391 FeaturePolicy* policy4 =
392 FeaturePolicy::createFromParentPolicy(policy2, originC);
393 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
394 EXPECT_FALSE(policy2->isFeatureEnabled(&kVibrateFeature));
395 EXPECT_FALSE(policy3->isFeatureEnabled(&kVibrateFeature));
396 EXPECT_FALSE(policy4->isFeatureEnabled(&kVibrateFeature));
397 }
398
399 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegate) {
400 // +-------------------------------------------------+
401 // |(1) Origin A |
402 // |Policy: {"vibrate": ["self", "Origin B"]} |
403 // | +---------------------------------------------+ |
404 // | |(2) Origin B | |
405 // | |Policy: {"vibrate": ["self", "Origin C"]} | |
406 // | | +-------------+ | |
407 // | | |(3)Origin C | | |
408 // | | |No Policy | | |
409 // | | +-------------+ | |
410 // | +---------------------------------------------+ |
411 // +-------------------------------------------------+
412 // Feature should be enabled in all frames.
413 FeaturePolicy* policy1 =
414 FeaturePolicy::createFromParentPolicy(nullptr, originA);
415 policy1->setHeaderPolicy("{\"vibrate\": [\"self\", \"" ORIGIN_B "\"]}");
416 FeaturePolicy* policy2 =
417 FeaturePolicy::createFromParentPolicy(policy1, originB);
418 policy2->setHeaderPolicy("{\"vibrate\": [\"self\", \"" ORIGIN_C "\"]}");
419 FeaturePolicy* policy3 =
420 FeaturePolicy::createFromParentPolicy(policy2, originC);
421 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
422 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
423 EXPECT_TRUE(policy3->isFeatureEnabled(&kVibrateFeature));
424 }
425
426 TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegateByDefault) {
427 // +-----------------------------------------------+
428 // |(1) Origin A |
429 // |Policy: {"docwrite": ["self", "Origin B"]} |
430 // | +--------------------+ +--------------------+ |
431 // | |(2) Origin B | | (4) Origin C | |
432 // | |No Policy | | No Policy | |
433 // | | +-------------+ | | | |
434 // | | |(3)Origin C | | | | |
435 // | | |No Policy | | | | |
436 // | | +-------------+ | | | |
437 // | +--------------------+ +--------------------+ |
438 // +-----------------------------------------------+
439 // Feature should be enabled in frames 1, 2, and 3, and disabled in frame 4.
440 FeaturePolicy* policy1 =
441 FeaturePolicy::createFromParentPolicy(nullptr, originA);
442 policy1->setHeaderPolicy("{\"docwrite\": [\"self\", \"" ORIGIN_B "\"]}");
443 FeaturePolicy* policy2 =
444 FeaturePolicy::createFromParentPolicy(policy1, originB);
445 FeaturePolicy* policy3 =
446 FeaturePolicy::createFromParentPolicy(policy2, originC);
447 FeaturePolicy* policy4 =
448 FeaturePolicy::createFromParentPolicy(policy1, originC);
449 EXPECT_TRUE(policy1->isFeatureEnabled(&kDocumentWrite));
450 EXPECT_TRUE(policy2->isFeatureEnabled(&kDocumentWrite));
451 EXPECT_TRUE(policy3->isFeatureEnabled(&kDocumentWrite));
452 EXPECT_FALSE(policy4->isFeatureEnabled(&kDocumentWrite));
453 }
454
455 TEST_F(FeaturePolicyTest, TestNonNestedFeaturesDontDelegateByDefault) {
456 // +-----------------------------------------------+
457 // |(1) Origin A |
458 // |Policy: {"vibrate": ["self", "Origin B"]} |
459 // | +--------------------+ +--------------------+ |
460 // | |(2) Origin B | | (4) Origin C | |
461 // | |No Policy | | No Policy | |
462 // | | +-------------+ | | | |
463 // | | |(3)Origin C | | | | |
464 // | | |No Policy | | | | |
465 // | | +-------------+ | | | |
466 // | +--------------------+ +--------------------+ |
467 // +-----------------------------------------------+
468 // Feature should be enabled in frames 1 and 2, and disabled in frames 3 and
469 // 4.
470 FeaturePolicy* policy1 =
471 FeaturePolicy::createFromParentPolicy(nullptr, originA);
472 policy1->setHeaderPolicy("{\"vibrate\": [\"self\", \"" ORIGIN_B "\"]}");
473 FeaturePolicy* policy2 =
474 FeaturePolicy::createFromParentPolicy(policy1, originB);
475 FeaturePolicy* policy3 =
476 FeaturePolicy::createFromParentPolicy(policy2, originC);
477 FeaturePolicy* policy4 =
478 FeaturePolicy::createFromParentPolicy(policy1, originC);
479 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
480 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
481 EXPECT_FALSE(policy3->isFeatureEnabled(&kVibrateFeature));
482 EXPECT_FALSE(policy4->isFeatureEnabled(&kVibrateFeature));
483 }
484
485 TEST_F(FeaturePolicyTest, TestFeaturesAreIndependent) {
486 // +---------------------------------------------+
487 // |(1) Origin A |
488 // |Policy: {"vibrate": ["self", "Origin B"], |
489 // | "docwrite": ["self"]} |
490 // | +-----------------------------------------+ |
491 // | |(2) Origin B | |
492 // | |Policy: {"vibrate": ["*"], | |
493 // | | "docwrite": ["*"]} | |
494 // | | +-------------+ | |
495 // | | |(3)Origin C | | |
496 // | | |No Policy | | |
497 // | | +-------------+ | |
498 // | +-----------------------------------------+ |
499 // +---------------------------------------------+
500 // Vibrate feature should be enabled in all frames; Docwrite feature
501 // should be enabled in frame 1, and disabled in frames 2 and 3.
502 FeaturePolicy* policy1 =
503 FeaturePolicy::createFromParentPolicy(nullptr, originA);
504 policy1->setHeaderPolicy("{\"vibrate\": [\"self\", \"" ORIGIN_B
505 "\"], \"docwrite\": [\"self\"]}");
506 FeaturePolicy* policy2 =
507 FeaturePolicy::createFromParentPolicy(policy1, originB);
508 policy2->setHeaderPolicy("{\"vibrate\": [\"*\"], \"docwrite\": [\"*\"]}");
509 FeaturePolicy* policy3 =
510 FeaturePolicy::createFromParentPolicy(policy2, originC);
511 EXPECT_TRUE(policy1->isFeatureEnabled(&kVibrateFeature));
512 EXPECT_TRUE(policy1->isFeatureEnabled(&kDocumentWrite));
513 EXPECT_TRUE(policy2->isFeatureEnabled(&kVibrateFeature));
514 EXPECT_FALSE(policy2->isFeatureEnabled(&kDocumentWrite));
515 EXPECT_TRUE(policy3->isFeatureEnabled(&kVibrateFeature));
516 EXPECT_FALSE(policy3->isFeatureEnabled(&kDocumentWrite));
517 }
518
519 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698