OLD | NEW |
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/base_feature_provider.h" | 5 #include "extensions/common/features/base_feature_provider.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/permission_feature.h" | 9 #include "extensions/common/features/permission_feature.h" |
10 #include "extensions/common/value_builder.h" | 10 #include "extensions/common/value_builder.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using chrome::VersionInfo; | 13 using chrome::VersionInfo; |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 template <class FeatureClass> | 19 template <class FeatureClass> |
20 SimpleFeature* CreateFeature() { | 20 SimpleFeature* CreateFeature() { |
21 SimpleFeature* feature = new FeatureClass(); | 21 SimpleFeature* feature = new FeatureClass(); |
22 feature->AddFilter( | 22 feature->AddFilter( |
23 scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature))); | 23 scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature))); |
24 return feature; | 24 return feature; |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 TEST(BaseFeatureProviderTest, ManifestFeatures) { | 29 TEST(BaseFeatureProviderTest, ManifestFeatures) { |
30 FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); | 30 const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); |
31 SimpleFeature* feature = | 31 SimpleFeature* feature = |
32 static_cast<SimpleFeature*>(provider->GetFeature("description")); | 32 static_cast<SimpleFeature*>(provider->GetFeature("description")); |
33 ASSERT_TRUE(feature); | 33 ASSERT_TRUE(feature); |
34 EXPECT_EQ(6u, feature->extension_types()->size()); | 34 EXPECT_EQ(6u, feature->extension_types()->size()); |
35 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); | 35 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); |
36 EXPECT_EQ(1u, | 36 EXPECT_EQ(1u, |
37 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); | 37 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); |
38 EXPECT_EQ(1u, | 38 EXPECT_EQ(1u, |
39 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); | 39 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); |
40 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_HOSTED_APP)); | 40 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_HOSTED_APP)); |
(...skipping 22 matching lines...) Expand all Loading... |
63 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); | 63 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); |
64 | 64 |
65 feature = | 65 feature = |
66 static_cast<SimpleFeature*>(provider->GetFeature("devtools_page")); | 66 static_cast<SimpleFeature*>(provider->GetFeature("devtools_page")); |
67 ASSERT_TRUE(feature); | 67 ASSERT_TRUE(feature); |
68 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( | 68 EXPECT_EQ(Feature::NOT_PRESENT, feature->IsAvailableToContext( |
69 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); | 69 extension.get(), Feature::UNSPECIFIED_CONTEXT).result()); |
70 } | 70 } |
71 | 71 |
72 TEST(BaseFeatureProviderTest, PermissionFeatures) { | 72 TEST(BaseFeatureProviderTest, PermissionFeatures) { |
73 FeatureProvider* provider = BaseFeatureProvider::GetByName("permission"); | 73 const FeatureProvider* provider = |
| 74 BaseFeatureProvider::GetByName("permission"); |
74 SimpleFeature* feature = | 75 SimpleFeature* feature = |
75 static_cast<SimpleFeature*>(provider->GetFeature("contextMenus")); | 76 static_cast<SimpleFeature*>(provider->GetFeature("contextMenus")); |
76 ASSERT_TRUE(feature); | 77 ASSERT_TRUE(feature); |
77 EXPECT_EQ(3u, feature->extension_types()->size()); | 78 EXPECT_EQ(3u, feature->extension_types()->size()); |
78 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); | 79 EXPECT_EQ(1u, feature->extension_types()->count(Manifest::TYPE_EXTENSION)); |
79 EXPECT_EQ(1u, | 80 EXPECT_EQ(1u, |
80 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); | 81 feature->extension_types()->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); |
81 EXPECT_EQ(1u, | 82 EXPECT_EQ(1u, |
82 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); | 83 feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); |
83 | 84 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 EXPECT_NE( | 203 EXPECT_NE( |
203 Feature::IS_AVAILABLE, | 204 Feature::IS_AVAILABLE, |
204 feature->IsAvailableToManifest("2", | 205 feature->IsAvailableToManifest("2", |
205 Manifest::TYPE_LEGACY_PACKAGED_APP, | 206 Manifest::TYPE_LEGACY_PACKAGED_APP, |
206 Manifest::INVALID_LOCATION, | 207 Manifest::INVALID_LOCATION, |
207 Feature::UNSPECIFIED_PLATFORM).result()); | 208 Feature::UNSPECIFIED_PLATFORM).result()); |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
211 } // namespace extensions | 212 } // namespace extensions |
OLD | NEW |