| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/api_feature.h" | 5 #include "extensions/common/features/api_feature.h" |
| 6 #include "extensions/common/features/complex_feature.h" | 6 #include "extensions/common/features/complex_feature.h" |
| 7 #include "extensions/common/features/feature.h" | 7 #include "extensions/common/features/feature.h" |
| 8 #include "extensions/common/features/simple_feature.h" | 8 #include "extensions/common/features/simple_feature.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "tools/json_schema_compiler/test/features_test.h" | 10 #include "tools/json_schema_compiler/test/features_compiler_test.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 template <typename T> | 16 template <typename T> |
| 17 void ExpectVectorsEqual(std::vector<T> expected, | 17 void ExpectVectorsEqual(std::vector<T> expected, |
| 18 std::vector<T> actual, | 18 std::vector<T> actual, |
| 19 const std::string& name) { | 19 const std::string& name) { |
| 20 std::sort(expected.begin(), expected.end()); | 20 std::sort(expected.begin(), expected.end()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 feature->component_extensions_auto_granted()) | 82 feature->component_extensions_auto_granted()) |
| 83 << name; | 83 << name; |
| 84 EXPECT_EQ(command_line_switch, feature->command_line_switch()) << name; | 84 EXPECT_EQ(command_line_switch, feature->command_line_switch()) << name; |
| 85 ASSERT_EQ(channel.get() != nullptr, feature->has_channel()) << name; | 85 ASSERT_EQ(channel.get() != nullptr, feature->has_channel()) << name; |
| 86 if (channel) | 86 if (channel) |
| 87 EXPECT_EQ(*channel, feature->channel()) << name; | 87 EXPECT_EQ(*channel, feature->channel()) << name; |
| 88 EXPECT_EQ(internal, feature->IsInternal()) << name; | 88 EXPECT_EQ(internal, feature->IsInternal()) << name; |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST(FeaturesGenerationTest, FeaturesTest) { | 91 TEST(FeaturesGenerationTest, FeaturesTest) { |
| 92 TestAPIFeatureProvider provider; | 92 CompilerTestFeatureProvider provider; |
| 93 | 93 |
| 94 auto GetAPIFeature = [&provider](const std::string& name) { | 94 auto GetAPIFeature = [&provider](const std::string& name) { |
| 95 Feature* feature = provider.GetFeature(name); | 95 Feature* feature = provider.GetFeature(name); |
| 96 // Shame we can't test this more safely, but if our feature is declared as | 96 // Shame we can't test this more safely, but if our feature is declared as |
| 97 // the wrong class, things should blow up in a spectacular fashion. | 97 // the wrong class, things should blow up in a spectacular fashion. |
| 98 return static_cast<APIFeature*>(feature); | 98 return static_cast<APIFeature*>(feature); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 // Check some simple features for accuracy. | 101 // Check some simple features for accuracy. |
| 102 { | 102 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 comparator.component_extensions_auto_granted = false; | 118 comparator.component_extensions_auto_granted = false; |
| 119 comparator.CompareFeature(feature); | 119 comparator.CompareFeature(feature); |
| 120 } | 120 } |
| 121 { | 121 { |
| 122 APIFeature* feature = GetAPIFeature("gamma"); | 122 APIFeature* feature = GetAPIFeature("gamma"); |
| 123 FeatureComparator comparator("gamma"); | 123 FeatureComparator comparator("gamma"); |
| 124 comparator.channel.reset( | 124 comparator.channel.reset( |
| 125 new version_info::Channel(version_info::Channel::BETA)); | 125 new version_info::Channel(version_info::Channel::BETA)); |
| 126 comparator.platforms = {Feature::WIN_PLATFORM, Feature::MACOSX_PLATFORM}; | 126 comparator.platforms = {Feature::WIN_PLATFORM, Feature::MACOSX_PLATFORM}; |
| 127 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; | 127 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; |
| 128 comparator.dependencies = {"permission:gamma"}; |
| 128 comparator.extension_types = {Manifest::TYPE_EXTENSION}; | 129 comparator.extension_types = {Manifest::TYPE_EXTENSION}; |
| 129 comparator.internal = true; | 130 comparator.internal = true; |
| 130 comparator.CompareFeature(feature); | 131 comparator.CompareFeature(feature); |
| 131 | 132 |
| 132 // A child feature should inherit all fields from its parent, except in the | 133 // A child feature should inherit all fields from its parent, except in the |
| 133 // case that it specifies its own value. Thus, we reuse |comparator|. | 134 // case that it specifies its own value. Thus, we reuse |comparator|. |
| 134 feature = GetAPIFeature("gamma.child"); | 135 feature = GetAPIFeature("gamma.child"); |
| 135 comparator.name = "gamma.child"; | 136 comparator.name = "gamma.child"; |
| 136 comparator.dependencies = {"permission:gamma.child"}; | |
| 137 comparator.whitelist = {"ccc"}; | 137 comparator.whitelist = {"ccc"}; |
| 138 comparator.platforms = {Feature::LINUX_PLATFORM}; | 138 comparator.platforms = {Feature::LINUX_PLATFORM}; |
| 139 comparator.dependencies.clear(); |
| 139 comparator.CompareFeature(feature); | 140 comparator.CompareFeature(feature); |
| 140 } | 141 } |
| 141 { | 142 { |
| 142 // Features that specify 'noparent' should not inherit features from any | 143 // Features that specify 'noparent' should not inherit features from any |
| 143 // other feature. | 144 // other feature. |
| 144 APIFeature* feature = GetAPIFeature("gamma.unparented"); | 145 APIFeature* feature = GetAPIFeature("gamma.unparented"); |
| 145 FeatureComparator comparator("gamma.unparented"); | 146 FeatureComparator comparator("gamma.unparented"); |
| 146 comparator.blacklist = {"ddd"}; | 147 comparator.blacklist = {"ddd"}; |
| 147 comparator.contexts = {Feature::UNBLESSED_EXTENSION_CONTEXT}; | 148 comparator.contexts = {Feature::UNBLESSED_EXTENSION_CONTEXT}; |
| 148 comparator.CompareFeature(feature); | 149 comparator.CompareFeature(feature); |
| 149 } | 150 } |
| 150 { | 151 { |
| 152 ComplexFeature* complex_feature = static_cast<ComplexFeature*>( |
| 153 provider.GetFeature("gamma.complex_unparented")); |
| 154 FeatureComparator comparator("gamma.complex_unparented"); |
| 155 comparator.contexts = {Feature::UNBLESSED_EXTENSION_CONTEXT}; |
| 156 comparator.channel.reset( |
| 157 new version_info::Channel(version_info::Channel::STABLE)); |
| 158 // We cheat and have both children exactly the same for ease of comparing; |
| 159 // complex features are tested more thoroughly below. |
| 160 for (const auto& feature : complex_feature->features_) |
| 161 comparator.CompareFeature(static_cast<SimpleFeature*>(feature.get())); |
| 162 } |
| 163 { |
| 151 APIFeature* feature = GetAPIFeature("delta"); | 164 APIFeature* feature = GetAPIFeature("delta"); |
| 152 FeatureComparator comparator("delta"); | 165 FeatureComparator comparator("delta"); |
| 153 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT, | 166 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT, |
| 154 Feature::WEBUI_CONTEXT}; | 167 Feature::WEBUI_CONTEXT}; |
| 155 comparator.matches.AddPattern( | 168 comparator.matches.AddPattern( |
| 156 URLPattern(URLPattern::SCHEME_ALL, "*://example.com/*")); | 169 URLPattern(URLPattern::SCHEME_ALL, "*://example.com/*")); |
| 157 comparator.CompareFeature(feature); | 170 comparator.CompareFeature(feature); |
| 158 } | 171 } |
| 159 { | 172 { |
| 160 // Omega is imported from a second .json file. | 173 // Omega is imported from a second .json file. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 new version_info::Channel(version_info::Channel::BETA)); | 230 new version_info::Channel(version_info::Channel::BETA)); |
| 218 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; | 231 comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; |
| 219 comparator.extension_types = {Manifest::TYPE_EXTENSION}; | 232 comparator.extension_types = {Manifest::TYPE_EXTENSION}; |
| 220 comparator.whitelist = {"aaa"}; | 233 comparator.whitelist = {"aaa"}; |
| 221 comparator.CompareFeature(other_parent); | 234 comparator.CompareFeature(other_parent); |
| 222 } | 235 } |
| 223 } | 236 } |
| 224 } | 237 } |
| 225 | 238 |
| 226 } // namespace extensions | 239 } // namespace extensions |
| OLD | NEW |