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

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

Issue 414633002: Remove service worker concepts from _api_features.json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « extensions/common/features/complex_feature.cc ('k') | extensions/common/features/feature.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/common/extensions/features/chrome_channel_feature_filter.h"
8 #include "chrome/common/extensions/features/feature_channel.h" 8 #include "chrome/common/extensions/features/feature_channel.h"
9 #include "extensions/common/features/api_feature.h"
10 #include "extensions/common/features/simple_feature.h" 9 #include "extensions/common/features/simple_feature.h"
11 #include "extensions/common/test_util.h"
12 #include "extensions/common/value_builder.h" 10 #include "extensions/common/value_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
14 12
15 using chrome::VersionInfo; 13 using chrome::VersionInfo;
16 using extensions::APIFeature;
17 using extensions::ComplexFeature; 14 using extensions::ComplexFeature;
18 using extensions::DictionaryBuilder; 15 using extensions::DictionaryBuilder;
19 using extensions::Feature; 16 using extensions::Feature;
20 using extensions::ListBuilder; 17 using extensions::ListBuilder;
21 using extensions::Manifest; 18 using extensions::Manifest;
22 using extensions::ScopedCurrentChannel; 19 using extensions::ScopedCurrentChannel;
23 using extensions::SimpleFeature; 20 using extensions::SimpleFeature;
24 using extensions::test_util::ParseJsonDictionaryWithSingleQuotes;
25 21
26 namespace { 22 namespace {
27 23
28 class ExtensionComplexFeatureTest : public testing::Test { 24 class ExtensionComplexFeatureTest : public testing::Test {
29 protected: 25 protected:
30 ExtensionComplexFeatureTest() 26 ExtensionComplexFeatureTest()
31 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} 27 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
32 virtual ~ExtensionComplexFeatureTest() {} 28 virtual ~ExtensionComplexFeatureTest() {}
33 29
34 SimpleFeature* CreateFeature() { 30 SimpleFeature* CreateFeature() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 EXPECT_NE( 154 EXPECT_NE(
159 Feature::IS_AVAILABLE, 155 Feature::IS_AVAILABLE,
160 feature->IsAvailableToManifest("1", 156 feature->IsAvailableToManifest("1",
161 Manifest::TYPE_EXTENSION, 157 Manifest::TYPE_EXTENSION,
162 Manifest::INVALID_LOCATION, 158 Manifest::INVALID_LOCATION,
163 Feature::UNSPECIFIED_PLATFORM, 159 Feature::UNSPECIFIED_PLATFORM,
164 Feature::GetCurrentPlatform()).result()); 160 Feature::GetCurrentPlatform()).result());
165 } 161 }
166 } 162 }
167 163
168 // Tests a complex feature with blocked_in_service_worker returns true for
169 // IsBlockedInServiceWorker().
170 TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) {
171 scoped_ptr<ComplexFeature::FeatureList> features(
172 new ComplexFeature::FeatureList());
173
174 // Two feature rules, both with blocked_in_service_worker: true.
175 scoped_ptr<SimpleFeature> api_feature(new APIFeature());
176 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
177 "{"
178 " 'channel': 'trunk',"
179 " 'blocked_in_service_worker': true"
180 "}").get());
181 features->push_back(api_feature.release());
182
183 api_feature.reset(new APIFeature());
184 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
185 "{"
186 " 'channel': 'stable',"
187 " 'blocked_in_service_worker': true"
188 "}").get());
189 features->push_back(api_feature.release());
190
191 EXPECT_TRUE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
192 }
193
194 // Tests a complex feature without blocked_in_service_worker returns false for
195 // IsBlockedInServiceWorker().
196 TEST_F(ExtensionComplexFeatureTest, NotBlockedInServiceWorker) {
197 scoped_ptr<ComplexFeature::FeatureList> features(
198 new ComplexFeature::FeatureList());
199
200 // Two feature rules without blocked_in_service_worker.
201 scoped_ptr<SimpleFeature> api_feature(new APIFeature());
202 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
203 "{"
204 " 'channel': 'trunk'"
205 "}").get());
206 features->push_back(api_feature.release());
207
208 api_feature.reset(new APIFeature());
209 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
210 "{"
211 " 'channel': 'stable'"
212 "}").get());
213 features->push_back(api_feature.release());
214
215 EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
216 }
217
218 // Tests that dependencies are correctly checked. 164 // Tests that dependencies are correctly checked.
219 TEST_F(ExtensionComplexFeatureTest, Dependencies) { 165 TEST_F(ExtensionComplexFeatureTest, Dependencies) {
220 scoped_ptr<ComplexFeature::FeatureList> features( 166 scoped_ptr<ComplexFeature::FeatureList> features(
221 new ComplexFeature::FeatureList()); 167 new ComplexFeature::FeatureList());
222 168
223 // Rule which depends on an extension-only feature (omnibox). 169 // Rule which depends on an extension-only feature (omnibox).
224 scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); 170 scoped_ptr<SimpleFeature> simple_feature(CreateFeature());
225 scoped_ptr<base::DictionaryValue> rule = 171 scoped_ptr<base::DictionaryValue> rule =
226 DictionaryBuilder() 172 DictionaryBuilder()
227 .Set("dependencies", ListBuilder().Append("manifest:omnibox")) 173 .Set("dependencies", ListBuilder().Append("manifest:omnibox"))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 EXPECT_EQ( 207 EXPECT_EQ(
262 Feature::INVALID_TYPE, 208 Feature::INVALID_TYPE,
263 feature->IsAvailableToManifest("hostedappid", 209 feature->IsAvailableToManifest("hostedappid",
264 Manifest::TYPE_HOSTED_APP, 210 Manifest::TYPE_HOSTED_APP,
265 Manifest::INVALID_LOCATION, 211 Manifest::INVALID_LOCATION,
266 Feature::UNSPECIFIED_PLATFORM, 212 Feature::UNSPECIFIED_PLATFORM,
267 Feature::GetCurrentPlatform()).result()); 213 Feature::GetCurrentPlatform()).result());
268 } 214 }
269 215
270 } // namespace 216 } // namespace
OLDNEW
« no previous file with comments | « extensions/common/features/complex_feature.cc ('k') | extensions/common/features/feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698