Chromium Code Reviews| Index: chrome/common/extensions/features/complex_feature_unittest.cc |
| diff --git a/chrome/common/extensions/features/complex_feature_unittest.cc b/chrome/common/extensions/features/complex_feature_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5ad256e73ebdbd41fad6190a3a4343a0219ea3a |
| --- /dev/null |
| +++ b/chrome/common/extensions/features/complex_feature_unittest.cc |
| @@ -0,0 +1,142 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// 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/complex_feature.h" |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using chrome::VersionInfo; |
| +using extensions::ComplexFeature; |
| +using extensions::Extension; |
| +using extensions::Feature; |
| +using extensions::PermissionFeature; |
| + |
| +namespace { |
| + |
| +class ExtensionComplexFeatureTest : public testing::Test { |
| + protected: |
| + ExtensionComplexFeatureTest() |
| + : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} |
| + virtual ~ExtensionComplexFeatureTest() {} |
| + |
| + private: |
| + Feature::ScopedCurrentChannel current_channel_; |
| +}; |
| + |
| +TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) { |
| + scoped_ptr<ComplexFeature> feature(new ComplexFeature()); |
| + |
| + // Rule: "extension", whitelist "foo". |
| + scoped_ptr<PermissionFeature> simple_feature(new PermissionFeature()); |
| + scoped_ptr<DictionaryValue> rule(new DictionaryValue()); |
| + ListValue* whitelist = new ListValue(); |
| + whitelist->Append(Value::CreateStringValue("foo")); |
| + rule->Set("whitelist", whitelist); |
| + ListValue* extension_types = new ListValue(); |
| + extension_types->Append(Value::CreateStringValue("extension")); |
| + rule->Set("extension_types", extension_types); |
| + simple_feature->Parse(rule.get()); |
| + feature->AddSimpleFeature(simple_feature.get()); |
| + |
|
not at google - send to devlin
2012/12/12 17:42:41
ditto
justinlin
2012/12/14 12:26:26
Done.
|
| + // Rule: "packaged_app", whitelist "bar". |
| + simple_feature.reset(new PermissionFeature()); |
| + rule.reset(new DictionaryValue()); |
| + whitelist = new ListValue(); |
| + whitelist->Append(Value::CreateStringValue("bar")); |
| + rule->Set("whitelist", whitelist); |
| + extension_types = new ListValue(); |
| + extension_types->Append(Value::CreateStringValue("packaged_app")); |
| + rule->Set("extension_types", extension_types); |
| + simple_feature->Parse(rule.get()); |
| + feature->AddSimpleFeature(simple_feature.get()); |
| + |
| + // Test match 1st rule. |
| + EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "foo", |
| + Extension::TYPE_EXTENSION, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + |
| + // Test match 2nd rule. |
| + EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "bar", |
| + Extension::TYPE_LEGACY_PACKAGED_APP, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + |
| + // Test whitelist with wrong extension type. |
| + EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "bar", |
| + Extension::TYPE_EXTENSION, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "foo", |
| + Extension::TYPE_LEGACY_PACKAGED_APP, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| +} |
| + |
| +TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) { |
| + scoped_ptr<ComplexFeature> feature(new ComplexFeature()); |
| + |
| + // Rule: "extension", channel trunk. |
| + scoped_ptr<PermissionFeature> simple_feature(new PermissionFeature()); |
| + scoped_ptr<DictionaryValue> rule(new DictionaryValue()); |
| + ListValue* extension_types = new ListValue(); |
| + extension_types->Append(Value::CreateStringValue("extension")); |
| + rule->Set("extension_types", extension_types); |
| + rule->SetString("channel", "trunk"); |
| + simple_feature->Parse(rule.get()); |
| + feature->AddSimpleFeature(simple_feature.get()); |
| + |
| + // Rule: "packaged_app", channel stable. |
| + simple_feature.reset(new PermissionFeature()); |
| + rule.reset(new DictionaryValue()); |
| + extension_types = new ListValue(); |
| + extension_types->Append(Value::CreateStringValue("packaged_app")); |
| + rule->Set("extension_types", extension_types); |
| + rule->SetString("channel", "stable"); |
| + simple_feature->Parse(rule.get()); |
| + feature->AddSimpleFeature(simple_feature.get()); |
| + |
| + // Test match 1st rule. |
| + { |
| + Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN); |
| + EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "1", |
| + Extension::TYPE_EXTENSION, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + } |
| + |
| + // Test match 2nd rule. |
| + { |
| + Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); |
| + EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "2", |
| + Extension::TYPE_LEGACY_PACKAGED_APP, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + } |
| + |
| + // Test feature not available to extensions above channel unknown. |
| + { |
| + Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); |
| + EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
| + "1", |
| + Extension::TYPE_EXTENSION, |
| + Feature::UNSPECIFIED_LOCATION, |
| + Feature::UNSPECIFIED_PLATFORM, |
| + Feature::GetCurrentPlatform()).result()); |
| + } |
| +} |
| + |
| +} // namespace |