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