Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1064)

Side by Side Diff: extensions/common/features/complex_feature_unittest.cc

Issue 2201653003: Revert of Further reduction of feature_compiler.py generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test-with-leiz
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/complex_feature.h" 5 #include "extensions/common/features/complex_feature.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "extensions/common/features/simple_feature.h" 10 #include "extensions/common/features/simple_feature.h"
11 #include "extensions/common/manifest.h" 11 #include "extensions/common/manifest.h"
12 #include "extensions/common/value_builder.h" 12 #include "extensions/common/value_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 TEST(ComplexFeatureTest, MultipleRulesWhitelist) { 17 TEST(ComplexFeatureTest, MultipleRulesWhitelist) {
18 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 18 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
19 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 19 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
20 std::vector<Feature*> features; 20 std::unique_ptr<ComplexFeature::FeatureList> features(
21 new ComplexFeature::FeatureList());
21 22
22 // Rule: "extension", whitelist "foo". 23 // Rule: "extension", whitelist "foo".
23 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); 24 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature);
24 std::unique_ptr<base::DictionaryValue> rule( 25 std::unique_ptr<base::DictionaryValue> rule(
25 DictionaryBuilder() 26 DictionaryBuilder()
26 .Set("whitelist", ListBuilder().Append(kIdFoo).Build()) 27 .Set("whitelist", ListBuilder().Append(kIdFoo).Build())
27 .Set("extension_types", ListBuilder().Append("extension").Build()) 28 .Set("extension_types", ListBuilder().Append("extension").Build())
28 .Build()); 29 .Build());
29 simple_feature->Parse(rule.get()); 30 simple_feature->Parse(rule.get());
30 features.push_back(simple_feature.release()); 31 features->push_back(std::move(simple_feature));
31 32
32 // Rule: "legacy_packaged_app", whitelist "bar". 33 // Rule: "legacy_packaged_app", whitelist "bar".
33 simple_feature.reset(new SimpleFeature); 34 simple_feature.reset(new SimpleFeature);
34 rule = DictionaryBuilder() 35 rule = DictionaryBuilder()
35 .Set("whitelist", ListBuilder().Append(kIdBar).Build()) 36 .Set("whitelist", ListBuilder().Append(kIdBar).Build())
36 .Set("extension_types", 37 .Set("extension_types",
37 ListBuilder().Append("legacy_packaged_app").Build()) 38 ListBuilder().Append("legacy_packaged_app").Build())
38 .Build(); 39 .Build();
39 simple_feature->Parse(rule.get()); 40 simple_feature->Parse(rule.get());
40 features.push_back(simple_feature.release()); 41 features->push_back(std::move(simple_feature));
41 42
42 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); 43 std::unique_ptr<ComplexFeature> feature(
44 new ComplexFeature(std::move(features)));
43 45
44 // Test match 1st rule. 46 // Test match 1st rule.
45 EXPECT_EQ( 47 EXPECT_EQ(
46 Feature::IS_AVAILABLE, 48 Feature::IS_AVAILABLE,
47 feature->IsAvailableToManifest(kIdFoo, 49 feature->IsAvailableToManifest(kIdFoo,
48 Manifest::TYPE_EXTENSION, 50 Manifest::TYPE_EXTENSION,
49 Manifest::INVALID_LOCATION, 51 Manifest::INVALID_LOCATION,
50 Feature::UNSPECIFIED_PLATFORM, 52 Feature::UNSPECIFIED_PLATFORM,
51 Feature::GetCurrentPlatform()).result()); 53 Feature::GetCurrentPlatform()).result());
52 54
(...skipping 18 matching lines...) Expand all
71 Feature::IS_AVAILABLE, 73 Feature::IS_AVAILABLE,
72 feature->IsAvailableToManifest(kIdFoo, 74 feature->IsAvailableToManifest(kIdFoo,
73 Manifest::TYPE_LEGACY_PACKAGED_APP, 75 Manifest::TYPE_LEGACY_PACKAGED_APP,
74 Manifest::INVALID_LOCATION, 76 Manifest::INVALID_LOCATION,
75 Feature::UNSPECIFIED_PLATFORM, 77 Feature::UNSPECIFIED_PLATFORM,
76 Feature::GetCurrentPlatform()).result()); 78 Feature::GetCurrentPlatform()).result());
77 } 79 }
78 80
79 // Tests that dependencies are correctly checked. 81 // Tests that dependencies are correctly checked.
80 TEST(ComplexFeatureTest, Dependencies) { 82 TEST(ComplexFeatureTest, Dependencies) {
81 std::vector<Feature*> features; 83 std::unique_ptr<ComplexFeature::FeatureList> features(
84 new ComplexFeature::FeatureList());
82 85
83 // Rule which depends on an extension-only feature (content_security_policy). 86 // Rule which depends on an extension-only feature (content_security_policy).
84 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); 87 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature);
85 std::unique_ptr<base::DictionaryValue> rule = 88 std::unique_ptr<base::DictionaryValue> rule =
86 DictionaryBuilder() 89 DictionaryBuilder()
87 .Set("dependencies", 90 .Set("dependencies",
88 ListBuilder().Append("manifest:content_security_policy").Build()) 91 ListBuilder().Append("manifest:content_security_policy").Build())
89 .Build(); 92 .Build();
90 simple_feature->Parse(rule.get()); 93 simple_feature->Parse(rule.get());
91 features.push_back(simple_feature.release()); 94 features->push_back(std::move(simple_feature));
92 95
93 // Rule which depends on an platform-app-only feature (serial). 96 // Rule which depends on an platform-app-only feature (serial).
94 simple_feature.reset(new SimpleFeature); 97 simple_feature.reset(new SimpleFeature);
95 rule = DictionaryBuilder() 98 rule = DictionaryBuilder()
96 .Set("dependencies", 99 .Set("dependencies",
97 ListBuilder().Append("permission:serial").Build()) 100 ListBuilder().Append("permission:serial").Build())
98 .Build(); 101 .Build();
99 simple_feature->Parse(rule.get()); 102 simple_feature->Parse(rule.get());
100 features.push_back(simple_feature.release()); 103 features->push_back(std::move(simple_feature));
101 104
102 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); 105 std::unique_ptr<ComplexFeature> feature(
106 new ComplexFeature(std::move(features)));
103 107
104 // Available to extensions because of the content_security_policy rule. 108 // Available to extensions because of the content_security_policy rule.
105 EXPECT_EQ( 109 EXPECT_EQ(
106 Feature::IS_AVAILABLE, 110 Feature::IS_AVAILABLE,
107 feature->IsAvailableToManifest("extensionid", 111 feature->IsAvailableToManifest("extensionid",
108 Manifest::TYPE_EXTENSION, 112 Manifest::TYPE_EXTENSION,
109 Manifest::INVALID_LOCATION, 113 Manifest::INVALID_LOCATION,
110 Feature::UNSPECIFIED_PLATFORM, 114 Feature::UNSPECIFIED_PLATFORM,
111 Feature::GetCurrentPlatform()).result()); 115 Feature::GetCurrentPlatform()).result());
112 116
(...skipping 10 matching lines...) Expand all
123 EXPECT_EQ( 127 EXPECT_EQ(
124 Feature::INVALID_TYPE, 128 Feature::INVALID_TYPE,
125 feature->IsAvailableToManifest("hostedappid", 129 feature->IsAvailableToManifest("hostedappid",
126 Manifest::TYPE_HOSTED_APP, 130 Manifest::TYPE_HOSTED_APP,
127 Manifest::INVALID_LOCATION, 131 Manifest::INVALID_LOCATION,
128 Feature::UNSPECIFIED_PLATFORM, 132 Feature::UNSPECIFIED_PLATFORM,
129 Feature::GetCurrentPlatform()).result()); 133 Feature::GetCurrentPlatform()).result());
130 } 134 }
131 135
132 } // namespace extensions 136 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/complex_feature.cc ('k') | extensions/common/features/json_feature_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698