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