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

Side by Side Diff: extensions/common/features/simple_feature_unittest.cc

Issue 241673002: Support a "policy" extension location in extension features files. At the same (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: format Created 6 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
« no previous file with comments | « extensions/common/features/simple_feature_filter.cc ('k') | extensions/common/manifest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/features/simple_feature.h" 5 #include "extensions/common/features/simple_feature.h"
6 6
7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" 7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h"
8 #include "chrome/common/extensions/features/feature_channel.h" 8 #include "chrome/common/extensions/features/feature_channel.h"
9 #include "extensions/common/value_builder.h" 9 #include "extensions/common/value_builder.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using chrome::VersionInfo; 12 using chrome::VersionInfo;
13 using extensions::DictionaryBuilder; 13 using extensions::DictionaryBuilder;
14 using extensions::Extension; 14 using extensions::Extension;
15 using extensions::Feature; 15 using extensions::Feature;
16 using extensions::ListBuilder; 16 using extensions::ListBuilder;
17 using extensions::Manifest; 17 using extensions::Manifest;
18 using extensions::ScopedCurrentChannel; 18 using extensions::ScopedCurrentChannel;
19 using extensions::SimpleFeature; 19 using extensions::SimpleFeature;
20 20
21 namespace extensions {
22
21 namespace { 23 namespace {
22 24
23 struct IsAvailableTestData { 25 struct IsAvailableTestData {
24 std::string extension_id; 26 std::string extension_id;
25 Manifest::Type extension_type; 27 Manifest::Type extension_type;
26 Feature::Location location; 28 Manifest::Location location;
27 Feature::Platform platform; 29 Feature::Platform platform;
28 int manifest_version; 30 int manifest_version;
29 Feature::AvailabilityResult expected_result; 31 Feature::AvailabilityResult expected_result;
30 }; 32 };
31 33
34 } // namespace
35
32 class ExtensionSimpleFeatureTest : public testing::Test { 36 class ExtensionSimpleFeatureTest : public testing::Test {
33 protected: 37 protected:
34 ExtensionSimpleFeatureTest() 38 ExtensionSimpleFeatureTest()
35 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} 39 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
36 virtual ~ExtensionSimpleFeatureTest() {} 40 virtual ~ExtensionSimpleFeatureTest() {}
37 41
42 bool LocationIsAvailable(SimpleFeature::Location feature_location,
43 Manifest::Location manifest_location) {
44 SimpleFeature feature;
45 feature.set_location(feature_location);
46 Feature::AvailabilityResult availability_result =
47 feature.IsAvailableToManifest(std::string(),
48 Manifest::TYPE_UNKNOWN,
49 manifest_location,
50 -1,
51 Feature::UNSPECIFIED_PLATFORM).result();
52 return availability_result == Feature::IS_AVAILABLE;
53 }
54
38 private: 55 private:
39 ScopedCurrentChannel current_channel_; 56 ScopedCurrentChannel current_channel_;
40 }; 57 };
41 58
42 TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) { 59 TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) {
43 const IsAvailableTestData tests[] = { 60 const IsAvailableTestData tests[] = {
44 { "", Manifest::TYPE_UNKNOWN, 61 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
45 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, 62 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
46 Feature::IS_AVAILABLE }, 63 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
47 { "random-extension", Manifest::TYPE_UNKNOWN, 64 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
48 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, 65 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION,
49 Feature::IS_AVAILABLE }, 66 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
50 { "", Manifest::TYPE_LEGACY_PACKAGED_APP, 67 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
51 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, 68 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
52 Feature::IS_AVAILABLE }, 69 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT,
53 { "", Manifest::TYPE_UNKNOWN, 70 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
54 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, 71 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
55 Feature::IS_AVAILABLE }, 72 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE},
56 { "", Manifest::TYPE_UNKNOWN, 73 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
57 Feature::COMPONENT_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, 74 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}};
58 Feature::IS_AVAILABLE },
59 { "", Manifest::TYPE_UNKNOWN,
60 Feature::UNSPECIFIED_LOCATION, Feature::CHROMEOS_PLATFORM, -1,
61 Feature::IS_AVAILABLE },
62 { "", Manifest::TYPE_UNKNOWN,
63 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, 25,
64 Feature::IS_AVAILABLE }
65 };
66 75
67 SimpleFeature feature; 76 SimpleFeature feature;
68 for (size_t i = 0; i < arraysize(tests); ++i) { 77 for (size_t i = 0; i < arraysize(tests); ++i) {
69 const IsAvailableTestData& test = tests[i]; 78 const IsAvailableTestData& test = tests[i];
70 EXPECT_EQ(test.expected_result, 79 EXPECT_EQ(test.expected_result,
71 feature.IsAvailableToManifest(test.extension_id, 80 feature.IsAvailableToManifest(test.extension_id,
72 test.extension_type, 81 test.extension_type,
73 test.location, 82 test.location,
74 test.manifest_version, 83 test.manifest_version,
75 test.platform).result()); 84 test.platform).result());
76 } 85 }
77 } 86 }
78 87
79 TEST_F(ExtensionSimpleFeatureTest, Whitelist) { 88 TEST_F(ExtensionSimpleFeatureTest, Whitelist) {
80 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 89 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
81 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 90 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
82 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); 91 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh");
83 SimpleFeature feature; 92 SimpleFeature feature;
84 feature.whitelist()->insert(kIdFoo); 93 feature.whitelist()->insert(kIdFoo);
85 feature.whitelist()->insert(kIdBar); 94 feature.whitelist()->insert(kIdBar);
86 95
87 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( 96 EXPECT_EQ(
88 kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, 97 Feature::IS_AVAILABLE,
89 Feature::UNSPECIFIED_PLATFORM).result()); 98 feature.IsAvailableToManifest(kIdFoo,
90 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( 99 Manifest::TYPE_UNKNOWN,
91 kIdBar, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, 100 Manifest::INVALID_LOCATION,
92 Feature::UNSPECIFIED_PLATFORM).result()); 101 -1,
102 Feature::UNSPECIFIED_PLATFORM).result());
103 EXPECT_EQ(
104 Feature::IS_AVAILABLE,
105 feature.IsAvailableToManifest(kIdBar,
106 Manifest::TYPE_UNKNOWN,
107 Manifest::INVALID_LOCATION,
108 -1,
109 Feature::UNSPECIFIED_PLATFORM).result());
93 110
94 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( 111 EXPECT_EQ(
95 kIdBaz, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, 112 Feature::NOT_FOUND_IN_WHITELIST,
96 Feature::UNSPECIFIED_PLATFORM).result()); 113 feature.IsAvailableToManifest(kIdBaz,
114 Manifest::TYPE_UNKNOWN,
115 Manifest::INVALID_LOCATION,
116 -1,
117 Feature::UNSPECIFIED_PLATFORM).result());
97 EXPECT_EQ( 118 EXPECT_EQ(
98 Feature::NOT_FOUND_IN_WHITELIST, 119 Feature::NOT_FOUND_IN_WHITELIST,
99 feature.IsAvailableToManifest(std::string(), 120 feature.IsAvailableToManifest(std::string(),
100 Manifest::TYPE_UNKNOWN, 121 Manifest::TYPE_UNKNOWN,
101 Feature::UNSPECIFIED_LOCATION, 122 Manifest::INVALID_LOCATION,
102 -1, 123 -1,
103 Feature::UNSPECIFIED_PLATFORM).result()); 124 Feature::UNSPECIFIED_PLATFORM).result());
104 125
105 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 126 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
106 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( 127 EXPECT_EQ(
107 kIdBaz, Manifest::TYPE_LEGACY_PACKAGED_APP, 128 Feature::NOT_FOUND_IN_WHITELIST,
108 Feature::UNSPECIFIED_LOCATION, -1, 129 feature.IsAvailableToManifest(kIdBaz,
109 Feature::UNSPECIFIED_PLATFORM).result()); 130 Manifest::TYPE_LEGACY_PACKAGED_APP,
131 Manifest::INVALID_LOCATION,
132 -1,
133 Feature::UNSPECIFIED_PLATFORM).result());
110 } 134 }
111 135
112 TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) { 136 TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) {
113 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | 137 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" |
114 // sha1sum | tr '[:lower:]' '[:upper:]' 138 // sha1sum | tr '[:lower:]' '[:upper:]'
115 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 139 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
116 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); 140 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897");
117 SimpleFeature feature; 141 SimpleFeature feature;
118 142
119 feature.whitelist()->insert(kIdFooHashed); 143 feature.whitelist()->insert(kIdFooHashed);
120 144
121 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( 145 EXPECT_EQ(
122 kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, 146 Feature::IS_AVAILABLE,
123 Feature::UNSPECIFIED_PLATFORM).result()); 147 feature.IsAvailableToManifest(kIdFoo,
124 EXPECT_NE(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( 148 Manifest::TYPE_UNKNOWN,
125 kIdFooHashed, Manifest::TYPE_UNKNOWN, 149 Manifest::INVALID_LOCATION,
126 Feature::UNSPECIFIED_LOCATION, -1, 150 -1,
127 Feature::UNSPECIFIED_PLATFORM).result()); 151 Feature::UNSPECIFIED_PLATFORM).result());
128 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( 152 EXPECT_NE(
129 "slightlytoooolongforanextensionid", Manifest::TYPE_UNKNOWN, 153 Feature::IS_AVAILABLE,
130 Feature::UNSPECIFIED_LOCATION, -1, 154 feature.IsAvailableToManifest(kIdFooHashed,
131 Feature::UNSPECIFIED_PLATFORM).result()); 155 Manifest::TYPE_UNKNOWN,
132 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( 156 Manifest::INVALID_LOCATION,
133 "tooshortforanextensionid", Manifest::TYPE_UNKNOWN, 157 -1,
134 Feature::UNSPECIFIED_LOCATION, -1, 158 Feature::UNSPECIFIED_PLATFORM).result());
135 Feature::UNSPECIFIED_PLATFORM).result()); 159 EXPECT_EQ(
160 Feature::NOT_FOUND_IN_WHITELIST,
161 feature.IsAvailableToManifest("slightlytoooolongforanextensionid",
162 Manifest::TYPE_UNKNOWN,
163 Manifest::INVALID_LOCATION,
164 -1,
165 Feature::UNSPECIFIED_PLATFORM).result());
166 EXPECT_EQ(
167 Feature::NOT_FOUND_IN_WHITELIST,
168 feature.IsAvailableToManifest("tooshortforanextensionid",
169 Manifest::TYPE_UNKNOWN,
170 Manifest::INVALID_LOCATION,
171 -1,
172 Feature::UNSPECIFIED_PLATFORM).result());
136 } 173 }
137 174
138 TEST_F(ExtensionSimpleFeatureTest, PackageType) { 175 TEST_F(ExtensionSimpleFeatureTest, PackageType) {
139 SimpleFeature feature; 176 SimpleFeature feature;
140 feature.extension_types()->insert(Manifest::TYPE_EXTENSION); 177 feature.extension_types()->insert(Manifest::TYPE_EXTENSION);
141 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 178 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
142 179
143 EXPECT_EQ( 180 EXPECT_EQ(
144 Feature::IS_AVAILABLE, 181 Feature::IS_AVAILABLE,
145 feature.IsAvailableToManifest(std::string(), 182 feature.IsAvailableToManifest(std::string(),
146 Manifest::TYPE_EXTENSION, 183 Manifest::TYPE_EXTENSION,
147 Feature::UNSPECIFIED_LOCATION, 184 Manifest::INVALID_LOCATION,
148 -1, 185 -1,
149 Feature::UNSPECIFIED_PLATFORM).result()); 186 Feature::UNSPECIFIED_PLATFORM).result());
150 EXPECT_EQ( 187 EXPECT_EQ(
151 Feature::IS_AVAILABLE, 188 Feature::IS_AVAILABLE,
152 feature.IsAvailableToManifest(std::string(), 189 feature.IsAvailableToManifest(std::string(),
153 Manifest::TYPE_LEGACY_PACKAGED_APP, 190 Manifest::TYPE_LEGACY_PACKAGED_APP,
154 Feature::UNSPECIFIED_LOCATION, 191 Manifest::INVALID_LOCATION,
155 -1, 192 -1,
156 Feature::UNSPECIFIED_PLATFORM).result()); 193 Feature::UNSPECIFIED_PLATFORM).result());
157 194
158 EXPECT_EQ( 195 EXPECT_EQ(
159 Feature::INVALID_TYPE, 196 Feature::INVALID_TYPE,
160 feature.IsAvailableToManifest(std::string(), 197 feature.IsAvailableToManifest(std::string(),
161 Manifest::TYPE_UNKNOWN, 198 Manifest::TYPE_UNKNOWN,
162 Feature::UNSPECIFIED_LOCATION, 199 Manifest::INVALID_LOCATION,
163 -1, 200 -1,
164 Feature::UNSPECIFIED_PLATFORM).result()); 201 Feature::UNSPECIFIED_PLATFORM).result());
165 EXPECT_EQ( 202 EXPECT_EQ(
166 Feature::INVALID_TYPE, 203 Feature::INVALID_TYPE,
167 feature.IsAvailableToManifest(std::string(), 204 feature.IsAvailableToManifest(std::string(),
168 Manifest::TYPE_THEME, 205 Manifest::TYPE_THEME,
169 Feature::UNSPECIFIED_LOCATION, 206 Manifest::INVALID_LOCATION,
170 -1, 207 -1,
171 Feature::UNSPECIFIED_PLATFORM).result()); 208 Feature::UNSPECIFIED_PLATFORM).result());
172 } 209 }
173 210
174 TEST_F(ExtensionSimpleFeatureTest, Context) { 211 TEST_F(ExtensionSimpleFeatureTest, Context) {
175 SimpleFeature feature; 212 SimpleFeature feature;
176 feature.set_name("somefeature"); 213 feature.set_name("somefeature");
177 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 214 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
178 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 215 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
179 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); 216 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 269 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
233 Feature::CHROMEOS_PLATFORM); 270 Feature::CHROMEOS_PLATFORM);
234 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); 271 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result());
235 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " 272 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, "
236 "content scripts, and web pages, but this is a privileged page", 273 "content scripts, and web pages, but this is a privileged page",
237 availability.message()); 274 availability.message());
238 } 275 }
239 276
240 feature.GetContexts()->clear(); 277 feature.GetContexts()->clear();
241 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 278 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
242 feature.set_location(Feature::COMPONENT_LOCATION); 279 feature.set_location(SimpleFeature::COMPONENT_LOCATION);
243 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( 280 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext(
244 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 281 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
245 Feature::CHROMEOS_PLATFORM).result()); 282 Feature::CHROMEOS_PLATFORM).result());
246 feature.set_location(Feature::UNSPECIFIED_LOCATION); 283 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION);
247 284
248 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( 285 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext(
249 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 286 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
250 Feature::UNSPECIFIED_PLATFORM).result()); 287 Feature::UNSPECIFIED_PLATFORM).result());
251 288
252 feature.set_min_manifest_version(22); 289 feature.set_min_manifest_version(22);
253 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext( 290 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext(
254 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 291 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
255 Feature::CHROMEOS_PLATFORM).result()); 292 Feature::CHROMEOS_PLATFORM).result());
256 feature.set_min_manifest_version(21); 293 feature.set_min_manifest_version(21);
257 294
258 feature.set_max_manifest_version(18); 295 feature.set_max_manifest_version(18);
259 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( 296 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext(
260 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 297 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
261 Feature::CHROMEOS_PLATFORM).result()); 298 Feature::CHROMEOS_PLATFORM).result());
262 feature.set_max_manifest_version(25); 299 feature.set_max_manifest_version(25);
263 } 300 }
264 301
265 TEST_F(ExtensionSimpleFeatureTest, Location) { 302 TEST_F(ExtensionSimpleFeatureTest, Location) {
266 SimpleFeature feature; 303 // Component extensions can access any location.
304 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
305 Manifest::COMPONENT));
306 EXPECT_TRUE(
307 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT));
308 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION,
309 Manifest::COMPONENT));
267 310
268 // If the feature specifies "component" as its location, then only component 311 // Only component extensions can access the "component" location.
269 // extensions can access it. 312 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
270 feature.set_location(Feature::COMPONENT_LOCATION); 313 Manifest::INVALID_LOCATION));
271 EXPECT_EQ( 314 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
272 Feature::IS_AVAILABLE, 315 Manifest::UNPACKED));
273 feature.IsAvailableToManifest(std::string(), 316 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
274 Manifest::TYPE_UNKNOWN, 317 Manifest::EXTERNAL_PREF_DOWNLOAD));
275 Feature::COMPONENT_LOCATION, 318 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
276 -1, 319 Manifest::EXTERNAL_POLICY));
277 Feature::UNSPECIFIED_PLATFORM).result()); 320 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
278 EXPECT_EQ( 321 Manifest::EXTERNAL_POLICY_DOWNLOAD));
279 Feature::INVALID_LOCATION,
280 feature.IsAvailableToManifest(std::string(),
281 Manifest::TYPE_UNKNOWN,
282 Feature::UNSPECIFIED_LOCATION,
283 -1,
284 Feature::UNSPECIFIED_PLATFORM).result());
285 322
286 // But component extensions can access anything else, whatever their location. 323 // Policy extensions can access the "policy" location.
287 feature.set_location(Feature::UNSPECIFIED_LOCATION); 324 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION,
288 EXPECT_EQ( 325 Manifest::EXTERNAL_POLICY));
289 Feature::IS_AVAILABLE, 326 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION,
290 feature.IsAvailableToManifest(std::string(), 327 Manifest::EXTERNAL_POLICY_DOWNLOAD));
291 Manifest::TYPE_UNKNOWN, 328
292 Feature::COMPONENT_LOCATION, 329 // Non-policy (except component) extensions cannot access policy.
293 -1, 330 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION,
294 Feature::UNSPECIFIED_PLATFORM).result()); 331 Manifest::INVALID_LOCATION));
332 EXPECT_FALSE(
333 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::UNPACKED));
334 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION,
335 Manifest::EXTERNAL_PREF_DOWNLOAD));
295 } 336 }
296 337
297 TEST_F(ExtensionSimpleFeatureTest, Platform) { 338 TEST_F(ExtensionSimpleFeatureTest, Platform) {
298 SimpleFeature feature; 339 SimpleFeature feature;
299 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); 340 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
300 EXPECT_EQ(Feature::IS_AVAILABLE, 341 EXPECT_EQ(Feature::IS_AVAILABLE,
301 feature.IsAvailableToManifest(std::string(), 342 feature.IsAvailableToManifest(std::string(),
302 Manifest::TYPE_UNKNOWN, 343 Manifest::TYPE_UNKNOWN,
303 Feature::UNSPECIFIED_LOCATION, 344 Manifest::INVALID_LOCATION,
304 -1, 345 -1,
305 Feature::CHROMEOS_PLATFORM).result()); 346 Feature::CHROMEOS_PLATFORM).result());
306 EXPECT_EQ( 347 EXPECT_EQ(
307 Feature::INVALID_PLATFORM, 348 Feature::INVALID_PLATFORM,
308 feature.IsAvailableToManifest(std::string(), 349 feature.IsAvailableToManifest(std::string(),
309 Manifest::TYPE_UNKNOWN, 350 Manifest::TYPE_UNKNOWN,
310 Feature::UNSPECIFIED_LOCATION, 351 Manifest::INVALID_LOCATION,
311 -1, 352 -1,
312 Feature::UNSPECIFIED_PLATFORM).result()); 353 Feature::UNSPECIFIED_PLATFORM).result());
313 } 354 }
314 355
315 TEST_F(ExtensionSimpleFeatureTest, Version) { 356 TEST_F(ExtensionSimpleFeatureTest, Version) {
316 SimpleFeature feature; 357 SimpleFeature feature;
317 feature.set_min_manifest_version(5); 358 feature.set_min_manifest_version(5);
318 359
319 EXPECT_EQ( 360 EXPECT_EQ(
320 Feature::INVALID_MIN_MANIFEST_VERSION, 361 Feature::INVALID_MIN_MANIFEST_VERSION,
321 feature.IsAvailableToManifest(std::string(), 362 feature.IsAvailableToManifest(std::string(),
322 Manifest::TYPE_UNKNOWN, 363 Manifest::TYPE_UNKNOWN,
323 Feature::UNSPECIFIED_LOCATION, 364 Manifest::INVALID_LOCATION,
324 0, 365 0,
325 Feature::UNSPECIFIED_PLATFORM).result()); 366 Feature::UNSPECIFIED_PLATFORM).result());
326 EXPECT_EQ( 367 EXPECT_EQ(
327 Feature::INVALID_MIN_MANIFEST_VERSION, 368 Feature::INVALID_MIN_MANIFEST_VERSION,
328 feature.IsAvailableToManifest(std::string(), 369 feature.IsAvailableToManifest(std::string(),
329 Manifest::TYPE_UNKNOWN, 370 Manifest::TYPE_UNKNOWN,
330 Feature::UNSPECIFIED_LOCATION, 371 Manifest::INVALID_LOCATION,
331 4, 372 4,
332 Feature::UNSPECIFIED_PLATFORM).result()); 373 Feature::UNSPECIFIED_PLATFORM).result());
333 374
334 EXPECT_EQ( 375 EXPECT_EQ(
335 Feature::IS_AVAILABLE, 376 Feature::IS_AVAILABLE,
336 feature.IsAvailableToManifest(std::string(), 377 feature.IsAvailableToManifest(std::string(),
337 Manifest::TYPE_UNKNOWN, 378 Manifest::TYPE_UNKNOWN,
338 Feature::UNSPECIFIED_LOCATION, 379 Manifest::INVALID_LOCATION,
339 5, 380 5,
340 Feature::UNSPECIFIED_PLATFORM).result()); 381 Feature::UNSPECIFIED_PLATFORM).result());
341 EXPECT_EQ( 382 EXPECT_EQ(
342 Feature::IS_AVAILABLE, 383 Feature::IS_AVAILABLE,
343 feature.IsAvailableToManifest(std::string(), 384 feature.IsAvailableToManifest(std::string(),
344 Manifest::TYPE_UNKNOWN, 385 Manifest::TYPE_UNKNOWN,
345 Feature::UNSPECIFIED_LOCATION, 386 Manifest::INVALID_LOCATION,
346 10, 387 10,
347 Feature::UNSPECIFIED_PLATFORM).result()); 388 Feature::UNSPECIFIED_PLATFORM).result());
348 389
349 feature.set_max_manifest_version(8); 390 feature.set_max_manifest_version(8);
350 391
351 EXPECT_EQ( 392 EXPECT_EQ(
352 Feature::INVALID_MAX_MANIFEST_VERSION, 393 Feature::INVALID_MAX_MANIFEST_VERSION,
353 feature.IsAvailableToManifest(std::string(), 394 feature.IsAvailableToManifest(std::string(),
354 Manifest::TYPE_UNKNOWN, 395 Manifest::TYPE_UNKNOWN,
355 Feature::UNSPECIFIED_LOCATION, 396 Manifest::INVALID_LOCATION,
356 10, 397 10,
357 Feature::UNSPECIFIED_PLATFORM).result()); 398 Feature::UNSPECIFIED_PLATFORM).result());
358 EXPECT_EQ( 399 EXPECT_EQ(
359 Feature::IS_AVAILABLE, 400 Feature::IS_AVAILABLE,
360 feature.IsAvailableToManifest(std::string(), 401 feature.IsAvailableToManifest(std::string(),
361 Manifest::TYPE_UNKNOWN, 402 Manifest::TYPE_UNKNOWN,
362 Feature::UNSPECIFIED_LOCATION, 403 Manifest::INVALID_LOCATION,
363 8, 404 8,
364 Feature::UNSPECIFIED_PLATFORM).result()); 405 Feature::UNSPECIFIED_PLATFORM).result());
365 EXPECT_EQ( 406 EXPECT_EQ(
366 Feature::IS_AVAILABLE, 407 Feature::IS_AVAILABLE,
367 feature.IsAvailableToManifest(std::string(), 408 feature.IsAvailableToManifest(std::string(),
368 Manifest::TYPE_UNKNOWN, 409 Manifest::TYPE_UNKNOWN,
369 Feature::UNSPECIFIED_LOCATION, 410 Manifest::INVALID_LOCATION,
370 7, 411 7,
371 Feature::UNSPECIFIED_PLATFORM).result()); 412 Feature::UNSPECIFIED_PLATFORM).result());
372 } 413 }
373 414
374 TEST_F(ExtensionSimpleFeatureTest, ParseNull) { 415 TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
375 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 416 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
376 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 417 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
377 feature->Parse(value.get()); 418 feature->Parse(value.get());
378 EXPECT_TRUE(feature->whitelist()->empty()); 419 EXPECT_TRUE(feature->whitelist()->empty());
379 EXPECT_TRUE(feature->extension_types()->empty()); 420 EXPECT_TRUE(feature->extension_types()->empty());
380 EXPECT_TRUE(feature->GetContexts()->empty()); 421 EXPECT_TRUE(feature->GetContexts()->empty());
381 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); 422 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
382 EXPECT_TRUE(feature->platforms()->empty()); 423 EXPECT_TRUE(feature->platforms()->empty());
383 EXPECT_EQ(0, feature->min_manifest_version()); 424 EXPECT_EQ(0, feature->min_manifest_version());
384 EXPECT_EQ(0, feature->max_manifest_version()); 425 EXPECT_EQ(0, feature->max_manifest_version());
385 } 426 }
386 427
387 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { 428 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) {
388 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 429 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
389 base::ListValue* whitelist = new base::ListValue(); 430 base::ListValue* whitelist = new base::ListValue();
390 whitelist->Append(new base::StringValue("foo")); 431 whitelist->Append(new base::StringValue("foo"));
391 whitelist->Append(new base::StringValue("bar")); 432 whitelist->Append(new base::StringValue("bar"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); 492 scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
452 feature2->Parse(value.get()); 493 feature2->Parse(value.get());
453 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts())); 494 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts()));
454 } 495 }
455 496
456 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { 497 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
457 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 498 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
458 value->SetString("location", "component"); 499 value->SetString("location", "component");
459 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 500 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
460 feature->Parse(value.get()); 501 feature->Parse(value.get());
461 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location()); 502 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location());
462 } 503 }
463 504
464 TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) { 505 TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) {
465 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 506 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
466 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 507 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
467 base::ListValue* platforms = new base::ListValue(); 508 base::ListValue* platforms = new base::ListValue();
468 value->Set("platforms", platforms); 509 value->Set("platforms", platforms);
469 feature->Parse(value.get()); 510 feature->Parse(value.get());
470 EXPECT_TRUE(feature->platforms()->empty()); 511 EXPECT_TRUE(feature->platforms()->empty());
471 512
(...skipping 28 matching lines...) Expand all
500 feature->Parse(value.get()); 541 feature->Parse(value.get());
501 EXPECT_EQ(1, feature->min_manifest_version()); 542 EXPECT_EQ(1, feature->min_manifest_version());
502 EXPECT_EQ(5, feature->max_manifest_version()); 543 EXPECT_EQ(5, feature->max_manifest_version());
503 } 544 }
504 545
505 TEST_F(ExtensionSimpleFeatureTest, Inheritance) { 546 TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
506 SimpleFeature feature; 547 SimpleFeature feature;
507 feature.whitelist()->insert("foo"); 548 feature.whitelist()->insert("foo");
508 feature.extension_types()->insert(Manifest::TYPE_THEME); 549 feature.extension_types()->insert(Manifest::TYPE_THEME);
509 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 550 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
510 feature.set_location(Feature::COMPONENT_LOCATION); 551 feature.set_location(SimpleFeature::COMPONENT_LOCATION);
511 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); 552 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
512 feature.set_min_manifest_version(1); 553 feature.set_min_manifest_version(1);
513 feature.set_max_manifest_version(2); 554 feature.set_max_manifest_version(2);
514 555
515 // Test additive parsing. Parsing an empty dictionary should result in no 556 // Test additive parsing. Parsing an empty dictionary should result in no
516 // changes to a SimpleFeature. 557 // changes to a SimpleFeature.
517 base::DictionaryValue definition; 558 base::DictionaryValue definition;
518 feature.Parse(&definition); 559 feature.Parse(&definition);
519 EXPECT_EQ(1u, feature.whitelist()->size()); 560 EXPECT_EQ(1u, feature.whitelist()->size());
520 EXPECT_EQ(1u, feature.extension_types()->size()); 561 EXPECT_EQ(1u, feature.extension_types()->size());
521 EXPECT_EQ(1u, feature.GetContexts()->size()); 562 EXPECT_EQ(1u, feature.GetContexts()->size());
522 EXPECT_EQ(1u, feature.whitelist()->count("foo")); 563 EXPECT_EQ(1u, feature.whitelist()->count("foo"));
523 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature.location()); 564 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location());
524 EXPECT_EQ(1u, feature.platforms()->size()); 565 EXPECT_EQ(1u, feature.platforms()->size());
525 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM)); 566 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM));
526 EXPECT_EQ(1, feature.min_manifest_version()); 567 EXPECT_EQ(1, feature.min_manifest_version());
527 EXPECT_EQ(2, feature.max_manifest_version()); 568 EXPECT_EQ(2, feature.max_manifest_version());
528 569
529 base::ListValue* whitelist = new base::ListValue(); 570 base::ListValue* whitelist = new base::ListValue();
530 base::ListValue* extension_types = new base::ListValue(); 571 base::ListValue* extension_types = new base::ListValue();
531 base::ListValue* contexts = new base::ListValue(); 572 base::ListValue* contexts = new base::ListValue();
532 whitelist->Append(new base::StringValue("bar")); 573 whitelist->Append(new base::StringValue("bar"));
533 extension_types->Append(new base::StringValue("extension")); 574 extension_types->Append(new base::StringValue("extension"));
(...skipping 23 matching lines...) Expand all
557 598
558 SimpleFeature feature; 599 SimpleFeature feature;
559 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( 600 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>(
560 new extensions::ChromeChannelFeatureFilter(&feature))); 601 new extensions::ChromeChannelFeatureFilter(&feature)));
561 if (!channel.empty()) { 602 if (!channel.empty()) {
562 base::DictionaryValue feature_value; 603 base::DictionaryValue feature_value;
563 feature_value.SetString("channel", channel); 604 feature_value.SetString("channel", channel);
564 feature.Parse(&feature_value); 605 feature.Parse(&feature_value);
565 } 606 }
566 607
567 return feature.IsAvailableToManifest( 608 return feature.IsAvailableToManifest("random-extension",
568 "random-extension", 609 Manifest::TYPE_UNKNOWN,
569 Manifest::TYPE_UNKNOWN, 610 Manifest::INVALID_LOCATION,
570 Feature::UNSPECIFIED_LOCATION, 611 -1,
571 -1, 612 Feature::GetCurrentPlatform()).result();
572 Feature::GetCurrentPlatform()).result();
573 } 613 }
574 614
575 TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) { 615 TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) {
576 // stable supported. 616 // stable supported.
577 EXPECT_EQ(Feature::IS_AVAILABLE, 617 EXPECT_EQ(Feature::IS_AVAILABLE,
578 IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN)); 618 IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN));
579 EXPECT_EQ(Feature::IS_AVAILABLE, 619 EXPECT_EQ(Feature::IS_AVAILABLE,
580 IsAvailableInChannel("stable", VersionInfo::CHANNEL_CANARY)); 620 IsAvailableInChannel("stable", VersionInfo::CHANNEL_CANARY));
581 EXPECT_EQ(Feature::IS_AVAILABLE, 621 EXPECT_EQ(Feature::IS_AVAILABLE,
582 IsAvailableInChannel("stable", VersionInfo::CHANNEL_DEV)); 622 IsAvailableInChannel("stable", VersionInfo::CHANNEL_DEV));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 667 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
628 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY)); 668 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY));
629 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 669 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
630 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV)); 670 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV));
631 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 671 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
632 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA)); 672 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA));
633 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 673 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
634 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE)); 674 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE));
635 } 675 }
636 676
637 } // namespace 677 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature_filter.cc ('k') | extensions/common/manifest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698