| 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" | |
| 8 #include "chrome/common/extensions/value_builder.h" | 7 #include "chrome/common/extensions/value_builder.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 9 |
| 11 using chrome::VersionInfo; | 10 using chrome::VersionInfo; |
| 12 using extensions::BaseFeatureProvider; | 11 using extensions::BaseFeatureProvider; |
| 13 using extensions::DictionaryBuilder; | 12 using extensions::DictionaryBuilder; |
| 14 using extensions::Extension; | 13 using extensions::Extension; |
| 15 using extensions::Feature; | 14 using extensions::Feature; |
| 16 using extensions::ListBuilder; | 15 using extensions::ListBuilder; |
| 17 using extensions::Manifest; | 16 using extensions::Manifest; |
| 18 using extensions::PermissionFeature; | |
| 19 using extensions::SimpleFeature; | 17 using extensions::SimpleFeature; |
| 20 | 18 |
| 21 TEST(BaseFeatureProvider, ManifestFeatures) { | 19 TEST(BaseFeatureProvider, ManifestFeatures) { |
| 22 BaseFeatureProvider* provider = | 20 BaseFeatureProvider* provider = |
| 23 BaseFeatureProvider::GetManifestFeatures(); | 21 BaseFeatureProvider::GetManifestFeatures(); |
| 24 SimpleFeature* feature = | 22 SimpleFeature* feature = |
| 25 static_cast<SimpleFeature*>(provider->GetFeature("description")); | 23 static_cast<SimpleFeature*>(provider->GetFeature("description")); |
| 26 ASSERT_TRUE(feature); | 24 ASSERT_TRUE(feature); |
| 27 EXPECT_EQ(5u, feature->extension_types()->size()); | 25 EXPECT_EQ(5u, feature->extension_types()->size()); |
| 28 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); | 26 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature->IsAvailableToContext( | 93 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature->IsAvailableToContext( |
| 96 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); | 94 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); |
| 97 | 95 |
| 98 feature = | 96 feature = |
| 99 static_cast<SimpleFeature*>(provider->GetFeature("clipboardWrite")); | 97 static_cast<SimpleFeature*>(provider->GetFeature("clipboardWrite")); |
| 100 ASSERT_TRUE(feature); | 98 ASSERT_TRUE(feature); |
| 101 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( | 99 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( |
| 102 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); | 100 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); |
| 103 } | 101 } |
| 104 | 102 |
| 105 SimpleFeature* CreatePermissionFeature() { | |
| 106 return new PermissionFeature(); | |
| 107 } | |
| 108 | |
| 109 TEST(BaseFeatureProvider, Validation) { | 103 TEST(BaseFeatureProvider, Validation) { |
| 110 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 104 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 111 | 105 |
| 112 base::DictionaryValue* feature1 = new base::DictionaryValue(); | 106 base::DictionaryValue* feature1 = new base::DictionaryValue(); |
| 113 value->Set("feature1", feature1); | 107 value->Set("feature1", feature1); |
| 114 | 108 |
| 115 base::DictionaryValue* feature2 = new base::DictionaryValue(); | 109 base::DictionaryValue* feature2 = new base::DictionaryValue(); |
| 116 base::ListValue* extension_types = new base::ListValue(); | 110 base::ListValue* extension_types = new base::ListValue(); |
| 117 extension_types->Append(new base::StringValue("extension")); | 111 extension_types->Append(new base::StringValue("extension")); |
| 118 feature2->Set("extension_types", extension_types); | 112 feature2->Set("extension_types", extension_types); |
| 119 base::ListValue* contexts = new base::ListValue(); | 113 base::ListValue* contexts = new base::ListValue(); |
| 120 contexts->Append(new base::StringValue("blessed_extension")); | 114 contexts->Append(new base::StringValue("blessed_extension")); |
| 121 feature2->Set("contexts", contexts); | 115 feature2->Set("contexts", contexts); |
| 122 value->Set("feature2", feature2); | 116 value->Set("feature2", feature2); |
| 123 | 117 |
| 124 scoped_ptr<BaseFeatureProvider> provider( | 118 scoped_ptr<BaseFeatureProvider> provider( |
| 125 new BaseFeatureProvider(*value, CreatePermissionFeature)); | 119 new BaseFeatureProvider(*value, NULL)); |
| 126 | 120 |
| 127 // feature1 won't validate because it lacks an extension type. | 121 // feature1 won't validate because it lacks an extension type. |
| 128 EXPECT_FALSE(provider->GetFeature("feature1")); | 122 EXPECT_FALSE(provider->GetFeature("feature1")); |
| 129 | 123 |
| 130 // If we add one, it works. | 124 // If we add one, it works. |
| 131 feature1->Set("extension_types", extension_types->DeepCopy()); | 125 feature1->Set("extension_types", extension_types->DeepCopy()); |
| 132 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); | 126 provider.reset(new BaseFeatureProvider(*value, NULL)); |
| 133 EXPECT_TRUE(provider->GetFeature("feature1")); | 127 EXPECT_TRUE(provider->GetFeature("feature1")); |
| 134 | 128 |
| 135 // feature2 won't validate because of the presence of "contexts". | 129 // feature2 won't validate because of the presence of "contexts". |
| 136 EXPECT_FALSE(provider->GetFeature("feature2")); | 130 EXPECT_FALSE(provider->GetFeature("feature2")); |
| 137 | 131 |
| 138 // If we remove it, it works. | 132 // If we remove it, it works. |
| 139 feature2->Remove("contexts", NULL); | 133 feature2->Remove("contexts", NULL); |
| 140 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); | 134 provider.reset(new BaseFeatureProvider(*value, NULL)); |
| 141 EXPECT_TRUE(provider->GetFeature("feature2")); | 135 EXPECT_TRUE(provider->GetFeature("feature2")); |
| 142 } | 136 } |
| 143 | 137 |
| 144 TEST(BaseFeatureProvider, ComplexFeatures) { | 138 TEST(BaseFeatureProvider, ComplexFeatures) { |
| 145 scoped_ptr<base::DictionaryValue> rule( | 139 scoped_ptr<base::DictionaryValue> rule( |
| 146 DictionaryBuilder() | 140 DictionaryBuilder() |
| 147 .Set("feature1", | 141 .Set("feature1", |
| 148 ListBuilder().Append(DictionaryBuilder() | 142 ListBuilder().Append(DictionaryBuilder() |
| 149 .Set("channel", "beta") | 143 .Set("channel", "beta") |
| 150 .Set("extension_types", | 144 .Set("extension_types", |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 Manifest::TYPE_EXTENSION, | 176 Manifest::TYPE_EXTENSION, |
| 183 Feature::UNSPECIFIED_LOCATION, | 177 Feature::UNSPECIFIED_LOCATION, |
| 184 Feature::UNSPECIFIED_PLATFORM).result()); | 178 Feature::UNSPECIFIED_PLATFORM).result()); |
| 185 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( | 179 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| 186 "2", | 180 "2", |
| 187 Manifest::TYPE_LEGACY_PACKAGED_APP, | 181 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 188 Feature::UNSPECIFIED_LOCATION, | 182 Feature::UNSPECIFIED_LOCATION, |
| 189 Feature::UNSPECIFIED_PLATFORM).result()); | 183 Feature::UNSPECIFIED_PLATFORM).result()); |
| 190 } | 184 } |
| 191 } | 185 } |
| OLD | NEW |