OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/common/extensions/features/complex_feature.h" | 5 #include "chrome/common/extensions/features/complex_feature.h" |
6 | 6 |
7 #include "chrome/common/extensions/features/api_feature.h" | |
7 #include "chrome/common/extensions/features/feature_channel.h" | 8 #include "chrome/common/extensions/features/feature_channel.h" |
8 #include "chrome/common/extensions/features/simple_feature.h" | 9 #include "chrome/common/extensions/features/simple_feature.h" |
10 #include "extensions/common/test_util.h" | |
9 #include "extensions/common/value_builder.h" | 11 #include "extensions/common/value_builder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 using chrome::VersionInfo; | 14 using chrome::VersionInfo; |
15 using extensions::APIFeature; | |
13 using extensions::ComplexFeature; | 16 using extensions::ComplexFeature; |
14 using extensions::DictionaryBuilder; | 17 using extensions::DictionaryBuilder; |
15 using extensions::Feature; | 18 using extensions::Feature; |
16 using extensions::ListBuilder; | 19 using extensions::ListBuilder; |
17 using extensions::Manifest; | 20 using extensions::Manifest; |
18 using extensions::ScopedCurrentChannel; | 21 using extensions::ScopedCurrentChannel; |
19 using extensions::SimpleFeature; | 22 using extensions::SimpleFeature; |
23 using extensions::test_util::ParseJsonDictionaryWithSingleQuotes; | |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 class ExtensionComplexFeatureTest : public testing::Test { | 27 class ExtensionComplexFeatureTest : public testing::Test { |
24 protected: | 28 protected: |
25 ExtensionComplexFeatureTest() | 29 ExtensionComplexFeatureTest() |
26 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} | 30 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} |
27 virtual ~ExtensionComplexFeatureTest() {} | 31 virtual ~ExtensionComplexFeatureTest() {} |
28 | 32 |
29 private: | 33 private: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); | 142 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); |
139 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( | 143 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( |
140 "1", | 144 "1", |
141 Manifest::TYPE_EXTENSION, | 145 Manifest::TYPE_EXTENSION, |
142 Feature::UNSPECIFIED_LOCATION, | 146 Feature::UNSPECIFIED_LOCATION, |
143 Feature::UNSPECIFIED_PLATFORM, | 147 Feature::UNSPECIFIED_PLATFORM, |
144 Feature::GetCurrentPlatform()).result()); | 148 Feature::GetCurrentPlatform()).result()); |
145 } | 149 } |
146 } | 150 } |
147 | 151 |
152 // Tests a complex feature with blocked_in_service_worker returns true for | |
153 // IsBlockedInServiceWorker(). | |
154 TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) { | |
155 scoped_ptr<ComplexFeature::FeatureList> features( | |
156 new ComplexFeature::FeatureList()); | |
157 | |
158 // Two feature rules, both with blocked_in_service_worker: true. | |
159 scoped_ptr<SimpleFeature> api_feature(new APIFeature()); | |
160 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
161 "{" | |
162 " 'channel': 'trunk'," | |
163 " 'blocked_in_service_worker': true" | |
164 "}").get()); | |
165 features->push_back(api_feature.release()); | |
166 | |
167 api_feature.reset(new APIFeature()); | |
168 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
169 "{" | |
170 " 'channel': 'stable'," | |
171 " 'blocked_in_service_worker': true" | |
172 "}").get()); | |
173 features->push_back(api_feature.release()); | |
174 | |
175 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); | |
not at google - send to devlin
2014/03/28 17:30:49
allocate on stack?
scheib
2014/03/28 18:15:21
Done.
| |
176 | |
177 EXPECT_TRUE(feature->IsBlockedInServiceWorker()); | |
178 } | |
179 | |
180 // Tests a complex feature without blocked_in_service_worker returns false for | |
181 // IsBlockedInServiceWorker(). | |
182 TEST_F(ExtensionComplexFeatureTest, NotBlockedInServiceWorker) { | |
183 scoped_ptr<ComplexFeature::FeatureList> features( | |
184 new ComplexFeature::FeatureList()); | |
185 | |
186 // Two feature rules without blocked_in_service_worker. | |
187 scoped_ptr<SimpleFeature> api_feature(new APIFeature()); | |
188 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
189 "{" | |
190 " 'channel': 'trunk'" | |
191 "}").get()); | |
192 features->push_back(api_feature.release()); | |
193 | |
194 api_feature.reset(new APIFeature()); | |
195 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
196 "{" | |
197 " 'channel': 'stable'" | |
198 "}").get()); | |
199 features->push_back(api_feature.release()); | |
200 | |
201 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); | |
not at google - send to devlin
2014/03/28 17:30:49
ditto
scheib
2014/03/28 18:15:21
Done.
| |
202 | |
203 EXPECT_FALSE(feature->IsBlockedInServiceWorker()); | |
204 } | |
205 | |
206 // Tests that a complex feature composing different values for | |
207 // blocked_in_service_worker will DCHECK. | |
not at google - send to devlin
2014/03/28 17:30:49
testing DCHECKs isn't that useful. DCHECK means th
scheib
2014/03/28 18:15:21
Done.
| |
208 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | |
209 TEST_F(ExtensionComplexFeatureTest, MixedBlockedInServiceWorker) { | |
210 scoped_ptr<ComplexFeature::FeatureList> features( | |
211 new ComplexFeature::FeatureList()); | |
212 | |
213 // mixed blocked_in_service_worker. | |
214 scoped_ptr<SimpleFeature> api_feature(new APIFeature()); | |
215 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
216 "{" | |
217 " 'channel': 'trunk'," | |
218 " 'blocked_in_service_worker': true" | |
219 "}").get()); | |
220 features->push_back(api_feature.release()); | |
221 | |
222 api_feature.reset(new APIFeature()); | |
223 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( | |
224 "{" | |
225 " 'channel': 'stable'" | |
226 "}").get()); | |
227 features->push_back(api_feature.release()); | |
228 | |
229 ASSERT_DEATH( | |
230 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())), | |
231 ""); | |
232 } | |
233 #endif | |
234 | |
148 } // namespace | 235 } // namespace |
OLD | NEW |