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

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

Issue 14694010: Consolidate manifest handler registration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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/extension_unittest.h"
8 #include "chrome/common/extensions/features/permission_feature.h" 7 #include "chrome/common/extensions/features/permission_feature.h"
9 #include "chrome/common/extensions/value_builder.h" 8 #include "chrome/common/extensions/value_builder.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 using chrome::VersionInfo; 11 using chrome::VersionInfo;
13 12
14 namespace extensions { 13 namespace extensions {
15 14
16 class BaseFeatureProviderTest : public ExtensionTest { 15 TEST(BaseFeatureProviderTest, ManifestFeatures) {
17 };
18
19 TEST_F(BaseFeatureProviderTest, ManifestFeatures) {
20 FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); 16 FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest");
21 SimpleFeature* feature = 17 SimpleFeature* feature =
22 static_cast<SimpleFeature*>(provider->GetFeature("description")); 18 static_cast<SimpleFeature*>(provider->GetFeature("description"));
23 ASSERT_TRUE(feature); 19 ASSERT_TRUE(feature);
24 EXPECT_EQ(6u, feature->extension_types()->size()); 20 EXPECT_EQ(6u, feature->extension_types()->size());
25 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); 21 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION));
26 EXPECT_EQ(1u, 22 EXPECT_EQ(1u,
27 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); 23 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP));
28 EXPECT_EQ(1u, 24 EXPECT_EQ(1u,
29 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); 25 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP));
(...skipping 22 matching lines...) Expand all
52 EXPECT_EQ(Feature::INVALID_TYPE, feature->IsAvailableToContext( 48 EXPECT_EQ(Feature::INVALID_TYPE, feature->IsAvailableToContext(
53 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); 49 extension.get(), Feature::UNSPECIFIED_CONTEXT).result());
54 50
55 feature = 51 feature =
56 static_cast<SimpleFeature*>(provider->GetFeature("devtools_page")); 52 static_cast<SimpleFeature*>(provider->GetFeature("devtools_page"));
57 ASSERT_TRUE(feature); 53 ASSERT_TRUE(feature);
58 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( 54 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext(
59 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); 55 extension.get(), Feature::UNSPECIFIED_CONTEXT).result());
60 } 56 }
61 57
62 TEST_F(BaseFeatureProviderTest, PermissionFeatures) { 58 TEST(BaseFeatureProviderTest, PermissionFeatures) {
63 FeatureProvider* provider = BaseFeatureProvider::GetByName("permission"); 59 FeatureProvider* provider = BaseFeatureProvider::GetByName("permission");
64 SimpleFeature* feature = 60 SimpleFeature* feature =
65 static_cast<SimpleFeature*>(provider->GetFeature("contextMenus")); 61 static_cast<SimpleFeature*>(provider->GetFeature("contextMenus"));
66 ASSERT_TRUE(feature); 62 ASSERT_TRUE(feature);
67 EXPECT_EQ(3u, feature->extension_types()->size()); 63 EXPECT_EQ(3u, feature->extension_types()->size());
68 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); 64 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION));
69 EXPECT_EQ(1u, 65 EXPECT_EQ(1u,
70 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); 66 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP));
71 EXPECT_EQ(1u, 67 EXPECT_EQ(1u,
72 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); 68 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP));
(...skipping 24 matching lines...) Expand all
97 static_cast<SimpleFeature*>(provider->GetFeature("clipboardWrite")); 93 static_cast<SimpleFeature*>(provider->GetFeature("clipboardWrite"));
98 ASSERT_TRUE(feature); 94 ASSERT_TRUE(feature);
99 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( 95 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext(
100 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); 96 extension.get(), Feature::UNSPECIFIED_CONTEXT).result());
101 } 97 }
102 98
103 SimpleFeature* CreatePermissionFeature() { 99 SimpleFeature* CreatePermissionFeature() {
104 return new PermissionFeature(); 100 return new PermissionFeature();
105 } 101 }
106 102
107 TEST_F(BaseFeatureProviderTest, Validation) { 103 TEST(BaseFeatureProviderTest, Validation) {
108 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 104 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
109 105
110 base::DictionaryValue* feature1 = new base::DictionaryValue(); 106 base::DictionaryValue* feature1 = new base::DictionaryValue();
111 value->Set("feature1", feature1); 107 value->Set("feature1", feature1);
112 108
113 base::DictionaryValue* feature2 = new base::DictionaryValue(); 109 base::DictionaryValue* feature2 = new base::DictionaryValue();
114 base::ListValue* extension_types = new base::ListValue(); 110 base::ListValue* extension_types = new base::ListValue();
115 extension_types->Append(new base::StringValue("extension")); 111 extension_types->Append(new base::StringValue("extension"));
116 feature2->Set("extension_types", extension_types); 112 feature2->Set("extension_types", extension_types);
117 base::ListValue* contexts = new base::ListValue(); 113 base::ListValue* contexts = new base::ListValue();
(...skipping 14 matching lines...) Expand all
132 128
133 // feature2 won't validate because of the presence of "contexts". 129 // feature2 won't validate because of the presence of "contexts".
134 EXPECT_FALSE(provider->GetFeature("feature2")); 130 EXPECT_FALSE(provider->GetFeature("feature2"));
135 131
136 // If we remove it, it works. 132 // If we remove it, it works.
137 feature2->Remove("contexts", NULL); 133 feature2->Remove("contexts", NULL);
138 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature)); 134 provider.reset(new BaseFeatureProvider(*value, CreatePermissionFeature));
139 EXPECT_TRUE(provider->GetFeature("feature2")); 135 EXPECT_TRUE(provider->GetFeature("feature2"));
140 } 136 }
141 137
142 TEST_F(BaseFeatureProviderTest, ComplexFeatures) { 138 TEST(BaseFeatureProviderTest, ComplexFeatures) {
143 scoped_ptr<base::DictionaryValue> rule( 139 scoped_ptr<base::DictionaryValue> rule(
144 DictionaryBuilder() 140 DictionaryBuilder()
145 .Set("feature1", 141 .Set("feature1",
146 ListBuilder().Append(DictionaryBuilder() 142 ListBuilder().Append(DictionaryBuilder()
147 .Set("channel", "beta") 143 .Set("channel", "beta")
148 .Set("extension_types", 144 .Set("extension_types",
149 ListBuilder().Append("extension"))) 145 ListBuilder().Append("extension")))
150 .Append(DictionaryBuilder() 146 .Append(DictionaryBuilder()
151 .Set("channel", "beta") 147 .Set("channel", "beta")
152 .Set("extension_types", 148 .Set("extension_types",
(...skipping 29 matching lines...) Expand all
182 Feature::UNSPECIFIED_PLATFORM).result()); 178 Feature::UNSPECIFIED_PLATFORM).result());
183 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 179 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
184 "2", 180 "2",
185 Manifest::TYPE_LEGACY_PACKAGED_APP, 181 Manifest::TYPE_LEGACY_PACKAGED_APP,
186 Feature::UNSPECIFIED_LOCATION, 182 Feature::UNSPECIFIED_LOCATION,
187 Feature::UNSPECIFIED_PLATFORM).result()); 183 Feature::UNSPECIFIED_PLATFORM).result());
188 } 184 }
189 } 185 }
190 186
191 } // namespace extensions 187 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unittest.cc ('k') | chrome/common/extensions/manifest_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698