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

Side by Side Diff: extensions/common/features/complex_feature_unittest.cc

Issue 563923004: Move most extension feature unit tests to extensions_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (feature-tests) rebase Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/features/complex_feature.h" 5 #include "extensions/common/features/complex_feature.h"
6 6
7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" 7 #include <string>
8 #include "chrome/common/extensions/features/feature_channel.h" 8
9 #include "extensions/common/features/simple_feature.h" 9 #include "extensions/common/features/simple_feature.h"
10 #include "extensions/common/manifest.h"
10 #include "extensions/common/value_builder.h" 11 #include "extensions/common/value_builder.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 using chrome::VersionInfo; 14 namespace extensions {
14 using extensions::ComplexFeature;
15 using extensions::DictionaryBuilder;
16 using extensions::Feature;
17 using extensions::ListBuilder;
18 using extensions::Manifest;
19 using extensions::ScopedCurrentChannel;
20 using extensions::SimpleFeature;
21 15
22 namespace { 16 TEST(ComplexFeatureTest, MultipleRulesWhitelist) {
23
24 class ExtensionComplexFeatureTest : public testing::Test {
25 protected:
26 ExtensionComplexFeatureTest()
27 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
28 virtual ~ExtensionComplexFeatureTest() {}
29
30 SimpleFeature* CreateFeature() {
31 SimpleFeature* feature = new SimpleFeature();
32 feature->AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>(
33 new extensions::ChromeChannelFeatureFilter(feature)));
34 return feature;
35 }
36
37 private:
38 ScopedCurrentChannel current_channel_;
39 };
40
41 TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) {
42 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 17 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
43 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 18 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
44 scoped_ptr<ComplexFeature::FeatureList> features( 19 scoped_ptr<ComplexFeature::FeatureList> features(
45 new ComplexFeature::FeatureList()); 20 new ComplexFeature::FeatureList());
46 21
47 // Rule: "extension", whitelist "foo". 22 // Rule: "extension", whitelist "foo".
48 scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); 23 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature);
49 scoped_ptr<base::DictionaryValue> rule( 24 scoped_ptr<base::DictionaryValue> rule(
50 DictionaryBuilder() 25 DictionaryBuilder()
51 .Set("whitelist", ListBuilder().Append(kIdFoo)) 26 .Set("whitelist", ListBuilder().Append(kIdFoo))
52 .Set("extension_types", ListBuilder() 27 .Set("extension_types", ListBuilder()
53 .Append("extension")).Build()); 28 .Append("extension")).Build());
54 simple_feature->Parse(rule.get()); 29 simple_feature->Parse(rule.get());
55 features->push_back(simple_feature.release()); 30 features->push_back(simple_feature.release());
56 31
57 // Rule: "legacy_packaged_app", whitelist "bar". 32 // Rule: "legacy_packaged_app", whitelist "bar".
58 simple_feature.reset(CreateFeature()); 33 simple_feature.reset(new SimpleFeature);
59 rule = DictionaryBuilder() 34 rule = DictionaryBuilder()
60 .Set("whitelist", ListBuilder().Append(kIdBar)) 35 .Set("whitelist", ListBuilder().Append(kIdBar))
61 .Set("extension_types", ListBuilder() 36 .Set("extension_types", ListBuilder()
62 .Append("legacy_packaged_app")).Build(); 37 .Append("legacy_packaged_app")).Build();
63 simple_feature->Parse(rule.get()); 38 simple_feature->Parse(rule.get());
64 features->push_back(simple_feature.release()); 39 features->push_back(simple_feature.release());
65 40
66 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); 41 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
67 42
68 // Test match 1st rule. 43 // Test match 1st rule.
(...skipping 24 matching lines...) Expand all
93 Feature::GetCurrentPlatform()).result()); 68 Feature::GetCurrentPlatform()).result());
94 EXPECT_NE( 69 EXPECT_NE(
95 Feature::IS_AVAILABLE, 70 Feature::IS_AVAILABLE,
96 feature->IsAvailableToManifest(kIdFoo, 71 feature->IsAvailableToManifest(kIdFoo,
97 Manifest::TYPE_LEGACY_PACKAGED_APP, 72 Manifest::TYPE_LEGACY_PACKAGED_APP,
98 Manifest::INVALID_LOCATION, 73 Manifest::INVALID_LOCATION,
99 Feature::UNSPECIFIED_PLATFORM, 74 Feature::UNSPECIFIED_PLATFORM,
100 Feature::GetCurrentPlatform()).result()); 75 Feature::GetCurrentPlatform()).result());
101 } 76 }
102 77
103 TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) { 78 // Tests that dependencies are correctly checked.
79 TEST(ComplexFeatureTest, Dependencies) {
104 scoped_ptr<ComplexFeature::FeatureList> features( 80 scoped_ptr<ComplexFeature::FeatureList> features(
105 new ComplexFeature::FeatureList()); 81 new ComplexFeature::FeatureList());
106 82
107 // Rule: "extension", channel trunk. 83 // Rule which depends on an extension-only feature (content_security_policy).
108 scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); 84 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature);
109 scoped_ptr<base::DictionaryValue> rule(
110 DictionaryBuilder()
111 .Set("channel", "trunk")
112 .Set("extension_types", ListBuilder().Append("extension")).Build());
113 simple_feature->Parse(rule.get());
114 features->push_back(simple_feature.release());
115
116 // Rule: "legacy_packaged_app", channel stable.
117 simple_feature.reset(CreateFeature());
118 rule = DictionaryBuilder()
119 .Set("channel", "stable")
120 .Set("extension_types", ListBuilder()
121 .Append("legacy_packaged_app")).Build();
122 simple_feature->Parse(rule.get());
123 features->push_back(simple_feature.release());
124
125 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
126
127 // Test match 1st rule.
128 {
129 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN);
130 EXPECT_EQ(
131 Feature::IS_AVAILABLE,
132 feature->IsAvailableToManifest("1",
133 Manifest::TYPE_EXTENSION,
134 Manifest::INVALID_LOCATION,
135 Feature::UNSPECIFIED_PLATFORM,
136 Feature::GetCurrentPlatform()).result());
137 }
138
139 // Test match 2nd rule.
140 {
141 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
142 EXPECT_EQ(
143 Feature::IS_AVAILABLE,
144 feature->IsAvailableToManifest("2",
145 Manifest::TYPE_LEGACY_PACKAGED_APP,
146 Manifest::INVALID_LOCATION,
147 Feature::UNSPECIFIED_PLATFORM,
148 Feature::GetCurrentPlatform()).result());
149 }
150
151 // Test feature not available to extensions above channel unknown.
152 {
153 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
154 EXPECT_NE(
155 Feature::IS_AVAILABLE,
156 feature->IsAvailableToManifest("1",
157 Manifest::TYPE_EXTENSION,
158 Manifest::INVALID_LOCATION,
159 Feature::UNSPECIFIED_PLATFORM,
160 Feature::GetCurrentPlatform()).result());
161 }
162 }
163
164 // Tests that dependencies are correctly checked.
165 TEST_F(ExtensionComplexFeatureTest, Dependencies) {
166 scoped_ptr<ComplexFeature::FeatureList> features(
167 new ComplexFeature::FeatureList());
168
169 // Rule which depends on an extension-only feature (omnibox).
170 scoped_ptr<SimpleFeature> simple_feature(CreateFeature());
171 scoped_ptr<base::DictionaryValue> rule = 85 scoped_ptr<base::DictionaryValue> rule =
172 DictionaryBuilder() 86 DictionaryBuilder()
173 .Set("dependencies", ListBuilder().Append("manifest:omnibox")) 87 .Set("dependencies",
88 ListBuilder().Append("manifest:content_security_policy"))
174 .Build(); 89 .Build();
175 simple_feature->Parse(rule.get()); 90 simple_feature->Parse(rule.get());
176 features->push_back(simple_feature.release()); 91 features->push_back(simple_feature.release());
177 92
178 // Rule which depends on an platform-app-only feature (serial). 93 // Rule which depends on an platform-app-only feature (serial).
179 simple_feature.reset(CreateFeature()); 94 simple_feature.reset(new SimpleFeature);
180 rule = DictionaryBuilder() 95 rule = DictionaryBuilder()
181 .Set("dependencies", ListBuilder().Append("permission:serial")) 96 .Set("dependencies", ListBuilder().Append("permission:serial"))
182 .Build(); 97 .Build();
183 simple_feature->Parse(rule.get()); 98 simple_feature->Parse(rule.get());
184 features->push_back(simple_feature.release()); 99 features->push_back(simple_feature.release());
185 100
186 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); 101 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
187 102
188 // Available to extensions because of the omnibox rule. 103 // Available to extensions because of the content_security_policy rule.
189 EXPECT_EQ( 104 EXPECT_EQ(
190 Feature::IS_AVAILABLE, 105 Feature::IS_AVAILABLE,
191 feature->IsAvailableToManifest("extensionid", 106 feature->IsAvailableToManifest("extensionid",
192 Manifest::TYPE_EXTENSION, 107 Manifest::TYPE_EXTENSION,
193 Manifest::INVALID_LOCATION, 108 Manifest::INVALID_LOCATION,
194 Feature::UNSPECIFIED_PLATFORM, 109 Feature::UNSPECIFIED_PLATFORM,
195 Feature::GetCurrentPlatform()).result()); 110 Feature::GetCurrentPlatform()).result());
196 111
197 // Available to platofrm apps because of the serial rule. 112 // Available to platform apps because of the serial rule.
198 EXPECT_EQ( 113 EXPECT_EQ(
199 Feature::IS_AVAILABLE, 114 Feature::IS_AVAILABLE,
200 feature->IsAvailableToManifest("platformappid", 115 feature->IsAvailableToManifest("platformappid",
201 Manifest::TYPE_PLATFORM_APP, 116 Manifest::TYPE_PLATFORM_APP,
202 Manifest::INVALID_LOCATION, 117 Manifest::INVALID_LOCATION,
203 Feature::UNSPECIFIED_PLATFORM, 118 Feature::UNSPECIFIED_PLATFORM,
204 Feature::GetCurrentPlatform()).result()); 119 Feature::GetCurrentPlatform()).result());
205 120
206 // Not available to hosted apps. 121 // Not available to hosted apps.
207 EXPECT_EQ( 122 EXPECT_EQ(
208 Feature::INVALID_TYPE, 123 Feature::INVALID_TYPE,
209 feature->IsAvailableToManifest("hostedappid", 124 feature->IsAvailableToManifest("hostedappid",
210 Manifest::TYPE_HOSTED_APP, 125 Manifest::TYPE_HOSTED_APP,
211 Manifest::INVALID_LOCATION, 126 Manifest::INVALID_LOCATION,
212 Feature::UNSPECIFIED_PLATFORM, 127 Feature::UNSPECIFIED_PLATFORM,
213 Feature::GetCurrentPlatform()).result()); 128 Feature::GetCurrentPlatform()).result());
214 } 129 }
215 130
216 } // namespace 131 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/base_feature_provider_unittest.cc ('k') | extensions/common/features/simple_feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698