OLD | NEW |
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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 std::string error; | 38 std::string error; |
39 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error)); | 39 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error)); |
40 if (!result.get()) { | 40 if (!result.get()) { |
41 EXPECT_EQ("", error); | 41 EXPECT_EQ("", error); |
42 return NULL; | 42 return NULL; |
43 } | 43 } |
44 | 44 |
45 scoped_refptr<Extension> extension = Extension::Create( | 45 scoped_refptr<Extension> extension = Extension::Create( |
46 path.DirName(), Extension::INVALID, | 46 path.DirName(), Extension::INVALID, |
47 *static_cast<DictionaryValue*>(result.get()), extra_flags, &error); | 47 *static_cast<DictionaryValue*>(result.get()), extra_flags, &error); |
48 EXPECT_TRUE(extension) << error; | 48 EXPECT_TRUE(extension.get()) << error; |
49 return extension; | 49 return extension; |
50 } | 50 } |
51 | 51 |
52 scoped_refptr<Extension> LoadManifest(const std::string& dir, | 52 scoped_refptr<Extension> LoadManifest(const std::string& dir, |
53 const std::string& test_file) { | 53 const std::string& test_file) { |
54 return LoadManifest(dir, test_file, Extension::NO_FLAGS); | 54 return LoadManifest(dir, test_file, Extension::NO_FLAGS); |
55 } | 55 } |
56 | 56 |
57 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 57 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
58 int schemes = URLPattern::SCHEME_ALL; | 58 int schemes = URLPattern::SCHEME_ALL; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 expected_apis.insert(APIPermission::kBackground); | 294 expected_apis.insert(APIPermission::kBackground); |
295 expected_apis.insert(permission); | 295 expected_apis.insert(permission); |
296 | 296 |
297 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 297 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
298 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 298 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
299 AddPattern(&effective_hosts, "http://*.google.com/*"); | 299 AddPattern(&effective_hosts, "http://*.google.com/*"); |
300 | 300 |
301 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 301 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
302 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 302 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
303 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 303 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
304 EXPECT_TRUE(set1->Contains(*set2)); | 304 EXPECT_TRUE(set1->Contains(*set2.get())); |
305 EXPECT_TRUE(set1->Contains(*union_set)); | 305 EXPECT_TRUE(set1->Contains(*union_set.get())); |
306 EXPECT_FALSE(set2->Contains(*set1)); | 306 EXPECT_FALSE(set2->Contains(*set1.get())); |
307 EXPECT_FALSE(set2->Contains(*union_set)); | 307 EXPECT_FALSE(set2->Contains(*union_set.get())); |
308 EXPECT_TRUE(union_set->Contains(*set1)); | 308 EXPECT_TRUE(union_set->Contains(*set1.get())); |
309 EXPECT_TRUE(union_set->Contains(*set2)); | 309 EXPECT_TRUE(union_set->Contains(*set2.get())); |
310 | 310 |
311 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); | 311 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); |
312 EXPECT_EQ(expected_apis, union_set->apis()); | 312 EXPECT_EQ(expected_apis, union_set->apis()); |
313 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 313 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
314 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 314 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
315 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); | 315 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); |
316 | 316 |
317 // Now use a real second set. | 317 // Now use a real second set. |
318 apis2.insert(APIPermission::kTab); | 318 apis2.insert(APIPermission::kTab); |
319 apis2.insert(APIPermission::kProxy); | 319 apis2.insert(APIPermission::kProxy); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 354 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
355 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); | 355 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); |
356 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); | 356 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); |
357 | 357 |
358 URLPatternSet::CreateUnion( | 358 URLPatternSet::CreateUnion( |
359 explicit_hosts2, scriptable_hosts2, &effective_hosts); | 359 explicit_hosts2, scriptable_hosts2, &effective_hosts); |
360 | 360 |
361 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 361 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
362 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 362 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
363 | 363 |
364 EXPECT_FALSE(set1->Contains(*set2)); | 364 EXPECT_FALSE(set1->Contains(*set2.get())); |
365 EXPECT_FALSE(set1->Contains(*union_set)); | 365 EXPECT_FALSE(set1->Contains(*union_set.get())); |
366 EXPECT_FALSE(set2->Contains(*set1)); | 366 EXPECT_FALSE(set2->Contains(*set1.get())); |
367 EXPECT_FALSE(set2->Contains(*union_set)); | 367 EXPECT_FALSE(set2->Contains(*union_set.get())); |
368 EXPECT_TRUE(union_set->Contains(*set1)); | 368 EXPECT_TRUE(union_set->Contains(*set1.get())); |
369 EXPECT_TRUE(union_set->Contains(*set2)); | 369 EXPECT_TRUE(union_set->Contains(*set2.get())); |
370 | 370 |
371 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); | 371 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); |
372 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); | 372 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); |
373 EXPECT_EQ(expected_apis, union_set->apis()); | 373 EXPECT_EQ(expected_apis, union_set->apis()); |
374 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 374 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
375 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 375 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
376 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); | 376 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); |
377 } | 377 } |
378 | 378 |
379 TEST(PermissionsTest, CreateIntersection) { | 379 TEST(PermissionsTest, CreateIntersection) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 } | 415 } |
416 apis1.insert(permission); | 416 apis1.insert(permission); |
417 | 417 |
418 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 418 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
419 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 419 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
420 | 420 |
421 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 421 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
422 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 422 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
423 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 423 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
424 EXPECT_TRUE(set1->Contains(*new_set)); | 424 EXPECT_TRUE(set1->Contains(*new_set.get())); |
425 EXPECT_TRUE(set2->Contains(*new_set)); | 425 EXPECT_TRUE(set2->Contains(*new_set.get())); |
426 EXPECT_TRUE(set1->Contains(*set2)); | 426 EXPECT_TRUE(set1->Contains(*set2.get())); |
427 EXPECT_FALSE(set2->Contains(*set1)); | 427 EXPECT_FALSE(set2->Contains(*set1.get())); |
428 EXPECT_FALSE(new_set->Contains(*set1)); | 428 EXPECT_FALSE(new_set->Contains(*set1.get())); |
429 EXPECT_TRUE(new_set->Contains(*set2)); | 429 EXPECT_TRUE(new_set->Contains(*set2.get())); |
430 | 430 |
431 EXPECT_TRUE(new_set->IsEmpty()); | 431 EXPECT_TRUE(new_set->IsEmpty()); |
432 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 432 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
433 EXPECT_EQ(expected_apis, new_set->apis()); | 433 EXPECT_EQ(expected_apis, new_set->apis()); |
434 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 434 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
435 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 435 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
436 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); | 436 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); |
437 | 437 |
438 // Now use a real second set. | 438 // Now use a real second set. |
439 apis2.insert(APIPermission::kTab); | 439 apis2.insert(APIPermission::kTab); |
(...skipping 28 matching lines...) Expand all Loading... |
468 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 468 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
469 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 469 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
470 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 470 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
471 | 471 |
472 effective_hosts.ClearPatterns(); | 472 effective_hosts.ClearPatterns(); |
473 AddPattern(&effective_hosts, "http://*.google.com/*"); | 473 AddPattern(&effective_hosts, "http://*.google.com/*"); |
474 | 474 |
475 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 475 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
476 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 476 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
477 | 477 |
478 EXPECT_TRUE(set1->Contains(*new_set)); | 478 EXPECT_TRUE(set1->Contains(*new_set.get())); |
479 EXPECT_TRUE(set2->Contains(*new_set)); | 479 EXPECT_TRUE(set2->Contains(*new_set.get())); |
480 EXPECT_FALSE(set1->Contains(*set2)); | 480 EXPECT_FALSE(set1->Contains(*set2.get())); |
481 EXPECT_FALSE(set2->Contains(*set1)); | 481 EXPECT_FALSE(set2->Contains(*set1.get())); |
482 EXPECT_FALSE(new_set->Contains(*set1)); | 482 EXPECT_FALSE(new_set->Contains(*set1.get())); |
483 EXPECT_FALSE(new_set->Contains(*set2)); | 483 EXPECT_FALSE(new_set->Contains(*set2.get())); |
484 | 484 |
485 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 485 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
486 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 486 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
487 EXPECT_EQ(expected_apis, new_set->apis()); | 487 EXPECT_EQ(expected_apis, new_set->apis()); |
488 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 488 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
489 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 489 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
490 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 490 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
491 } | 491 } |
492 | 492 |
493 TEST(PermissionsTest, CreateDifference) { | 493 TEST(PermissionsTest, CreateDifference) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 528 } |
529 } | 529 } |
530 apis1.insert(permission); | 530 apis1.insert(permission); |
531 | 531 |
532 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 532 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
533 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 533 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
534 | 534 |
535 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 535 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
536 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 536 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
537 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 537 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
538 EXPECT_EQ(*set1, *new_set); | 538 EXPECT_EQ(*set1.get(), *new_set.get()); |
539 | 539 |
540 // Now use a real second set. | 540 // Now use a real second set. |
541 apis2.insert(APIPermission::kTab); | 541 apis2.insert(APIPermission::kTab); |
542 apis2.insert(APIPermission::kProxy); | 542 apis2.insert(APIPermission::kProxy); |
543 apis2.insert(APIPermission::kClipboardWrite); | 543 apis2.insert(APIPermission::kClipboardWrite); |
544 apis2.insert(APIPermission::kPlugin); | 544 apis2.insert(APIPermission::kPlugin); |
545 permission = permission_info->CreateAPIPermission(); | 545 permission = permission_info->CreateAPIPermission(); |
546 { | 546 { |
547 scoped_ptr<ListValue> value(new ListValue()); | 547 scoped_ptr<ListValue> value(new ListValue()); |
548 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); | 548 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
(...skipping 20 matching lines...) Expand all Loading... |
569 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 569 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
570 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 570 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
571 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); | 571 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); |
572 | 572 |
573 effective_hosts.ClearPatterns(); | 573 effective_hosts.ClearPatterns(); |
574 AddPattern(&effective_hosts, "http://www.reddit.com/*"); | 574 AddPattern(&effective_hosts, "http://www.reddit.com/*"); |
575 | 575 |
576 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 576 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
577 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 577 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
578 | 578 |
579 EXPECT_TRUE(set1->Contains(*new_set)); | 579 EXPECT_TRUE(set1->Contains(*new_set.get())); |
580 EXPECT_FALSE(set2->Contains(*new_set)); | 580 EXPECT_FALSE(set2->Contains(*new_set.get())); |
581 | 581 |
582 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 582 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
583 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 583 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
584 EXPECT_EQ(expected_apis, new_set->apis()); | 584 EXPECT_EQ(expected_apis, new_set->apis()); |
585 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 585 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
586 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 586 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
587 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 587 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
588 | 588 |
589 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set | 589 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set |
590 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); | 590 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; | 631 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; |
632 if (!new_extension.get()) | 632 if (!new_extension.get()) |
633 continue; | 633 continue; |
634 | 634 |
635 scoped_refptr<const PermissionSet> old_p( | 635 scoped_refptr<const PermissionSet> old_p( |
636 old_extension->GetActivePermissions()); | 636 old_extension->GetActivePermissions()); |
637 scoped_refptr<const PermissionSet> new_p( | 637 scoped_refptr<const PermissionSet> new_p( |
638 new_extension->GetActivePermissions()); | 638 new_extension->GetActivePermissions()); |
639 | 639 |
640 EXPECT_EQ(kTests[i].expect_increase, | 640 EXPECT_EQ(kTests[i].expect_increase, |
641 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name; | 641 old_p->HasLessPrivilegesThan(new_p.get())) << kTests[i].base_name; |
642 } | 642 } |
643 } | 643 } |
644 | 644 |
645 TEST(PermissionsTest, PermissionMessages) { | 645 TEST(PermissionsTest, PermissionMessages) { |
646 // Ensure that all permissions that needs to show install UI actually have | 646 // Ensure that all permissions that needs to show install UI actually have |
647 // strings associated with them. | 647 // strings associated with them. |
648 APIPermissionSet skip; | 648 APIPermissionSet skip; |
649 | 649 |
650 // These are considered "nuisance" or "trivial" permissions that don't need | 650 // These are considered "nuisance" or "trivial" permissions that don't need |
651 // a prompt. | 651 // a prompt. |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 apis.insert(APIPermission::kWebRequest); | 1341 apis.insert(APIPermission::kWebRequest); |
1342 apis.insert(APIPermission::kFileBrowserHandler); | 1342 apis.insert(APIPermission::kFileBrowserHandler); |
1343 EXPECT_EQ(2U, apis.size()); | 1343 EXPECT_EQ(2U, apis.size()); |
1344 | 1344 |
1345 scoped_refptr<PermissionSet> perm_set; | 1345 scoped_refptr<PermissionSet> perm_set; |
1346 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1346 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
1347 EXPECT_EQ(4U, perm_set->apis().size()); | 1347 EXPECT_EQ(4U, perm_set->apis().size()); |
1348 } | 1348 } |
1349 | 1349 |
1350 } // namespace extensions | 1350 } // namespace extensions |
OLD | NEW |