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

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

Issue 241673002: Support a "policy" extension location in extension features files. At the same (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: format Created 6 years, 8 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 | Annotate | Revision Log
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 "chrome/common/extensions/features/chrome_channel_feature_filter.h" 7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h"
8 #include "chrome/common/extensions/features/feature_channel.h" 8 #include "chrome/common/extensions/features/feature_channel.h"
9 #include "extensions/common/features/api_feature.h" 9 #include "extensions/common/features/api_feature.h"
10 #include "extensions/common/features/simple_feature.h" 10 #include "extensions/common/features/simple_feature.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 rule = DictionaryBuilder() 63 rule = DictionaryBuilder()
64 .Set("whitelist", ListBuilder().Append(kIdBar)) 64 .Set("whitelist", ListBuilder().Append(kIdBar))
65 .Set("extension_types", ListBuilder() 65 .Set("extension_types", ListBuilder()
66 .Append("legacy_packaged_app")).Build(); 66 .Append("legacy_packaged_app")).Build();
67 simple_feature->Parse(rule.get()); 67 simple_feature->Parse(rule.get());
68 features->push_back(simple_feature.release()); 68 features->push_back(simple_feature.release());
69 69
70 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); 70 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
71 71
72 // Test match 1st rule. 72 // Test match 1st rule.
73 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 73 EXPECT_EQ(
74 kIdFoo, 74 Feature::IS_AVAILABLE,
75 Manifest::TYPE_EXTENSION, 75 feature->IsAvailableToManifest(kIdFoo,
76 Feature::UNSPECIFIED_LOCATION, 76 Manifest::TYPE_EXTENSION,
77 Feature::UNSPECIFIED_PLATFORM, 77 Manifest::INVALID_LOCATION,
78 Feature::GetCurrentPlatform()).result()); 78 Feature::UNSPECIFIED_PLATFORM,
79 Feature::GetCurrentPlatform()).result());
79 80
80 // Test match 2nd rule. 81 // Test match 2nd rule.
81 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 82 EXPECT_EQ(
82 kIdBar, 83 Feature::IS_AVAILABLE,
83 Manifest::TYPE_LEGACY_PACKAGED_APP, 84 feature->IsAvailableToManifest(kIdBar,
84 Feature::UNSPECIFIED_LOCATION, 85 Manifest::TYPE_LEGACY_PACKAGED_APP,
85 Feature::UNSPECIFIED_PLATFORM, 86 Manifest::INVALID_LOCATION,
86 Feature::GetCurrentPlatform()).result()); 87 Feature::UNSPECIFIED_PLATFORM,
88 Feature::GetCurrentPlatform()).result());
87 89
88 // Test whitelist with wrong extension type. 90 // Test whitelist with wrong extension type.
89 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 91 EXPECT_NE(
90 kIdBar, 92 Feature::IS_AVAILABLE,
91 Manifest::TYPE_EXTENSION, 93 feature->IsAvailableToManifest(kIdBar,
92 Feature::UNSPECIFIED_LOCATION, 94 Manifest::TYPE_EXTENSION,
93 Feature::UNSPECIFIED_PLATFORM, 95 Manifest::INVALID_LOCATION,
94 Feature::GetCurrentPlatform()).result()); 96 Feature::UNSPECIFIED_PLATFORM,
95 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(kIdFoo, 97 Feature::GetCurrentPlatform()).result());
96 Manifest::TYPE_LEGACY_PACKAGED_APP, 98 EXPECT_NE(
97 Feature::UNSPECIFIED_LOCATION, 99 Feature::IS_AVAILABLE,
98 Feature::UNSPECIFIED_PLATFORM, 100 feature->IsAvailableToManifest(kIdFoo,
99 Feature::GetCurrentPlatform()).result()); 101 Manifest::TYPE_LEGACY_PACKAGED_APP,
102 Manifest::INVALID_LOCATION,
103 Feature::UNSPECIFIED_PLATFORM,
104 Feature::GetCurrentPlatform()).result());
100 } 105 }
101 106
102 TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) { 107 TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) {
103 scoped_ptr<ComplexFeature::FeatureList> features( 108 scoped_ptr<ComplexFeature::FeatureList> features(
104 new ComplexFeature::FeatureList()); 109 new ComplexFeature::FeatureList());
105 110
106 // Rule: "extension", channel trunk. 111 // Rule: "extension", channel trunk.
107 scoped_ptr<SimpleFeature> simple_feature(CreateFeature()); 112 scoped_ptr<SimpleFeature> simple_feature(CreateFeature());
108 scoped_ptr<base::DictionaryValue> rule( 113 scoped_ptr<base::DictionaryValue> rule(
109 DictionaryBuilder() 114 DictionaryBuilder()
110 .Set("channel", "trunk") 115 .Set("channel", "trunk")
111 .Set("extension_types", ListBuilder().Append("extension")).Build()); 116 .Set("extension_types", ListBuilder().Append("extension")).Build());
112 simple_feature->Parse(rule.get()); 117 simple_feature->Parse(rule.get());
113 features->push_back(simple_feature.release()); 118 features->push_back(simple_feature.release());
114 119
115 // Rule: "legacy_packaged_app", channel stable. 120 // Rule: "legacy_packaged_app", channel stable.
116 simple_feature.reset(CreateFeature()); 121 simple_feature.reset(CreateFeature());
117 rule = DictionaryBuilder() 122 rule = DictionaryBuilder()
118 .Set("channel", "stable") 123 .Set("channel", "stable")
119 .Set("extension_types", ListBuilder() 124 .Set("extension_types", ListBuilder()
120 .Append("legacy_packaged_app")).Build(); 125 .Append("legacy_packaged_app")).Build();
121 simple_feature->Parse(rule.get()); 126 simple_feature->Parse(rule.get());
122 features->push_back(simple_feature.release()); 127 features->push_back(simple_feature.release());
123 128
124 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); 129 scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass()));
125 130
126 // Test match 1st rule. 131 // Test match 1st rule.
127 { 132 {
128 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN); 133 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN);
129 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 134 EXPECT_EQ(
130 "1", 135 Feature::IS_AVAILABLE,
131 Manifest::TYPE_EXTENSION, 136 feature->IsAvailableToManifest("1",
132 Feature::UNSPECIFIED_LOCATION, 137 Manifest::TYPE_EXTENSION,
133 Feature::UNSPECIFIED_PLATFORM, 138 Manifest::INVALID_LOCATION,
134 Feature::GetCurrentPlatform()).result()); 139 Feature::UNSPECIFIED_PLATFORM,
140 Feature::GetCurrentPlatform()).result());
135 } 141 }
136 142
137 // Test match 2nd rule. 143 // Test match 2nd rule.
138 { 144 {
139 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); 145 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
140 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 146 EXPECT_EQ(
141 "2", 147 Feature::IS_AVAILABLE,
142 Manifest::TYPE_LEGACY_PACKAGED_APP, 148 feature->IsAvailableToManifest("2",
143 Feature::UNSPECIFIED_LOCATION, 149 Manifest::TYPE_LEGACY_PACKAGED_APP,
144 Feature::UNSPECIFIED_PLATFORM, 150 Manifest::INVALID_LOCATION,
145 Feature::GetCurrentPlatform()).result()); 151 Feature::UNSPECIFIED_PLATFORM,
152 Feature::GetCurrentPlatform()).result());
146 } 153 }
147 154
148 // Test feature not available to extensions above channel unknown. 155 // Test feature not available to extensions above channel unknown.
149 { 156 {
150 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA); 157 ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
151 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest( 158 EXPECT_NE(
152 "1", 159 Feature::IS_AVAILABLE,
153 Manifest::TYPE_EXTENSION, 160 feature->IsAvailableToManifest("1",
154 Feature::UNSPECIFIED_LOCATION, 161 Manifest::TYPE_EXTENSION,
155 Feature::UNSPECIFIED_PLATFORM, 162 Manifest::INVALID_LOCATION,
156 Feature::GetCurrentPlatform()).result()); 163 Feature::UNSPECIFIED_PLATFORM,
164 Feature::GetCurrentPlatform()).result());
157 } 165 }
158 } 166 }
159 167
160 // Tests a complex feature with blocked_in_service_worker returns true for 168 // Tests a complex feature with blocked_in_service_worker returns true for
161 // IsBlockedInServiceWorker(). 169 // IsBlockedInServiceWorker().
162 TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) { 170 TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) {
163 scoped_ptr<ComplexFeature::FeatureList> features( 171 scoped_ptr<ComplexFeature::FeatureList> features(
164 new ComplexFeature::FeatureList()); 172 new ComplexFeature::FeatureList());
165 173
166 // Two feature rules, both with blocked_in_service_worker: true. 174 // Two feature rules, both with blocked_in_service_worker: true.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( 209 api_feature->Parse(ParseJsonDictionaryWithSingleQuotes(
202 "{" 210 "{"
203 " 'channel': 'stable'" 211 " 'channel': 'stable'"
204 "}").get()); 212 "}").get());
205 features->push_back(api_feature.release()); 213 features->push_back(api_feature.release());
206 214
207 EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker()); 215 EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
208 } 216 }
209 217
210 } // namespace 218 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698