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

Side by Side Diff: chrome/common/extensions/extension_permission_set_unittest.cc

Issue 10049006: Add OAuth2 scopes to the ExtensionPermissionSet and granted permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/common/extensions/extension_permission_set.h" 5 #include "chrome/common/extensions/extension_permission_set.h"
6 6
7 #include "base/command_line.h"
7 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_manifest_constants.h" 15 #include "chrome/common/extensions/extension_manifest_constants.h"
14 #include "chrome/common/extensions/extension_error_utils.h" 16 #include "chrome/common/extensions/extension_error_utils.h"
15 #include "chrome/common/extensions/extension_permission_set.h" 17 #include "chrome/common/extensions/extension_permission_set.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 namespace errors = extension_manifest_errors; 20 namespace errors = extension_manifest_errors;
19 namespace keys = extension_manifest_keys; 21 namespace keys = extension_manifest_keys;
20 namespace values = extension_manifest_values; 22 namespace values = extension_manifest_values;
21 namespace { 23 namespace {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 ExtensionAPIPermissionSet expected_apis; 248 ExtensionAPIPermissionSet expected_apis;
247 249
248 URLPatternSet explicit_hosts1; 250 URLPatternSet explicit_hosts1;
249 URLPatternSet explicit_hosts2; 251 URLPatternSet explicit_hosts2;
250 URLPatternSet expected_explicit_hosts; 252 URLPatternSet expected_explicit_hosts;
251 253
252 URLPatternSet scriptable_hosts1; 254 URLPatternSet scriptable_hosts1;
253 URLPatternSet scriptable_hosts2; 255 URLPatternSet scriptable_hosts2;
254 URLPatternSet expected_scriptable_hosts; 256 URLPatternSet expected_scriptable_hosts;
255 257
258 ExtensionOAuth2Scopes scopes1;
259 ExtensionOAuth2Scopes scopes2;
260 ExtensionOAuth2Scopes expected_scopes;
261
256 URLPatternSet effective_hosts; 262 URLPatternSet effective_hosts;
257 263
258 scoped_refptr<ExtensionPermissionSet> set1; 264 scoped_refptr<ExtensionPermissionSet> set1;
259 scoped_refptr<ExtensionPermissionSet> set2; 265 scoped_refptr<ExtensionPermissionSet> set2;
260 scoped_refptr<ExtensionPermissionSet> union_set; 266 scoped_refptr<ExtensionPermissionSet> union_set;
261 267
262 // Union with an empty set. 268 // Union with an empty set.
263 apis1.insert(ExtensionAPIPermission::kTab); 269 apis1.insert(ExtensionAPIPermission::kTab);
264 apis1.insert(ExtensionAPIPermission::kBackground); 270 apis1.insert(ExtensionAPIPermission::kBackground);
265 expected_apis.insert(ExtensionAPIPermission::kTab); 271 expected_apis.insert(ExtensionAPIPermission::kTab);
266 expected_apis.insert(ExtensionAPIPermission::kBackground); 272 expected_apis.insert(ExtensionAPIPermission::kBackground);
267 273
268 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 274 AddPattern(&explicit_hosts1, "http://*.google.com/*");
269 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 275 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
270 AddPattern(&effective_hosts, "http://*.google.com/*"); 276 AddPattern(&effective_hosts, "http://*.google.com/*");
271 277
272 set1 = new ExtensionPermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 278 scopes1.insert("first-scope");
273 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 279 scopes1.insert("second-scope");
280 expected_scopes.insert("first-scope");
281 expected_scopes.insert("second-scope");
282
283 set1 = new ExtensionPermissionSet(
284 apis1, explicit_hosts1, scriptable_hosts1, scopes1);
285 set2 = new ExtensionPermissionSet(
286 apis2, explicit_hosts2, scriptable_hosts2, scopes2);
274 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get()); 287 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get());
275 EXPECT_TRUE(set1->Contains(*set2)); 288 EXPECT_TRUE(set1->Contains(*set2));
276 EXPECT_TRUE(set1->Contains(*union_set)); 289 EXPECT_TRUE(set1->Contains(*union_set));
277 EXPECT_FALSE(set2->Contains(*set1)); 290 EXPECT_FALSE(set2->Contains(*set1));
278 EXPECT_FALSE(set2->Contains(*union_set)); 291 EXPECT_FALSE(set2->Contains(*union_set));
279 EXPECT_TRUE(union_set->Contains(*set1)); 292 EXPECT_TRUE(union_set->Contains(*set1));
280 EXPECT_TRUE(union_set->Contains(*set2)); 293 EXPECT_TRUE(union_set->Contains(*set2));
281 294
282 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); 295 EXPECT_FALSE(union_set->HasEffectiveFullAccess());
283 EXPECT_EQ(expected_apis, union_set->apis()); 296 EXPECT_EQ(expected_apis, union_set->apis());
284 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 297 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
285 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 298 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
286 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); 299 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts());
300 EXPECT_EQ(expected_scopes, union_set->scopes());
287 301
288 // Now use a real second set. 302 // Now use a real second set.
289 apis2.insert(ExtensionAPIPermission::kTab); 303 apis2.insert(ExtensionAPIPermission::kTab);
290 apis2.insert(ExtensionAPIPermission::kProxy); 304 apis2.insert(ExtensionAPIPermission::kProxy);
291 apis2.insert(ExtensionAPIPermission::kClipboardWrite); 305 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
292 apis2.insert(ExtensionAPIPermission::kPlugin); 306 apis2.insert(ExtensionAPIPermission::kPlugin);
293 expected_apis.insert(ExtensionAPIPermission::kTab); 307 expected_apis.insert(ExtensionAPIPermission::kTab);
294 expected_apis.insert(ExtensionAPIPermission::kProxy); 308 expected_apis.insert(ExtensionAPIPermission::kProxy);
295 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite); 309 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite);
296 expected_apis.insert(ExtensionAPIPermission::kPlugin); 310 expected_apis.insert(ExtensionAPIPermission::kPlugin);
297 311
298 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 312 AddPattern(&explicit_hosts2, "http://*.example.com/*");
299 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 313 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
300 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); 314 AddPattern(&expected_explicit_hosts, "http://*.example.com/*");
301 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); 315 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*");
302 316
317 scopes2.insert("real-scope");
318 scopes2.insert("anotherscope");
319 expected_scopes.insert("real-scope");
320 expected_scopes.insert("anotherscope");
321
303 URLPatternSet::CreateUnion( 322 URLPatternSet::CreateUnion(
304 explicit_hosts2, scriptable_hosts2, &effective_hosts); 323 explicit_hosts2, scriptable_hosts2, &effective_hosts);
305 324
306 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 325 set2 = new ExtensionPermissionSet(
326 apis2, explicit_hosts2, scriptable_hosts2, scopes2);
307 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get()); 327 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get());
308 328
309 EXPECT_FALSE(set1->Contains(*set2)); 329 EXPECT_FALSE(set1->Contains(*set2));
310 EXPECT_FALSE(set1->Contains(*union_set)); 330 EXPECT_FALSE(set1->Contains(*union_set));
311 EXPECT_FALSE(set2->Contains(*set1)); 331 EXPECT_FALSE(set2->Contains(*set1));
312 EXPECT_FALSE(set2->Contains(*union_set)); 332 EXPECT_FALSE(set2->Contains(*union_set));
313 EXPECT_TRUE(union_set->Contains(*set1)); 333 EXPECT_TRUE(union_set->Contains(*set1));
314 EXPECT_TRUE(union_set->Contains(*set2)); 334 EXPECT_TRUE(union_set->Contains(*set2));
315 335
316 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 336 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
317 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 337 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
318 EXPECT_EQ(expected_apis, union_set->apis()); 338 EXPECT_EQ(expected_apis, union_set->apis());
319 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 339 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
320 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 340 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
341 EXPECT_EQ(expected_scopes, union_set->scopes());
321 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); 342 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
322 } 343 }
323 344
324 TEST(ExtensionPermissionsTest, CreateIntersection) { 345 TEST(ExtensionPermissionsTest, CreateIntersection) {
325 ExtensionAPIPermissionSet apis1; 346 ExtensionAPIPermissionSet apis1;
326 ExtensionAPIPermissionSet apis2; 347 ExtensionAPIPermissionSet apis2;
327 ExtensionAPIPermissionSet expected_apis; 348 ExtensionAPIPermissionSet expected_apis;
328 349
329 URLPatternSet explicit_hosts1; 350 URLPatternSet explicit_hosts1;
330 URLPatternSet explicit_hosts2; 351 URLPatternSet explicit_hosts2;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 ExtensionAPIPermissionSet expected_apis; 424 ExtensionAPIPermissionSet expected_apis;
404 425
405 URLPatternSet explicit_hosts1; 426 URLPatternSet explicit_hosts1;
406 URLPatternSet explicit_hosts2; 427 URLPatternSet explicit_hosts2;
407 URLPatternSet expected_explicit_hosts; 428 URLPatternSet expected_explicit_hosts;
408 429
409 URLPatternSet scriptable_hosts1; 430 URLPatternSet scriptable_hosts1;
410 URLPatternSet scriptable_hosts2; 431 URLPatternSet scriptable_hosts2;
411 URLPatternSet expected_scriptable_hosts; 432 URLPatternSet expected_scriptable_hosts;
412 433
434 ExtensionOAuth2Scopes scopes1;
435 ExtensionOAuth2Scopes scopes2;
436 ExtensionOAuth2Scopes expected_scopes;
437
413 URLPatternSet effective_hosts; 438 URLPatternSet effective_hosts;
414 439
415 scoped_refptr<ExtensionPermissionSet> set1; 440 scoped_refptr<ExtensionPermissionSet> set1;
416 scoped_refptr<ExtensionPermissionSet> set2; 441 scoped_refptr<ExtensionPermissionSet> set2;
417 scoped_refptr<ExtensionPermissionSet> new_set; 442 scoped_refptr<ExtensionPermissionSet> new_set;
418 443
419 // Difference with an empty set. 444 // Difference with an empty set.
420 apis1.insert(ExtensionAPIPermission::kTab); 445 apis1.insert(ExtensionAPIPermission::kTab);
421 apis1.insert(ExtensionAPIPermission::kBackground); 446 apis1.insert(ExtensionAPIPermission::kBackground);
422 447
423 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 448 AddPattern(&explicit_hosts1, "http://*.google.com/*");
424 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); 449 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
425 450
426 set1 = new ExtensionPermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 451 scopes1.insert("my-scope");
427 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 452 scopes1.insert("other-scope");
453
454 set1 = new ExtensionPermissionSet(
455 apis1, explicit_hosts1, scriptable_hosts1, scopes1);
456 set2 = new ExtensionPermissionSet(
457 apis2, explicit_hosts2, scriptable_hosts2, scopes2);
428 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get()); 458 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get());
429 EXPECT_EQ(*set1, *new_set); 459 EXPECT_EQ(*set1, *new_set);
430 460
431 // Now use a real second set. 461 // Now use a real second set.
432 apis2.insert(ExtensionAPIPermission::kTab); 462 apis2.insert(ExtensionAPIPermission::kTab);
433 apis2.insert(ExtensionAPIPermission::kProxy); 463 apis2.insert(ExtensionAPIPermission::kProxy);
434 apis2.insert(ExtensionAPIPermission::kClipboardWrite); 464 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
435 apis2.insert(ExtensionAPIPermission::kPlugin); 465 apis2.insert(ExtensionAPIPermission::kPlugin);
436 expected_apis.insert(ExtensionAPIPermission::kBackground); 466 expected_apis.insert(ExtensionAPIPermission::kBackground);
437 467
438 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 468 AddPattern(&explicit_hosts2, "http://*.example.com/*");
439 AddPattern(&explicit_hosts2, "http://*.google.com/*"); 469 AddPattern(&explicit_hosts2, "http://*.google.com/*");
440 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 470 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
441 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); 471 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*");
442 472
473 scopes2.insert("other-scope");
474 expected_scopes.insert("my-scope");
475
443 effective_hosts.ClearPatterns(); 476 effective_hosts.ClearPatterns();
444 AddPattern(&effective_hosts, "http://www.reddit.com/*"); 477 AddPattern(&effective_hosts, "http://www.reddit.com/*");
445 478
446 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 479 set2 = new ExtensionPermissionSet(
480 apis2, explicit_hosts2, scriptable_hosts2, scopes2);
447 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get()); 481 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get());
448 482
449 EXPECT_TRUE(set1->Contains(*new_set)); 483 EXPECT_TRUE(set1->Contains(*new_set));
450 EXPECT_FALSE(set2->Contains(*new_set)); 484 EXPECT_FALSE(set2->Contains(*new_set));
451 485
452 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 486 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
453 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 487 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
454 EXPECT_EQ(expected_apis, new_set->apis()); 488 EXPECT_EQ(expected_apis, new_set->apis());
455 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 489 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
456 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 490 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
491 EXPECT_EQ(expected_scopes, new_set->scopes());
457 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 492 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
458 493
459 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set 494 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set
460 set1 = ExtensionPermissionSet::CreateIntersection(new_set.get(), set2.get()); 495 set1 = ExtensionPermissionSet::CreateIntersection(new_set.get(), set2.get());
461 EXPECT_TRUE(set1->IsEmpty()); 496 EXPECT_TRUE(set1->IsEmpty());
462 } 497 }
463 498
464 TEST(ExtensionPermissionsTest, HasLessPrivilegesThan) { 499 TEST(ExtensionPermissionsTest, HasLessPrivilegesThan) {
465 const struct { 500 const struct {
466 const char* base_name; 501 const char* base_name;
467 // Increase these sizes if you have more than 10.
468 const char* granted_apis[10];
Yoyo Zhou 2012/04/24 23:16:36 You pruned these because they were getting unmaint
jstritar 2012/04/24 23:33:34 They were no longer being used in the actual test
469 const char* granted_hosts[10];
470 bool full_access;
471 bool expect_increase; 502 bool expect_increase;
472 } kTests[] = { 503 } kTests[] = {
473 { "allhosts1", {NULL}, {"http://*/", NULL}, false, 504 { "allhosts1", false }, // all -> all
474 false }, // all -> all 505 { "allhosts2", false }, // all -> one
475 { "allhosts2", {NULL}, {"http://*/", NULL}, false, 506 { "allhosts3", true }, // one -> all
476 false }, // all -> one 507 { "hosts1", false }, // http://a,http://b -> http://a,http://b
477 { "allhosts3", {NULL}, {NULL}, false, true }, // one -> all 508 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b
478 { "hosts1", {NULL}, 509 { "hosts3", false }, // http://a,http://b -> http://a
479 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false, 510 { "hosts4", true }, // http://a -> http://a,http://b
480 false }, // http://a,http://b -> http://a,http://b 511 { "hosts5", false }, // http://a,b,c -> http://a,b,c + https://a,b,c
481 { "hosts2", {NULL}, 512 { "hosts6", false }, // http://a.com -> http://a.com + http://a.co.uk
482 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false, 513 { "permissions1", false }, // tabs -> tabs
483 true }, // http://a,http://b -> https://a,http://*.b 514 { "permissions2", true }, // tabs -> tabs,bookmarks
484 { "hosts3", {NULL}, 515 { "permissions3", true }, // http://a -> http://a,tabs
485 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false, 516 { "permissions5", true }, // bookmarks -> bookmarks,history
486 false }, // http://a,http://b -> http://a 517 { "equivalent_warnings", false }, // tabs --> tabs, webNavigation
487 { "hosts4", {NULL},
488 {"http://www.google.com/", NULL}, false,
489 true }, // http://a -> http://a,http://b
490 { "hosts5", {"tabs", "notifications", NULL},
491 {"http://*.example.com/", "http://*.example.com/*",
492 "http://*.example.co.uk/*", "http://*.example.com.au/*",
493 NULL}, false,
494 false }, // http://a,b,c -> http://a,b,c + https://a,b,c
495 { "hosts6", {"tabs", "notifications", NULL},
496 {"http://*.example.com/", "http://*.example.com/*", NULL}, false,
497 false }, // http://a.com -> http://a.com + http://a.co.uk
498 { "permissions1", {"tabs", NULL},
499 {NULL}, false, false }, // tabs -> tabs
500 { "permissions2", {"tabs", NULL},
501 {NULL}, false, true }, // tabs -> tabs,bookmarks
502 { "permissions3", {NULL},
503 {"http://*/*", NULL},
504 false, true }, // http://a -> http://a,tabs
505 { "permissions5", {"bookmarks", NULL},
506 {NULL}, false, true }, // bookmarks -> bookmarks,history
507 { "equivalent_warnings", {NULL}, {NULL},
508 false, false }, // tabs --> tabs, webNavigation
509 #if !defined(OS_CHROMEOS) // plugins aren't allowed in ChromeOS 518 #if !defined(OS_CHROMEOS) // plugins aren't allowed in ChromeOS
510 { "permissions4", {NULL}, 519 { "permissions4", false }, // plugin -> plugin,tabs
511 {NULL}, true, false }, // plugin -> plugin,tabs 520 { "plugin1", false }, // plugin -> plugin
512 { "plugin1", {NULL}, 521 { "plugin2", false }, // plugin -> none
513 {NULL}, true, false }, // plugin -> plugin 522 { "plugin3", true }, // none -> plugin
514 { "plugin2", {NULL},
515 {NULL}, true, false }, // plugin -> none
516 { "plugin3", {NULL},
517 {NULL}, false, true }, // none -> plugin
518 #endif 523 #endif
519 { "storage", {NULL}, 524 { "storage", false }, // none -> storage
520 {NULL}, false, false }, // none -> storage 525 { "notifications", false }, // none -> notifications
521 { "notifications", {NULL}, 526 { "scopes1", true }, // scope1 -> scope1,scope2
522 {NULL}, false, false } // none -> notifications 527 { "scopes2", false }, // scope1,scope2 -> scope1
528 { "scopes3", true }, // none -> scope1
523 }; 529 };
524 530
525 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 531 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps);
526 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 532 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
527 scoped_refptr<Extension> old_extension( 533 scoped_refptr<Extension> old_extension(
528 LoadManifest("allow_silent_upgrade", 534 LoadManifest("allow_silent_upgrade",
529 std::string(kTests[i].base_name) + "_old.json")); 535 std::string(kTests[i].base_name) + "_old.json"));
530 scoped_refptr<Extension> new_extension( 536 scoped_refptr<Extension> new_extension(
531 LoadManifest("allow_silent_upgrade", 537 LoadManifest("allow_silent_upgrade",
532 std::string(kTests[i].base_name) + "_new.json")); 538 std::string(kTests[i].base_name) + "_new.json"));
533 539
534 ExtensionAPIPermissionSet granted_apis;
535 for (size_t j = 0; kTests[i].granted_apis[j] != NULL; ++j) {
536 granted_apis.insert(info->GetByName(kTests[i].granted_apis[j])->id());
537 }
538
539 URLPatternSet granted_hosts;
540 for (size_t j = 0; kTests[i].granted_hosts[j] != NULL; ++j)
541 AddPattern(&granted_hosts, kTests[i].granted_hosts[j]);
542
543 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; 540 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json";
544 if (!new_extension.get()) 541 if (!new_extension.get())
545 continue; 542 continue;
546 543
547 scoped_refptr<const ExtensionPermissionSet> old_p( 544 scoped_refptr<const ExtensionPermissionSet> old_p(
548 old_extension->GetActivePermissions()); 545 old_extension->GetActivePermissions());
549 scoped_refptr<const ExtensionPermissionSet> new_p( 546 scoped_refptr<const ExtensionPermissionSet> new_p(
550 new_extension->GetActivePermissions()); 547 new_extension->GetActivePermissions());
551 548
552 EXPECT_EQ(kTests[i].expect_increase, 549 EXPECT_EQ(kTests[i].expect_increase,
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 AddPattern(&non_empty_extent, "http://www.google.com/*"); 1091 AddPattern(&non_empty_extent, "http://www.google.com/*");
1095 1092
1096 perm_set = new ExtensionPermissionSet( 1093 perm_set = new ExtensionPermissionSet(
1097 empty_apis, non_empty_extent, empty_extent); 1094 empty_apis, non_empty_extent, empty_extent);
1098 EXPECT_FALSE(perm_set->IsEmpty()); 1095 EXPECT_FALSE(perm_set->IsEmpty());
1099 1096
1100 perm_set = new ExtensionPermissionSet( 1097 perm_set = new ExtensionPermissionSet(
1101 empty_apis, empty_extent, non_empty_extent); 1098 empty_apis, empty_extent, non_empty_extent);
1102 EXPECT_FALSE(perm_set->IsEmpty()); 1099 EXPECT_FALSE(perm_set->IsEmpty());
1103 } 1100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698