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 EXPECT_TRUE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker()); |
| 176 } |
| 177 |
| 178 // Tests a complex feature without blocked_in_service_worker returns false for |
| 179 // IsBlockedInServiceWorker(). |
| 180 TEST_F(ExtensionComplexFeatureTest, NotBlockedInServiceWorker) { |
| 181 scoped_ptr<ComplexFeature::FeatureList> features( |
| 182 new ComplexFeature::FeatureList()); |
| 183 |
| 184 // Two feature rules without blocked_in_service_worker. |
| 185 scoped_ptr<SimpleFeature> api_feature(new APIFeature()); |
| 186 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
| 187 "{" |
| 188 " 'channel': 'trunk'" |
| 189 "}").get()); |
| 190 features->push_back(api_feature.release()); |
| 191 |
| 192 api_feature.reset(new APIFeature()); |
| 193 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
| 194 "{" |
| 195 " 'channel': 'stable'" |
| 196 "}").get()); |
| 197 features->push_back(api_feature.release()); |
| 198 |
| 199 EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker()); |
| 200 } |
| 201 |
148 } // namespace | 202 } // namespace |
OLD | NEW |