| 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 |
| 11 #define ORIGIN_A "https://example.com/" | 11 #define ORIGIN_A "https://example.com/" |
| 12 #define ORIGIN_B "https://example.net/" | 12 #define ORIGIN_B "https://example.net/" |
| 13 #define ORIGIN_C "https://example.org/" | 13 #define ORIGIN_C "https://example.org/" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char* g_k_valid_policies[] = { | 19 const char* const kValidPolicies[] = { |
| 20 "{\"vibrate\": []}", | 20 "{\"vibrate\": []}", |
| 21 "{\"vibrate\": [\"self\"]}", | 21 "{\"vibrate\": [\"self\"]}", |
| 22 "{\"vibrate\": [\"*\"]}", | 22 "{\"vibrate\": [\"*\"]}", |
| 23 "{\"vibrate\": [\"" ORIGIN_A "\"]}", | 23 "{\"vibrate\": [\"" ORIGIN_A "\"]}", |
| 24 "{\"vibrate\": [\"" ORIGIN_B "\"]}", | 24 "{\"vibrate\": [\"" ORIGIN_B "\"]}", |
| 25 "{\"vibrate\": [\"" ORIGIN_A "\", \"" ORIGIN_B "\"]}", | 25 "{\"vibrate\": [\"" ORIGIN_A "\", \"" ORIGIN_B "\"]}", |
| 26 "{\"fullscreen\": [\"" ORIGIN_A "\"], \"payment\": [\"self\"]}", | 26 "{\"fullscreen\": [\"" ORIGIN_A "\"], \"payment\": [\"self\"]}", |
| 27 "{\"fullscreen\": [\"" ORIGIN_A "\"]}, {\"payment\": [\"self\"]}"}; | 27 "{\"fullscreen\": [\"" ORIGIN_A "\"]}, {\"payment\": [\"self\"]}"}; |
| 28 | 28 |
| 29 const char* g_k_invalid_policies[] = { | 29 const char* g_k_invalid_policies[] = { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 ~FeaturePolicyTest() { | 43 ~FeaturePolicyTest() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 RefPtr<SecurityOrigin> origin_a_ = SecurityOrigin::CreateFromString(ORIGIN_A); | 46 RefPtr<SecurityOrigin> origin_a_ = SecurityOrigin::CreateFromString(ORIGIN_A); |
| 47 RefPtr<SecurityOrigin> origin_b_ = SecurityOrigin::CreateFromString(ORIGIN_B); | 47 RefPtr<SecurityOrigin> origin_b_ = SecurityOrigin::CreateFromString(ORIGIN_B); |
| 48 RefPtr<SecurityOrigin> origin_c_ = SecurityOrigin::CreateFromString(ORIGIN_C); | 48 RefPtr<SecurityOrigin> origin_c_ = SecurityOrigin::CreateFromString(ORIGIN_C); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(FeaturePolicyTest, ParseValidPolicy) { | 51 TEST_F(FeaturePolicyTest, ParseValidPolicy) { |
| 52 Vector<String> messages; | 52 Vector<String> messages; |
| 53 for (const char* policy_string : g_k_valid_policies) { | 53 for (const char* policy_string : kValidPolicies) { |
| 54 messages.Clear(); | 54 messages.Clear(); |
| 55 ParseFeaturePolicy(policy_string, origin_a_.Get(), &messages); | 55 ParseFeaturePolicy(policy_string, origin_a_.Get(), &messages); |
| 56 EXPECT_EQ(0UL, messages.size()); | 56 EXPECT_EQ(0UL, messages.size()); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST_F(FeaturePolicyTest, ParseInvalidPolicy) { | 60 TEST_F(FeaturePolicyTest, ParseInvalidPolicy) { |
| 61 Vector<String> messages; | 61 Vector<String> messages; |
| 62 for (const char* policy_string : g_k_invalid_policies) { | 62 for (const char* policy_string : g_k_invalid_policies) { |
| 63 messages.Clear(); | 63 messages.Clear(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( | 137 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( |
| 138 container_policy[0].origins[0].Get())); | 138 container_policy[0].origins[0].Get())); |
| 139 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature); | 139 EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature); |
| 140 EXPECT_FALSE(container_policy[1].matches_all_origins); | 140 EXPECT_FALSE(container_policy[1].matches_all_origins); |
| 141 EXPECT_EQ(1UL, container_policy[1].origins.size()); | 141 EXPECT_EQ(1UL, container_policy[1].origins.size()); |
| 142 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( | 142 EXPECT_TRUE(origin_a_->IsSameSchemeHostPortAndSuborigin( |
| 143 container_policy[1].origins[0].Get())); | 143 container_policy[1].origins[0].Get())); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace blink | 146 } // namespace blink |
| OLD | NEW |