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 <algorithm> |
7 #include <set> | 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 | 10 |
| 11 #include "base/stl_util.h" |
10 #include "extensions/common/extension_builder.h" | 12 #include "extensions/common/extension_builder.h" |
11 #include "extensions/common/features/feature.h" | 13 #include "extensions/common/features/feature.h" |
12 #include "extensions/common/features/simple_feature.h" | 14 #include "extensions/common/features/simple_feature.h" |
13 #include "extensions/common/manifest.h" | 15 #include "extensions/common/manifest.h" |
14 #include "extensions/common/value_builder.h" | 16 #include "extensions/common/value_builder.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 namespace extensions { | 19 namespace extensions { |
18 | 20 |
19 // Tests that a real manifest feature is available for the correct types of | 21 // Tests that a real manifest feature is available for the correct types of |
20 // extensions and apps. | 22 // extensions and apps. |
21 TEST(BaseFeatureProviderTest, ManifestFeatureTypes) { | 23 TEST(BaseFeatureProviderTest, ManifestFeatureTypes) { |
22 // NOTE: This feature cannot have multiple rules, otherwise it is not a | 24 // NOTE: This feature cannot have multiple rules, otherwise it is not a |
23 // SimpleFeature. | 25 // SimpleFeature. |
24 const SimpleFeature* feature = static_cast<const SimpleFeature*>( | 26 const SimpleFeature* feature = static_cast<const SimpleFeature*>( |
25 FeatureProvider::GetManifestFeature("description")); | 27 FeatureProvider::GetManifestFeature("description")); |
26 ASSERT_TRUE(feature); | 28 ASSERT_TRUE(feature); |
27 const std::set<Manifest::Type>* extension_types = feature->extension_types(); | 29 const std::vector<Manifest::Type>* extension_types = |
| 30 feature->extension_types(); |
28 EXPECT_EQ(6u, extension_types->size()); | 31 EXPECT_EQ(6u, extension_types->size()); |
29 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); | 32 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_EXTENSION)); |
30 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); | 33 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_LEGACY_PACKAGED_APP)); |
31 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_PLATFORM_APP)); | 34 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_PLATFORM_APP)); |
32 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_HOSTED_APP)); | 35 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_HOSTED_APP)); |
33 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_THEME)); | 36 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_THEME)); |
34 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_SHARED_MODULE)); | 37 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_SHARED_MODULE)); |
35 } | 38 } |
36 | 39 |
37 // Tests that real manifest features have the correct availability for an | 40 // Tests that real manifest features have the correct availability for an |
38 // extension. | 41 // extension. |
39 TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) { | 42 TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) { |
40 const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); | 43 const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); |
41 | 44 |
42 scoped_refptr<const Extension> extension = | 45 scoped_refptr<const Extension> extension = |
43 ExtensionBuilder() | 46 ExtensionBuilder() |
44 .SetManifest(DictionaryBuilder() | 47 .SetManifest(DictionaryBuilder() |
(...skipping 27 matching lines...) Expand all Loading... |
72 } | 75 } |
73 | 76 |
74 // Tests that a real permission feature is available for the correct types of | 77 // Tests that a real permission feature is available for the correct types of |
75 // extensions and apps. | 78 // extensions and apps. |
76 TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { | 79 TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { |
77 // NOTE: This feature cannot have multiple rules, otherwise it is not a | 80 // NOTE: This feature cannot have multiple rules, otherwise it is not a |
78 // SimpleFeature. | 81 // SimpleFeature. |
79 const SimpleFeature* feature = static_cast<const SimpleFeature*>( | 82 const SimpleFeature* feature = static_cast<const SimpleFeature*>( |
80 BaseFeatureProvider::GetPermissionFeature("power")); | 83 BaseFeatureProvider::GetPermissionFeature("power")); |
81 ASSERT_TRUE(feature); | 84 ASSERT_TRUE(feature); |
82 const std::set<Manifest::Type>* extension_types = feature->extension_types(); | 85 const std::vector<Manifest::Type>* extension_types = |
| 86 feature->extension_types(); |
83 EXPECT_EQ(3u, extension_types->size()); | 87 EXPECT_EQ(3u, extension_types->size()); |
84 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); | 88 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_EXTENSION)); |
85 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); | 89 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_LEGACY_PACKAGED_APP)); |
86 EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_PLATFORM_APP)); | 90 EXPECT_EQ(1u, STLCount(extension_types, Manifest::TYPE_PLATFORM_APP)); |
87 } | 91 } |
88 | 92 |
89 // Tests that real permission features have the correct availability for an app. | 93 // Tests that real permission features have the correct availability for an app. |
90 TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) { | 94 TEST(BaseFeatureProviderTest, PermissionFeatureAvailability) { |
91 const FeatureProvider* provider = | 95 const FeatureProvider* provider = |
92 BaseFeatureProvider::GetByName("permission"); | 96 BaseFeatureProvider::GetByName("permission"); |
93 | 97 |
94 scoped_refptr<const Extension> app = | 98 scoped_refptr<const Extension> app = |
95 ExtensionBuilder() | 99 ExtensionBuilder() |
96 .SetManifest(DictionaryBuilder() | 100 .SetManifest(DictionaryBuilder() |
(...skipping 29 matching lines...) Expand all Loading... |
126 // A permission that isn't part of the manifest returns NOT_PRESENT. | 130 // A permission that isn't part of the manifest returns NOT_PRESENT. |
127 feature = provider->GetFeature("serial"); | 131 feature = provider->GetFeature("serial"); |
128 ASSERT_TRUE(feature); | 132 ASSERT_TRUE(feature); |
129 EXPECT_EQ( | 133 EXPECT_EQ( |
130 Feature::NOT_PRESENT, | 134 Feature::NOT_PRESENT, |
131 feature->IsAvailableToContext( | 135 feature->IsAvailableToContext( |
132 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); | 136 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); |
133 } | 137 } |
134 | 138 |
135 } // namespace extensions | 139 } // namespace extensions |
OLD | NEW |