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

Unified 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: different approach (yoz) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/common/features/simple_feature_filter.cc ('k') | extensions/common/manifest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/features/simple_feature_unittest.cc
diff --git a/extensions/common/features/simple_feature_unittest.cc b/extensions/common/features/simple_feature_unittest.cc
index aa84bf82becaebd335d9dd875bd463023455a795..330978b27ebb7e0eb65c9f4b7428116b49ac053f 100644
--- a/extensions/common/features/simple_feature_unittest.cc
+++ b/extensions/common/features/simple_feature_unittest.cc
@@ -18,17 +18,21 @@ using extensions::Manifest;
using extensions::ScopedCurrentChannel;
using extensions::SimpleFeature;
+namespace extensions {
+
namespace {
struct IsAvailableTestData {
std::string extension_id;
Manifest::Type extension_type;
- Feature::Location location;
+ Manifest::Location location;
Feature::Platform platform;
int manifest_version;
Feature::AvailabilityResult expected_result;
};
+} // namespace
+
class ExtensionSimpleFeatureTest : public testing::Test {
protected:
ExtensionSimpleFeatureTest()
@@ -41,28 +45,20 @@ class ExtensionSimpleFeatureTest : public testing::Test {
TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) {
const IsAvailableTestData tests[] = {
- { "", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "random-extension", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "", Manifest::TYPE_LEGACY_PACKAGED_APP,
- Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "", Manifest::TYPE_UNKNOWN,
- Feature::COMPONENT_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, Feature::CHROMEOS_PLATFORM, -1,
- Feature::IS_AVAILABLE },
- { "", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, 25,
- Feature::IS_AVAILABLE }
- };
+ {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
+ Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
+ Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION,
+ Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
+ Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT,
+ Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
+ Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE},
+ {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
+ Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}};
SimpleFeature feature;
for (size_t i = 0; i < arraysize(tests); ++i) {
@@ -84,29 +80,44 @@ TEST_F(ExtensionSimpleFeatureTest, Whitelist) {
feature.whitelist()->insert(kIdFoo);
feature.whitelist()->insert(kIdBar);
- EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
- kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
- EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
- kIdBar, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::IS_AVAILABLE,
+ feature.IsAvailableToManifest(kIdFoo,
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::IS_AVAILABLE,
+ feature.IsAvailableToManifest(kIdBar,
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
- EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest(
- kIdBaz, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::NOT_FOUND_IN_WHITELIST,
+ feature.IsAvailableToManifest(kIdBaz,
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::NOT_FOUND_IN_WHITELIST,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP);
- EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest(
- kIdBaz, Manifest::TYPE_LEGACY_PACKAGED_APP,
- Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::NOT_FOUND_IN_WHITELIST,
+ feature.IsAvailableToManifest(kIdBaz,
+ Manifest::TYPE_LEGACY_PACKAGED_APP,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
}
TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) {
@@ -118,21 +129,34 @@ TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) {
feature.whitelist()->insert(kIdFooHashed);
- EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
- kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
- EXPECT_NE(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
- kIdFooHashed, Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
- EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest(
- "slightlytoooolongforanextensionid", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
- EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest(
- "tooshortforanextensionid", Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION, -1,
- Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::IS_AVAILABLE,
+ feature.IsAvailableToManifest(kIdFoo,
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_NE(
+ Feature::IS_AVAILABLE,
+ feature.IsAvailableToManifest(kIdFooHashed,
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::NOT_FOUND_IN_WHITELIST,
+ feature.IsAvailableToManifest("slightlytoooolongforanextensionid",
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
+ EXPECT_EQ(
+ Feature::NOT_FOUND_IN_WHITELIST,
+ feature.IsAvailableToManifest("tooshortforanextensionid",
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::UNSPECIFIED_PLATFORM).result());
}
TEST_F(ExtensionSimpleFeatureTest, PackageType) {
@@ -144,14 +168,14 @@ TEST_F(ExtensionSimpleFeatureTest, PackageType) {
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_EXTENSION,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_LEGACY_PACKAGED_APP,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
@@ -159,14 +183,14 @@ TEST_F(ExtensionSimpleFeatureTest, PackageType) {
Feature::INVALID_TYPE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::INVALID_TYPE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_THEME,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
}
@@ -239,11 +263,11 @@ TEST_F(ExtensionSimpleFeatureTest, Context) {
feature.GetContexts()->clear();
feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
- feature.set_location(Feature::COMPONENT_LOCATION);
+ feature.set_location(SimpleFeature::COMPONENT_LOCATION);
EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext(
extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
Feature::CHROMEOS_PLATFORM).result());
- feature.set_location(Feature::UNSPECIFIED_LOCATION);
+ feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION);
EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext(
extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
@@ -267,29 +291,29 @@ TEST_F(ExtensionSimpleFeatureTest, Location) {
// If the feature specifies "component" as its location, then only component
// extensions can access it.
- feature.set_location(Feature::COMPONENT_LOCATION);
+ feature.set_location(SimpleFeature::COMPONENT_LOCATION);
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::COMPONENT_LOCATION,
+ Manifest::COMPONENT,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::INVALID_LOCATION,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
// But component extensions can access anything else, whatever their location.
- feature.set_location(Feature::UNSPECIFIED_LOCATION);
+ feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION);
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::COMPONENT_LOCATION,
+ Manifest::COMPONENT,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
}
@@ -300,14 +324,14 @@ TEST_F(ExtensionSimpleFeatureTest, Platform) {
EXPECT_EQ(Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::CHROMEOS_PLATFORM).result());
EXPECT_EQ(
Feature::INVALID_PLATFORM,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
}
@@ -320,14 +344,14 @@ TEST_F(ExtensionSimpleFeatureTest, Version) {
Feature::INVALID_MIN_MANIFEST_VERSION,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
0,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::INVALID_MIN_MANIFEST_VERSION,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
4,
Feature::UNSPECIFIED_PLATFORM).result());
@@ -335,14 +359,14 @@ TEST_F(ExtensionSimpleFeatureTest, Version) {
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
5,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
10,
Feature::UNSPECIFIED_PLATFORM).result());
@@ -352,21 +376,21 @@ TEST_F(ExtensionSimpleFeatureTest, Version) {
Feature::INVALID_MAX_MANIFEST_VERSION,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
10,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
8,
Feature::UNSPECIFIED_PLATFORM).result());
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
+ Manifest::INVALID_LOCATION,
7,
Feature::UNSPECIFIED_PLATFORM).result());
}
@@ -378,7 +402,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
EXPECT_TRUE(feature->whitelist()->empty());
EXPECT_TRUE(feature->extension_types()->empty());
EXPECT_TRUE(feature->GetContexts()->empty());
- EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
+ EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
EXPECT_TRUE(feature->platforms()->empty());
EXPECT_EQ(0, feature->min_manifest_version());
EXPECT_EQ(0, feature->max_manifest_version());
@@ -458,7 +482,7 @@ TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
value->SetString("location", "component");
scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
- EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location());
+ EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location());
}
TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) {
@@ -507,7 +531,7 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
feature.whitelist()->insert("foo");
feature.extension_types()->insert(Manifest::TYPE_THEME);
feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
- feature.set_location(Feature::COMPONENT_LOCATION);
+ feature.set_location(SimpleFeature::COMPONENT_LOCATION);
feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(1);
feature.set_max_manifest_version(2);
@@ -520,7 +544,7 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
EXPECT_EQ(1u, feature.extension_types()->size());
EXPECT_EQ(1u, feature.GetContexts()->size());
EXPECT_EQ(1u, feature.whitelist()->count("foo"));
- EXPECT_EQ(Feature::COMPONENT_LOCATION, feature.location());
+ EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location());
EXPECT_EQ(1u, feature.platforms()->size());
EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM));
EXPECT_EQ(1, feature.min_manifest_version());
@@ -564,12 +588,11 @@ Feature::AvailabilityResult IsAvailableInChannel(
feature.Parse(&feature_value);
}
- return feature.IsAvailableToManifest(
- "random-extension",
- Manifest::TYPE_UNKNOWN,
- Feature::UNSPECIFIED_LOCATION,
- -1,
- Feature::GetCurrentPlatform()).result();
+ return feature.IsAvailableToManifest("random-extension",
+ Manifest::TYPE_UNKNOWN,
+ Manifest::INVALID_LOCATION,
+ -1,
+ Feature::GetCurrentPlatform()).result();
}
TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) {
@@ -634,4 +657,4 @@ TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) {
IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE));
}
-} // namespace
+} // namespace extensions
« 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