This source file includes following definitions.
- CreateFeature
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#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 "extensions/common/features/api_feature.h"
#include "extensions/common/features/simple_feature.h"
#include "extensions/common/test_util.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
using chrome::VersionInfo;
using extensions::APIFeature;
using extensions::ComplexFeature;
using extensions::DictionaryBuilder;
using extensions::Feature;
using extensions::ListBuilder;
using extensions::Manifest;
using extensions::ScopedCurrentChannel;
using extensions::SimpleFeature;
using extensions::test_util::ParseJsonDictionaryWithSingleQuotes;
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) {
const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
scoped_ptr<ComplexFeature::FeatureList> features(
new ComplexFeature::FeatureList());
scoped_ptr<SimpleFeature> simple_feature(CreateFeature());
scoped_ptr<base::DictionaryValue> rule(
DictionaryBuilder()
.Set("whitelist", ListBuilder().Append(kIdFoo))
.Set("extension_types", ListBuilder()
.Append("extension")).Build());
simple_feature->Parse(rule.get());
features->push_back(simple_feature.release());
simple_feature.reset(CreateFeature());
rule = DictionaryBuilder()
.Set("whitelist", ListBuilder().Append(kIdBar))
.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()));
EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
kIdFoo,
Manifest::TYPE_EXTENSION,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
kIdBar,
Manifest::TYPE_LEGACY_PACKAGED_APP,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
kIdBar,
Manifest::TYPE_EXTENSION,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(kIdFoo,
Manifest::TYPE_LEGACY_PACKAGED_APP,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
}
TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) {
scoped_ptr<ComplexFeature::FeatureList> features(
new ComplexFeature::FeatureList());
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());
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()));
{
ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN);
EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
"1",
Manifest::TYPE_EXTENSION,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
}
{
ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
"2",
Manifest::TYPE_LEGACY_PACKAGED_APP,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
}
{
ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
"1",
Manifest::TYPE_EXTENSION,
Feature::UNSPECIFIED_LOCATION,
Feature::UNSPECIFIED_PLATFORM,
Feature::GetCurrentPlatform()).result());
}
}
TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) {
scoped_ptr<ComplexFeature::FeatureList> features(
new ComplexFeature::FeatureList());
scoped_ptr<SimpleFeature> api_feature(new APIFeature());
api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
"{"
" 'channel': 'trunk',"
" 'blocked_in_service_worker': true"
"}").get());
features->push_back(api_feature.release());
api_feature.reset(new APIFeature());
api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
"{"
" 'channel': 'stable',"
" 'blocked_in_service_worker': true"
"}").get());
features->push_back(api_feature.release());
EXPECT_TRUE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
}
TEST_F(ExtensionComplexFeatureTest, NotBlockedInServiceWorker) {
scoped_ptr<ComplexFeature::FeatureList> features(
new ComplexFeature::FeatureList());
scoped_ptr<SimpleFeature> api_feature(new APIFeature());
api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
"{"
" 'channel': 'trunk'"
"}").get());
features->push_back(api_feature.release());
api_feature.reset(new APIFeature());
api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
"{"
" 'channel': 'stable'"
"}").get());
features->push_back(api_feature.release());
EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
}
}