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/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::unique_ptr<ComplexFeature::FeatureList> features( | 20 std::vector<Feature*> features; |
21 new ComplexFeature::FeatureList()); | |
22 | 21 |
23 // Rule: "extension", whitelist "foo". | 22 // Rule: "extension", whitelist "foo". |
24 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); | 23 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); |
25 std::unique_ptr<base::DictionaryValue> rule( | 24 std::unique_ptr<base::DictionaryValue> rule( |
26 DictionaryBuilder() | 25 DictionaryBuilder() |
27 .Set("whitelist", ListBuilder().Append(kIdFoo).Build()) | 26 .Set("whitelist", ListBuilder().Append(kIdFoo).Build()) |
28 .Set("extension_types", ListBuilder().Append("extension").Build()) | 27 .Set("extension_types", ListBuilder().Append("extension").Build()) |
29 .Build()); | 28 .Build()); |
30 simple_feature->Parse(rule.get()); | 29 simple_feature->Parse(rule.get()); |
31 features->push_back(std::move(simple_feature)); | 30 features.push_back(simple_feature.release()); |
32 | 31 |
33 // Rule: "legacy_packaged_app", whitelist "bar". | 32 // Rule: "legacy_packaged_app", whitelist "bar". |
34 simple_feature.reset(new SimpleFeature); | 33 simple_feature.reset(new SimpleFeature); |
35 rule = DictionaryBuilder() | 34 rule = DictionaryBuilder() |
36 .Set("whitelist", ListBuilder().Append(kIdBar).Build()) | 35 .Set("whitelist", ListBuilder().Append(kIdBar).Build()) |
37 .Set("extension_types", | 36 .Set("extension_types", |
38 ListBuilder().Append("legacy_packaged_app").Build()) | 37 ListBuilder().Append("legacy_packaged_app").Build()) |
39 .Build(); | 38 .Build(); |
40 simple_feature->Parse(rule.get()); | 39 simple_feature->Parse(rule.get()); |
41 features->push_back(std::move(simple_feature)); | 40 features.push_back(simple_feature.release()); |
42 | 41 |
43 std::unique_ptr<ComplexFeature> feature( | 42 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); |
44 new ComplexFeature(std::move(features))); | |
45 | 43 |
46 // Test match 1st rule. | 44 // Test match 1st rule. |
47 EXPECT_EQ( | 45 EXPECT_EQ( |
48 Feature::IS_AVAILABLE, | 46 Feature::IS_AVAILABLE, |
49 feature->IsAvailableToManifest(kIdFoo, | 47 feature->IsAvailableToManifest(kIdFoo, |
50 Manifest::TYPE_EXTENSION, | 48 Manifest::TYPE_EXTENSION, |
51 Manifest::INVALID_LOCATION, | 49 Manifest::INVALID_LOCATION, |
52 Feature::UNSPECIFIED_PLATFORM, | 50 Feature::UNSPECIFIED_PLATFORM, |
53 Feature::GetCurrentPlatform()).result()); | 51 Feature::GetCurrentPlatform()).result()); |
54 | 52 |
(...skipping 18 matching lines...) Expand all Loading... |
73 Feature::IS_AVAILABLE, | 71 Feature::IS_AVAILABLE, |
74 feature->IsAvailableToManifest(kIdFoo, | 72 feature->IsAvailableToManifest(kIdFoo, |
75 Manifest::TYPE_LEGACY_PACKAGED_APP, | 73 Manifest::TYPE_LEGACY_PACKAGED_APP, |
76 Manifest::INVALID_LOCATION, | 74 Manifest::INVALID_LOCATION, |
77 Feature::UNSPECIFIED_PLATFORM, | 75 Feature::UNSPECIFIED_PLATFORM, |
78 Feature::GetCurrentPlatform()).result()); | 76 Feature::GetCurrentPlatform()).result()); |
79 } | 77 } |
80 | 78 |
81 // Tests that dependencies are correctly checked. | 79 // Tests that dependencies are correctly checked. |
82 TEST(ComplexFeatureTest, Dependencies) { | 80 TEST(ComplexFeatureTest, Dependencies) { |
83 std::unique_ptr<ComplexFeature::FeatureList> features( | 81 std::vector<Feature*> features; |
84 new ComplexFeature::FeatureList()); | |
85 | 82 |
86 // Rule which depends on an extension-only feature (content_security_policy). | 83 // Rule which depends on an extension-only feature (content_security_policy). |
87 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); | 84 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); |
88 std::unique_ptr<base::DictionaryValue> rule = | 85 std::unique_ptr<base::DictionaryValue> rule = |
89 DictionaryBuilder() | 86 DictionaryBuilder() |
90 .Set("dependencies", | 87 .Set("dependencies", |
91 ListBuilder().Append("manifest:content_security_policy").Build()) | 88 ListBuilder().Append("manifest:content_security_policy").Build()) |
92 .Build(); | 89 .Build(); |
93 simple_feature->Parse(rule.get()); | 90 simple_feature->Parse(rule.get()); |
94 features->push_back(std::move(simple_feature)); | 91 features.push_back(simple_feature.release()); |
95 | 92 |
96 // Rule which depends on an platform-app-only feature (serial). | 93 // Rule which depends on an platform-app-only feature (serial). |
97 simple_feature.reset(new SimpleFeature); | 94 simple_feature.reset(new SimpleFeature); |
98 rule = DictionaryBuilder() | 95 rule = DictionaryBuilder() |
99 .Set("dependencies", | 96 .Set("dependencies", |
100 ListBuilder().Append("permission:serial").Build()) | 97 ListBuilder().Append("permission:serial").Build()) |
101 .Build(); | 98 .Build(); |
102 simple_feature->Parse(rule.get()); | 99 simple_feature->Parse(rule.get()); |
103 features->push_back(std::move(simple_feature)); | 100 features.push_back(simple_feature.release()); |
104 | 101 |
105 std::unique_ptr<ComplexFeature> feature( | 102 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); |
106 new ComplexFeature(std::move(features))); | |
107 | 103 |
108 // Available to extensions because of the content_security_policy rule. | 104 // Available to extensions because of the content_security_policy rule. |
109 EXPECT_EQ( | 105 EXPECT_EQ( |
110 Feature::IS_AVAILABLE, | 106 Feature::IS_AVAILABLE, |
111 feature->IsAvailableToManifest("extensionid", | 107 feature->IsAvailableToManifest("extensionid", |
112 Manifest::TYPE_EXTENSION, | 108 Manifest::TYPE_EXTENSION, |
113 Manifest::INVALID_LOCATION, | 109 Manifest::INVALID_LOCATION, |
114 Feature::UNSPECIFIED_PLATFORM, | 110 Feature::UNSPECIFIED_PLATFORM, |
115 Feature::GetCurrentPlatform()).result()); | 111 Feature::GetCurrentPlatform()).result()); |
116 | 112 |
(...skipping 10 matching lines...) Expand all Loading... |
127 EXPECT_EQ( | 123 EXPECT_EQ( |
128 Feature::INVALID_TYPE, | 124 Feature::INVALID_TYPE, |
129 feature->IsAvailableToManifest("hostedappid", | 125 feature->IsAvailableToManifest("hostedappid", |
130 Manifest::TYPE_HOSTED_APP, | 126 Manifest::TYPE_HOSTED_APP, |
131 Manifest::INVALID_LOCATION, | 127 Manifest::INVALID_LOCATION, |
132 Feature::UNSPECIFIED_PLATFORM, | 128 Feature::UNSPECIFIED_PLATFORM, |
133 Feature::GetCurrentPlatform()).result()); | 129 Feature::GetCurrentPlatform()).result()); |
134 } | 130 } |
135 | 131 |
136 } // namespace extensions | 132 } // namespace extensions |
OLD | NEW |