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

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

Powered by Google App Engine
This is Rietveld 408576698