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

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

Issue 12207167: Cleanup: Remove deprecated base::Value methods from chrome/common. Use base::Value too. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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/simple_feature.h" 5 #include "chrome/common/extensions/features/simple_feature.h"
6 6
7 #include "chrome/common/extensions/value_builder.h" 7 #include "chrome/common/extensions/value_builder.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using chrome::VersionInfo; 10 using chrome::VersionInfo;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 120 }
121 121
122 TEST_F(ExtensionSimpleFeatureTest, Context) { 122 TEST_F(ExtensionSimpleFeatureTest, Context) {
123 SimpleFeature feature; 123 SimpleFeature feature;
124 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 124 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
125 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 125 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
126 feature.set_platform(Feature::CHROMEOS_PLATFORM); 126 feature.set_platform(Feature::CHROMEOS_PLATFORM);
127 feature.set_min_manifest_version(21); 127 feature.set_min_manifest_version(21);
128 feature.set_max_manifest_version(25); 128 feature.set_max_manifest_version(25);
129 129
130 DictionaryValue manifest; 130 base::DictionaryValue manifest;
131 manifest.SetString("name", "test"); 131 manifest.SetString("name", "test");
132 manifest.SetString("version", "1"); 132 manifest.SetString("version", "1");
133 manifest.SetInteger("manifest_version", 21); 133 manifest.SetInteger("manifest_version", 21);
134 manifest.SetString("app.launch.local_path", "foo.html"); 134 manifest.SetString("app.launch.local_path", "foo.html");
135 135
136 std::string error; 136 std::string error;
137 scoped_refptr<const Extension> extension(Extension::Create( 137 scoped_refptr<const Extension> extension(Extension::Create(
138 base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS, 138 base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS,
139 &error)); 139 &error));
140 EXPECT_EQ("", error); 140 EXPECT_EQ("", error);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(Feature::IS_AVAILABLE, 245 EXPECT_EQ(Feature::IS_AVAILABLE,
246 feature.IsAvailableToManifest( 246 feature.IsAvailableToManifest(
247 "", Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, 247 "", Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION,
248 8, Feature::UNSPECIFIED_PLATFORM).result()); 248 8, Feature::UNSPECIFIED_PLATFORM).result());
249 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( 249 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
250 "", Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, 250 "", Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION,
251 7, Feature::UNSPECIFIED_PLATFORM).result()); 251 7, Feature::UNSPECIFIED_PLATFORM).result());
252 } 252 }
253 253
254 TEST_F(ExtensionSimpleFeatureTest, ParseNull) { 254 TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
255 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 255 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
256 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 256 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
257 feature->Parse(value.get()); 257 feature->Parse(value.get());
258 EXPECT_TRUE(feature->whitelist()->empty()); 258 EXPECT_TRUE(feature->whitelist()->empty());
259 EXPECT_TRUE(feature->extension_types()->empty()); 259 EXPECT_TRUE(feature->extension_types()->empty());
260 EXPECT_TRUE(feature->GetContexts()->empty()); 260 EXPECT_TRUE(feature->GetContexts()->empty());
261 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); 261 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
262 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform()); 262 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
263 EXPECT_EQ(0, feature->min_manifest_version()); 263 EXPECT_EQ(0, feature->min_manifest_version());
264 EXPECT_EQ(0, feature->max_manifest_version()); 264 EXPECT_EQ(0, feature->max_manifest_version());
265 } 265 }
266 266
267 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { 267 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) {
268 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 268 scoped_ptr<base::DictionaryValue> value(new DictionaryValue());
269 ListValue* whitelist = new ListValue(); 269 base::ListValue* whitelist = new base::ListValue();
270 whitelist->Append(Value::CreateStringValue("foo")); 270 whitelist->Append(new base::StringValue("foo"));
271 whitelist->Append(Value::CreateStringValue("bar")); 271 whitelist->Append(new base::StringValue("bar"));
272 value->Set("whitelist", whitelist); 272 value->Set("whitelist", whitelist);
273 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 273 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
274 feature->Parse(value.get()); 274 feature->Parse(value.get());
275 EXPECT_EQ(2u, feature->whitelist()->size()); 275 EXPECT_EQ(2u, feature->whitelist()->size());
276 EXPECT_TRUE(feature->whitelist()->count("foo")); 276 EXPECT_TRUE(feature->whitelist()->count("foo"));
277 EXPECT_TRUE(feature->whitelist()->count("bar")); 277 EXPECT_TRUE(feature->whitelist()->count("bar"));
278 } 278 }
279 279
280 TEST_F(ExtensionSimpleFeatureTest, ParsePackageTypes) { 280 TEST_F(ExtensionSimpleFeatureTest, ParsePackageTypes) {
281 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 281 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
282 ListValue* extension_types = new ListValue(); 282 base::ListValue* extension_types = new base::ListValue();
283 extension_types->Append(Value::CreateStringValue("extension")); 283 extension_types->Append(new base::StringValue("extension"));
284 extension_types->Append(Value::CreateStringValue("theme")); 284 extension_types->Append(new base::StringValue("theme"));
285 extension_types->Append(Value::CreateStringValue("packaged_app")); 285 extension_types->Append(new base::StringValue("packaged_app"));
286 extension_types->Append(Value::CreateStringValue("hosted_app")); 286 extension_types->Append(new base::StringValue("hosted_app"));
287 extension_types->Append(Value::CreateStringValue("platform_app")); 287 extension_types->Append(new base::StringValue("platform_app"));
288 value->Set("extension_types", extension_types); 288 value->Set("extension_types", extension_types);
289 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 289 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
290 feature->Parse(value.get()); 290 feature->Parse(value.get());
291 EXPECT_EQ(5u, feature->extension_types()->size()); 291 EXPECT_EQ(5u, feature->extension_types()->size());
292 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_EXTENSION)); 292 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_EXTENSION));
293 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_THEME)); 293 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_THEME));
294 EXPECT_TRUE(feature->extension_types()->count( 294 EXPECT_TRUE(feature->extension_types()->count(
295 Manifest::TYPE_LEGACY_PACKAGED_APP)); 295 Manifest::TYPE_LEGACY_PACKAGED_APP));
296 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_HOSTED_APP)); 296 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_HOSTED_APP));
297 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); 297 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP));
298 298
299 value->SetString("extension_types", "all"); 299 value->SetString("extension_types", "all");
300 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); 300 scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
301 feature2->Parse(value.get()); 301 feature2->Parse(value.get());
302 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); 302 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types()));
303 } 303 }
304 304
305 TEST_F(ExtensionSimpleFeatureTest, ParseContexts) { 305 TEST_F(ExtensionSimpleFeatureTest, ParseContexts) {
306 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 306 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
307 ListValue* contexts = new ListValue(); 307 base::ListValue* contexts = new base::ListValue();
308 contexts->Append(Value::CreateStringValue("blessed_extension")); 308 contexts->Append(new base::StringValue("blessed_extension"));
309 contexts->Append(Value::CreateStringValue("unblessed_extension")); 309 contexts->Append(new base::StringValue("unblessed_extension"));
310 contexts->Append(Value::CreateStringValue("content_script")); 310 contexts->Append(new base::StringValue("content_script"));
311 contexts->Append(Value::CreateStringValue("web_page")); 311 contexts->Append(new base::StringValue("web_page"));
312 value->Set("contexts", contexts); 312 value->Set("contexts", contexts);
313 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 313 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
314 feature->Parse(value.get()); 314 feature->Parse(value.get());
315 EXPECT_EQ(4u, feature->GetContexts()->size()); 315 EXPECT_EQ(4u, feature->GetContexts()->size());
316 EXPECT_TRUE( 316 EXPECT_TRUE(
317 feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT)); 317 feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT));
318 EXPECT_TRUE( 318 EXPECT_TRUE(
319 feature->GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); 319 feature->GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
320 EXPECT_TRUE( 320 EXPECT_TRUE(
321 feature->GetContexts()->count(Feature::CONTENT_SCRIPT_CONTEXT)); 321 feature->GetContexts()->count(Feature::CONTENT_SCRIPT_CONTEXT));
322 EXPECT_TRUE( 322 EXPECT_TRUE(
323 feature->GetContexts()->count(Feature::WEB_PAGE_CONTEXT)); 323 feature->GetContexts()->count(Feature::WEB_PAGE_CONTEXT));
324 324
325 value->SetString("contexts", "all"); 325 value->SetString("contexts", "all");
326 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); 326 scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
327 feature2->Parse(value.get()); 327 feature2->Parse(value.get());
328 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts())); 328 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts()));
329 } 329 }
330 330
331 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { 331 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
332 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 332 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
333 value->SetString("location", "component"); 333 value->SetString("location", "component");
334 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 334 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
335 feature->Parse(value.get()); 335 feature->Parse(value.get());
336 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location()); 336 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location());
337 } 337 }
338 338
339 TEST_F(ExtensionSimpleFeatureTest, ParsePlatform) { 339 TEST_F(ExtensionSimpleFeatureTest, ParsePlatform) {
340 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 340 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
341 value->SetString("platform", "chromeos"); 341 value->SetString("platform", "chromeos");
342 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 342 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
343 feature->Parse(value.get()); 343 feature->Parse(value.get());
344 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, feature->platform()); 344 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, feature->platform());
345 } 345 }
346 346
347 TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) { 347 TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) {
348 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 348 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
349 value->SetInteger("min_manifest_version", 1); 349 value->SetInteger("min_manifest_version", 1);
350 value->SetInteger("max_manifest_version", 5); 350 value->SetInteger("max_manifest_version", 5);
351 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 351 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
352 feature->Parse(value.get()); 352 feature->Parse(value.get());
353 EXPECT_EQ(1, feature->min_manifest_version()); 353 EXPECT_EQ(1, feature->min_manifest_version());
354 EXPECT_EQ(5, feature->max_manifest_version()); 354 EXPECT_EQ(5, feature->max_manifest_version());
355 } 355 }
356 356
357 TEST_F(ExtensionSimpleFeatureTest, Inheritance) { 357 TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
358 SimpleFeature feature; 358 SimpleFeature feature;
359 feature.whitelist()->insert("foo"); 359 feature.whitelist()->insert("foo");
360 feature.extension_types()->insert(Manifest::TYPE_THEME); 360 feature.extension_types()->insert(Manifest::TYPE_THEME);
361 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 361 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
362 feature.set_location(Feature::COMPONENT_LOCATION); 362 feature.set_location(Feature::COMPONENT_LOCATION);
363 feature.set_platform(Feature::CHROMEOS_PLATFORM); 363 feature.set_platform(Feature::CHROMEOS_PLATFORM);
364 feature.set_min_manifest_version(1); 364 feature.set_min_manifest_version(1);
365 feature.set_max_manifest_version(2); 365 feature.set_max_manifest_version(2);
366 366
367 SimpleFeature feature2 = feature; 367 SimpleFeature feature2 = feature;
368 EXPECT_TRUE(feature2.Equals(feature)); 368 EXPECT_TRUE(feature2.Equals(feature));
369 369
370 DictionaryValue definition; 370 base::DictionaryValue definition;
371 feature2.Parse(&definition); 371 feature2.Parse(&definition);
372 EXPECT_TRUE(feature2.Equals(feature)); 372 EXPECT_TRUE(feature2.Equals(feature));
373 373
374 ListValue* whitelist = new ListValue(); 374 base::ListValue* whitelist = new base::ListValue();
375 ListValue* extension_types = new ListValue(); 375 base::ListValue* extension_types = new base::ListValue();
376 ListValue* contexts = new ListValue(); 376 base::ListValue* contexts = new base::ListValue();
377 whitelist->Append(Value::CreateStringValue("bar")); 377 whitelist->Append(new base::StringValue("bar"));
378 extension_types->Append(Value::CreateStringValue("extension")); 378 extension_types->Append(new base::StringValue("extension"));
379 contexts->Append(Value::CreateStringValue("unblessed_extension")); 379 contexts->Append(new base::StringValue("unblessed_extension"));
380 definition.Set("whitelist", whitelist); 380 definition.Set("whitelist", whitelist);
381 definition.Set("extension_types", extension_types); 381 definition.Set("extension_types", extension_types);
382 definition.Set("contexts", contexts); 382 definition.Set("contexts", contexts);
383 // Can't test location or platform because we only have one value so far. 383 // Can't test location or platform because we only have one value so far.
384 definition.Set("min_manifest_version", Value::CreateIntegerValue(2)); 384 definition.Set("min_manifest_version", new base::FundamentalValue(2));
385 definition.Set("max_manifest_version", Value::CreateIntegerValue(3)); 385 definition.Set("max_manifest_version", new base::FundamentalValue(3));
386 386
387 feature2.Parse(&definition); 387 feature2.Parse(&definition);
388 EXPECT_FALSE(feature2.Equals(feature)); 388 EXPECT_FALSE(feature2.Equals(feature));
389 EXPECT_EQ(1u, feature2.whitelist()->size()); 389 EXPECT_EQ(1u, feature2.whitelist()->size());
390 EXPECT_EQ(1u, feature2.extension_types()->size()); 390 EXPECT_EQ(1u, feature2.extension_types()->size());
391 EXPECT_EQ(1u, feature2.GetContexts()->size()); 391 EXPECT_EQ(1u, feature2.GetContexts()->size());
392 EXPECT_EQ(1u, feature2.whitelist()->count("bar")); 392 EXPECT_EQ(1u, feature2.whitelist()->count("bar"));
393 EXPECT_EQ(1u, feature2.extension_types()->count(Manifest::TYPE_EXTENSION)); 393 EXPECT_EQ(1u, feature2.extension_types()->count(Manifest::TYPE_EXTENSION));
394 EXPECT_EQ(1u, feature2.GetContexts()->count( 394 EXPECT_EQ(1u, feature2.GetContexts()->count(
395 Feature::UNBLESSED_EXTENSION_CONTEXT)); 395 Feature::UNBLESSED_EXTENSION_CONTEXT));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 feature2.set_max_manifest_version(0); 437 feature2.set_max_manifest_version(0);
438 EXPECT_FALSE(feature2.Equals(feature)); 438 EXPECT_FALSE(feature2.Equals(feature));
439 } 439 }
440 440
441 Feature::AvailabilityResult IsAvailableInChannel( 441 Feature::AvailabilityResult IsAvailableInChannel(
442 const std::string& channel, VersionInfo::Channel channel_for_testing) { 442 const std::string& channel, VersionInfo::Channel channel_for_testing) {
443 Feature::ScopedCurrentChannel current_channel(channel_for_testing); 443 Feature::ScopedCurrentChannel current_channel(channel_for_testing);
444 444
445 SimpleFeature feature; 445 SimpleFeature feature;
446 if (!channel.empty()) { 446 if (!channel.empty()) {
447 DictionaryValue feature_value; 447 base::DictionaryValue feature_value;
448 feature_value.SetString("channel", channel); 448 feature_value.SetString("channel", channel);
449 feature.Parse(&feature_value); 449 feature.Parse(&feature_value);
450 } 450 }
451 451
452 return feature.IsAvailableToManifest( 452 return feature.IsAvailableToManifest(
453 "random-extension", 453 "random-extension",
454 Manifest::TYPE_UNKNOWN, 454 Manifest::TYPE_UNKNOWN,
455 Feature::UNSPECIFIED_LOCATION, 455 Feature::UNSPECIFIED_LOCATION,
456 -1, 456 -1,
457 Feature::GetCurrentPlatform()).result(); 457 Feature::GetCurrentPlatform()).result();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 IsAvailableInChannel("", VersionInfo::CHANNEL_CANARY)); 525 IsAvailableInChannel("", VersionInfo::CHANNEL_CANARY));
526 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 526 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
527 IsAvailableInChannel("", VersionInfo::CHANNEL_DEV)); 527 IsAvailableInChannel("", VersionInfo::CHANNEL_DEV));
528 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 528 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
529 IsAvailableInChannel("", VersionInfo::CHANNEL_BETA)); 529 IsAvailableInChannel("", VersionInfo::CHANNEL_BETA));
530 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 530 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
531 IsAvailableInChannel("", VersionInfo::CHANNEL_STABLE)); 531 IsAvailableInChannel("", VersionInfo::CHANNEL_STABLE));
532 } 532 }
533 533
534 } // namespace 534 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698