| 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_compiler_test.h" |   10 #include "tools/json_schema_compiler/test/features_compiler_test.h" | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   46   std::vector<Feature::Context> contexts; |   46   std::vector<Feature::Context> contexts; | 
|   47   std::vector<Feature::Platform> platforms; |   47   std::vector<Feature::Platform> platforms; | 
|   48   URLPatternSet matches; |   48   URLPatternSet matches; | 
|   49   SimpleFeature::Location location; |   49   SimpleFeature::Location location; | 
|   50   int min_manifest_version; |   50   int min_manifest_version; | 
|   51   int max_manifest_version; |   51   int max_manifest_version; | 
|   52   bool component_extensions_auto_granted; |   52   bool component_extensions_auto_granted; | 
|   53   std::string command_line_switch; |   53   std::string command_line_switch; | 
|   54   std::unique_ptr<version_info::Channel> channel; |   54   std::unique_ptr<version_info::Channel> channel; | 
|   55   bool internal; |   55   bool internal; | 
 |   56   std::string alias; | 
 |   57   std::string source; | 
|   56 }; |   58 }; | 
|   57  |   59  | 
|   58 FeatureComparator::FeatureComparator(const std::string& name) |   60 FeatureComparator::FeatureComparator(const std::string& name) | 
|   59     : name(name), |   61     : name(name), | 
|   60       location(kDefaultLocation), |   62       location(kDefaultLocation), | 
|   61       min_manifest_version(kDefaultMinVersion), |   63       min_manifest_version(kDefaultMinVersion), | 
|   62       max_manifest_version(kDefaultMaxVersion), |   64       max_manifest_version(kDefaultMaxVersion), | 
|   63       component_extensions_auto_granted(kDefaultAutoGrant), |   65       component_extensions_auto_granted(kDefaultAutoGrant), | 
|   64       internal(kDefaultInternal) {} |   66       internal(kDefaultInternal) {} | 
|   65  |   67  | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|   79   EXPECT_EQ(min_manifest_version, feature->min_manifest_version()) << name; |   81   EXPECT_EQ(min_manifest_version, feature->min_manifest_version()) << name; | 
|   80   EXPECT_EQ(max_manifest_version, feature->max_manifest_version()) << name; |   82   EXPECT_EQ(max_manifest_version, feature->max_manifest_version()) << name; | 
|   81   EXPECT_EQ(component_extensions_auto_granted, |   83   EXPECT_EQ(component_extensions_auto_granted, | 
|   82             feature->component_extensions_auto_granted()) |   84             feature->component_extensions_auto_granted()) | 
|   83       << name; |   85       << name; | 
|   84   EXPECT_EQ(command_line_switch, feature->command_line_switch()) << name; |   86   EXPECT_EQ(command_line_switch, feature->command_line_switch()) << name; | 
|   85   ASSERT_EQ(channel.get() != nullptr, feature->has_channel()) << name; |   87   ASSERT_EQ(channel.get() != nullptr, feature->has_channel()) << name; | 
|   86   if (channel) |   88   if (channel) | 
|   87     EXPECT_EQ(*channel, feature->channel()) << name; |   89     EXPECT_EQ(*channel, feature->channel()) << name; | 
|   88   EXPECT_EQ(internal, feature->IsInternal()) << name; |   90   EXPECT_EQ(internal, feature->IsInternal()) << name; | 
 |   91   EXPECT_EQ(alias, feature->alias()) << name; | 
 |   92   EXPECT_EQ(source, feature->source()) << name; | 
