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

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

Issue 2202733003: [Extensions] Remove JSONFeatureProvider, SimpleFeature::Parse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lei's 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::vector<Feature*> features;
21 21
22 // Rule: "extension", whitelist "foo". 22 {
23 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); 23 // Rule: "extension", whitelist "foo".
24 std::unique_ptr<base::DictionaryValue> rule( 24 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature());
25 DictionaryBuilder() 25 simple_feature->set_whitelist({kIdFoo.c_str()});
26 .Set("whitelist", ListBuilder().Append(kIdFoo).Build()) 26 simple_feature->set_extension_types({Manifest::TYPE_EXTENSION});
27 .Set("extension_types", ListBuilder().Append("extension").Build()) 27 features.push_back(simple_feature.release());
28 .Build()); 28 }
29 simple_feature->Parse(rule.get());
30 features.push_back(simple_feature.release());
31 29
32 // Rule: "legacy_packaged_app", whitelist "bar". 30 {
33 simple_feature.reset(new SimpleFeature); 31 // Rule: "legacy_packaged_app", whitelist "bar".
34 rule = DictionaryBuilder() 32 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature());
35 .Set("whitelist", ListBuilder().Append(kIdBar).Build()) 33 simple_feature->set_whitelist({kIdBar.c_str()});
36 .Set("extension_types", 34 simple_feature->set_extension_types({Manifest::TYPE_LEGACY_PACKAGED_APP});
37 ListBuilder().Append("legacy_packaged_app").Build()) 35 features.push_back(simple_feature.release());
38 .Build(); 36 }
39 simple_feature->Parse(rule.get());
40 features.push_back(simple_feature.release());
41 37
42 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); 38 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features));
43 39
44 // Test match 1st rule. 40 // Test match 1st rule.
45 EXPECT_EQ( 41 EXPECT_EQ(
46 Feature::IS_AVAILABLE, 42 Feature::IS_AVAILABLE,
47 feature->IsAvailableToManifest(kIdFoo, 43 feature->IsAvailableToManifest(kIdFoo,
48 Manifest::TYPE_EXTENSION, 44 Manifest::TYPE_EXTENSION,
49 Manifest::INVALID_LOCATION, 45 Manifest::INVALID_LOCATION,
50 Feature::UNSPECIFIED_PLATFORM, 46 Feature::UNSPECIFIED_PLATFORM,
(...skipping 22 matching lines...) Expand all
73 Manifest::TYPE_LEGACY_PACKAGED_APP, 69 Manifest::TYPE_LEGACY_PACKAGED_APP,
74 Manifest::INVALID_LOCATION, 70 Manifest::INVALID_LOCATION,
75 Feature::UNSPECIFIED_PLATFORM, 71 Feature::UNSPECIFIED_PLATFORM,
76 Feature::GetCurrentPlatform()).result()); 72 Feature::GetCurrentPlatform()).result());
77 } 73 }
78 74
79 // Tests that dependencies are correctly checked. 75 // Tests that dependencies are correctly checked.
80 TEST(ComplexFeatureTest, Dependencies) { 76 TEST(ComplexFeatureTest, Dependencies) {
81 std::vector<Feature*> features; 77 std::vector<Feature*> features;
82 78
83 // Rule which depends on an extension-only feature (content_security_policy). 79 {
84 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); 80 // Rule which depends on an extension-only feature
85 std::unique_ptr<base::DictionaryValue> rule = 81 // (content_security_policy).
86 DictionaryBuilder() 82 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature());
87 .Set("dependencies", 83 simple_feature->set_dependencies({"manifest:content_security_policy"});
88 ListBuilder().Append("manifest:content_security_policy").Build()) 84 features.push_back(simple_feature.release());
89 .Build(); 85 }
90 simple_feature->Parse(rule.get());
91 features.push_back(simple_feature.release());
92 86
93 // Rule which depends on an platform-app-only feature (serial). 87 {
94 simple_feature.reset(new SimpleFeature); 88 // Rule which depends on an platform-app-only feature (serial).
95 rule = DictionaryBuilder() 89 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature());
96 .Set("dependencies", 90 simple_feature->set_dependencies({"permission:serial"});
97 ListBuilder().Append("permission:serial").Build()) 91 features.push_back(simple_feature.release());
98 .Build(); 92 }
99 simple_feature->Parse(rule.get());
100 features.push_back(simple_feature.release());
101 93
102 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); 94 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features));
103 95
104 // Available to extensions because of the content_security_policy rule. 96 // Available to extensions because of the content_security_policy rule.
105 EXPECT_EQ( 97 EXPECT_EQ(
106 Feature::IS_AVAILABLE, 98 Feature::IS_AVAILABLE,
107 feature->IsAvailableToManifest("extensionid", 99 feature->IsAvailableToManifest("extensionid",
108 Manifest::TYPE_EXTENSION, 100 Manifest::TYPE_EXTENSION,
109 Manifest::INVALID_LOCATION, 101 Manifest::INVALID_LOCATION,
110 Feature::UNSPECIFIED_PLATFORM, 102 Feature::UNSPECIFIED_PLATFORM,
(...skipping 12 matching lines...) Expand all
123 EXPECT_EQ( 115 EXPECT_EQ(
124 Feature::INVALID_TYPE, 116 Feature::INVALID_TYPE,
125 feature->IsAvailableToManifest("hostedappid", 117 feature->IsAvailableToManifest("hostedappid",
126 Manifest::TYPE_HOSTED_APP, 118 Manifest::TYPE_HOSTED_APP,
127 Manifest::INVALID_LOCATION, 119 Manifest::INVALID_LOCATION,
128 Feature::UNSPECIFIED_PLATFORM, 120 Feature::UNSPECIFIED_PLATFORM,
129 Feature::GetCurrentPlatform()).result()); 121 Feature::GetCurrentPlatform()).result());
130 } 122 }
131 123
132 } // namespace extensions 124 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/api_feature.cc ('k') | extensions/common/features/json_feature_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698