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

Unified Diff: chrome/common/extensions/features/simple_feature_unittest.cc

Issue 11316164: Implement ComplexFeature to support permission features with multiple rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames and add TODO Created 8 years 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: chrome/common/extensions/features/simple_feature_unittest.cc
diff --git a/chrome/common/extensions/features/feature_unittest.cc b/chrome/common/extensions/features/simple_feature_unittest.cc
similarity index 85%
rename from chrome/common/extensions/features/feature_unittest.cc
rename to chrome/common/extensions/features/simple_feature_unittest.cc
index 24134db95eab2818a1459c46918a9f6f679213e2..7f66c2a1aa09a9e7d9ceacc3fa6bbed0a7d964ed 100644
--- a/chrome/common/extensions/features/feature_unittest.cc
+++ b/chrome/common/extensions/features/simple_feature_unittest.cc
@@ -2,13 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/extensions/features/feature.h"
+#include "chrome/common/extensions/features/simple_feature.h"
+#include "chrome/common/extensions/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::SimpleFeature;
namespace {
@@ -21,17 +25,17 @@ struct IsAvailableTestData {
Feature::AvailabilityResult expected_result;
};
-class ExtensionFeatureTest : public testing::Test {
+class ExtensionSimpleFeatureTest : public testing::Test {
protected:
- ExtensionFeatureTest()
+ ExtensionSimpleFeatureTest()
: current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
- virtual ~ExtensionFeatureTest() {}
+ virtual ~ExtensionSimpleFeatureTest() {}
private:
Feature::ScopedCurrentChannel current_channel_;
};
-TEST_F(ExtensionFeatureTest, IsAvailableNullCase) {
+TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) {
const IsAvailableTestData tests[] = {
{ "", Extension::TYPE_UNKNOWN,
Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1,
@@ -56,7 +60,7 @@ TEST_F(ExtensionFeatureTest, IsAvailableNullCase) {
Feature::IS_AVAILABLE }
};
- Feature feature;
+ SimpleFeature feature;
for (size_t i = 0; i < arraysize(tests); ++i) {
const IsAvailableTestData& test = tests[i];
EXPECT_EQ(test.expected_result,
@@ -68,8 +72,8 @@ TEST_F(ExtensionFeatureTest, IsAvailableNullCase) {
}
}
-TEST_F(ExtensionFeatureTest, Whitelist) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Whitelist) {
+ SimpleFeature feature;
feature.whitelist()->insert("foo");
feature.whitelist()->insert("bar");
@@ -94,8 +98,8 @@ TEST_F(ExtensionFeatureTest, Whitelist) {
Feature::UNSPECIFIED_PLATFORM).result());
}
-TEST_F(ExtensionFeatureTest, PackageType) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, PackageType) {
+ SimpleFeature feature;
feature.extension_types()->insert(Extension::TYPE_EXTENSION);
feature.extension_types()->insert(Extension::TYPE_LEGACY_PACKAGED_APP);
@@ -114,9 +118,9 @@ TEST_F(ExtensionFeatureTest, PackageType) {
Feature::UNSPECIFIED_PLATFORM).result());
}
-TEST_F(ExtensionFeatureTest, Context) {
- Feature feature;
- feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
+TEST_F(ExtensionSimpleFeatureTest, Context) {
+ SimpleFeature feature;
+ feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
feature.extension_types()->insert(Extension::TYPE_LEGACY_PACKAGED_APP);
feature.set_platform(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(21);
@@ -148,13 +152,13 @@ TEST_F(ExtensionFeatureTest, Context) {
feature.extension_types()->clear();
feature.extension_types()->insert(Extension::TYPE_LEGACY_PACKAGED_APP);
- feature.contexts()->clear();
- feature.contexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
+ feature.GetContexts()->clear();
+ feature.GetContexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
EXPECT_EQ(Feature::INVALID_CONTEXT, feature.IsAvailableToContext(
extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
Feature::CHROMEOS_PLATFORM).result());
- feature.contexts()->clear();
- feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
+ feature.GetContexts()->clear();
+ feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
feature.set_location(Feature::COMPONENT_LOCATION);
EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext(
@@ -179,8 +183,8 @@ TEST_F(ExtensionFeatureTest, Context) {
feature.set_max_manifest_version(25);
}
-TEST_F(ExtensionFeatureTest, Location) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Location) {
+ SimpleFeature feature;
// If the feature specifies "component" as its location, then only component
// extensions can access it.
@@ -199,8 +203,8 @@ TEST_F(ExtensionFeatureTest, Location) {
Feature::UNSPECIFIED_PLATFORM).result());
}
-TEST_F(ExtensionFeatureTest, Platform) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Platform) {
+ SimpleFeature feature;
feature.set_platform(Feature::CHROMEOS_PLATFORM);
EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest(
"", Extension::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1,
@@ -210,8 +214,8 @@ TEST_F(ExtensionFeatureTest, Platform) {
Feature::UNSPECIFIED_PLATFORM).result());
}
-TEST_F(ExtensionFeatureTest, Version) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Version) {
+ SimpleFeature feature;
feature.set_min_manifest_version(5);
EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION,
@@ -245,33 +249,33 @@ TEST_F(ExtensionFeatureTest, Version) {
7, Feature::UNSPECIFIED_PLATFORM).result());
}
-TEST_F(ExtensionFeatureTest, ParseNull) {
+TEST_F(ExtensionSimpleFeatureTest, ParseNull) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_TRUE(feature->whitelist()->empty());
EXPECT_TRUE(feature->extension_types()->empty());
- EXPECT_TRUE(feature->contexts()->empty());
+ EXPECT_TRUE(feature->GetContexts()->empty());
EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
EXPECT_EQ(0, feature->min_manifest_version());
EXPECT_EQ(0, feature->max_manifest_version());
}
-TEST_F(ExtensionFeatureTest, ParseWhitelist) {
+TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
ListValue* whitelist = new ListValue();
whitelist->Append(Value::CreateStringValue("foo"));
whitelist->Append(Value::CreateStringValue("bar"));
value->Set("whitelist", whitelist);
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_EQ(2u, feature->whitelist()->size());
EXPECT_TRUE(feature->whitelist()->count("foo"));
EXPECT_TRUE(feature->whitelist()->count("bar"));
}
-TEST_F(ExtensionFeatureTest, ParsePackageTypes) {
+TEST_F(ExtensionSimpleFeatureTest, ParsePackageTypes) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
ListValue* extension_types = new ListValue();
extension_types->Append(Value::CreateStringValue("extension"));
@@ -280,7 +284,7 @@ TEST_F(ExtensionFeatureTest, ParsePackageTypes) {
extension_types->Append(Value::CreateStringValue("hosted_app"));
extension_types->Append(Value::CreateStringValue("platform_app"));
value->Set("extension_types", extension_types);
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_EQ(5u, feature->extension_types()->size());
EXPECT_TRUE(feature->extension_types()->count(Extension::TYPE_EXTENSION));
@@ -291,12 +295,12 @@ TEST_F(ExtensionFeatureTest, ParsePackageTypes) {
EXPECT_TRUE(feature->extension_types()->count(Extension::TYPE_PLATFORM_APP));
value->SetString("extension_types", "all");
- scoped_ptr<Feature> feature2(new Feature());
+ scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
feature2->Parse(value.get());
EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types()));
}
-TEST_F(ExtensionFeatureTest, ParseContexts) {
+TEST_F(ExtensionSimpleFeatureTest, ParseContexts) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
ListValue* contexts = new ListValue();
contexts->Append(Value::CreateStringValue("blessed_extension"));
@@ -304,57 +308,61 @@ TEST_F(ExtensionFeatureTest, ParseContexts) {
contexts->Append(Value::CreateStringValue("content_script"));
contexts->Append(Value::CreateStringValue("web_page"));
value->Set("contexts", contexts);
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
- EXPECT_EQ(4u, feature->contexts()->size());
- EXPECT_TRUE(feature->contexts()->count(Feature::BLESSED_EXTENSION_CONTEXT));
- EXPECT_TRUE(feature->contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
- EXPECT_TRUE(feature->contexts()->count(Feature::CONTENT_SCRIPT_CONTEXT));
- EXPECT_TRUE(feature->contexts()->count(Feature::WEB_PAGE_CONTEXT));
+ EXPECT_EQ(4u, feature->GetContexts()->size());
+ EXPECT_TRUE(
+ feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT));
+ EXPECT_TRUE(
+ feature->GetContexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
+ EXPECT_TRUE(
+ feature->GetContexts()->count(Feature::CONTENT_SCRIPT_CONTEXT));
+ EXPECT_TRUE(
+ feature->GetContexts()->count(Feature::WEB_PAGE_CONTEXT));
value->SetString("contexts", "all");
- scoped_ptr<Feature> feature2(new Feature());
+ scoped_ptr<SimpleFeature> feature2(new SimpleFeature());
feature2->Parse(value.get());
- EXPECT_EQ(*(feature->contexts()), *(feature2->contexts()));
+ EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts()));
}
-TEST_F(ExtensionFeatureTest, ParseLocation) {
+TEST_F(ExtensionSimpleFeatureTest, ParseLocation) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
value->SetString("location", "component");
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location());
}
-TEST_F(ExtensionFeatureTest, ParsePlatform) {
+TEST_F(ExtensionSimpleFeatureTest, ParsePlatform) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
value->SetString("platform", "chromeos");
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_EQ(Feature::CHROMEOS_PLATFORM, feature->platform());
}
-TEST_F(ExtensionFeatureTest, ManifestVersion) {
+TEST_F(ExtensionSimpleFeatureTest, ManifestVersion) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
value->SetInteger("min_manifest_version", 1);
value->SetInteger("max_manifest_version", 5);
- scoped_ptr<Feature> feature(new Feature());
+ scoped_ptr<SimpleFeature> feature(new SimpleFeature());
feature->Parse(value.get());
EXPECT_EQ(1, feature->min_manifest_version());
EXPECT_EQ(5, feature->max_manifest_version());
}
-TEST_F(ExtensionFeatureTest, Inheritance) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Inheritance) {
+ SimpleFeature feature;
feature.whitelist()->insert("foo");
feature.extension_types()->insert(Extension::TYPE_THEME);
- feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
+ feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT);
feature.set_location(Feature::COMPONENT_LOCATION);
feature.set_platform(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(1);
feature.set_max_manifest_version(2);
- Feature feature2 = feature;
+ SimpleFeature feature2 = feature;
EXPECT_TRUE(feature2.Equals(feature));
DictionaryValue definition;
@@ -378,26 +386,26 @@ TEST_F(ExtensionFeatureTest, Inheritance) {
EXPECT_FALSE(feature2.Equals(feature));
EXPECT_EQ(1u, feature2.whitelist()->size());
EXPECT_EQ(1u, feature2.extension_types()->size());
- EXPECT_EQ(1u, feature2.contexts()->size());
+ EXPECT_EQ(1u, feature2.GetContexts()->size());
EXPECT_EQ(1u, feature2.whitelist()->count("bar"));
EXPECT_EQ(1u, feature2.extension_types()->count(Extension::TYPE_EXTENSION));
- EXPECT_EQ(1u,
- feature2.contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
+ EXPECT_EQ(1u, feature2.GetContexts()->count(
+ Feature::UNBLESSED_EXTENSION_CONTEXT));
EXPECT_EQ(2, feature2.min_manifest_version());
EXPECT_EQ(3, feature2.max_manifest_version());
}
-TEST_F(ExtensionFeatureTest, Equals) {
- Feature feature;
+TEST_F(ExtensionSimpleFeatureTest, Equals) {
+ SimpleFeature feature;
feature.whitelist()->insert("foo");
feature.extension_types()->insert(Extension::TYPE_THEME);
- feature.contexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
+ feature.GetContexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT);
feature.set_location(Feature::COMPONENT_LOCATION);
feature.set_platform(Feature::CHROMEOS_PLATFORM);
feature.set_min_manifest_version(18);
feature.set_max_manifest_version(25);
- Feature feature2(feature);
+ SimpleFeature feature2(feature);
EXPECT_TRUE(feature2.Equals(feature));
feature2.whitelist()->clear();
@@ -408,7 +416,7 @@ TEST_F(ExtensionFeatureTest, Equals) {
EXPECT_FALSE(feature2.Equals(feature));
feature2 = feature;
- feature2.contexts()->clear();
+ feature2.GetContexts()->clear();
EXPECT_FALSE(feature2.Equals(feature));
feature2 = feature;
@@ -432,7 +440,7 @@ Feature::AvailabilityResult IsAvailableInChannel(
const std::string& channel, VersionInfo::Channel channel_for_testing) {
Feature::ScopedCurrentChannel current_channel(channel_for_testing);
- Feature feature;
+ SimpleFeature feature;
if (!channel.empty()) {
DictionaryValue feature_value;
feature_value.SetString("channel", channel);
@@ -443,10 +451,11 @@ Feature::AvailabilityResult IsAvailableInChannel(
"random-extension",
Extension::TYPE_UNKNOWN,
Feature::UNSPECIFIED_LOCATION,
- -1).result();
+ -1,
+ Feature::GetCurrentPlatform()).result();
}
-TEST_F(ExtensionFeatureTest, SupportedChannel) {
+TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) {
// stable supported.
EXPECT_EQ(Feature::IS_AVAILABLE,
IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN));
« no previous file with comments | « chrome/common/extensions/features/simple_feature_provider_unittest.cc ('k') | chrome/common/extensions/manifest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698