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