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

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

Issue 2116293003: extensions: Generate hash of extension ID at a higher level Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/simple_feature.h" 5 #include "extensions/common/features/simple_feature.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 } // namespace 33 } // namespace
34 34
35 class SimpleFeatureTest : public testing::Test { 35 class SimpleFeatureTest : public testing::Test {
36 protected: 36 protected:
37 bool LocationIsAvailable(SimpleFeature::Location feature_location, 37 bool LocationIsAvailable(SimpleFeature::Location feature_location,
38 Manifest::Location manifest_location) { 38 Manifest::Location manifest_location) {
39 SimpleFeature feature; 39 SimpleFeature feature;
40 feature.set_location(feature_location); 40 feature.set_location(feature_location);
41 Feature::AvailabilityResult availability_result = 41 Feature::AvailabilityResult availability_result =
42 feature.IsAvailableToManifest(std::string(), 42 feature
43 Manifest::TYPE_UNKNOWN, 43 .IsAvailableToManifest(std::string(), std::string(),
44 manifest_location, 44 Manifest::TYPE_UNKNOWN, manifest_location,
45 -1, 45 -1, Feature::UNSPECIFIED_PLATFORM)
46 Feature::UNSPECIFIED_PLATFORM).result(); 46 .result();
47 return availability_result == Feature::IS_AVAILABLE; 47 return availability_result == Feature::IS_AVAILABLE;
48 } 48 }
49 }; 49 };
50 50
51 TEST_F(SimpleFeatureTest, IsAvailableNullCase) { 51 TEST_F(SimpleFeatureTest, IsAvailableNullCase) {
52 const IsAvailableTestData tests[] = { 52 const IsAvailableTestData tests[] = {
53 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 53 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
54 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 54 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
55 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 55 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
56 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 56 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
57 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION, 57 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION,
58 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 58 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
59 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 59 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
60 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 60 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
61 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT, 61 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT,
62 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 62 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
63 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 63 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
64 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE}, 64 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE},
65 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 65 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
66 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}}; 66 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}};
67 67
68 SimpleFeature feature; 68 SimpleFeature feature;
69 for (size_t i = 0; i < arraysize(tests); ++i) { 69 for (size_t i = 0; i < arraysize(tests); ++i) {
70 const IsAvailableTestData& test = tests[i]; 70 const IsAvailableTestData& test = tests[i];
71 EXPECT_EQ(test.expected_result, 71 EXPECT_EQ(test.expected_result,
72 feature.IsAvailableToManifest(test.extension_id, 72 feature
73 test.extension_type, 73 .IsAvailableToManifest(test.extension_id,
74 test.location, 74 HashedIdInHex(test.extension_id),
75 test.manifest_version, 75 test.extension_type, test.location,
76 test.platform).result()); 76 test.manifest_version, test.platform)
77 .result());
77 } 78 }
78 } 79 }
79 80
80 TEST_F(SimpleFeatureTest, Whitelist) { 81 TEST_F(SimpleFeatureTest, Whitelist) {
81 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 82 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
82 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 83 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
83 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); 84 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh");
84 SimpleFeature feature; 85 SimpleFeature feature;
85 feature.whitelist()->push_back(kIdFoo); 86 feature.whitelist()->push_back(kIdFoo);
86 feature.whitelist()->push_back(kIdBar); 87 feature.whitelist()->push_back(kIdBar);
87 88
88 EXPECT_EQ( 89 EXPECT_EQ(Feature::IS_AVAILABLE,
89 Feature::IS_AVAILABLE, 90 feature
90 feature.IsAvailableToManifest(kIdFoo, 91 .IsAvailableToManifest(kIdFoo, HashedIdInHex(kIdFoo),
91 Manifest::TYPE_UNKNOWN, 92 Manifest::TYPE_UNKNOWN,
92 Manifest::INVALID_LOCATION, 93 Manifest::INVALID_LOCATION, -1,
93 -1, 94 Feature::UNSPECIFIED_PLATFORM)
94 Feature::UNSPECIFIED_PLATFORM).result()); 95 .result());
95 EXPECT_EQ( 96 EXPECT_EQ(Feature::IS_AVAILABLE,
96 Feature::IS_AVAILABLE, 97 feature
97 feature.IsAvailableToManifest(kIdBar, 98 .IsAvailableToManifest(kIdBar, HashedIdInHex(kIdBar),
98 Manifest::TYPE_UNKNOWN, 99 Manifest::TYPE_UNKNOWN,
99 Manifest::INVALID_LOCATION, 100 Manifest::INVALID_LOCATION, -1,
100 -1, 101 Feature::UNSPECIFIED_PLATFORM)
101 Feature::UNSPECIFIED_PLATFORM).result()); 102 .result());
102 103
103 EXPECT_EQ( 104 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST,
104 Feature::NOT_FOUND_IN_WHITELIST, 105 feature
105 feature.IsAvailableToManifest(kIdBaz, 106 .IsAvailableToManifest(kIdBaz, HashedIdInHex(kIdBaz),
106 Manifest::TYPE_UNKNOWN, 107 Manifest::TYPE_UNKNOWN,
107 Manifest::INVALID_LOCATION, 108 Manifest::INVALID_LOCATION, -1,
108 -1, 109 Feature::UNSPECIFIED_PLATFORM)
109 Feature::UNSPECIFIED_PLATFORM).result()); 110 .result());
110 EXPECT_EQ( 111 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST,
111 Feature::NOT_FOUND_IN_WHITELIST, 112 feature
112 feature.IsAvailableToManifest(std::string(), 113 .IsAvailableToManifest(std::string(), std::string(),
113 Manifest::TYPE_UNKNOWN, 114 Manifest::TYPE_UNKNOWN,
114 Manifest::INVALID_LOCATION, 115 Manifest::INVALID_LOCATION, -1,
115 -1, 116 Feature::UNSPECIFIED_PLATFORM)
116 Feature::UNSPECIFIED_PLATFORM).result()); 117 .result());
117 118
118 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); 119 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP);
119 EXPECT_EQ( 120 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST,
120 Feature::NOT_FOUND_IN_WHITELIST, 121 feature
121 feature.IsAvailableToManifest(kIdBaz, 122 .IsAvailableToManifest(kIdBaz, HashedIdInHex(kIdBaz),
122 Manifest::TYPE_LEGACY_PACKAGED_APP, 123 Manifest::TYPE_LEGACY_PACKAGED_APP,
123 Manifest::INVALID_LOCATION, 124 Manifest::INVALID_LOCATION, -1,
124 -1, 125 Feature::UNSPECIFIED_PLATFORM)
125 Feature::UNSPECIFIED_PLATFORM).result()); 126 .result());
126 } 127 }
127 128
128 TEST_F(SimpleFeatureTest, HashedIdWhitelist) { 129 TEST_F(SimpleFeatureTest, HashedIdWhitelist) {
129 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | 130 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" |
130 // sha1sum | tr '[:lower:]' '[:upper:]' 131 // sha1sum | tr '[:lower:]' '[:upper:]'
131 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 132 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
132 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); 133 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897");
133 SimpleFeature feature; 134 SimpleFeature feature;
134 135
135 feature.whitelist()->push_back(kIdFooHashed); 136 feature.whitelist()->push_back(kIdFooHashed);
136 137
137 EXPECT_EQ( 138 EXPECT_EQ(Feature::IS_AVAILABLE,
138 Feature::IS_AVAILABLE, 139 feature
139 feature.IsAvailableToManifest(kIdFoo, 140 .IsAvailableToManifest(kIdFoo, HashedIdInHex(kIdFoo),
140 Manifest::TYPE_UNKNOWN, 141 Manifest::TYPE_UNKNOWN,
141 Manifest::INVALID_LOCATION, 142 Manifest::INVALID_LOCATION, -1,
142 -1, 143 Feature::UNSPECIFIED_PLATFORM)
143 Feature::UNSPECIFIED_PLATFORM).result()); 144 .result());
144 EXPECT_NE( 145 EXPECT_NE(
145 Feature::IS_AVAILABLE, 146 Feature::IS_AVAILABLE,
146 feature.IsAvailableToManifest(kIdFooHashed, 147 feature
147 Manifest::TYPE_UNKNOWN, 148 .IsAvailableToManifest(
148 Manifest::INVALID_LOCATION, 149 kIdFooHashed, HashedIdInHex(kIdFooHashed), Manifest::TYPE_UNKNOWN,
149 -1, 150 Manifest::INVALID_LOCATION, -1, Feature::UNSPECIFIED_PLATFORM)
150 Feature::UNSPECIFIED_PLATFORM).result()); 151 .result());
152 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST,
153 feature
154 .IsAvailableToManifest(
155 "slightlytoooolongforanextensionid",
156 HashedIdInHex("slightlytoooolongforanextensionid"),
157 Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, -1,
158 Feature::UNSPECIFIED_PLATFORM)
159 .result());
151 EXPECT_EQ( 160 EXPECT_EQ(
152 Feature::NOT_FOUND_IN_WHITELIST, 161 Feature::NOT_FOUND_IN_WHITELIST,
153 feature.IsAvailableToManifest("slightlytoooolongforanextensionid", 162 feature
154 Manifest::TYPE_UNKNOWN, 163 .IsAvailableToManifest(
155 Manifest::INVALID_LOCATION, 164 "tooshortforanextensionid",
156 -1, 165 HashedIdInHex("tooshortforanextensionid"), Manifest::TYPE_UNKNOWN,
157 Feature::UNSPECIFIED_PLATFORM).result()); 166 Manifest::INVALID_LOCATION, -1, Feature::UNSPECIFIED_PLATFORM)
158 EXPECT_EQ( 167 .result());
159 Feature::NOT_FOUND_IN_WHITELIST,
160 feature.IsAvailableToManifest("tooshortforanextensionid",
161 Manifest::TYPE_UNKNOWN,
162 Manifest::INVALID_LOCATION,
163 -1,
164 Feature::UNSPECIFIED_PLATFORM).result());
165 } 168 }
166 169
167 TEST_F(SimpleFeatureTest, Blacklist) { 170 TEST_F(SimpleFeatureTest, Blacklist) {
168 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 171 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
169 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 172 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
170 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); 173 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh");
171 SimpleFeature feature; 174 SimpleFeature feature;
172 feature.blacklist()->push_back(kIdFoo); 175 feature.blacklist()->push_back(kIdFoo);
173 feature.blacklist()->push_back(kIdBar); 176 feature.blacklist()->push_back(kIdBar);
174 177
175 EXPECT_EQ( 178 EXPECT_EQ(Feature::FOUND_IN_BLACKLIST,
176 Feature::FOUND_IN_BLACKLIST, 179 feature
177 feature.IsAvailableToManifest(kIdFoo, 180 .IsAvailableToManifest(kIdFoo, HashedIdInHex(kIdFoo),
178 Manifest::TYPE_UNKNOWN, 181 Manifest::TYPE_UNKNOWN,
179 Manifest::INVALID_LOCATION, 182 Manifest::INVALID_LOCATION, -1,
180 -1, 183 Feature::UNSPECIFIED_PLATFORM)
181 Feature::UNSPECIFIED_PLATFORM).result()); 184 .result());
182 EXPECT_EQ( 185 EXPECT_EQ(Feature::FOUND_IN_BLACKLIST,
183 Feature::FOUND_IN_BLACKLIST, 186 feature
184 feature.IsAvailableToManifest(kIdBar, 187 .IsAvailableToManifest(kIdBar, HashedIdInHex(kIdBar),
185 Manifest::TYPE_UNKNOWN, 188 Manifest::TYPE_UNKNOWN,
186 Manifest::INVALID_LOCATION, 189 Manifest::INVALID_LOCATION, -1,
187 -1, 190 Feature::UNSPECIFIED_PLATFORM)
188 Feature::UNSPECIFIED_PLATFORM).result()); 191 .result());
189 192
190 EXPECT_EQ( 193 EXPECT_EQ(Feature::IS_AVAILABLE,
191 Feature::IS_AVAILABLE, 194 feature
192 feature.IsAvailableToManifest(kIdBaz, 195 .IsAvailableToManifest(kIdBaz, HashedIdInHex(kIdBaz),
193 Manifest::TYPE_UNKNOWN, 196 Manifest::TYPE_UNKNOWN,
194 Manifest::INVALID_LOCATION, 197 Manifest::INVALID_LOCATION, -1,
195 -1, 198 Feature::UNSPECIFIED_PLATFORM)
196 Feature::UNSPECIFIED_PLATFORM).result()); 199 .result());
197 EXPECT_EQ( 200 EXPECT_EQ(Feature::IS_AVAILABLE,
198 Feature::IS_AVAILABLE, 201 feature
199 feature.IsAvailableToManifest(std::string(), 202 .IsAvailableToManifest(std::string(), std::string(),
200 Manifest::TYPE_UNKNOWN, 203 Manifest::TYPE_UNKNOWN,
201 Manifest::INVALID_LOCATION, 204 Manifest::INVALID_LOCATION, -1,
202 -1, 205 Feature::UNSPECIFIED_PLATFORM)
203 Feature::UNSPECIFIED_PLATFORM).result()); 206 .result());
204 } 207 }
205 208
206 TEST_F(SimpleFeatureTest, HashedIdBlacklist) { 209 TEST_F(SimpleFeatureTest, HashedIdBlacklist) {
207 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | 210 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" |
208 // sha1sum | tr '[:lower:]' '[:upper:]' 211 // sha1sum | tr '[:lower:]' '[:upper:]'
209 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 212 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
210 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); 213 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897");
211 SimpleFeature feature; 214 SimpleFeature feature;
212 215
213 feature.blacklist()->push_back(kIdFooHashed); 216 feature.blacklist()->push_back(kIdFooHashed);
214 217
215 EXPECT_EQ( 218 EXPECT_EQ(Feature::FOUND_IN_BLACKLIST,
216 Feature::FOUND_IN_BLACKLIST, 219 feature
217 feature.IsAvailableToManifest(kIdFoo, 220 .IsAvailableToManifest(kIdFoo, HashedIdInHex(kIdFoo),
218 Manifest::TYPE_UNKNOWN, 221 Manifest::TYPE_UNKNOWN,
219 Manifest::INVALID_LOCATION, 222 Manifest::INVALID_LOCATION, -1,
220 -1, 223 Feature::UNSPECIFIED_PLATFORM)
221 Feature::UNSPECIFIED_PLATFORM).result()); 224 .result());
222 EXPECT_NE( 225 EXPECT_NE(
223 Feature::FOUND_IN_BLACKLIST, 226 Feature::FOUND_IN_BLACKLIST,
224 feature.IsAvailableToManifest(kIdFooHashed, 227 feature
225 Manifest::TYPE_UNKNOWN, 228 .IsAvailableToManifest(
226 Manifest::INVALID_LOCATION, 229 kIdFooHashed, HashedIdInHex(kIdFooHashed), Manifest::TYPE_UNKNOWN,
227 -1, 230 Manifest::INVALID_LOCATION, -1, Feature::UNSPECIFIED_PLATFORM)
228 Feature::UNSPECIFIED_PLATFORM).result()); 231 .result());
232 EXPECT_EQ(Feature::IS_AVAILABLE,
233 feature
234 .IsAvailableToManifest(
235 "slightlytoooolongforanextensionid",
236 HashedIdInHex("slightlytoooolongforanextensionid"),
237 Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, -1,
238 Feature::UNSPECIFIED_PLATFORM)
239 .result());
229 EXPECT_EQ( 240 EXPECT_EQ(
230 Feature::IS_AVAILABLE, 241 Feature::IS_AVAILABLE,
231 feature.IsAvailableToManifest("slightlytoooolongforanextensionid", 242 feature
232 Manifest::TYPE_UNKNOWN, 243 .IsAvailableToManifest(
233 Manifest::INVALID_LOCATION, 244 "tooshortforanextensionid",
234 -1, 245 HashedIdInHex("tooshortforanextensionid"), Manifest::TYPE_UNKNOWN,
235 Feature::UNSPECIFIED_PLATFORM).result()); 246 Manifest::INVALID_LOCATION, -1, Feature::UNSPECIFIED_PLATFORM)
236 EXPECT_EQ( 247 .result());
237 Feature::IS_AVAILABLE,
238 feature.IsAvailableToManifest("tooshortforanextensionid",
239 Manifest::TYPE_UNKNOWN,
240 Manifest::INVALID_LOCATION,
241 -1,
242 Feature::UNSPECIFIED_PLATFORM).result());
243 } 248 }
244 249
245 TEST_F(SimpleFeatureTest, PackageType) { 250 TEST_F(SimpleFeatureTest, PackageType) {
246 SimpleFeature feature; 251 SimpleFeature feature;
247 feature.extension_types()->push_back(Manifest::TYPE_EXTENSION); 252 feature.extension_types()->push_back(Manifest::TYPE_EXTENSION);
248 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); 253 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP);
249 254
250 EXPECT_EQ( 255 EXPECT_EQ(Feature::IS_AVAILABLE,
251 Feature::IS_AVAILABLE, 256 feature
252 feature.IsAvailableToManifest(std::string(), 257 .IsAvailableToManifest(std::string(), std::string(),
253 Manifest::TYPE_EXTENSION, 258 Manifest::TYPE_EXTENSION,
254 Manifest::INVALID_LOCATION, 259 Manifest::INVALID_LOCATION, -1,
255 -1, 260 Feature::UNSPECIFIED_PLATFORM)
256 Feature::UNSPECIFIED_PLATFORM).result()); 261 .result());
257 EXPECT_EQ( 262 EXPECT_EQ(Feature::IS_AVAILABLE,
258 Feature::IS_AVAILABLE, 263 feature
259 feature.IsAvailableToManifest(std::string(), 264 .IsAvailableToManifest(std::string(), std::string(),
260 Manifest::TYPE_LEGACY_PACKAGED_APP, 265 Manifest::TYPE_LEGACY_PACKAGED_APP,
261 Manifest::INVALID_LOCATION, 266 Manifest::INVALID_LOCATION, -1,
262 -1, 267 Feature::UNSPECIFIED_PLATFORM)
263 Feature::UNSPECIFIED_PLATFORM).result()); 268 .result());
264 269
265 EXPECT_EQ( 270 EXPECT_EQ(Feature::INVALID_TYPE,
266 Feature::INVALID_TYPE, 271 feature
267 feature.IsAvailableToManifest(std::string(), 272 .IsAvailableToManifest(std::string(), std::string(),
268 Manifest::TYPE_UNKNOWN, 273 Manifest::TYPE_UNKNOWN,
269 Manifest::INVALID_LOCATION, 274 Manifest::INVALID_LOCATION, -1,
270 -1, 275 Feature::UNSPECIFIED_PLATFORM)
271 Feature::UNSPECIFIED_PLATFORM).result()); 276 .result());
272 EXPECT_EQ( 277 EXPECT_EQ(Feature::INVALID_TYPE,
273 Feature::INVALID_TYPE, 278 feature
274 feature.IsAvailableToManifest(std::string(), 279 .IsAvailableToManifest(std::string(), std::string(),
275 Manifest::TYPE_THEME, 280 Manifest::TYPE_THEME,
276 Manifest::INVALID_LOCATION, 281 Manifest::INVALID_LOCATION, -1,
277 -1, 282 Feature::UNSPECIFIED_PLATFORM)
278 Feature::UNSPECIFIED_PLATFORM).result()); 283 .result());
279 } 284 }
280 285
281 TEST_F(SimpleFeatureTest, Context) { 286 TEST_F(SimpleFeatureTest, Context) {
282 SimpleFeature feature; 287 SimpleFeature feature;
283 feature.set_name("somefeature"); 288 feature.set_name("somefeature");
284 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); 289 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT);
285 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); 290 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP);
286 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM); 291 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM);
287 feature.set_min_manifest_version(21); 292 feature.set_min_manifest_version(21);
288 feature.set_max_manifest_version(25); 293 feature.set_max_manifest_version(25);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // External component extensions can access the "external_component" 418 // External component extensions can access the "external_component"
414 // location. 419 // location.
415 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, 420 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION,
416 Manifest::EXTERNAL_COMPONENT)); 421 Manifest::EXTERNAL_COMPONENT));
417 } 422 }
418 423
419 TEST_F(SimpleFeatureTest, Platform) { 424 TEST_F(SimpleFeatureTest, Platform) {
420 SimpleFeature feature; 425 SimpleFeature feature;
421 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM); 426 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM);
422 EXPECT_EQ(Feature::IS_AVAILABLE, 427 EXPECT_EQ(Feature::IS_AVAILABLE,
423 feature.IsAvailableToManifest(std::string(), 428 feature
424 Manifest::TYPE_UNKNOWN, 429 .IsAvailableToManifest(
425 Manifest::INVALID_LOCATION, 430 std::string(), std::string(), Manifest::TYPE_UNKNOWN,
426 -1, 431 Manifest::INVALID_LOCATION, -1, Feature::CHROMEOS_PLATFORM)
427 Feature::CHROMEOS_PLATFORM).result()); 432 .result());
428 EXPECT_EQ( 433 EXPECT_EQ(Feature::INVALID_PLATFORM,
429 Feature::INVALID_PLATFORM, 434 feature
430 feature.IsAvailableToManifest(std::string(), 435 .IsAvailableToManifest(std::string(), std::string(),
431 Manifest::TYPE_UNKNOWN, 436 Manifest::TYPE_UNKNOWN,
432 Manifest::INVALID_LOCATION, 437 Manifest::INVALID_LOCATION, -1,
433 -1, 438 Feature::UNSPECIFIED_PLATFORM)
434 Feature::UNSPECIFIED_PLATFORM).result()); 439 .result());
435 } 440 }
436 441
437 TEST_F(SimpleFeatureTest, ManifestVersion) { 442 TEST_F(SimpleFeatureTest, ManifestVersion) {
438 SimpleFeature feature; 443 SimpleFeature feature;
439 feature.set_min_manifest_version(5); 444 feature.set_min_manifest_version(5);
440 445
441 EXPECT_EQ( 446 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION,
442 Feature::INVALID_MIN_MANIFEST_VERSION, 447 feature
443 feature.IsAvailableToManifest(std::string(), 448 .IsAvailableToManifest(std::string(), std::string(),
444 Manifest::TYPE_UNKNOWN, 449 Manifest::TYPE_UNKNOWN,
445 Manifest::INVALID_LOCATION, 450 Manifest::INVALID_LOCATION, 0,
446 0, 451 Feature::UNSPECIFIED_PLATFORM)
447 Feature::UNSPECIFIED_PLATFORM).result()); 452 .result());
448 EXPECT_EQ( 453 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION,
449 Feature::INVALID_MIN_MANIFEST_VERSION, 454 feature
450 feature.IsAvailableToManifest(std::string(), 455 .IsAvailableToManifest(std::string(), std::string(),
451 Manifest::TYPE_UNKNOWN, 456 Manifest::TYPE_UNKNOWN,
452 Manifest::INVALID_LOCATION, 457 Manifest::INVALID_LOCATION, 4,
453 4, 458 Feature::UNSPECIFIED_PLATFORM)
454 Feature::UNSPECIFIED_PLATFORM).result()); 459 .result());
455 460
456 EXPECT_EQ( 461 EXPECT_EQ(Feature::IS_AVAILABLE,
457 Feature::IS_AVAILABLE, 462 feature
458 feature.IsAvailableToManifest(std::string(), 463 .IsAvailableToManifest(std::string(), std::string(),
459 Manifest::TYPE_UNKNOWN, 464 Manifest::TYPE_UNKNOWN,
460 Manifest::INVALID_LOCATION, 465 Manifest::INVALID_LOCATION, 5,
461 5, 466 Feature::UNSPECIFIED_PLATFORM)
462 Feature::UNSPECIFIED_PLATFORM).result()); 467 .result());
463 EXPECT_EQ( 468 EXPECT_EQ(Feature::IS_AVAILABLE,
464 Feature::IS_AVAILABLE, 469 feature
465 feature.IsAvailableToManifest(std::string(), 470 .IsAvailableToManifest(std::string(), std::string(),
466 Manifest::TYPE_UNKNOWN, 471 Manifest::TYPE_UNKNOWN,
467 Manifest::INVALID_LOCATION, 472 Manifest::INVALID_LOCATION, 10,
468 10, 473 Feature::UNSPECIFIED_PLATFORM)
469 Feature::UNSPECIFIED_PLATFORM).result()); 474 .result());
470 475
471 feature.set_max_manifest_version(8); 476 feature.set_max_manifest_version(8);
472 477
473 EXPECT_EQ( 478 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION,
474 Feature::INVALID_MAX_MANIFEST_VERSION, 479 feature
475 feature.IsAvailableToManifest(std::string(), 480 .IsAvailableToManifest(std::string(), std::string(),
476 Manifest::TYPE_UNKNOWN, 481 Manifest::TYPE_UNKNOWN,
477 Manifest::INVALID_LOCATION, 482 Manifest::INVALID_LOCATION, 10,
478 10, 483 Feature::UNSPECIFIED_PLATFORM)
479 Feature::UNSPECIFIED_PLATFORM).result()); 484 .result());
480 EXPECT_EQ( 485 EXPECT_EQ(Feature::IS_AVAILABLE,
481 Feature::IS_AVAILABLE, 486 feature
482 feature.IsAvailableToManifest(std::string(), 487 .IsAvailableToManifest(std::string(), std::string(),
483 Manifest::TYPE_UNKNOWN, 488 Manifest::TYPE_UNKNOWN,
484 Manifest::INVALID_LOCATION, 489 Manifest::INVALID_LOCATION, 8,
485 8, 490 Feature::UNSPECIFIED_PLATFORM)
486 Feature::UNSPECIFIED_PLATFORM).result()); 491 .result());
487 EXPECT_EQ( 492 EXPECT_EQ(Feature::IS_AVAILABLE,
488 Feature::IS_AVAILABLE, 493 feature
489 feature.IsAvailableToManifest(std::string(), 494 .IsAvailableToManifest(std::string(), std::string(),
490 Manifest::TYPE_UNKNOWN, 495 Manifest::TYPE_UNKNOWN,
491 Manifest::INVALID_LOCATION, 496 Manifest::INVALID_LOCATION, 7,
492 7, 497 Feature::UNSPECIFIED_PLATFORM)
493 Feature::UNSPECIFIED_PLATFORM).result()); 498 .result());
494 } 499 }
495 500
496 TEST_F(SimpleFeatureTest, ParseNull) { 501 TEST_F(SimpleFeatureTest, ParseNull) {
497 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 502 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
498 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); 503 std::unique_ptr<SimpleFeature> feature(new SimpleFeature());
499 feature->Parse(value.get()); 504 feature->Parse(value.get());
500 EXPECT_TRUE(feature->whitelist()->empty()); 505 EXPECT_TRUE(feature->whitelist()->empty());
501 EXPECT_TRUE(feature->extension_types()->empty()); 506 EXPECT_TRUE(feature->extension_types()->empty());
502 EXPECT_TRUE(feature->contexts()->empty()); 507 EXPECT_TRUE(feature->contexts()->empty());
503 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); 508 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); 742 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray)));
738 EXPECT_FALSE(SimpleFeature::IsIdInArray( 743 EXPECT_FALSE(SimpleFeature::IsIdInArray(
739 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); 744 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray)));
740 EXPECT_TRUE(SimpleFeature::IsIdInArray( 745 EXPECT_TRUE(SimpleFeature::IsIdInArray(
741 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); 746 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray)));
742 EXPECT_TRUE(SimpleFeature::IsIdInArray( 747 EXPECT_TRUE(SimpleFeature::IsIdInArray(
743 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); 748 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray)));
744 } 749 }
745 750
746 } // namespace extensions 751 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698