diff options
author | jamescook <jamescook@chromium.org> | 2014-09-12 12:17:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-12 19:21:34 +0000 |
commit | 2a8b7f14f048318bfb1ce641a920d5c14e9842ba (patch) | |
tree | 0b2649dcc4e6b1cd216a432f40843266e63a4214 /extensions/common/features | |
parent | 4fc3e94be7a4851ca52a52c59b1dd498c9d60dca (diff) | |
download | chromium_src-2a8b7f14f048318bfb1ce641a920d5c14e9842ba.zip chromium_src-2a8b7f14f048318bfb1ce641a920d5c14e9842ba.tar.gz chromium_src-2a8b7f14f048318bfb1ce641a920d5c14e9842ba.tar.bz2 |
Move most extension feature unit tests to extensions_unittests
They don't need to run in Chrome's unit_tests suite any more.
The tests that depend on Chrome's version channel information move to
ChromeChannelFeatureFilterTest.
BUG=413319,397165
TEST=unit_tests ChromeChannelFeatureFilterTest.* and extensions_unittests
Review URL: https://codereview.chromium.org/563923004
Cr-Commit-Position: refs/heads/master@{#294627}
Diffstat (limited to 'extensions/common/features')
3 files changed, 155 insertions, 413 deletions
diff --git a/extensions/common/features/base_feature_provider_unittest.cc b/extensions/common/features/base_feature_provider_unittest.cc index 28c8ded..974ee76 100644 --- a/extensions/common/features/base_feature_provider_unittest.cc +++ b/extensions/common/features/base_feature_provider_unittest.cc @@ -4,209 +4,135 @@ #include "extensions/common/features/base_feature_provider.h" -#include "chrome/common/extensions/features/chrome_channel_feature_filter.h" -#include "chrome/common/extensions/features/feature_channel.h" -#include "extensions/common/features/permission_feature.h" +#include <set> +#include <string> + +#include "extensions/common/extension_builder.h" +#include "extensions/common/features/feature.h" +#include "extensions/common/features/simple_feature.h" +#include "extensions/common/manifest.h" #include "extensions/common/value_builder.h" #include "testing/gtest/include/gtest/gtest.h" -using chrome::VersionInfo; - namespace extensions { -namespace { - -template <class FeatureClass> -SimpleFeature* CreateFeature() { - SimpleFeature* feature = new FeatureClass(); - feature->AddFilter( - scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature))); - return feature; -} - -} // namespace - -TEST(BaseFeatureProviderTest, ManifestFeatures) { +// Tests that a real manifest feature is available for the correct types of +// extensions and apps. +TEST(BaseFeatureProviderTest, ManifestFeatureTypes) { const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); + // NOTE: This feature cannot have multiple rules, otherwise it is not a + // SimpleFeature. SimpleFeature* feature = static_cast<SimpleFeature*>(provider->GetFeature("description")); ASSERT_TRUE(feature); - EXPECT_EQ(6u, feature->extension_types()->size()); - EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); - EXPECT_EQ(1u, - feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); - EXPECT_EQ(1u, - feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); - EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_HOSTED_APP)); - EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_THEME)); - EXPECT_EQ(1u, - feature->extension_types()->count(Manifest::TYPE_SHARED_MODULE)); - - base::DictionaryValue manifest; - manifest.SetString("name", "test extension"); - manifest.SetString("version", "1"); - manifest.SetString("description", "hello there"); - - std::string error; - scoped_refptr<const Extension> extension(Extension::Create( - base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS, - &error)); + std::set<Manifest::Type>* extension_types = feature->extension_types(); + EXPECT_EQ(6u, extension_types->size()); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_PLATFORM_APP)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_HOSTED_APP)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_THEME)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_SHARED_MODULE)); +} + +// Tests that real manifest features have the correct availability for an +// extension. +TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) { + const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); + scoped_refptr<const Extension> extension = + ExtensionBuilder() + .SetManifest(DictionaryBuilder() + .Set("name", "test extension") + .Set("version", "1") + .Set("description", "hello there")) + .Build(); ASSERT_TRUE(extension.get()); - EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); - feature = - static_cast<SimpleFeature*>(provider->GetFeature("theme")); + Feature* feature = provider->GetFeature("description"); + EXPECT_EQ(Feature::IS_AVAILABLE, + feature->IsAvailableToContext(extension.get(), + Feature::UNSPECIFIED_CONTEXT, + GURL()).result()); + + // This is a generic extension, so an app-only feature isn't allowed. + feature = provider->GetFeature("app.background"); ASSERT_TRUE(feature); - EXPECT_EQ(Feature::INVALID_TYPE, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); + EXPECT_EQ(Feature::INVALID_TYPE, + feature->IsAvailableToContext(extension.get(), + Feature::UNSPECIFIED_CONTEXT, + GURL()).result()); - feature = - static_cast<SimpleFeature*>(provider->GetFeature("devtools_page")); + // A feature not listed in the manifest isn't allowed. + feature = provider->GetFeature("background"); ASSERT_TRUE(feature); - EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); + EXPECT_EQ(Feature::NOT_PRESENT, + feature->IsAvailableToContext(extension.get(), + Feature::UNSPECIFIED_CONTEXT, + GURL()).result()); } -TEST(BaseFeatureProviderTest, PermissionFeatures) { +// Tests that a real permission feature is available for the correct types of +// extensions and apps. +TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { const FeatureProvider* provider = BaseFeatureProvider::GetByName("permission"); + // NOTE: This feature cannot have multiple rules, otherwise it is not a + // SimpleFeature. SimpleFeature* feature = - static_cast<SimpleFeature*>(provider->GetFeature("contextMenus")); + static_cast<SimpleFeature*>(provider->GetFeature("power")); ASSERT_TRUE(feature); - EXPECT_EQ(3u, feature->extension_types()->size()); - EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); - EXPECT_EQ(1u, - feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); - EXPECT_EQ(1u, - feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); - - base::DictionaryValue manifest; - manifest.SetString("name", "test extension"); - manifest.SetString("version", "1"); - base::ListValue* permissions = new base::ListValue(); - manifest.Set("permissions", permissions); - permissions->Append(new base::StringValue("contextMenus")); - - std::string error; - scoped_refptr<const Extension> extension(Extension::Create( - base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS, - &error)); + std::set<Manifest::Type>* extension_types = feature->extension_types(); + EXPECT_EQ(3u, extension_types->size()); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); + EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_PLATFORM_APP)); +} - ASSERT_TRUE(extension.get()); - EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); +// Tests that real permission features have the correct availability for an app. +TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) { + const FeatureProvider* provider = + BaseFeatureProvider::GetByName("permission"); - feature = - static_cast<SimpleFeature*>(provider->GetFeature("chromePrivate")); + scoped_refptr<const Extension> app = + ExtensionBuilder() + .SetManifest(DictionaryBuilder() + .Set("name", "test app") + .Set("version", "1") + .Set("app", + DictionaryBuilder().Set( + "background", + DictionaryBuilder().Set( + "scripts", + ListBuilder().Append("background.js")))) + .Set("permissions", ListBuilder().Append("power"))) + .Build(); + ASSERT_TRUE(app.get()); + ASSERT_TRUE(app->is_platform_app()); + + // A permission requested in the manifest is available. + Feature* feature = provider->GetFeature("power"); + EXPECT_EQ( + Feature::IS_AVAILABLE, + feature->IsAvailableToContext( + app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); + + // A permission only available to whitelisted extensions returns availability + // NOT_FOUND_IN_WHITELIST. + feature = provider->GetFeature("bluetoothPrivate"); ASSERT_TRUE(feature); - EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); + EXPECT_EQ( + Feature::NOT_FOUND_IN_WHITELIST, + feature->IsAvailableToContext( + app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); - feature = - static_cast<SimpleFeature*>(provider->GetFeature("clipboardWrite")); + // A permission that isn't part of the manifest returns NOT_PRESENT. + feature = provider->GetFeature("serial"); ASSERT_TRUE(feature); - EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( - extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); -} - -TEST(BaseFeatureProviderTest, Validation) { - scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); - - base::DictionaryValue* feature1 = new base::DictionaryValue(); - feature1->SetString("channel", "trunk"); - value->Set("feature1", feature1); - - base::DictionaryValue* feature2 = new base::DictionaryValue(); - feature2->SetString("channel", "trunk"); - base::ListValue* extension_types = new base::ListValue(); - extension_types->Append(new base::StringValue("extension")); - feature2->Set("extension_types", extension_types); - base::ListValue* contexts = new base::ListValue(); - contexts->Append(new base::StringValue("blessed_extension")); - feature2->Set("contexts", contexts); - value->Set("feature2", feature2); - - scoped_ptr<BaseFeatureProvider> provider( - new BaseFeatureProvider(*value, CreateFeature<PermissionFeature>)); - - // feature1 won't validate because it lacks an extension type. - EXPECT_FALSE(provider->GetFeature("feature1")); - - // If we add one, it works. - feature1->Set("extension_types", extension_types->DeepCopy()); - provider.reset( - new BaseFeatureProvider(*value, CreateFeature<PermissionFeature>)); - EXPECT_TRUE(provider->GetFeature("feature1")); - - // Remove the channel, and feature1 won't validate. - feature1->Remove("channel", NULL); - provider.reset( - new BaseFeatureProvider(*value, CreateFeature<PermissionFeature>)); - EXPECT_FALSE(provider->GetFeature("feature1")); - - // feature2 won't validate because of the presence of "contexts". - EXPECT_FALSE(provider->GetFeature("feature2")); - - // If we remove it, it works. - feature2->Remove("contexts", NULL); - provider.reset( - new BaseFeatureProvider(*value, CreateFeature<PermissionFeature>)); - EXPECT_TRUE(provider->GetFeature("feature2")); -} - -TEST(BaseFeatureProviderTest, ComplexFeatures) { - scoped_ptr<base::DictionaryValue> rule( - DictionaryBuilder() - .Set("feature1", ListBuilder() - .Append(DictionaryBuilder() - .Set("channel", "beta") - .Set("extension_types", ListBuilder() - .Append("extension"))) - .Append(DictionaryBuilder() - .Set("channel", "beta") - .Set("extension_types", ListBuilder() - .Append("legacy_packaged_app")))) - .Build()); - - scoped_ptr<BaseFeatureProvider> provider( - new BaseFeatureProvider(*rule, CreateFeature<SimpleFeature>)); - - Feature* feature = provider->GetFeature("feature1"); - EXPECT_TRUE(feature); - - // Make sure both rules are applied correctly. - { - ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); - EXPECT_EQ( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("1", - Manifest::TYPE_EXTENSION, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM).result()); - EXPECT_EQ( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("2", - Manifest::TYPE_LEGACY_PACKAGED_APP, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM).result()); - } - { - ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_STABLE); - EXPECT_NE( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("1", - Manifest::TYPE_EXTENSION, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM).result()); - EXPECT_NE( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("2", - Manifest::TYPE_LEGACY_PACKAGED_APP, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM).result()); - } + EXPECT_EQ( + Feature::NOT_PRESENT, + feature->IsAvailableToContext( + app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); } } // namespace extensions diff --git a/extensions/common/features/complex_feature_unittest.cc b/extensions/common/features/complex_feature_unittest.cc index 54e52863..0f8a9ea 100644 --- a/extensions/common/features/complex_feature_unittest.cc +++ b/extensions/common/features/complex_feature_unittest.cc @@ -4,48 +4,23 @@ #include "extensions/common/features/complex_feature.h" -#include "chrome/common/extensions/features/chrome_channel_feature_filter.h" -#include "chrome/common/extensions/features/feature_channel.h" +#include <string> + #include "extensions/common/features/simple_feature.h" +#include "extensions/common/manifest.h" #include "extensions/common/value_builder.h" #include "testing/gtest/include/gtest/gtest.h" -using chrome::VersionInfo; -using extensions::ComplexFeature; -using extensions::DictionaryBuilder; -using extensions::Feature; -using extensions::ListBuilder; -using extensions::Manifest; -using extensions::ScopedCurrentChannel; -using extensions::SimpleFeature; - -namespace { - -class ExtensionComplexFeatureTest : public testing::Test { - protected: - ExtensionComplexFeatureTest() - : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} - virtual ~ExtensionComplexFeatureTest() {} - - SimpleFeature* CreateFeature() { - SimpleFeature* feature = new SimpleFeature(); - feature->AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( - new extensions::ChromeChannelFeatureFilter(feature))); - return feature; - } - - private: - ScopedCurrentChannel current_channel_; -}; - -TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) { +namespace extensions { + +TEST(ComplexFeatureTest, MultipleRulesWhitelist) { const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); scoped_ptr<ComplexFeature::FeatureList> features( new ComplexFeature::FeatureList()); // Rule: "extension", whitelist "foo". - scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); + scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature); scoped_ptr<base::DictionaryValue> rule( DictionaryBuilder() .Set("whitelist", ListBuilder().Append(kIdFoo)) @@ -55,7 +30,7 @@ TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) { features->push_back(simple_feature.release()); // Rule: "legacy_packaged_app", whitelist "bar". - simple_feature.reset(CreateFeature()); + simple_feature.reset(new SimpleFeature); rule = DictionaryBuilder() .Set("whitelist", ListBuilder().Append(kIdBar)) .Set("extension_types", ListBuilder() @@ -100,83 +75,23 @@ TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) { Feature::GetCurrentPlatform()).result()); } -TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) { - scoped_ptr<ComplexFeature::FeatureList> features( - new ComplexFeature::FeatureList()); - - // Rule: "extension", channel trunk. - scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); - scoped_ptr<base::DictionaryValue> rule( - DictionaryBuilder() - .Set("channel", "trunk") - .Set("extension_types", ListBuilder().Append("extension")).Build()); - simple_feature->Parse(rule.get()); - features->push_back(simple_feature.release()); - - // Rule: "legacy_packaged_app", channel stable. - simple_feature.reset(CreateFeature()); - rule = DictionaryBuilder() - .Set("channel", "stable") - .Set("extension_types", ListBuilder() - .Append("legacy_packaged_app")).Build(); - simple_feature->Parse(rule.get()); - features->push_back(simple_feature.release()); - - scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); - - // Test match 1st rule. - { - ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN); - EXPECT_EQ( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("1", - Manifest::TYPE_EXTENSION, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM, - Feature::GetCurrentPlatform()).result()); - } - - // Test match 2nd rule. - { - ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); - EXPECT_EQ( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("2", - Manifest::TYPE_LEGACY_PACKAGED_APP, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM, - Feature::GetCurrentPlatform()).result()); - } - - // Test feature not available to extensions above channel unknown. - { - ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); - EXPECT_NE( - Feature::IS_AVAILABLE, - feature->IsAvailableToManifest("1", - Manifest::TYPE_EXTENSION, - Manifest::INVALID_LOCATION, - Feature::UNSPECIFIED_PLATFORM, - Feature::GetCurrentPlatform()).result()); - } -} - // Tests that dependencies are correctly checked. -TEST_F(ExtensionComplexFeatureTest, Dependencies) { +TEST(ComplexFeatureTest, Dependencies) { scoped_ptr<ComplexFeature::FeatureList> features( new ComplexFeature::FeatureList()); - // Rule which depends on an extension-only feature (omnibox). - scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); + // Rule which depends on an extension-only feature (content_security_policy). + scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature); scoped_ptr<base::DictionaryValue> rule = DictionaryBuilder() - .Set("dependencies", ListBuilder().Append("manifest:omnibox")) + .Set("dependencies", + ListBuilder().Append("manifest:content_security_policy")) .Build(); simple_feature->Parse(rule.get()); features->push_back(simple_feature.release()); // Rule which depends on an platform-app-only feature (serial). - simple_feature.reset(CreateFeature()); + simple_feature.reset(new SimpleFeature); rule = DictionaryBuilder() .Set("dependencies", ListBuilder().Append("permission:serial")) .Build(); @@ -185,7 +100,7 @@ TEST_F(ExtensionComplexFeatureTest, Dependencies) { scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); - // Available to extensions because of the omnibox rule. + // Available to extensions because of the content_security_policy rule. EXPECT_EQ( Feature::IS_AVAILABLE, feature->IsAvailableToManifest("extensionid", @@ -194,7 +109,7 @@ TEST_F(ExtensionComplexFeatureTest, Dependencies) { Feature::UNSPECIFIED_PLATFORM, Feature::GetCurrentPlatform()).result()); - // Available to platofrm apps because of the serial rule. + // Available to platform apps because of the serial rule. EXPECT_EQ( Feature::IS_AVAILABLE, feature->IsAvailableToManifest("platformappid", @@ -213,4 +128,4 @@ TEST_F(ExtensionComplexFeatureTest, Dependencies) { Feature::GetCurrentPlatform()).result()); } -} // namespace +} // namespace extensions diff --git a/extensions/common/features/simple_feature_unittest.cc b/extensions/common/features/simple_feature_unittest.cc index 725dec9..40e1e2a 100644 --- a/extensions/common/features/simple_feature_unittest.cc +++ b/extensions/common/features/simple_feature_unittest.cc @@ -4,20 +4,13 @@ #include "extensions/common/features/simple_feature.h" -#include "chrome/common/extensions/features/chrome_channel_feature_filter.h" -#include "chrome/common/extensions/features/feature_channel.h" +#include <string> + +#include "base/values.h" +#include "extensions/common/manifest.h" #include "extensions/common/value_builder.h" #include "testing/gtest/include/gtest/gtest.h" -using chrome::VersionInfo; -using extensions::DictionaryBuilder; -using extensions::Extension; -using extensions::Feature; -using extensions::ListBuilder; -using extensions::Manifest; -using extensions::ScopedCurrentChannel; -using extensions::SimpleFeature; - namespace extensions { namespace { @@ -31,32 +24,22 @@ struct IsAvailableTestData { Feature::AvailabilityResult expected_result; }; -} // namespace - -class ExtensionSimpleFeatureTest : public testing::Test { - protected: - ExtensionSimpleFeatureTest() - : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} - virtual ~ExtensionSimpleFeatureTest() {} - - bool LocationIsAvailable(SimpleFeature::Location feature_location, - Manifest::Location manifest_location) { - SimpleFeature feature; - feature.set_location(feature_location); - Feature::AvailabilityResult availability_result = - feature.IsAvailableToManifest(std::string(), - Manifest::TYPE_UNKNOWN, - manifest_location, - -1, - Feature::UNSPECIFIED_PLATFORM).result(); - return availability_result == Feature::IS_AVAILABLE; - } +bool LocationIsAvailable(SimpleFeature::Location feature_location, + Manifest::Location manifest_location) { + SimpleFeature feature; + feature.set_location(feature_location); + Feature::AvailabilityResult availability_result = + feature.IsAvailableToManifest(std::string(), + Manifest::TYPE_UNKNOWN, + manifest_location, + -1, + Feature::UNSPECIFIED_PLATFORM).result(); + return availability_result == Feature::IS_AVAILABLE; +} - private: - ScopedCurrentChannel current_channel_; -}; +} // namespace -TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) { +TEST(SimpleFeatureTest, IsAvailableNullCase) { const IsAvailableTestData tests[] = { {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, @@ -85,7 +68,7 @@ TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) { } } -TEST_F(ExtensionSimpleFeatureTest, Whitelist) { +TEST(SimpleFeatureTest, Whitelist) { const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); @@ -133,7 +116,7 @@ TEST_F(ExtensionSimpleFeatureTest, Whitelist) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) { +TEST(SimpleFeatureTest, HashedIdWhitelist) { // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | // sha1sum | tr '[:lower:]' '[:upper:]' const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); @@ -172,7 +155,7 @@ TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, Blacklist) { +TEST(SimpleFeatureTest, Blacklist) { const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); @@ -211,7 +194,7 @@ TEST_F(ExtensionSimpleFeatureTest, Blacklist) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, HashedIdBlacklist) { +TEST(SimpleFeatureTest, HashedIdBlacklist) { // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | // sha1sum | tr '[:lower:]' '[:upper:]' const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); @@ -250,7 +233,7 @@ TEST_F(ExtensionSimpleFeatureTest, HashedIdBlacklist) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, PackageType) { +TEST(SimpleFeatureTest, PackageType) { SimpleFeature feature; feature.extension_types()->insert(Manifest::TYPE_EXTENSION); feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); @@ -286,7 +269,7 @@ TEST_F(ExtensionSimpleFeatureTest, PackageType) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, Context) { +TEST(SimpleFeatureTest, Context) { SimpleFeature feature; feature.set_name("somefeature"); feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); @@ -377,7 +360,7 @@ TEST_F(ExtensionSimpleFeatureTest, Context) { feature.set_max_manifest_version(25); } -TEST_F(ExtensionSimpleFeatureTest, Location) { +TEST(SimpleFeatureTest, Location) { // Component extensions can access any location. EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, Manifest::COMPONENT)); @@ -413,7 +396,7 @@ TEST_F(ExtensionSimpleFeatureTest, Location) { Manifest::EXTERNAL_PREF_DOWNLOAD)); } -TEST_F(ExtensionSimpleFeatureTest, Platform) { +TEST(SimpleFeatureTest, Platform) { SimpleFeature feature; feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); EXPECT_EQ(Feature::IS_AVAILABLE, @@ -431,7 +414,7 @@ TEST_F(ExtensionSimpleFeatureTest, Platform) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, Version) { +TEST(SimpleFeatureTest, ManifestVersion) { SimpleFeature feature; feature.set_min_manifest_version(5); @@ -490,7 +473,7 @@ TEST_F(ExtensionSimpleFeatureTest, Version) { Feature::UNSPECIFIED_PLATFORM).result()); } -TEST_F(ExtensionSimpleFeatureTest, ParseNull) { +TEST(SimpleFeatureTest, ParseNull) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); scoped_ptr<SimpleFeature> feature(new SimpleFeature()); feature->Parse(value.get()); @@ -503,7 +486,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseNull) { EXPECT_EQ(0, feature->max_manifest_version()); } -TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { +TEST(SimpleFeatureTest, ParseWhitelist) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); base::ListValue* whitelist = new base::ListValue(); whitelist->Append(new base::StringValue("foo")); @@ -516,7 +499,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { EXPECT_TRUE(feature->whitelist()->count("bar")); } -TEST_F(ExtensionSimpleFeatureTest, ParsePackageTypes) { +TEST(SimpleFeatureTest, ParsePackageTypes) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); base::ListValue* extension_types = new base::ListValue(); extension_types->Append(new base::StringValue("extension")); @@ -543,7 +526,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParsePackageTypes) { EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); } -TEST_F(ExtensionSimpleFeatureTest, ParseContexts) { +TEST(SimpleFeatureTest, ParseContexts) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); base::ListValue* contexts = new base::ListValue(); contexts->Append(new base::StringValue("blessed_extension")); @@ -568,7 +551,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseContexts) { EXPECT_EQ(*(feature->contexts()), *(feature2->contexts())); } -TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { +TEST(SimpleFeatureTest, ParseLocation) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); value->SetString("location", "component"); scoped_ptr<SimpleFeature> feature(new SimpleFeature()); @@ -576,7 +559,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); } -TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) { +TEST(SimpleFeatureTest, ParsePlatforms) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); scoped_ptr<SimpleFeature> feature(new SimpleFeature()); base::ListValue* platforms = new base::ListValue(); @@ -607,7 +590,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) { EXPECT_EQ(expected_platforms, *feature->platforms()); } -TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) { +TEST(SimpleFeatureTest, ParseManifestVersion) { scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); value->SetInteger("min_manifest_version", 1); value->SetInteger("max_manifest_version", 5); @@ -617,7 +600,7 @@ TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) { EXPECT_EQ(5, feature->max_manifest_version()); } -TEST_F(ExtensionSimpleFeatureTest, Inheritance) { +TEST(SimpleFeatureTest, Inheritance) { SimpleFeature feature; feature.whitelist()->insert("foo"); feature.extension_types()->insert(Manifest::TYPE_THEME); @@ -666,86 +649,4 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) { EXPECT_EQ(3, feature.max_manifest_version()); } -Feature::AvailabilityResult IsAvailableInChannel( - const std::string& channel, VersionInfo::Channel channel_for_testing) { - ScopedCurrentChannel current_channel(channel_for_testing); - - SimpleFeature feature; - feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( - new extensions::ChromeChannelFeatureFilter(&feature))); - if (!channel.empty()) { - base::DictionaryValue feature_value; - feature_value.SetString("channel", channel); - feature.Parse(&feature_value); - } - - return feature.IsAvailableToManifest("random-extension", - Manifest::TYPE_UNKNOWN, - Manifest::INVALID_LOCATION, - -1, - Feature::GetCurrentPlatform()).result(); -} - -TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) { - // stable supported. - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("stable", VersionInfo::CHANNEL_CANARY)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("stable", VersionInfo::CHANNEL_DEV)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("stable", VersionInfo::CHANNEL_BETA)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("stable", VersionInfo::CHANNEL_STABLE)); - - // beta supported. - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("beta", VersionInfo::CHANNEL_UNKNOWN)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("beta", VersionInfo::CHANNEL_CANARY)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("beta", VersionInfo::CHANNEL_DEV)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("beta", VersionInfo::CHANNEL_BETA)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("beta", VersionInfo::CHANNEL_STABLE)); - - // dev supported. - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("dev", VersionInfo::CHANNEL_UNKNOWN)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("dev", VersionInfo::CHANNEL_CANARY)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("dev", VersionInfo::CHANNEL_DEV)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("dev", VersionInfo::CHANNEL_BETA)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("dev", VersionInfo::CHANNEL_STABLE)); - - // canary supported. - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("canary", VersionInfo::CHANNEL_UNKNOWN)); - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("canary", VersionInfo::CHANNEL_CANARY)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("canary", VersionInfo::CHANNEL_DEV)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("canary", VersionInfo::CHANNEL_BETA)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("canary", VersionInfo::CHANNEL_STABLE)); - - // trunk supported. - EXPECT_EQ(Feature::IS_AVAILABLE, - IsAvailableInChannel("trunk", VersionInfo::CHANNEL_UNKNOWN)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA)); - EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, - IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE)); -} - } // namespace extensions |