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

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: 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 side-by-side diff with in-line comments
Download patch
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..8202e4992b7681a1a406aaa3e158d65dc63fee76 100644
--- a/extensions/common/features/simple_feature_unittest.cc
+++ b/extensions/common/features/simple_feature_unittest.cc
@@ -23,12 +23,25 @@ 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;
};
+template <typename T>
+std::set<T> Set(const T& t) {
+ std::set<T> set;
+ set.insert(t);
+ return set;
+}
+template <typename T>
+std::set<T> Set(const T& t1, const T& t2) {
+ std::set<T> set = Set(t1);
+ set.insert(t2);
+ return set;
+}
+
class ExtensionSimpleFeatureTest : public testing::Test {
protected:
ExtensionSimpleFeatureTest()
@@ -41,28 +54,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 +89,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 +138,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 +177,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 +192,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 +272,11 @@ TEST_F(ExtensionSimpleFeatureTest, Context) {
feature.GetContexts()->clear();
feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
- feature.set_location(Feature::COMPONENT_LOCATION);
+ *feature.locations() = Set(Manifest::COMPONENT);
EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext(
extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
Feature::CHROMEOS_PLATFORM).result());
- feature.set_location(Feature::UNSPECIFIED_LOCATION);
+ feature.locations()->clear();
EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext(
extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
@@ -267,29 +300,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.locations() = Set(Manifest::COMPONENT);
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.locations()->clear();
EXPECT_EQ(
Feature::IS_AVAILABLE,
feature.IsAvailableToManifest(std::string(),
Manifest::TYPE_UNKNOWN,
- Feature::COMPONENT_LOCATION,
+ Manifest::COMPONENT,
-1,
Feature::UNSPECIFIED_PLATFORM).result());
}
@@ -300,14 +333,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 +353,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 +368,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 +385,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 +411,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_TRUE(feature->locations()->empty());
EXPECT_TRUE(feature->platforms()->empty());
EXPECT_EQ(0, feature->min_manifest_version());
EXPECT_EQ(0, feature->max_manifest_version());
@@ -453,12 +486,22 @@ TEST_F(ExtensionSimpleFeatureTest, ParseContexts) {
EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts()));
}
-TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
+TEST_F(ExtensionSimpleFeatureTest, ParseComponentLocation) {
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
value->SetString("location", "component");
scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
- EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location());
+ EXPECT_EQ(Set(Manifest::COMPONENT, Manifest::EXTERNAL_COMPONENT),
+ *feature->locations());
+}
+
+TEST_F(ExtensionSimpleFeatureTest, ParsePolicyLocation) {
+ scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
+ value->SetString("location", "policy");
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
+ feature->Parse(value.get());
+ EXPECT_EQ(Set(Manifest::EXTERNAL_POLICY, Manifest::EXTERNAL_POLICY_DOWNLOAD),
+ *feature->locations());
}
TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) {
@@ -507,7 +550,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.locations() = Set(Manifest::COMPONENT);
feature.platforms()->insert(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(1);
feature.set_max_manifest_version(2);
@@ -516,13 +559,11 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
// changes to a SimpleFeature.
base::DictionaryValue definition;
feature.Parse(&definition);
- EXPECT_EQ(1u, feature.whitelist()->size());
- 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(1u, feature.platforms()->size());
- EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM));
+ EXPECT_EQ(Set(std::string("foo")), *feature.whitelist());
+ EXPECT_EQ(Set(Manifest::TYPE_THEME), *feature.extension_types());
+ EXPECT_EQ(Set(Feature::BLESSED_EXTENSION_CONTEXT), *feature.GetContexts());
+ EXPECT_EQ(Set(Manifest::COMPONENT), *feature.locations());
+ EXPECT_EQ(Set(Feature::CHROMEOS_PLATFORM), *feature.platforms());
EXPECT_EQ(1, feature.min_manifest_version());
EXPECT_EQ(2, feature.max_manifest_version());
@@ -535,18 +576,18 @@ TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
definition.Set("whitelist", whitelist);
definition.Set("extension_types", extension_types);
definition.Set("contexts", contexts);
- // Can't test location or platform because we only have one value so far.
+ definition.SetString("location", "policy");
+ // Can't test platform because we only have one value so far.
definition.Set("min_manifest_version", new base::FundamentalValue(2));
definition.Set("max_manifest_version", new base::FundamentalValue(3));
feature.Parse(&definition);
- EXPECT_EQ(1u, feature.whitelist()->size());
- EXPECT_EQ(1u, feature.extension_types()->size());
- EXPECT_EQ(1u, feature.GetContexts()->size());
- EXPECT_EQ(1u, feature.whitelist()->count("bar"));
- EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION));
- EXPECT_EQ(1u,
- feature.GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
+ EXPECT_EQ(Set(std::string("bar")), *feature.whitelist());
+ EXPECT_EQ(Set(Manifest::TYPE_EXTENSION), *feature.extension_types());
+ EXPECT_EQ(Set(Feature::UNBLESSED_EXTENSION_CONTEXT), *feature.GetContexts());
+ EXPECT_EQ(Set(Manifest::EXTERNAL_POLICY, Manifest::EXTERNAL_POLICY_DOWNLOAD),
+ *feature.locations());
+ EXPECT_EQ(Set(Feature::CHROMEOS_PLATFORM), *feature.platforms());
EXPECT_EQ(2, feature.min_manifest_version());
EXPECT_EQ(3, feature.max_manifest_version());
}
@@ -564,12 +605,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) {

Powered by Google App Engine
This is Rietveld 408576698