OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/features/base_feature_provider.h" | 5 #include "chrome/common/extensions/features/base_feature_provider.h" |
6 | 6 |
7 #include "chrome/common/extensions/features/permission_feature.h" | 7 #include "chrome/common/extensions/features/permission_feature.h" |
8 #include "chrome/common/extensions/value_builder.h" | 8 #include "chrome/common/extensions/value_builder.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 SimpleFeature* CreatePermissionFeature() { | 99 SimpleFeature* CreatePermissionFeature() { |
100 return new PermissionFeature(); | 100 return new PermissionFeature(); |
101 } | 101 } |
102 | 102 |
103 TEST(BaseFeatureProviderTest, Validation) { | 103 TEST(BaseFeatureProviderTest, Validation) { |
104 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 104 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
105 | 105 |
106 base::DictionaryValue* feature1 = new base::DictionaryValue(); | 106 base::DictionaryValue* feature1 = new base::DictionaryValue(); |
| 107 feature1->SetString("channel", "trunk"); |
107 value->Set("feature1", feature1); | 108 value->Set("feature1", feature1); |
108 | 109 |
109 base::DictionaryValue* feature2 = new base::DictionaryValue(); | 110 base::DictionaryValue* feature2 = new base::DictionaryValue(); |
| 111 feature2->SetString("channel", "trunk"); |
110 base::ListValue* extension_types = new base::ListValue(); | 112 base::ListValue* extension_types = new base::ListValue(); |
111 extension_types->Append(new base::StringValue("extension")); | 113 extension_types->Append(new base::StringValue("extension")); |
112 feature2->Set("extension_types", extension_types); | 114 feature2->Set("extension_types", extension_types); |
113 base::ListValue* contexts = new base::ListValue(); | 115 base::ListValue* contexts = new base::ListValue(); |
114 contexts->Append(new base::StringValue("blessed_extension")); | 116 contexts->Append(new base::StringValue("blessed_extension")); |
115 feature2->Set("contexts", contexts); | 117 feature2->Set("contexts", contexts); |
116 value->Set("feature2", feature2); | 118 value->Set("feature2", feature2); |
117 | 119 |
118 scoped_ptr<BaseFeatureProvider> provider( | 120 scoped_ptr<BaseFeatureProvider> provider( |
119 new BaseFeatureProvider(*value, CreatePermissionFeature)); | 121 new BaseFeatureProvider(*value, CreatePermissionFeature)); |
120 | 122 |
121 // feature1 won't validate because it lacks an extension type. | 123 // feature1 won't validate because it lacks an extension type. |
122 EXPECT_FALSE(provider->GetFeature("feature1")); | 124 EXPECT_FALSE(provider->GetFeature("feature1")); |
123 | 125 |
124 // If we add one, it works. | 126 // If we add one, it works. |
125 feature1->Set("extension_types", extension_types->DeepCopy()); | 127 feature1->Set("extension_types", extension_types->DeepCopy()); |
126 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); | 128 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); |
127 EXPECT_TRUE(provider->GetFeature("feature1")); | 129 EXPECT_TRUE(provider->GetFeature("feature1")); |
128 | 130 |
| 131 // Remove the channel, and feature1 won't validate. |
| 132 feature1->Remove("channel", NULL); |
| 133 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); |
| 134 EXPECT_FALSE(provider->GetFeature("feature1")); |
| 135 |
129 // feature2 won't validate because of the presence of "contexts". | 136 // feature2 won't validate because of the presence of "contexts". |
130 EXPECT_FALSE(provider->GetFeature("feature2")); | 137 EXPECT_FALSE(provider->GetFeature("feature2")); |
131 | 138 |
132 // If we remove it, it works. | 139 // If we remove it, it works. |
133 feature2->Remove("contexts", NULL); | 140 feature2->Remove("contexts", NULL); |
134 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); | 141 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); |
135 EXPECT_TRUE(provider->GetFeature("feature2")); | 142 EXPECT_TRUE(provider->GetFeature("feature2")); |
136 } | 143 } |
137 | 144 |
138 TEST(BaseFeatureProviderTest, ComplexFeatures) { | 145 TEST(BaseFeatureProviderTest, ComplexFeatures) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 Feature::UNSPECIFIED_PLATFORM).result()); | 185 Feature::UNSPECIFIED_PLATFORM).result()); |
179 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( | 186 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
180 "2", | 187 "2", |
181 Manifest::TYPE_LEGACY_PACKAGED_APP, | 188 Manifest::TYPE_LEGACY_PACKAGED_APP, |
182 Feature::UNSPECIFIED_LOCATION, | 189 Feature::UNSPECIFIED_LOCATION, |
183 Feature::UNSPECIFIED_PLATFORM).result()); | 190 Feature::UNSPECIFIED_PLATFORM).result()); |
184 } | 191 } |
185 } | 192 } |
186 | 193 |
187 } // namespace extensions | 194 } // namespace extensions |
OLD | NEW |