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 15 matching lines...) Expand all Loading... |
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 = |
704 extension->GetActivePermissions()->GetWarningMessages(); | 704 extension->GetActivePermissions()->GetWarningMessages(extension); |
705 ASSERT_EQ(1u, warnings.size()); | 705 ASSERT_EQ(1u, warnings.size()); |
706 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", | 706 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", |
707 UTF16ToUTF8(warnings[0])); | 707 UTF16ToUTF8(warnings[0])); |
708 } | 708 } |
709 | 709 |
710 TEST(PermissionsTest, GetWarningMessages_Plugins) { | 710 TEST(PermissionsTest, GetWarningMessages_Plugins) { |
711 scoped_refptr<Extension> extension; | 711 scoped_refptr<Extension> extension; |
712 scoped_refptr<PermissionSet> permissions; | 712 scoped_refptr<PermissionSet> permissions; |
713 | 713 |
714 extension = LoadManifest("permissions", "plugins.json"); | 714 extension = LoadManifest("permissions", "plugins.json"); |
715 std::vector<string16> warnings = | 715 std::vector<string16> warnings = |
716 extension->GetActivePermissions()->GetWarningMessages(); | 716 extension->GetActivePermissions()->GetWarningMessages(extension); |
717 // We don't parse the plugins key on Chrome OS, so it should not ask for any | 717 // We don't parse the plugins key on Chrome OS, so it should not ask for any |
718 // permissions. | 718 // permissions. |
719 #if defined(OS_CHROMEOS) | 719 #if defined(OS_CHROMEOS) |
720 ASSERT_EQ(0u, warnings.size()); | 720 ASSERT_EQ(0u, warnings.size()); |
721 #else | 721 #else |
722 ASSERT_EQ(1u, warnings.size()); | 722 ASSERT_EQ(1u, warnings.size()); |
723 EXPECT_EQ("Access all data on your computer and the websites you visit", | 723 EXPECT_EQ("Access all data on your computer and the websites you visit", |
724 UTF16ToUTF8(warnings[0])); | 724 UTF16ToUTF8(warnings[0])); |
725 #endif | 725 #endif |
726 } | 726 } |
727 | 727 |
728 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { | 728 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
729 // Both audio and video present. | 729 // Both audio and video present. |
730 scoped_refptr<Extension> extension = | 730 scoped_refptr<Extension> extension = |
731 LoadManifest("permissions", "audio-video.json"); | 731 LoadManifest("permissions", "audio-video.json"); |
732 PermissionSet* set = | 732 PermissionSet* set = |
733 const_cast<PermissionSet*>( | 733 const_cast<PermissionSet*>( |
734 extension->GetActivePermissions().get()); | 734 extension->GetActivePermissions().get()); |
735 std::vector<string16> warnings = set->GetWarningMessages(); | 735 std::vector<string16> warnings = set->GetWarningMessages(extension); |
736 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 736 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
737 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 737 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
738 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); | 738 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); |
739 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); | 739 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); |
740 size_t combined_size = warnings.size(); | 740 size_t combined_size = warnings.size(); |
741 | 741 |
742 // Just audio present. | 742 // Just audio present. |
743 set->apis_.erase(APIPermission::kVideoCapture); | 743 set->apis_.erase(APIPermission::kVideoCapture); |
744 warnings = set->GetWarningMessages(); | 744 warnings = set->GetWarningMessages(extension); |
745 EXPECT_EQ(combined_size, warnings.size()); | 745 EXPECT_EQ(combined_size, warnings.size()); |
746 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); | 746 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); |
747 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 747 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
748 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 748 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
749 | 749 |
750 // Just video present. | 750 // Just video present. |
751 set->apis_.erase(APIPermission::kAudioCapture); | 751 set->apis_.erase(APIPermission::kAudioCapture); |
752 set->apis_.insert(APIPermission::kVideoCapture); | 752 set->apis_.insert(APIPermission::kVideoCapture); |
753 warnings = set->GetWarningMessages(); | 753 warnings = set->GetWarningMessages(extension); |
754 EXPECT_EQ(combined_size, warnings.size()); | 754 EXPECT_EQ(combined_size, warnings.size()); |
755 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 755 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
756 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 756 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
757 EXPECT_TRUE(Contains(warnings, "Use your camera")); | 757 EXPECT_TRUE(Contains(warnings, "Use your camera")); |
758 } | 758 } |
759 | 759 |
| 760 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { |
| 761 scoped_refptr<Extension> extension; |
| 762 |
| 763 extension = LoadManifest("permissions", "platform_app_hosts.json"); |
| 764 EXPECT_TRUE(extension->is_platform_app()); |
| 765 std::vector<string16> warnings = |
| 766 extension->GetActivePermissions()->GetWarningMessages(extension); |
| 767 ASSERT_EQ(0u, warnings.size()); |
| 768 |
| 769 extension = LoadManifest("permissions", "platform_app_all_urls.json"); |
| 770 EXPECT_TRUE(extension->is_platform_app()); |
| 771 warnings = extension->GetActivePermissions()->GetWarningMessages(extension); |
| 772 ASSERT_EQ(0u, warnings.size()); |
| 773 } |
| 774 |
760 TEST(PermissionsTest, GetDistinctHostsForDisplay) { | 775 TEST(PermissionsTest, GetDistinctHostsForDisplay) { |
761 scoped_refptr<PermissionSet> perm_set; | 776 scoped_refptr<PermissionSet> perm_set; |
762 APIPermissionSet empty_perms; | 777 APIPermissionSet empty_perms; |
763 std::set<std::string> expected; | 778 std::set<std::string> expected; |
764 expected.insert("www.foo.com"); | 779 expected.insert("www.foo.com"); |
765 expected.insert("www.bar.com"); | 780 expected.insert("www.bar.com"); |
766 expected.insert("www.baz.com"); | 781 expected.insert("www.baz.com"); |
767 URLPatternSet explicit_hosts; | 782 URLPatternSet explicit_hosts; |
768 URLPatternSet scriptable_hosts; | 783 URLPatternSet scriptable_hosts; |
769 | 784 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 apis.insert(APIPermission::kWebRequest); | 1149 apis.insert(APIPermission::kWebRequest); |
1135 apis.insert(APIPermission::kFileBrowserHandler); | 1150 apis.insert(APIPermission::kFileBrowserHandler); |
1136 EXPECT_EQ(2U, apis.size()); | 1151 EXPECT_EQ(2U, apis.size()); |
1137 | 1152 |
1138 scoped_refptr<PermissionSet> perm_set; | 1153 scoped_refptr<PermissionSet> perm_set; |
1139 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1154 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
1140 EXPECT_EQ(4U, perm_set->apis().size()); | 1155 EXPECT_EQ(4U, perm_set->apis().size()); |
1141 } | 1156 } |
1142 | 1157 |
1143 } // namespace extensions | 1158 } // namespace extensions |
OLD | NEW |