|   89 } |   93 } | 
|   90  |   94  | 
|   91 TEST(FeaturesGenerationTest, FeaturesTest) { |   95 TEST(FeaturesGenerationTest, FeaturesTest) { | 
|   92   CompilerTestFeatureProvider provider; |   96   CompilerTestFeatureProvider provider; | 
|   93  |   97  | 
|   94   auto GetAPIFeature = [&provider](const std::string& name) { |   98   auto GetAPIFeature = [&provider](const std::string& name) { | 
|   95     Feature* feature = provider.GetFeature(name); |   99     Feature* feature = provider.GetFeature(name); | 
|   96     // Shame we can't test this more safely, but if our feature is declared as |  100     // 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. |  101     // the wrong class, things should blow up in a spectacular fashion. | 
|   98     return static_cast<APIFeature*>(feature); |  102     return static_cast<APIFeature*>(feature); | 
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  255       // Finally, check the branch of the complex feature. |  259       // Finally, check the branch of the complex feature. | 
|  256       FeatureComparator comparator("complex"); |  260       FeatureComparator comparator("complex"); | 
|  257       comparator.channel.reset( |  261       comparator.channel.reset( | 
|  258           new version_info::Channel(version_info::Channel::BETA)); |  262           new version_info::Channel(version_info::Channel::BETA)); | 
|  259       comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; |  263       comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; | 
|  260       comparator.extension_types = {Manifest::TYPE_EXTENSION}; |  264       comparator.extension_types = {Manifest::TYPE_EXTENSION}; | 
|  261       comparator.whitelist = {"aaa"}; |  265       comparator.whitelist = {"aaa"}; | 
|  262       comparator.CompareFeature(other_parent); |  266       comparator.CompareFeature(other_parent); | 
|  263     } |  267     } | 
|  264   } |  268   } | 
 |  269  | 
 |  270   // Test API aliases. | 
 |  271   { | 
 |  272     APIFeature* feature = GetAPIFeature("alias"); | 
 |  273     FeatureComparator comparator("alias"); | 
 |  274     comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; | 
 |  275     comparator.channel.reset( | 
 |  276         new version_info::Channel(version_info::Channel::STABLE)); | 
 |  277     comparator.source = "alias_source"; | 
 |  278     comparator.CompareFeature(feature); | 
 |  279   } | 
 |  280   { | 
 |  281     APIFeature* feature = GetAPIFeature("alias_source"); | 
 |  282     FeatureComparator comparator("alias_source"); | 
 |  283     comparator.contexts = {Feature::BLESSED_EXTENSION_CONTEXT}; | 
 |  284     comparator.channel.reset( | 
 |  285         new version_info::Channel(version_info::Channel::STABLE)); | 
 |  286     comparator.alias = "alias"; | 
 |  287     comparator.CompareFeature(feature); | 
 |  288   } | 
 |  289   { | 
 |  290     Feature* feature = GetAPIFeature("complex_alias"); | 
 |  291     ASSERT_EQ("", feature->alias()); | 
 |  292     ASSERT_EQ("complex_alias_source", feature->source()); | 
 |  293   } | 
 |  294   { | 
 |  295     Feature* feature = GetAPIFeature("complex_alias_source"); | 
 |  296     ASSERT_EQ("complex_alias", feature->alias()); | 
 |  297     ASSERT_EQ("", feature->source()); | 
 |  298   } | 
 |  299   { | 
 |  300     Feature* feature = GetAPIFeature("parent_source"); | 
 |  301     ASSERT_EQ("parent_source_alias", feature->alias()); | 
 |  302     ASSERT_EQ("", feature->source()); | 
 |  303   } | 
 |  304   { | 
 |  305     Feature* feature = GetAPIFeature("parent_source.child"); | 
 |  306     ASSERT_EQ("parent_source_alias", feature->alias()); | 
 |  307     ASSERT_EQ("", feature->source()); | 
 |  308   } | 
 |  309   { | 
 |  310     Feature* feature = GetAPIFeature("parent_source.child_source"); | 
 |  311     ASSERT_EQ("parent_source_child_alias", feature->alias()); | 
 |  312     ASSERT_EQ("", feature->source()); | 
 |  313   } | 
 |  314   { | 
 |  315     Feature* feature = GetAPIFeature("alias_parent"); | 
 |  316     ASSERT_EQ("", feature->alias()); | 
 |  317     ASSERT_EQ("", feature->source()); | 
 |  318   } | 
 |  319   { | 
 |  320     Feature* feature = GetAPIFeature("alias_parent.child"); | 
 |  321     ASSERT_EQ("", feature->alias()); | 
 |  322     ASSERT_EQ("child_source", feature->source()); | 
 |  323   } | 
|  265 } |  324 } | 
|  266  |  325  | 
|  267 }  // namespace extensions |  326 }  // namespace extensions | 
| OLD | NEW |