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

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

Issue 377753003: Remove GetContexts() from the public interface of extensions::Feature. It was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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.cc ('k') | no next file » | 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"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 feature.IsAvailableToManifest(std::string(), 282 feature.IsAvailableToManifest(std::string(),
283 Manifest::TYPE_THEME, 283 Manifest::TYPE_THEME,
284 Manifest::INVALID_LOCATION, 284 Manifest::INVALID_LOCATION,
285 -1, 285 -1,
286 Feature::UNSPECIFIED_PLATFORM).result()); 286 Feature::UNSPECIFIED_PLATFORM).result());
287 } 287 }
288 288
289 TEST_F(ExtensionSimpleFeatureTest, Context) { 289 TEST_F(ExtensionSimpleFeatureTest, Context) {
290 SimpleFeature feature; 290 SimpleFeature feature;
291 feature.set_name("somefeature"); 291 feature.set_name("somefeature");
292 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 292 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
293 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 293 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
294 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); 294 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
295 feature.set_min_manifest_version(21); 295 feature.set_min_manifest_version(21);
296 feature.set_max_manifest_version(25); 296 feature.set_max_manifest_version(25);
297 297
298 base::DictionaryValue manifest; 298 base::DictionaryValue manifest;
299 manifest.SetString("name", "test"); 299 manifest.SetString("name", "test");
300 manifest.SetString("version", "1"); 300 manifest.SetString("version", "1");
301 manifest.SetInteger("manifest_version", 21); 301 manifest.SetInteger("manifest_version", 21);
302 manifest.SetString("app.launch.local_path", "foo.html"); 302 manifest.SetString("app.launch.local_path", "foo.html");
(...skipping 18 matching lines...) Expand all
321 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 321 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
322 Feature::CHROMEOS_PLATFORM); 322 Feature::CHROMEOS_PLATFORM);
323 EXPECT_EQ(Feature::INVALID_TYPE, availability.result()); 323 EXPECT_EQ(Feature::INVALID_TYPE, availability.result());
324 EXPECT_EQ("'somefeature' is only allowed for themes, " 324 EXPECT_EQ("'somefeature' is only allowed for themes, "
325 "but this is a legacy packaged app.", 325 "but this is a legacy packaged app.",
326 availability.message()); 326 availability.message());
327 } 327 }
328 328
329 feature.extension_types()->clear(); 329 feature.extension_types()->clear();
330 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); 330 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
331 feature.GetContexts()->clear(); 331 feature.contexts()->clear();
332 feature.GetContexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT); 332 feature.contexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
333 feature.GetContexts()->insert(Feature::CONTENT_SCRIPT_CONTEXT); 333 feature.contexts()->insert(Feature::CONTENT_SCRIPT_CONTEXT);
334 { 334 {
335 Feature::Availability availability = feature.IsAvailableToContext( 335 Feature::Availability availability = feature.IsAvailableToContext(
336 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 336 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
337 Feature::CHROMEOS_PLATFORM); 337 Feature::CHROMEOS_PLATFORM);
338 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); 338 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result());
339 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes and " 339 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes and "
340 "content scripts, but this is a privileged page", 340 "content scripts, but this is a privileged page",
341 availability.message()); 341 availability.message());
342 } 342 }
343 343
344 feature.GetContexts()->insert(Feature::WEB_PAGE_CONTEXT); 344 feature.contexts()->insert(Feature::WEB_PAGE_CONTEXT);
345 { 345 {
346 Feature::Availability availability = feature.IsAvailableToContext( 346 Feature::Availability availability = feature.IsAvailableToContext(
347 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 347 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
348 Feature::CHROMEOS_PLATFORM); 348 Feature::CHROMEOS_PLATFORM);
349 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); 349 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result());
350 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " 350 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, "
351 "content scripts, and web pages, but this is a privileged page", 351 "content scripts, and web pages, but this is a privileged page",
352 availability.message()); 352 availability.message());
353 } 353 }
354 354
355 feature.GetContexts()->clear(); 355 feature.contexts()->clear();
356 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 356 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
357 feature.set_location(SimpleFeature::COMPONENT_LOCATION); 357 feature.set_location(SimpleFeature::COMPONENT_LOCATION);
358 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( 358 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext(
359 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 359 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
360 Feature::CHROMEOS_PLATFORM).result()); 360 Feature::CHROMEOS_PLATFORM).result());
361 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION); 361 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION);
362 362
363 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( 363 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext(
364 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 364 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
365 Feature::UNSPECIFIED_PLATFORM).result()); 365 Feature::UNSPECIFIED_PLATFORM).result());
366 366
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 7, 489 7,
490 Feature::UNSPECIFIED_PLATFORM).result()); 490 Feature::UNSPECIFIED_PLATFORM).result());
491 } 491 }
492 492
493 TEST_F(ExtensionSimpleFeatureTest, ParseNull) { 493 TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
494 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 494 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
495 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 495 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
496 feature->Parse(value.get()); 496 feature->Parse(value.get());
497 EXPECT_TRUE(feature->whitelist()->empty()); 497 EXPECT_TRUE(feature->whitelist()->empty());
498 EXPECT_TRUE(feature->extension_types()->empty()); 498 EXPECT_TRUE(feature->extension_types()->empty());
499 EXPECT_TRUE(feature->GetContexts()->empty()); 499 EXPECT_TRUE(feature->contexts()->empty());
500 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); 500 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
501 EXPECT_TRUE(feature->platforms()->empty()); 501 EXPECT_TRUE(feature->platforms()->empty());
502 EXPECT_EQ(0, feature->min_manifest_version()); 502 EXPECT_EQ(0, feature->min_manifest_version());
503 EXPECT_EQ(0, feature->max_manifest_version()); 503 EXPECT_EQ(0, feature->max_manifest_version());
504 } 504 }
505 505
506 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { 506 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) {
507 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 507 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
508 base::ListValue* whitelist = new base::ListValue(); 508 base::ListValue* whitelist = new base::ListValue();
509 whitelist->Append(new base::StringValue("foo")); 509 whitelist->Append(new base::StringValue("foo"));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 547 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
548 base::ListValue* contexts = new base::ListValue(); 548 base::ListValue* contexts = new base::ListValue();
549 contexts->Append(new base::StringValue("blessed_extension")); 549 contexts->Append(new base::StringValue("blessed_extension"));
550 contexts->Append(new base::StringValue("unblessed_extension")); 550 contexts->Append(new base::StringValue("unblessed_extension"));
551 contexts->Append(new base::StringValue("content_script")); 551 contexts->Append(new base::StringValue("content_script"));
552 contexts->Append(new base::StringValue("web_page")); 552 contexts->Append(new base::StringValue("web_page"));
553 contexts->Append(new base::StringValue("blessed_web_page")); 553 contexts->Append(new base::StringValue("blessed_web_page"));
554 value->Set("contexts", contexts); 554 value->Set("contexts", contexts);
555 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 555 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
556 feature->Parse(value.get()); 556 feature->Parse(value.get());
557 EXPECT_EQ(5u, feature->GetContexts()->size()); 557 EXPECT_EQ(5u, feature->contexts()->size());
558 EXPECT_TRUE( 558 EXPECT_TRUE(feature->contexts()->count(Feature::BLESSED_EXTENSION_CONTEXT));
559 feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT)); 559 EXPECT_TRUE(feature->contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
560 EXPECT_TRUE( 560 EXPECT_TRUE(feature->contexts()->count(Feature::CONTENT_SCRIPT_CONTEXT));
561 feature->GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); 561 EXPECT_TRUE(feature->contexts()->count(Feature::WEB_PAGE_CONTEXT));
562 EXPECT_TRUE( 562 EXPECT_TRUE(feature->contexts()->count(Feature::BLESSED_WEB_PAGE_CONTEXT));
563 feature->GetContexts()->count(Feature::CONTENT_SCRIPT_CONTEXT));
564 EXPECT_TRUE(
565 feature->GetContexts()->count(Feature::WEB_PAGE_CONTEXT));
566 EXPECT_TRUE(
567 feature->GetContexts()->count(Feature::BLESSED_WEB_PAGE_CONTEXT));
568 563
569 value->SetString("contexts", "all"); 564 value->SetString("contexts", "all");
570 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); 565 scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
571 feature2->Parse(value.get()); 566 feature2->Parse(value.get());
572 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts())); 567 EXPECT_EQ(*(feature->contexts()), *(feature2->contexts()));
573 } 568 }
574 569
575 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { 570 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
576 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 571 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
577 value->SetString("location", "component"); 572 value->SetString("location", "component");
578 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 573 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
579 feature->Parse(value.get()); 574 feature->Parse(value.get());
580 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); 575 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location());
581 } 576 }
582 577
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); 613 scoped_ptr<SimpleFeature> feature(new SimpleFeature());
619 feature->Parse(value.get()); 614 feature->Parse(value.get());
620 EXPECT_EQ(1, feature->min_manifest_version()); 615 EXPECT_EQ(1, feature->min_manifest_version());
621 EXPECT_EQ(5, feature->max_manifest_version()); 616 EXPECT_EQ(5, feature->max_manifest_version());
622 } 617 }
623 618
624 TEST_F(ExtensionSimpleFeatureTest, Inheritance) { 619 TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
625 SimpleFeature feature; 620 SimpleFeature feature;
626 feature.whitelist()->insert("foo"); 621 feature.whitelist()->insert("foo");
627 feature.extension_types()->insert(Manifest::TYPE_THEME); 622 feature.extension_types()->insert(Manifest::TYPE_THEME);
628 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); 623 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
629 feature.set_location(SimpleFeature::COMPONENT_LOCATION); 624 feature.set_location(SimpleFeature::COMPONENT_LOCATION);
630 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); 625 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
631 feature.set_min_manifest_version(1); 626 feature.set_min_manifest_version(1);
632 feature.set_max_manifest_version(2); 627 feature.set_max_manifest_version(2);
633 628
634 // Test additive parsing. Parsing an empty dictionary should result in no 629 // Test additive parsing. Parsing an empty dictionary should result in no
635 // changes to a SimpleFeature. 630 // changes to a SimpleFeature.
636 base::DictionaryValue definition; 631 base::DictionaryValue definition;
637 feature.Parse(&definition); 632 feature.Parse(&definition);
638 EXPECT_EQ(1u, feature.whitelist()->size()); 633 EXPECT_EQ(1u, feature.whitelist()->size());
639 EXPECT_EQ(1u, feature.extension_types()->size()); 634 EXPECT_EQ(1u, feature.extension_types()->size());
640 EXPECT_EQ(1u, feature.GetContexts()->size()); 635 EXPECT_EQ(1u, feature.contexts()->size());
641 EXPECT_EQ(1u, feature.whitelist()->count("foo")); 636 EXPECT_EQ(1u, feature.whitelist()->count("foo"));
642 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); 637 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location());
643 EXPECT_EQ(1u, feature.platforms()->size()); 638 EXPECT_EQ(1u, feature.platforms()->size());
644 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM)); 639 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM));
645 EXPECT_EQ(1, feature.min_manifest_version()); 640 EXPECT_EQ(1, feature.min_manifest_version());
646 EXPECT_EQ(2, feature.max_manifest_version()); 641 EXPECT_EQ(2, feature.max_manifest_version());
647 642
648 base::ListValue* whitelist = new base::ListValue(); 643 base::ListValue* whitelist = new base::ListValue();
649 base::ListValue* extension_types = new base::ListValue(); 644 base::ListValue* extension_types = new base::ListValue();
650 base::ListValue* contexts = new base::ListValue(); 645 base::ListValue* contexts = new base::ListValue();
651 whitelist->Append(new base::StringValue("bar")); 646 whitelist->Append(new base::StringValue("bar"));
652 extension_types->Append(new base::StringValue("extension")); 647 extension_types->Append(new base::StringValue("extension"));
653 contexts->Append(new base::StringValue("unblessed_extension")); 648 contexts->Append(new base::StringValue("unblessed_extension"));
654 definition.Set("whitelist", whitelist); 649 definition.Set("whitelist", whitelist);
655 definition.Set("extension_types", extension_types); 650 definition.Set("extension_types", extension_types);
656 definition.Set("contexts", contexts); 651 definition.Set("contexts", contexts);
657 // Can't test location or platform because we only have one value so far. 652 // Can't test location or platform because we only have one value so far.
658 definition.Set("min_manifest_version", new base::FundamentalValue(2)); 653 definition.Set("min_manifest_version", new base::FundamentalValue(2));
659 definition.Set("max_manifest_version", new base::FundamentalValue(3)); 654 definition.Set("max_manifest_version", new base::FundamentalValue(3));
660 655
661 feature.Parse(&definition); 656 feature.Parse(&definition);
662 EXPECT_EQ(1u, feature.whitelist()->size()); 657 EXPECT_EQ(1u, feature.whitelist()->size());
663 EXPECT_EQ(1u, feature.extension_types()->size()); 658 EXPECT_EQ(1u, feature.extension_types()->size());
664 EXPECT_EQ(1u, feature.GetContexts()->size()); 659 EXPECT_EQ(1u, feature.contexts()->size());
665 EXPECT_EQ(1u, feature.whitelist()->count("bar")); 660 EXPECT_EQ(1u, feature.whitelist()->count("bar"));
666 EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION)); 661 EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION));
667 EXPECT_EQ(1u, 662 EXPECT_EQ(1u,
668 feature.GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); 663 feature.contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
669 EXPECT_EQ(2, feature.min_manifest_version()); 664 EXPECT_EQ(2, feature.min_manifest_version());
670 EXPECT_EQ(3, feature.max_manifest_version()); 665 EXPECT_EQ(3, feature.max_manifest_version());
671 } 666 }
672 667
673 Feature::AvailabilityResult IsAvailableInChannel( 668 Feature::AvailabilityResult IsAvailableInChannel(
674 const std::string& channel, VersionInfo::Channel channel_for_testing) { 669 const std::string& channel, VersionInfo::Channel channel_for_testing) {
675 ScopedCurrentChannel current_channel(channel_for_testing); 670 ScopedCurrentChannel current_channel(channel_for_testing);
676 671
677 SimpleFeature feature; 672 SimpleFeature feature;
678 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( 673 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY)); 741 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY));
747 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 742 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
748 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV)); 743 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV));
749 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 744 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
750 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA)); 745 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA));
751 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 746 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
752 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE)); 747 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE));
753 } 748 }
754 749
755 } // namespace extensions 750 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698