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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 }; | 658 }; |
659 | 659 |
660 scoped_refptr<PermissionSet> empty = new PermissionSet(); | 660 scoped_refptr<PermissionSet> empty = new PermissionSet(); |
661 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 661 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
662 EXPECT_EQ(kTests[i].expect_success, | 662 EXPECT_EQ(kTests[i].expect_success, |
663 empty->HasAccessToFunction(kTests[i].permission_name)); | 663 empty->HasAccessToFunction(kTests[i].permission_name)); |
664 } | 664 } |
665 } | 665 } |
666 | 666 |
667 // Tests the default permissions (empty API permission set). | 667 // Tests the default permissions (empty API permission set). |
668 TEST(PermissionSetTest, DefaultAnyAPIAccess) { | 668 TEST(PermissionsTest, DefaultAnyAPIAccess) { |
669 const struct { | 669 const struct { |
670 const char* api_name; | 670 const char* api_name; |
671 bool expect_success; | 671 bool expect_success; |
672 } kTests[] = { | 672 } kTests[] = { |
673 // Negative test. | 673 // Negative test. |
674 { "non_existing_permission", false }, | 674 { "non_existing_permission", false }, |
675 // Test default module/package permission. | 675 // Test default module/package permission. |
676 { "browserAction", true }, | 676 { "browserAction", true }, |
677 { "devtools", true }, | 677 { "devtools", true }, |
678 { "extension", true }, | 678 { "extension", true }, |
(...skipping 14 matching lines...) Expand all Loading... |
693 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 693 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
694 EXPECT_EQ(kTests[i].expect_success, | 694 EXPECT_EQ(kTests[i].expect_success, |
695 empty->HasAnyAccessToAPI(kTests[i].api_name)); | 695 empty->HasAnyAccessToAPI(kTests[i].api_name)); |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { | 699 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { |
700 scoped_refptr<Extension> extension; | 700 scoped_refptr<Extension> extension; |
701 | 701 |
702 extension = LoadManifest("permissions", "many-hosts.json"); | 702 extension = LoadManifest("permissions", "many-hosts.json"); |
703 std::vector<string16> warnings = | 703 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
704 extension->GetActivePermissions()->GetWarningMessages(); | |
705 ASSERT_EQ(1u, warnings.size()); | 704 ASSERT_EQ(1u, warnings.size()); |
706 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", | 705 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", |
707 UTF16ToUTF8(warnings[0])); | 706 UTF16ToUTF8(warnings[0])); |
708 } | 707 } |
709 | 708 |
710 TEST(PermissionsTest, GetWarningMessages_Plugins) { | 709 TEST(PermissionsTest, GetWarningMessages_Plugins) { |
711 scoped_refptr<Extension> extension; | 710 scoped_refptr<Extension> extension; |
712 scoped_refptr<PermissionSet> permissions; | 711 scoped_refptr<PermissionSet> permissions; |
713 | 712 |
714 extension = LoadManifest("permissions", "plugins.json"); | 713 extension = LoadManifest("permissions", "plugins.json"); |
715 std::vector<string16> warnings = | 714 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
716 extension->GetActivePermissions()->GetWarningMessages(); | |
717 // We don't parse the plugins key on Chrome OS, so it should not ask for any | 715 // We don't parse the plugins key on Chrome OS, so it should not ask for any |
718 // permissions. | 716 // permissions. |
719 #if defined(OS_CHROMEOS) | 717 #if defined(OS_CHROMEOS) |
720 ASSERT_EQ(0u, warnings.size()); | 718 ASSERT_EQ(0u, warnings.size()); |
721 #else | 719 #else |
722 ASSERT_EQ(1u, warnings.size()); | 720 ASSERT_EQ(1u, warnings.size()); |
723 EXPECT_EQ("Access all data on your computer and the websites you visit", | 721 EXPECT_EQ("Access all data on your computer and the websites you visit", |
724 UTF16ToUTF8(warnings[0])); | 722 UTF16ToUTF8(warnings[0])); |
725 #endif | 723 #endif |
726 } | 724 } |
727 | 725 |
728 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { | 726 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
729 // Both audio and video present. | 727 // Both audio and video present. |
730 scoped_refptr<Extension> extension = | 728 scoped_refptr<Extension> extension = |
731 LoadManifest("permissions", "audio-video.json"); | 729 LoadManifest("permissions", "audio-video.json"); |
732 PermissionSet* set = | 730 PermissionSet* set = |
733 const_cast<PermissionSet*>( | 731 const_cast<PermissionSet*>( |
734 extension->GetActivePermissions().get()); | 732 extension->GetActivePermissions().get()); |
735 std::vector<string16> warnings = set->GetWarningMessages(); | 733 std::vector<string16> warnings = |
| 734 set->GetWarningMessages(extension->GetType()); |
736 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 735 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
737 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 736 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
738 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); | 737 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); |
739 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); | 738 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); |
740 size_t combined_size = warnings.size(); | 739 size_t combined_size = warnings.size(); |
741 | 740 |
742 // Just audio present. | 741 // Just audio present. |
743 set->apis_.erase(APIPermission::kVideoCapture); | 742 set->apis_.erase(APIPermission::kVideoCapture); |
744 warnings = set->GetWarningMessages(); | 743 warnings = set->GetWarningMessages(extension->GetType()); |
745 EXPECT_EQ(combined_size, warnings.size()); | 744 EXPECT_EQ(combined_size, warnings.size()); |
746 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); | 745 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); |
747 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 746 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
748 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 747 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
749 | 748 |
750 // Just video present. | 749 // Just video present. |
751 set->apis_.erase(APIPermission::kAudioCapture); | 750 set->apis_.erase(APIPermission::kAudioCapture); |
752 set->apis_.insert(APIPermission::kVideoCapture); | 751 set->apis_.insert(APIPermission::kVideoCapture); |
753 warnings = set->GetWarningMessages(); | 752 warnings = set->GetWarningMessages(extension->GetType()); |
754 EXPECT_EQ(combined_size, warnings.size()); | 753 EXPECT_EQ(combined_size, warnings.size()); |
755 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 754 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
756 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 755 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
757 EXPECT_TRUE(Contains(warnings, "Use your camera")); | 756 EXPECT_TRUE(Contains(warnings, "Use your camera")); |
758 } | 757 } |
759 | 758 |
| 759 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { |
| 760 scoped_refptr<Extension> extension; |
| 761 |
| 762 extension = LoadManifest("permissions", "platform_app_hosts.json"); |
| 763 EXPECT_TRUE(extension->is_platform_app()); |
| 764 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 765 ASSERT_EQ(0u, warnings.size()); |
| 766 |
| 767 extension = LoadManifest("permissions", "platform_app_all_urls.json"); |
| 768 EXPECT_TRUE(extension->is_platform_app()); |
| 769 warnings = extension->GetPermissionMessageStrings(); |
| 770 ASSERT_EQ(0u, warnings.size()); |
| 771 } |
| 772 |
760 TEST(PermissionsTest, GetDistinctHostsForDisplay) { | 773 TEST(PermissionsTest, GetDistinctHostsForDisplay) { |
761 scoped_refptr<PermissionSet> perm_set; | 774 scoped_refptr<PermissionSet> perm_set; |
762 APIPermissionSet empty_perms; | 775 APIPermissionSet empty_perms; |
763 std::set<std::string> expected; | 776 std::set<std::string> expected; |
764 expected.insert("www.foo.com"); | 777 expected.insert("www.foo.com"); |
765 expected.insert("www.bar.com"); | 778 expected.insert("www.bar.com"); |
766 expected.insert("www.baz.com"); | 779 expected.insert("www.baz.com"); |
767 URLPatternSet explicit_hosts; | 780 URLPatternSet explicit_hosts; |
768 URLPatternSet scriptable_hosts; | 781 URLPatternSet scriptable_hosts; |
769 | 782 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 apis.insert(APIPermission::kWebRequest); | 1147 apis.insert(APIPermission::kWebRequest); |
1135 apis.insert(APIPermission::kFileBrowserHandler); | 1148 apis.insert(APIPermission::kFileBrowserHandler); |
1136 EXPECT_EQ(2U, apis.size()); | 1149 EXPECT_EQ(2U, apis.size()); |
1137 | 1150 |
1138 scoped_refptr<PermissionSet> perm_set; | 1151 scoped_refptr<PermissionSet> perm_set; |
1139 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1152 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
1140 EXPECT_EQ(4U, perm_set->apis().size()); | 1153 EXPECT_EQ(4U, perm_set->apis().size()); |
1141 } | 1154 } |
1142 | 1155 |
1143 } // namespace extensions | 1156 } // namespace extensions |
OLD | NEW |