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

Side by Side Diff: chrome/common/extensions/features/base_feature_provider_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698