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

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

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 for (size_t i = 0; i < expected.size(); ++i) { 51 for (size_t i = 0; i < expected.size(); ++i) {
52 EXPECT_EQ(expected[i], actual[i]); 52 EXPECT_EQ(expected[i], actual[i]);
53 } 53 }
54 } 54 }
55 55
56 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 56 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
57 int schemes = URLPattern::SCHEME_ALL; 57 int schemes = URLPattern::SCHEME_ALL;
58 extent->AddPattern(URLPattern(schemes, pattern)); 58 extent->AddPattern(URLPattern(schemes, pattern));
59 } 59 }
60 60
61 static void AssertEqualExtents(const URLPatternSet& extent1,
62 const URLPatternSet& extent2) {
63 URLPatternList patterns1 = extent1.patterns();
64 URLPatternList patterns2 = extent2.patterns();
65 std::set<std::string> strings1;
66 EXPECT_EQ(patterns1.size(), patterns2.size());
67
68 for (size_t i = 0; i < patterns1.size(); ++i)
69 strings1.insert(patterns1.at(i).GetAsString());
70
71 std::set<std::string> strings2;
72 for (size_t i = 0; i < patterns2.size(); ++i)
73 strings2.insert(patterns2.at(i).GetAsString());
74
75 EXPECT_EQ(strings1, strings2);
76 }
77
78 } // namespace 61 } // namespace
79 62
80 class ExtensionAPIPermissionTest : public testing::Test { 63 class ExtensionAPIPermissionTest : public testing::Test {
81 }; 64 };
82 65
83 class ExtensionPermissionSetTest : public testing::Test { 66 class ExtensionPermissionSetTest : public testing::Test {
84 }; 67 };
85 68
86 69
87 // Tests GetByID. 70 // Tests GetByID.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 AddPattern(&effective_hosts, "http://*.google.com/*"); 312 AddPattern(&effective_hosts, "http://*.google.com/*");
330 313
331 set1.reset(new ExtensionPermissionSet( 314 set1.reset(new ExtensionPermissionSet(
332 apis1, explicit_hosts1, scriptable_hosts1)); 315 apis1, explicit_hosts1, scriptable_hosts1));
333 set2.reset(new ExtensionPermissionSet( 316 set2.reset(new ExtensionPermissionSet(
334 apis2, explicit_hosts2, scriptable_hosts2)); 317 apis2, explicit_hosts2, scriptable_hosts2));
335 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get())); 318 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get()));
336 319
337 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); 320 EXPECT_FALSE(union_set->HasEffectiveFullAccess());
338 EXPECT_EQ(expected_apis, union_set->apis()); 321 EXPECT_EQ(expected_apis, union_set->apis());
339 AssertEqualExtents(expected_explicit_hosts, union_set->explicit_hosts()); 322 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
340 AssertEqualExtents(expected_scriptable_hosts, union_set->scriptable_hosts()); 323 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
341 AssertEqualExtents(expected_explicit_hosts, union_set->effective_hosts()); 324 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts());
342 325
343 // Now use a real second set. 326 // Now use a real second set.
344 apis2.insert(ExtensionAPIPermission::kTab); 327 apis2.insert(ExtensionAPIPermission::kTab);
345 apis2.insert(ExtensionAPIPermission::kProxy); 328 apis2.insert(ExtensionAPIPermission::kProxy);
346 apis2.insert(ExtensionAPIPermission::kClipboardWrite); 329 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
347 apis2.insert(ExtensionAPIPermission::kPlugin); 330 apis2.insert(ExtensionAPIPermission::kPlugin);
348 expected_apis.insert(ExtensionAPIPermission::kTab); 331 expected_apis.insert(ExtensionAPIPermission::kTab);
349 expected_apis.insert(ExtensionAPIPermission::kProxy); 332 expected_apis.insert(ExtensionAPIPermission::kProxy);
350 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite); 333 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite);
351 expected_apis.insert(ExtensionAPIPermission::kPlugin); 334 expected_apis.insert(ExtensionAPIPermission::kPlugin);
352 335
353 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 336 AddPattern(&explicit_hosts2, "http://*.example.com/*");
354 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 337 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
355 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); 338 AddPattern(&expected_explicit_hosts, "http://*.example.com/*");
356 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); 339 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*");
357 340
358 effective_hosts.ClearPatterns(); 341 effective_hosts.ClearPatterns();
359 AddPattern(&effective_hosts, "<all_urls>"); 342 AddPattern(&effective_hosts, "<all_urls>");
360 343
361 set2.reset(new ExtensionPermissionSet( 344 set2.reset(new ExtensionPermissionSet(
362 apis2, explicit_hosts2, scriptable_hosts2)); 345 apis2, explicit_hosts2, scriptable_hosts2));
363 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get())); 346 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get()));
364 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 347 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
365 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 348 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
366 EXPECT_EQ(expected_apis, union_set->apis()); 349 EXPECT_EQ(expected_apis, union_set->apis());
367 AssertEqualExtents(expected_explicit_hosts, union_set->explicit_hosts()); 350 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
368 AssertEqualExtents(expected_scriptable_hosts, union_set->scriptable_hosts()); 351 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
369 AssertEqualExtents(effective_hosts, union_set->effective_hosts()); 352 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
370 } 353 }
371 354
372 TEST(ExtensionPermissionSetTest, HasLessPrivilegesThan) { 355 TEST(ExtensionPermissionSetTest, HasLessPrivilegesThan) {
373 const struct { 356 const struct {
374 const char* base_name; 357 const char* base_name;
375 // Increase these sizes if you have more than 10. 358 // Increase these sizes if you have more than 10.
376 const char* granted_apis[10]; 359 const char* granted_apis[10];
377 const char* granted_hosts[10]; 360 const char* granted_hosts[10];
378 bool full_access; 361 bool full_access;
379 bool expect_increase; 362 bool expect_increase;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 540 }
558 } 541 }
559 542
560 TEST(ExtensionPermissionSetTest, GetWarningMessages_ManyHosts) { 543 TEST(ExtensionPermissionSetTest, GetWarningMessages_ManyHosts) {
561 scoped_refptr<Extension> extension; 544 scoped_refptr<Extension> extension;
562 545
563 extension = LoadManifest("permissions", "many-hosts.json"); 546 extension = LoadManifest("permissions", "many-hosts.json");
564 std::vector<string16> warnings = 547 std::vector<string16> warnings =
565 extension->permission_set()->GetWarningMessages(); 548 extension->permission_set()->GetWarningMessages();
566 ASSERT_EQ(1u, warnings.size()); 549 ASSERT_EQ(1u, warnings.size());
567 EXPECT_EQ("Your data on www.google.com and encrypted.google.com", 550 EXPECT_EQ("Your data on encrypted.google.com and www.google.com",
568 UTF16ToUTF8(warnings[0])); 551 UTF16ToUTF8(warnings[0]));
569 } 552 }
570 553
571 TEST(ExtensionPermissionSetTest, GetWarningMessages_Plugins) { 554 TEST(ExtensionPermissionSetTest, GetWarningMessages_Plugins) {
572 scoped_refptr<Extension> extension; 555 scoped_refptr<Extension> extension;
573 scoped_ptr<ExtensionPermissionSet> permissions; 556 scoped_ptr<ExtensionPermissionSet> permissions;
574 557
575 extension = LoadManifest("permissions", "plugins.json"); 558 extension = LoadManifest("permissions", "plugins.json");
576 std::vector<string16> warnings = 559 std::vector<string16> warnings =
577 extension->permission_set()->GetWarningMessages(); 560 extension->permission_set()->GetWarningMessages();
578 // We don't parse the plugins key on Chrome OS, so it should not ask for any 561 // We don't parse the plugins key on Chrome OS, so it should not ask for any
579 // permissions. 562 // permissions.
580 #if defined(OS_CHROMEOS) 563 #if defined(OS_CHROMEOS)
581 ASSERT_EQ(0u, warnings.size()); 564 ASSERT_EQ(0u, warnings.size());
582 #else 565 #else
583 ASSERT_EQ(1u, warnings.size()); 566 ASSERT_EQ(1u, warnings.size());
584 EXPECT_EQ("All data on your computer and the websites you visit", 567 EXPECT_EQ("All data on your computer and the websites you visit",
585 UTF16ToUTF8(warnings[0])); 568 UTF16ToUTF8(warnings[0]));
586 #endif 569 #endif
587 } 570 }
588 571
589 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { 572 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) {
590 scoped_ptr<ExtensionPermissionSet> perm_set; 573 scoped_ptr<ExtensionPermissionSet> perm_set;
591 ExtensionAPIPermissionSet empty_perms; 574 ExtensionAPIPermissionSet empty_perms;
592 std::vector<std::string> expected; 575 std::set<std::string> expected;
593 expected.push_back("www.foo.com"); 576 expected.insert("www.foo.com");
594 expected.push_back("www.bar.com"); 577 expected.insert("www.bar.com");
595 expected.push_back("www.baz.com"); 578 expected.insert("www.baz.com");
596 URLPatternSet explicit_hosts; 579 URLPatternSet explicit_hosts;
597 URLPatternSet scriptable_hosts; 580 URLPatternSet scriptable_hosts;
598 581
599 { 582 {
600 SCOPED_TRACE("no dupes"); 583 SCOPED_TRACE("no dupes");
601 584
602 // Simple list with no dupes. 585 // Simple list with no dupes.
603 explicit_hosts.AddPattern( 586 explicit_hosts.AddPattern(
604 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 587 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
605 explicit_hosts.AddPattern( 588 explicit_hosts.AddPattern(
606 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); 589 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path"));
607 explicit_hosts.AddPattern( 590 explicit_hosts.AddPattern(
608 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); 591 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
609 perm_set.reset(new ExtensionPermissionSet( 592 perm_set.reset(new ExtensionPermissionSet(
610 empty_perms, explicit_hosts, scriptable_hosts)); 593 empty_perms, explicit_hosts, scriptable_hosts));
611 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 594 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
612 } 595 }
613 596
614 { 597 {
615 SCOPED_TRACE("two dupes"); 598 SCOPED_TRACE("two dupes");
616 599
617 // Add some dupes. 600 // Add some dupes.
618 explicit_hosts.AddPattern( 601 explicit_hosts.AddPattern(
619 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 602 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
620 explicit_hosts.AddPattern( 603 explicit_hosts.AddPattern(
621 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); 604 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
622 perm_set.reset(new ExtensionPermissionSet( 605 perm_set.reset(new ExtensionPermissionSet(
623 empty_perms, explicit_hosts, scriptable_hosts)); 606 empty_perms, explicit_hosts, scriptable_hosts));
624 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 607 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
625 } 608 }
626 609
627 { 610 {
628 SCOPED_TRACE("schemes differ"); 611 SCOPED_TRACE("schemes differ");
629 612
630 // Add a pattern that differs only by scheme. This should be filtered out. 613 // Add a pattern that differs only by scheme. This should be filtered out.
631 explicit_hosts.AddPattern( 614 explicit_hosts.AddPattern(
632 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); 615 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path"));
633 perm_set.reset(new ExtensionPermissionSet( 616 perm_set.reset(new ExtensionPermissionSet(
634 empty_perms, explicit_hosts, scriptable_hosts)); 617 empty_perms, explicit_hosts, scriptable_hosts));
635 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 618 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
636 } 619 }
637 620
638 { 621 {
639 SCOPED_TRACE("paths differ"); 622 SCOPED_TRACE("paths differ");
640 623
641 // Add some dupes by path. 624 // Add some dupes by path.
642 explicit_hosts.AddPattern( 625 explicit_hosts.AddPattern(
643 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); 626 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath"));
644 perm_set.reset(new ExtensionPermissionSet( 627 perm_set.reset(new ExtensionPermissionSet(
645 empty_perms, explicit_hosts, scriptable_hosts)); 628 empty_perms, explicit_hosts, scriptable_hosts));
646 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 629 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
647 } 630 }
648 631
649 { 632 {
650 SCOPED_TRACE("subdomains differ"); 633 SCOPED_TRACE("subdomains differ");
651 634
652 // We don't do anything special for subdomains. 635 // We don't do anything special for subdomains.
653 explicit_hosts.AddPattern( 636 explicit_hosts.AddPattern(
654 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); 637 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path"));
655 explicit_hosts.AddPattern( 638 explicit_hosts.AddPattern(
656 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); 639 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path"));
657 640
658 expected.push_back("monkey.www.bar.com"); 641 expected.insert("monkey.www.bar.com");
659 expected.push_back("bar.com"); 642 expected.insert("bar.com");
660 643
661 perm_set.reset(new ExtensionPermissionSet( 644 perm_set.reset(new ExtensionPermissionSet(
662 empty_perms, explicit_hosts, scriptable_hosts)); 645 empty_perms, explicit_hosts, scriptable_hosts));
663 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 646 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
664 } 647 }
665 648
666 { 649 {
667 SCOPED_TRACE("RCDs differ"); 650 SCOPED_TRACE("RCDs differ");
668 651
669 // Now test for RCD uniquing. 652 // Now test for RCD uniquing.
670 explicit_hosts.AddPattern( 653 explicit_hosts.AddPattern(
671 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 654 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
672 explicit_hosts.AddPattern( 655 explicit_hosts.AddPattern(
673 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 656 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
674 explicit_hosts.AddPattern( 657 explicit_hosts.AddPattern(
675 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); 658 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path"));
676 explicit_hosts.AddPattern( 659 explicit_hosts.AddPattern(
677 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); 660 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path"));
678 explicit_hosts.AddPattern( 661 explicit_hosts.AddPattern(
679 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 662 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
680 explicit_hosts.AddPattern( 663 explicit_hosts.AddPattern(
681 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); 664 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path"));
682 665
683 // This is an unknown RCD, which shouldn't be uniqued out. 666 // This is an unknown RCD, which shouldn't be uniqued out.
684 explicit_hosts.AddPattern( 667 explicit_hosts.AddPattern(
685 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); 668 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
686 // But it should only occur once. 669 // But it should only occur once.
687 explicit_hosts.AddPattern( 670 explicit_hosts.AddPattern(
688 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); 671 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
689 672
690 expected.push_back("www.foo.xyzzy"); 673 expected.insert("www.foo.xyzzy");
691 674
692 perm_set.reset(new ExtensionPermissionSet( 675 perm_set.reset(new ExtensionPermissionSet(
693 empty_perms, explicit_hosts, scriptable_hosts)); 676 empty_perms, explicit_hosts, scriptable_hosts));
694 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 677 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
695 } 678 }
696 679
697 { 680 {
698 SCOPED_TRACE("wildcards"); 681 SCOPED_TRACE("wildcards");
699 682
700 explicit_hosts.AddPattern( 683 explicit_hosts.AddPattern(
701 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); 684 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
702 685
703 expected.push_back("*.google.com"); 686 expected.insert("*.google.com");
704 687
705 perm_set.reset(new ExtensionPermissionSet( 688 perm_set.reset(new ExtensionPermissionSet(
706 empty_perms, explicit_hosts, scriptable_hosts)); 689 empty_perms, explicit_hosts, scriptable_hosts));
707 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 690 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
708 } 691 }
709 692
710 { 693 {
711 SCOPED_TRACE("scriptable hosts"); 694 SCOPED_TRACE("scriptable hosts");
712 explicit_hosts.ClearPatterns(); 695 explicit_hosts.ClearPatterns();
713 scriptable_hosts.ClearPatterns(); 696 scriptable_hosts.ClearPatterns();
714 expected.clear(); 697 expected.clear();
715 698
716 explicit_hosts.AddPattern( 699 explicit_hosts.AddPattern(
717 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); 700 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
718 scriptable_hosts.AddPattern( 701 scriptable_hosts.AddPattern(
719 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); 702 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*"));
720 703
721 expected.push_back("*.google.com"); 704 expected.insert("*.google.com");
722 expected.push_back("*.example.com"); 705 expected.insert("*.example.com");
723 706
724 perm_set.reset(new ExtensionPermissionSet( 707 perm_set.reset(new ExtensionPermissionSet(
725 empty_perms, explicit_hosts, scriptable_hosts)); 708 empty_perms, explicit_hosts, scriptable_hosts));
726 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 709 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
727 } 710 }
728 } 711 }
729 712
730 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_ComIsBestRcd) { 713 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
731 scoped_ptr<ExtensionPermissionSet> perm_set; 714 scoped_ptr<ExtensionPermissionSet> perm_set;
732 ExtensionAPIPermissionSet empty_perms; 715 ExtensionAPIPermissionSet empty_perms;
733 URLPatternSet explicit_hosts; 716 URLPatternSet explicit_hosts;
734 URLPatternSet scriptable_hosts; 717 URLPatternSet scriptable_hosts;
735 explicit_hosts.AddPattern( 718 explicit_hosts.AddPattern(
736 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 719 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
737 explicit_hosts.AddPattern( 720 explicit_hosts.AddPattern(
738 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 721 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
739 explicit_hosts.AddPattern( 722 explicit_hosts.AddPattern(
740 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 723 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
741 explicit_hosts.AddPattern( 724 explicit_hosts.AddPattern(
742 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 725 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
743 explicit_hosts.AddPattern( 726 explicit_hosts.AddPattern(
744 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 727 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
745 explicit_hosts.AddPattern( 728 explicit_hosts.AddPattern(
746 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 729 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
747 730
748 std::vector<std::string> expected; 731 std::set<std::string> expected;
749 expected.push_back("www.foo.com"); 732 expected.insert("www.foo.com");
750 perm_set.reset(new ExtensionPermissionSet( 733 perm_set.reset(new ExtensionPermissionSet(
751 empty_perms, explicit_hosts, scriptable_hosts)); 734 empty_perms, explicit_hosts, scriptable_hosts));
752 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 735 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
753 } 736 }
754 737
755 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { 738 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
756 scoped_ptr<ExtensionPermissionSet> perm_set; 739 scoped_ptr<ExtensionPermissionSet> perm_set;
757 ExtensionAPIPermissionSet empty_perms; 740 ExtensionAPIPermissionSet empty_perms;
758 URLPatternSet explicit_hosts; 741 URLPatternSet explicit_hosts;
759 URLPatternSet scriptable_hosts; 742 URLPatternSet scriptable_hosts;
760 explicit_hosts.AddPattern( 743 explicit_hosts.AddPattern(
761 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 744 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
762 explicit_hosts.AddPattern( 745 explicit_hosts.AddPattern(
763 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 746 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
764 explicit_hosts.AddPattern( 747 explicit_hosts.AddPattern(
765 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 748 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
766 explicit_hosts.AddPattern( 749 explicit_hosts.AddPattern(
767 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 750 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
768 explicit_hosts.AddPattern( 751 explicit_hosts.AddPattern(
769 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 752 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
770 // No http://www.foo.com/path 753 // No http://www.foo.com/path
771 754
772 std::vector<std::string> expected; 755 std::set<std::string> expected;
773 expected.push_back("www.foo.net"); 756 expected.insert("www.foo.net");
774 perm_set.reset(new ExtensionPermissionSet( 757 perm_set.reset(new ExtensionPermissionSet(
775 empty_perms, explicit_hosts, scriptable_hosts)); 758 empty_perms, explicit_hosts, scriptable_hosts));
776 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 759 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
777 } 760 }
778 761
779 TEST(ExtensionPermissionSetTest, 762 TEST(ExtensionPermissionSetTest,
780 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) { 763 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) {
781 scoped_ptr<ExtensionPermissionSet> perm_set; 764 scoped_ptr<ExtensionPermissionSet> perm_set;
782 ExtensionAPIPermissionSet empty_perms; 765 ExtensionAPIPermissionSet empty_perms;
783 URLPatternSet explicit_hosts; 766 URLPatternSet explicit_hosts;
784 URLPatternSet scriptable_hosts; 767 URLPatternSet scriptable_hosts;
785 explicit_hosts.AddPattern( 768 explicit_hosts.AddPattern(
786 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 769 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
787 explicit_hosts.AddPattern( 770 explicit_hosts.AddPattern(
788 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 771 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
789 explicit_hosts.AddPattern( 772 explicit_hosts.AddPattern(
790 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 773 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
791 // No http://www.foo.net/path 774 // No http://www.foo.net/path
792 explicit_hosts.AddPattern( 775 explicit_hosts.AddPattern(
793 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 776 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
794 // No http://www.foo.com/path 777 // No http://www.foo.com/path
795 778
796 std::vector<std::string> expected; 779 std::set<std::string> expected;
797 expected.push_back("www.foo.org"); 780 expected.insert("www.foo.org");
798 perm_set.reset(new ExtensionPermissionSet( 781 perm_set.reset(new ExtensionPermissionSet(
799 empty_perms, explicit_hosts, scriptable_hosts)); 782 empty_perms, explicit_hosts, scriptable_hosts));
800 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 783 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
801 } 784 }
802 785
803 TEST(ExtensionPermissionSetTest, 786 TEST(ExtensionPermissionSetTest,
804 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) { 787 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) {
805 scoped_ptr<ExtensionPermissionSet> perm_set; 788 scoped_ptr<ExtensionPermissionSet> perm_set;
806 ExtensionAPIPermissionSet empty_perms; 789 ExtensionAPIPermissionSet empty_perms;
807 URLPatternSet explicit_hosts; 790 URLPatternSet explicit_hosts;
808 URLPatternSet scriptable_hosts; 791 URLPatternSet scriptable_hosts;
809 explicit_hosts.AddPattern( 792 explicit_hosts.AddPattern(
810 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 793 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
811 // No http://www.foo.org/path 794 // No http://www.foo.org/path
812 explicit_hosts.AddPattern( 795 explicit_hosts.AddPattern(
813 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 796 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
814 // No http://www.foo.net/path 797 // No http://www.foo.net/path
815 explicit_hosts.AddPattern( 798 explicit_hosts.AddPattern(
816 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 799 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
817 // No http://www.foo.com/path 800 // No http://www.foo.com/path
818 801
819 std::vector<std::string> expected; 802 std::set<std::string> expected;
820 expected.push_back("www.foo.ca"); 803 expected.insert("www.foo.ca");
821 perm_set.reset(new ExtensionPermissionSet( 804 perm_set.reset(new ExtensionPermissionSet(
822 empty_perms, explicit_hosts, scriptable_hosts)); 805 empty_perms, explicit_hosts, scriptable_hosts));
823 CompareLists(expected, perm_set->GetDistinctHostsForDisplay()); 806 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
824 } 807 }
825 808
826 TEST(ExtensionPermissionSetTest, HasLessHostPrivilegesThan) { 809 TEST(ExtensionPermissionSetTest, HasLessHostPrivilegesThan) {
827 URLPatternSet elist1; 810 URLPatternSet elist1;
828 URLPatternSet elist2; 811 URLPatternSet elist2;
829 URLPatternSet slist1; 812 URLPatternSet slist1;
830 URLPatternSet slist2; 813 URLPatternSet slist2;
831 scoped_ptr<ExtensionPermissionSet> set1; 814 scoped_ptr<ExtensionPermissionSet> set1;
832 scoped_ptr<ExtensionPermissionSet> set2; 815 scoped_ptr<ExtensionPermissionSet> set2;
833 ExtensionAPIPermissionSet empty_perms; 816 ExtensionAPIPermissionSet empty_perms;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 AddPattern(&non_empty_extent, "http://www.google.com/*"); 915 AddPattern(&non_empty_extent, "http://www.google.com/*");
933 916
934 perm_set = ExtensionPermissionSet( 917 perm_set = ExtensionPermissionSet(
935 empty_apis, non_empty_extent, empty_extent); 918 empty_apis, non_empty_extent, empty_extent);
936 EXPECT_FALSE(perm_set.IsEmpty()); 919 EXPECT_FALSE(perm_set.IsEmpty());
937 920
938 perm_set = ExtensionPermissionSet( 921 perm_set = ExtensionPermissionSet(
939 empty_apis, empty_extent, non_empty_extent); 922 empty_apis, empty_extent, non_empty_extent);
940 EXPECT_FALSE(perm_set.IsEmpty()); 923 EXPECT_FALSE(perm_set.IsEmpty());
941 } 924 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_permission_set.cc ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698