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

Side by Side Diff: chrome/common/extensions/features/complex_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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/features/complex_feature.h"
6
7 #include "chrome/common/extensions/features/simple_feature.h"
8 #include "chrome/common/extensions/value_builder.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using chrome::VersionInfo;
12 using extensions::ComplexFeature;
13 using extensions::DictionaryBuilder;
14 using extensions::Extension;
15 using extensions::Feature;
16 using extensions::ListBuilder;
17 using extensions::SimpleFeature;
18
19 namespace {
20
21 class ExtensionComplexFeatureTest : public testing::Test {
22 protected:
23 ExtensionComplexFeatureTest()
24 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
25 virtual ~ExtensionComplexFeatureTest() {}
26
27 private:
28 Feature::ScopedCurrentChannel current_channel_;
29 };
30
31 TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) {
32 scoped_ptr<ComplexFeature::FeatureList> features(
33 new ComplexFeature::FeatureList());
34
35 // Rule: "extension", whitelist "foo".
36 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature());
37 scoped_ptr<DictionaryValue> rule(
38 DictionaryBuilder()
39 .Set("whitelist", ListBuilder().Append("foo"))
40 .Set("extension_types", ListBuilder().Append("extension")).Build());
41 simple_feature->Parse(rule.get());
42 features->push_back(simple_feature.release());
43
44 // Rule: "packaged_app", whitelist "bar".
45 simple_feature.reset(new SimpleFeature());
46 rule = DictionaryBuilder()
47 .Set("whitelist", ListBuilder().Append("bar"))
48 .Set("extension_types", ListBuilder().Append("packaged_app")).Build();
49 simple_feature->Parse(rule.get());
50 features->push_back(simple_feature.release());
51
52 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
53
54 // Test match 1st rule.
55 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
56 "foo",
57 Extension::TYPE_EXTENSION,
58 Feature::UNSPECIFIED_LOCATION,
59 Feature::UNSPECIFIED_PLATFORM,
60 Feature::GetCurrentPlatform()).result());
61
62 // Test match 2nd rule.
63 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
64 "bar",
65 Extension::TYPE_LEGACY_PACKAGED_APP,
66 Feature::UNSPECIFIED_LOCATION,
67 Feature::UNSPECIFIED_PLATFORM,
68 Feature::GetCurrentPlatform()).result());
69
70 // Test whitelist with wrong extension type.
71 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
72 "bar",
73 Extension::TYPE_EXTENSION,
74 Feature::UNSPECIFIED_LOCATION,
75 Feature::UNSPECIFIED_PLATFORM,
76 Feature::GetCurrentPlatform()).result());
77 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
78 "foo",
79 Extension::TYPE_LEGACY_PACKAGED_APP,
80 Feature::UNSPECIFIED_LOCATION,
81 Feature::UNSPECIFIED_PLATFORM,
82 Feature::GetCurrentPlatform()).result());
83 }
84
85 TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) {
86 scoped_ptr<ComplexFeature::FeatureList> features(
87 new ComplexFeature::FeatureList());
88
89 // Rule: "extension", channel trunk.
90 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature());
91 scoped_ptr<DictionaryValue> rule(
92 DictionaryBuilder()
93 .Set("channel", "trunk")
94 .Set("extension_types", ListBuilder().Append("extension")).Build());
95 simple_feature->Parse(rule.get());
96 features->push_back(simple_feature.release());
97
98 // Rule: "packaged_app", channel stable.
99 simple_feature.reset(new SimpleFeature());
100 rule = DictionaryBuilder()
101 .Set("channel", "stable")
102 .Set("extension_types", ListBuilder().Append("packaged_app")).Build();
103 simple_feature->Parse(rule.get());
104 features->push_back(simple_feature.release());
105
106 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
107
108 // Test match 1st rule.
109 {
110 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN);
111 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
112 "1",
113 Extension::TYPE_EXTENSION,
114 Feature::UNSPECIFIED_LOCATION,
115 Feature::UNSPECIFIED_PLATFORM,
116 Feature::GetCurrentPlatform()).result());
117 }
118
119 // Test match 2nd rule.
120 {
121 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
122 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
123 "2",
124 Extension::TYPE_LEGACY_PACKAGED_APP,
125 Feature::UNSPECIFIED_LOCATION,
126 Feature::UNSPECIFIED_PLATFORM,
127 Feature::GetCurrentPlatform()).result());
128 }
129
130 // Test feature not available to extensions above channel unknown.
131 {
132 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
133 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
134 "1",
135 Extension::TYPE_EXTENSION,
136 Feature::UNSPECIFIED_LOCATION,
137 Feature::UNSPECIFIED_PLATFORM,
138 Feature::GetCurrentPlatform()).result());
139 }
140 }
141
142 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/complex_feature.cc ('k') | chrome/common/extensions/features/feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698