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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_test_util.h" | 13 #include "chrome/common/extensions/extension_test_util.h" |
14 #include "chrome/common/extensions/features/feature_channel.h" | 14 #include "chrome/common/extensions/features/feature_channel.h" |
| 15 #include "chrome/common/extensions/permissions/base_permission_message_provider.
h" |
| 16 #include "chrome/common/extensions/permissions/permission_message_util.h" |
15 #include "chrome/common/extensions/permissions/permission_set.h" | 17 #include "chrome/common/extensions/permissions/permission_set.h" |
16 #include "chrome/common/extensions/permissions/permissions_data.h" | 18 #include "chrome/common/extensions/permissions/permissions_data.h" |
17 #include "chrome/common/extensions/permissions/socket_permission.h" | 19 #include "chrome/common/extensions/permissions/socket_permission.h" |
18 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
| 21 #include "extensions/common/permissions/permission_message_provider.h" |
19 #include "extensions/common/permissions/permissions_info.h" | 22 #include "extensions/common/permissions/permissions_info.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
21 | 24 |
22 using extension_test_util::LoadManifest; | 25 using extension_test_util::LoadManifest; |
23 | 26 |
24 namespace extensions { | 27 namespace extensions { |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 31 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 EXPECT_EQ(expected_apis, new_set->apis()); | 561 EXPECT_EQ(expected_apis, new_set->apis()); |
559 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 562 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
560 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 563 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
561 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 564 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
562 | 565 |
563 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set | 566 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set |
564 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); | 567 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); |
565 EXPECT_TRUE(set1->IsEmpty()); | 568 EXPECT_TRUE(set1->IsEmpty()); |
566 } | 569 } |
567 | 570 |
568 TEST(PermissionsTest, HasLessPrivilegesThan) { | 571 TEST(PermissionsTest, IsPrivilegeIncrease) { |
569 const struct { | 572 const struct { |
570 const char* base_name; | 573 const char* base_name; |
571 bool expect_increase; | 574 bool expect_increase; |
572 } kTests[] = { | 575 } kTests[] = { |
573 { "allhosts1", false }, // all -> all | 576 { "allhosts1", false }, // all -> all |
574 { "allhosts2", false }, // all -> one | 577 { "allhosts2", false }, // all -> one |
575 { "allhosts3", true }, // one -> all | 578 { "allhosts3", true }, // one -> all |
576 { "hosts1", false }, // http://a,http://b -> http://a,http://b | 579 { "hosts1", false }, // http://a,http://b -> http://a,http://b |
577 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b | 580 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b |
578 { "hosts3", false }, // http://a,http://b -> http://a | 581 { "hosts3", false }, // http://a,http://b -> http://a |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 if (!new_extension.get()) | 617 if (!new_extension.get()) |
615 continue; | 618 continue; |
616 | 619 |
617 scoped_refptr<const PermissionSet> old_p( | 620 scoped_refptr<const PermissionSet> old_p( |
618 old_extension->GetActivePermissions()); | 621 old_extension->GetActivePermissions()); |
619 scoped_refptr<const PermissionSet> new_p( | 622 scoped_refptr<const PermissionSet> new_p( |
620 new_extension->GetActivePermissions()); | 623 new_extension->GetActivePermissions()); |
621 Manifest::Type extension_type = old_extension->GetType(); | 624 Manifest::Type extension_type = old_extension->GetType(); |
622 | 625 |
623 EXPECT_EQ(kTests[i].expect_increase, | 626 EXPECT_EQ(kTests[i].expect_increase, |
624 old_p->HasLessPrivilegesThan(new_p.get(), extension_type)) | 627 PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
| 628 old_p.get(), new_p.get(), extension_type)) |
625 << kTests[i].base_name; | 629 << kTests[i].base_name; |
626 } | 630 } |
627 } | 631 } |
628 | 632 |
629 TEST(PermissionsTest, PermissionMessages) { | 633 TEST(PermissionsTest, PermissionMessages) { |
630 // Ensure that all permissions that needs to show install UI actually have | 634 // Ensure that all permissions that needs to show install UI actually have |
631 // strings associated with them. | 635 // strings associated with them. |
632 APIPermissionSet skip; | 636 APIPermissionSet skip; |
633 | 637 |
634 // These are considered "nuisance" or "trivial" permissions that don't need | 638 // These are considered "nuisance" or "trivial" permissions that don't need |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 767 } |
764 } | 768 } |
765 | 769 |
766 TEST(PermissionsTest, FileSystemPermissionMessages) { | 770 TEST(PermissionsTest, FileSystemPermissionMessages) { |
767 APIPermissionSet api_permissions; | 771 APIPermissionSet api_permissions; |
768 api_permissions.insert(APIPermission::kFileSystemWrite); | 772 api_permissions.insert(APIPermission::kFileSystemWrite); |
769 api_permissions.insert(APIPermission::kFileSystemDirectory); | 773 api_permissions.insert(APIPermission::kFileSystemDirectory); |
770 scoped_refptr<PermissionSet> permissions( | 774 scoped_refptr<PermissionSet> permissions( |
771 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); | 775 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); |
772 PermissionMessages messages = | 776 PermissionMessages messages = |
773 permissions->GetPermissionMessages(Manifest::TYPE_PLATFORM_APP); | 777 PermissionMessageProvider::Get()->GetPermissionMessages( |
| 778 permissions, Manifest::TYPE_PLATFORM_APP); |
774 ASSERT_EQ(2u, messages.size()); | 779 ASSERT_EQ(2u, messages.size()); |
775 std::sort(messages.begin(), messages.end()); | 780 std::sort(messages.begin(), messages.end()); |
776 std::set<PermissionMessage::ID> ids; | 781 std::set<PermissionMessage::ID> ids; |
777 for (PermissionMessages::const_iterator it = messages.begin(); | 782 for (PermissionMessages::const_iterator it = messages.begin(); |
778 it != messages.end(); ++it) { | 783 it != messages.end(); ++it) { |
779 ids.insert(it->id()); | 784 ids.insert(it->id()); |
780 } | 785 } |
781 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory)); | 786 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory)); |
782 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite)); | 787 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite)); |
783 } | 788 } |
784 | 789 |
785 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) { | 790 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) { |
786 APIPermissionSet api_permissions; | 791 APIPermissionSet api_permissions; |
787 api_permissions.insert(APIPermission::kFileSystemWrite); | 792 api_permissions.insert(APIPermission::kFileSystemWrite); |
788 api_permissions.insert(APIPermission::kFileSystemDirectory); | 793 api_permissions.insert(APIPermission::kFileSystemDirectory); |
789 api_permissions.insert(APIPermission::kFileSystemWriteDirectory); | 794 api_permissions.insert(APIPermission::kFileSystemWriteDirectory); |
790 scoped_refptr<PermissionSet> permissions( | 795 scoped_refptr<PermissionSet> permissions( |
791 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); | 796 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); |
792 PermissionMessages messages = | 797 PermissionMessages messages = |
793 permissions->GetPermissionMessages(Manifest::TYPE_PLATFORM_APP); | 798 PermissionMessageProvider::Get()->GetPermissionMessages( |
| 799 permissions, Manifest::TYPE_PLATFORM_APP); |
794 ASSERT_EQ(1u, messages.size()); | 800 ASSERT_EQ(1u, messages.size()); |
795 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id()); | 801 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id()); |
796 } | 802 } |
797 | 803 |
798 TEST(PermissionsTest, MergedFileSystemPermissionComparison) { | 804 TEST(PermissionsTest, MergedFileSystemPermissionComparison) { |
799 APIPermissionSet write_api_permissions; | 805 APIPermissionSet write_api_permissions; |
800 write_api_permissions.insert(APIPermission::kFileSystemWrite); | 806 write_api_permissions.insert(APIPermission::kFileSystemWrite); |
801 scoped_refptr<PermissionSet> write_permissions(new PermissionSet( | 807 scoped_refptr<PermissionSet> write_permissions(new PermissionSet( |
802 write_api_permissions, URLPatternSet(), URLPatternSet())); | 808 write_api_permissions, URLPatternSet(), URLPatternSet())); |
803 | 809 |
804 APIPermissionSet directory_api_permissions; | 810 APIPermissionSet directory_api_permissions; |
805 directory_api_permissions.insert(APIPermission::kFileSystemDirectory); | 811 directory_api_permissions.insert(APIPermission::kFileSystemDirectory); |
806 scoped_refptr<PermissionSet> directory_permissions(new PermissionSet( | 812 scoped_refptr<PermissionSet> directory_permissions(new PermissionSet( |
807 directory_api_permissions, URLPatternSet(), URLPatternSet())); | 813 directory_api_permissions, URLPatternSet(), URLPatternSet())); |
808 | 814 |
809 APIPermissionSet write_directory_api_permissions; | 815 APIPermissionSet write_directory_api_permissions; |
810 write_directory_api_permissions.insert( | 816 write_directory_api_permissions.insert( |
811 APIPermission::kFileSystemWriteDirectory); | 817 APIPermission::kFileSystemWriteDirectory); |
812 scoped_refptr<PermissionSet> write_directory_permissions(new PermissionSet( | 818 scoped_refptr<PermissionSet> write_directory_permissions(new PermissionSet( |
813 write_directory_api_permissions, URLPatternSet(), URLPatternSet())); | 819 write_directory_api_permissions, URLPatternSet(), URLPatternSet())); |
814 | 820 |
815 EXPECT_FALSE(write_directory_permissions->HasLessPrivilegesThan( | 821 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
816 write_permissions, Manifest::TYPE_PLATFORM_APP)); | 822 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, |
817 EXPECT_FALSE(write_directory_permissions->HasLessPrivilegesThan( | 823 write_permissions, |
818 directory_permissions, Manifest::TYPE_PLATFORM_APP)); | 824 Manifest::TYPE_PLATFORM_APP)); |
819 EXPECT_TRUE(write_permissions->HasLessPrivilegesThan( | 825 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, |
820 directory_permissions, Manifest::TYPE_PLATFORM_APP)); | 826 directory_permissions, |
821 EXPECT_TRUE(write_permissions->HasLessPrivilegesThan( | 827 Manifest::TYPE_PLATFORM_APP)); |
822 write_directory_permissions, Manifest::TYPE_PLATFORM_APP)); | 828 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions, |
823 EXPECT_TRUE(directory_permissions->HasLessPrivilegesThan( | 829 directory_permissions, |
824 write_permissions, Manifest::TYPE_PLATFORM_APP)); | 830 Manifest::TYPE_PLATFORM_APP)); |
825 EXPECT_TRUE(directory_permissions->HasLessPrivilegesThan( | 831 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions, |
826 write_directory_permissions, Manifest::TYPE_PLATFORM_APP)); | 832 write_directory_permissions, |
| 833 Manifest::TYPE_PLATFORM_APP)); |
| 834 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions, |
| 835 write_permissions, |
| 836 Manifest::TYPE_PLATFORM_APP)); |
| 837 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions, |
| 838 write_directory_permissions, |
| 839 Manifest::TYPE_PLATFORM_APP)); |
827 } | 840 } |
828 | 841 |
829 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { | 842 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { |
830 scoped_refptr<Extension> extension; | 843 scoped_refptr<Extension> extension; |
831 | 844 |
832 extension = LoadManifest("permissions", "many-hosts.json"); | 845 extension = LoadManifest("permissions", "many-hosts.json"); |
833 std::vector<string16> warnings = | 846 std::vector<string16> warnings = |
834 PermissionsData::GetPermissionMessageStrings(extension.get()); | 847 PermissionsData::GetPermissionMessageStrings(extension.get()); |
835 ASSERT_EQ(1u, warnings.size()); | 848 ASSERT_EQ(1u, warnings.size()); |
836 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", | 849 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", |
(...skipping 15 matching lines...) Expand all Loading... |
852 ASSERT_EQ(1u, warnings.size()); | 865 ASSERT_EQ(1u, warnings.size()); |
853 EXPECT_EQ("Access all data on your computer and the websites you visit", | 866 EXPECT_EQ("Access all data on your computer and the websites you visit", |
854 UTF16ToUTF8(warnings[0])); | 867 UTF16ToUTF8(warnings[0])); |
855 #endif | 868 #endif |
856 } | 869 } |
857 | 870 |
858 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { | 871 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
859 // Both audio and video present. | 872 // Both audio and video present. |
860 scoped_refptr<Extension> extension = | 873 scoped_refptr<Extension> extension = |
861 LoadManifest("permissions", "audio-video.json"); | 874 LoadManifest("permissions", "audio-video.json"); |
| 875 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
862 PermissionSet* set = | 876 PermissionSet* set = |
863 const_cast<PermissionSet*>( | 877 const_cast<PermissionSet*>( |
864 extension->GetActivePermissions().get()); | 878 extension->GetActivePermissions().get()); |
865 std::vector<string16> warnings = | 879 std::vector<string16> warnings = |
866 set->GetWarningMessages(extension->GetType()); | 880 provider->GetWarningMessages(set, extension->GetType()); |
867 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 881 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
868 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 882 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
869 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); | 883 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); |
870 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); | 884 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); |
871 size_t combined_size = warnings.size(); | 885 size_t combined_size = warnings.size(); |
872 | 886 |
873 // Just audio present. | 887 // Just audio present. |
874 set->apis_.erase(APIPermission::kVideoCapture); | 888 set->apis_.erase(APIPermission::kVideoCapture); |
875 warnings = set->GetWarningMessages(extension->GetType()); | 889 warnings = provider->GetWarningMessages(set, extension->GetType()); |
876 EXPECT_EQ(combined_size, warnings.size()); | 890 EXPECT_EQ(combined_size, warnings.size()); |
877 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); | 891 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); |
878 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 892 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
879 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 893 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
880 | 894 |
881 // Just video present. | 895 // Just video present. |
882 set->apis_.erase(APIPermission::kAudioCapture); | 896 set->apis_.erase(APIPermission::kAudioCapture); |
883 set->apis_.insert(APIPermission::kVideoCapture); | 897 set->apis_.insert(APIPermission::kVideoCapture); |
884 warnings = set->GetWarningMessages(extension->GetType()); | 898 warnings = provider->GetWarningMessages(set, extension->GetType()); |
885 EXPECT_EQ(combined_size, warnings.size()); | 899 EXPECT_EQ(combined_size, warnings.size()); |
886 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 900 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
887 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 901 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
888 EXPECT_TRUE(Contains(warnings, "Use your camera")); | 902 EXPECT_TRUE(Contains(warnings, "Use your camera")); |
889 } | 903 } |
890 | 904 |
891 TEST(PermissionsTest, GetWarningMessages_DeclarativeWebRequest) { | 905 TEST(PermissionsTest, GetWarningMessages_DeclarativeWebRequest) { |
892 // Test that if the declarativeWebRequest permission is present | 906 // Test that if the declarativeWebRequest permission is present |
893 // in combination with all hosts permission, then only the warning | 907 // in combination with all hosts permission, then only the warning |
894 // for host permissions is shown, because that covers the use of | 908 // for host permissions is shown, because that covers the use of |
895 // declarativeWebRequest. | 909 // declarativeWebRequest. |
896 | 910 |
897 // Until Declarative Web Request is in stable, let's make sure it is enabled | 911 // Until Declarative Web Request is in stable, let's make sure it is enabled |
898 // on the current channel. | 912 // on the current channel. |
899 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY); | 913 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY); |
900 | 914 |
901 // First verify that declarativeWebRequest produces a message when host | 915 // First verify that declarativeWebRequest produces a message when host |
902 // permissions do not cover all hosts. | 916 // permissions do not cover all hosts. |
903 scoped_refptr<Extension> extension = | 917 scoped_refptr<Extension> extension = |
904 LoadManifest("permissions", "web_request_com_host_permissions.json"); | 918 LoadManifest("permissions", "web_request_com_host_permissions.json"); |
| 919 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
905 const PermissionSet* set = extension->GetActivePermissions().get(); | 920 const PermissionSet* set = extension->GetActivePermissions().get(); |
906 std::vector<string16> warnings = | 921 std::vector<string16> warnings = |
907 set->GetWarningMessages(extension->GetType()); | 922 provider->GetWarningMessages(set, extension->GetType()); |
908 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); | 923 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); |
909 EXPECT_FALSE(Contains(warnings, "Access your data on all websites")); | 924 EXPECT_FALSE(Contains(warnings, "Access your data on all websites")); |
910 | 925 |
911 // Now verify that declarativeWebRequest does not produce a message when host | 926 // Now verify that declarativeWebRequest does not produce a message when host |
912 // permissions do cover all hosts. | 927 // permissions do cover all hosts. |
913 extension = | 928 extension = |
914 LoadManifest("permissions", "web_request_all_host_permissions.json"); | 929 LoadManifest("permissions", "web_request_all_host_permissions.json"); |
915 set = extension->GetActivePermissions().get(); | 930 set = extension->GetActivePermissions().get(); |
916 warnings = set->GetWarningMessages(extension->GetType()); | 931 warnings = provider->GetWarningMessages(set, extension->GetType()); |
917 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); | 932 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); |
918 EXPECT_TRUE(Contains(warnings, "Access your data on all websites")); | 933 EXPECT_TRUE(Contains(warnings, "Access your data on all websites")); |
919 } | 934 } |
920 | 935 |
921 TEST(PermissionsTest, GetWarningMessages_Serial) { | 936 TEST(PermissionsTest, GetWarningMessages_Serial) { |
922 scoped_refptr<Extension> extension = | 937 scoped_refptr<Extension> extension = |
923 LoadManifest("permissions", "serial.json"); | 938 LoadManifest("permissions", "serial.json"); |
924 | 939 |
925 EXPECT_TRUE(extension->is_platform_app()); | 940 EXPECT_TRUE(extension->is_platform_app()); |
926 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); | 941 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 SCOPED_TRACE("no dupes"); | 1036 SCOPED_TRACE("no dupes"); |
1022 | 1037 |
1023 // Simple list with no dupes. | 1038 // Simple list with no dupes. |
1024 explicit_hosts.AddPattern( | 1039 explicit_hosts.AddPattern( |
1025 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1040 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
1026 explicit_hosts.AddPattern( | 1041 explicit_hosts.AddPattern( |
1027 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); | 1042 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); |
1028 explicit_hosts.AddPattern( | 1043 explicit_hosts.AddPattern( |
1029 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); | 1044 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); |
1030 EXPECT_EQ(expected, | 1045 EXPECT_EQ(expected, |
1031 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1046 permission_message_util::GetDistinctHosts( |
| 1047 explicit_hosts, true, true)); |
1032 } | 1048 } |
1033 | 1049 |
1034 { | 1050 { |
1035 SCOPED_TRACE("two dupes"); | 1051 SCOPED_TRACE("two dupes"); |
1036 | 1052 |
1037 // Add some dupes. | 1053 // Add some dupes. |
1038 explicit_hosts.AddPattern( | 1054 explicit_hosts.AddPattern( |
1039 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1055 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
1040 explicit_hosts.AddPattern( | 1056 explicit_hosts.AddPattern( |
1041 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); | 1057 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); |
1042 EXPECT_EQ(expected, | 1058 EXPECT_EQ(expected, |
1043 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1059 permission_message_util::GetDistinctHosts( |
| 1060 explicit_hosts, true, true)); |
1044 } | 1061 } |
1045 | 1062 |
1046 { | 1063 { |
1047 SCOPED_TRACE("schemes differ"); | 1064 SCOPED_TRACE("schemes differ"); |
1048 | 1065 |
1049 // Add a pattern that differs only by scheme. This should be filtered out. | 1066 // Add a pattern that differs only by scheme. This should be filtered out. |
1050 explicit_hosts.AddPattern( | 1067 explicit_hosts.AddPattern( |
1051 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); | 1068 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); |
1052 EXPECT_EQ(expected, | 1069 EXPECT_EQ(expected, |
1053 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1070 permission_message_util::GetDistinctHosts( |
| 1071 explicit_hosts, true, true)); |
1054 } | 1072 } |
1055 | 1073 |
1056 { | 1074 { |
1057 SCOPED_TRACE("paths differ"); | 1075 SCOPED_TRACE("paths differ"); |
1058 | 1076 |
1059 // Add some dupes by path. | 1077 // Add some dupes by path. |
1060 explicit_hosts.AddPattern( | 1078 explicit_hosts.AddPattern( |
1061 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); | 1079 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); |
1062 EXPECT_EQ(expected, | 1080 EXPECT_EQ(expected, |
1063 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1081 permission_message_util::GetDistinctHosts( |
| 1082 explicit_hosts, true, true)); |
1064 } | 1083 } |
1065 | 1084 |
1066 { | 1085 { |
1067 SCOPED_TRACE("subdomains differ"); | 1086 SCOPED_TRACE("subdomains differ"); |
1068 | 1087 |
1069 // We don't do anything special for subdomains. | 1088 // We don't do anything special for subdomains. |
1070 explicit_hosts.AddPattern( | 1089 explicit_hosts.AddPattern( |
1071 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); | 1090 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); |
1072 explicit_hosts.AddPattern( | 1091 explicit_hosts.AddPattern( |
1073 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); | 1092 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); |
1074 | 1093 |
1075 expected.insert("monkey.www.bar.com"); | 1094 expected.insert("monkey.www.bar.com"); |
1076 expected.insert("bar.com"); | 1095 expected.insert("bar.com"); |
1077 | 1096 |
1078 EXPECT_EQ(expected, | 1097 EXPECT_EQ(expected, |
1079 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1098 permission_message_util::GetDistinctHosts( |
| 1099 explicit_hosts, true, true)); |
1080 } | 1100 } |
1081 | 1101 |
1082 { | 1102 { |
1083 SCOPED_TRACE("RCDs differ"); | 1103 SCOPED_TRACE("RCDs differ"); |
1084 | 1104 |
1085 // Now test for RCD uniquing. | 1105 // Now test for RCD uniquing. |
1086 explicit_hosts.AddPattern( | 1106 explicit_hosts.AddPattern( |
1087 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1107 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
1088 explicit_hosts.AddPattern( | 1108 explicit_hosts.AddPattern( |
1089 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1109 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
1090 explicit_hosts.AddPattern( | 1110 explicit_hosts.AddPattern( |
1091 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); | 1111 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); |
1092 explicit_hosts.AddPattern( | 1112 explicit_hosts.AddPattern( |
1093 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); | 1113 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); |
1094 explicit_hosts.AddPattern( | 1114 explicit_hosts.AddPattern( |
1095 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1115 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
1096 explicit_hosts.AddPattern( | 1116 explicit_hosts.AddPattern( |
1097 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); | 1117 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); |
1098 | 1118 |
1099 // This is an unknown RCD, which shouldn't be uniqued out. | 1119 // This is an unknown RCD, which shouldn't be uniqued out. |
1100 explicit_hosts.AddPattern( | 1120 explicit_hosts.AddPattern( |
1101 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); | 1121 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); |
1102 // But it should only occur once. | 1122 // But it should only occur once. |
1103 explicit_hosts.AddPattern( | 1123 explicit_hosts.AddPattern( |
1104 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); | 1124 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); |
1105 | 1125 |
1106 expected.insert("www.foo.xyzzy"); | 1126 expected.insert("www.foo.xyzzy"); |
1107 | 1127 |
1108 EXPECT_EQ(expected, | 1128 EXPECT_EQ(expected, |
1109 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1129 permission_message_util::GetDistinctHosts( |
| 1130 explicit_hosts, true, true)); |
1110 } | 1131 } |
1111 | 1132 |
1112 { | 1133 { |
1113 SCOPED_TRACE("wildcards"); | 1134 SCOPED_TRACE("wildcards"); |
1114 | 1135 |
1115 explicit_hosts.AddPattern( | 1136 explicit_hosts.AddPattern( |
1116 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); | 1137 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); |
1117 | 1138 |
1118 expected.insert("*.google.com"); | 1139 expected.insert("*.google.com"); |
1119 | 1140 |
1120 EXPECT_EQ(expected, | 1141 EXPECT_EQ(expected, |
1121 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1142 permission_message_util::GetDistinctHosts( |
| 1143 explicit_hosts, true, true)); |
1122 } | 1144 } |
1123 | 1145 |
1124 { | 1146 { |
1125 SCOPED_TRACE("scriptable hosts"); | 1147 SCOPED_TRACE("scriptable hosts"); |
1126 | 1148 |
1127 APIPermissionSet empty_perms; | 1149 APIPermissionSet empty_perms; |
1128 explicit_hosts.ClearPatterns(); | 1150 explicit_hosts.ClearPatterns(); |
1129 URLPatternSet scriptable_hosts; | 1151 URLPatternSet scriptable_hosts; |
1130 expected.clear(); | 1152 expected.clear(); |
1131 | 1153 |
1132 explicit_hosts.AddPattern( | 1154 explicit_hosts.AddPattern( |
1133 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); | 1155 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); |
1134 scriptable_hosts.AddPattern( | 1156 scriptable_hosts.AddPattern( |
1135 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); | 1157 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); |
1136 | 1158 |
1137 expected.insert("*.google.com"); | 1159 expected.insert("*.google.com"); |
1138 expected.insert("*.example.com"); | 1160 expected.insert("*.example.com"); |
1139 | 1161 |
1140 scoped_refptr<PermissionSet> perm_set(new PermissionSet( | 1162 scoped_refptr<PermissionSet> perm_set(new PermissionSet( |
1141 empty_perms, explicit_hosts, scriptable_hosts)); | 1163 empty_perms, explicit_hosts, scriptable_hosts)); |
1142 EXPECT_EQ(expected, | 1164 EXPECT_EQ(expected, |
1143 PermissionSet::GetDistinctHosts(perm_set->effective_hosts(), | 1165 permission_message_util::GetDistinctHosts( |
1144 true, true)); | 1166 perm_set->effective_hosts(), true, true)); |
1145 } | 1167 } |
1146 | 1168 |
1147 { | 1169 { |
1148 // We don't display warnings for file URLs because they are off by default. | 1170 // We don't display warnings for file URLs because they are off by default. |
1149 SCOPED_TRACE("file urls"); | 1171 SCOPED_TRACE("file urls"); |
1150 | 1172 |
1151 explicit_hosts.ClearPatterns(); | 1173 explicit_hosts.ClearPatterns(); |
1152 expected.clear(); | 1174 expected.clear(); |
1153 | 1175 |
1154 explicit_hosts.AddPattern( | 1176 explicit_hosts.AddPattern( |
1155 URLPattern(URLPattern::SCHEME_FILE, "file:///*")); | 1177 URLPattern(URLPattern::SCHEME_FILE, "file:///*")); |
1156 | 1178 |
1157 EXPECT_EQ(expected, | 1179 EXPECT_EQ(expected, |
1158 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1180 permission_message_util::GetDistinctHosts( |
| 1181 explicit_hosts, true, true)); |
1159 } | 1182 } |
1160 } | 1183 } |
1161 | 1184 |
1162 TEST(PermissionsTest, GetDistinctHosts_ComIsBestRcd) { | 1185 TEST(PermissionsTest, GetDistinctHosts_ComIsBestRcd) { |
1163 URLPatternSet explicit_hosts; | 1186 URLPatternSet explicit_hosts; |
1164 explicit_hosts.AddPattern( | 1187 explicit_hosts.AddPattern( |
1165 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1188 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
1166 explicit_hosts.AddPattern( | 1189 explicit_hosts.AddPattern( |
1167 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1190 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
1168 explicit_hosts.AddPattern( | 1191 explicit_hosts.AddPattern( |
1169 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1192 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
1170 explicit_hosts.AddPattern( | 1193 explicit_hosts.AddPattern( |
1171 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1194 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
1172 explicit_hosts.AddPattern( | 1195 explicit_hosts.AddPattern( |
1173 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1196 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
1174 explicit_hosts.AddPattern( | 1197 explicit_hosts.AddPattern( |
1175 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1198 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
1176 | 1199 |
1177 std::set<std::string> expected; | 1200 std::set<std::string> expected; |
1178 expected.insert("www.foo.com"); | 1201 expected.insert("www.foo.com"); |
1179 EXPECT_EQ(expected, | 1202 EXPECT_EQ(expected, |
1180 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1203 permission_message_util::GetDistinctHosts( |
| 1204 explicit_hosts, true, true)); |
1181 } | 1205 } |
1182 | 1206 |
1183 TEST(PermissionsTest, GetDistinctHosts_NetIs2ndBestRcd) { | 1207 TEST(PermissionsTest, GetDistinctHosts_NetIs2ndBestRcd) { |
1184 URLPatternSet explicit_hosts; | 1208 URLPatternSet explicit_hosts; |
1185 explicit_hosts.AddPattern( | 1209 explicit_hosts.AddPattern( |
1186 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1210 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
1187 explicit_hosts.AddPattern( | 1211 explicit_hosts.AddPattern( |
1188 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1212 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
1189 explicit_hosts.AddPattern( | 1213 explicit_hosts.AddPattern( |
1190 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1214 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
1191 explicit_hosts.AddPattern( | 1215 explicit_hosts.AddPattern( |
1192 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1216 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
1193 explicit_hosts.AddPattern( | 1217 explicit_hosts.AddPattern( |
1194 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1218 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
1195 // No http://www.foo.com/path | 1219 // No http://www.foo.com/path |
1196 | 1220 |
1197 std::set<std::string> expected; | 1221 std::set<std::string> expected; |
1198 expected.insert("www.foo.net"); | 1222 expected.insert("www.foo.net"); |
1199 EXPECT_EQ(expected, | 1223 EXPECT_EQ(expected, |
1200 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1224 permission_message_util::GetDistinctHosts( |
| 1225 explicit_hosts, true, true)); |
1201 } | 1226 } |
1202 | 1227 |
1203 TEST(PermissionsTest, GetDistinctHosts_OrgIs3rdBestRcd) { | 1228 TEST(PermissionsTest, GetDistinctHosts_OrgIs3rdBestRcd) { |
1204 URLPatternSet explicit_hosts; | 1229 URLPatternSet explicit_hosts; |
1205 explicit_hosts.AddPattern( | 1230 explicit_hosts.AddPattern( |
1206 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1231 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
1207 explicit_hosts.AddPattern( | 1232 explicit_hosts.AddPattern( |
1208 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1233 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
1209 explicit_hosts.AddPattern( | 1234 explicit_hosts.AddPattern( |
1210 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1235 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
1211 // No http://www.foo.net/path | 1236 // No http://www.foo.net/path |
1212 explicit_hosts.AddPattern( | 1237 explicit_hosts.AddPattern( |
1213 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1238 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
1214 // No http://www.foo.com/path | 1239 // No http://www.foo.com/path |
1215 | 1240 |
1216 std::set<std::string> expected; | 1241 std::set<std::string> expected; |
1217 expected.insert("www.foo.org"); | 1242 expected.insert("www.foo.org"); |
1218 EXPECT_EQ(expected, | 1243 EXPECT_EQ(expected, |
1219 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1244 permission_message_util::GetDistinctHosts( |
| 1245 explicit_hosts, true, true)); |
1220 } | 1246 } |
1221 | 1247 |
1222 TEST(PermissionsTest, GetDistinctHosts_FirstInListIs4thBestRcd) { | 1248 TEST(PermissionsTest, GetDistinctHosts_FirstInListIs4thBestRcd) { |
1223 URLPatternSet explicit_hosts; | 1249 URLPatternSet explicit_hosts; |
1224 explicit_hosts.AddPattern( | 1250 explicit_hosts.AddPattern( |
1225 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1251 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
1226 // No http://www.foo.org/path | 1252 // No http://www.foo.org/path |
1227 explicit_hosts.AddPattern( | 1253 explicit_hosts.AddPattern( |
1228 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1254 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
1229 // No http://www.foo.net/path | 1255 // No http://www.foo.net/path |
1230 explicit_hosts.AddPattern( | 1256 explicit_hosts.AddPattern( |
1231 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1257 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
1232 // No http://www.foo.com/path | 1258 // No http://www.foo.com/path |
1233 | 1259 |
1234 std::set<std::string> expected; | 1260 std::set<std::string> expected; |
1235 expected.insert("www.foo.ca"); | 1261 expected.insert("www.foo.ca"); |
1236 EXPECT_EQ(expected, | 1262 EXPECT_EQ(expected, |
1237 PermissionSet::GetDistinctHosts(explicit_hosts, true, true)); | 1263 permission_message_util::GetDistinctHosts( |
| 1264 explicit_hosts, true, true)); |
1238 } | 1265 } |
1239 | 1266 |
1240 TEST(PermissionsTest, HasLessHostPrivilegesThan) { | 1267 TEST(PermissionsTest, IsHostPrivilegeIncrease) { |
1241 Manifest::Type extension_type = Manifest::TYPE_EXTENSION; | 1268 Manifest::Type type = Manifest::TYPE_EXTENSION; |
| 1269 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
1242 URLPatternSet elist1; | 1270 URLPatternSet elist1; |
1243 URLPatternSet elist2; | 1271 URLPatternSet elist2; |
1244 URLPatternSet slist1; | 1272 URLPatternSet slist1; |
1245 URLPatternSet slist2; | 1273 URLPatternSet slist2; |
1246 scoped_refptr<PermissionSet> set1; | 1274 scoped_refptr<PermissionSet> set1; |
1247 scoped_refptr<PermissionSet> set2; | 1275 scoped_refptr<PermissionSet> set2; |
1248 APIPermissionSet empty_perms; | 1276 APIPermissionSet empty_perms; |
1249 elist1.AddPattern( | 1277 elist1.AddPattern( |
1250 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); | 1278 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); |
1251 elist1.AddPattern( | 1279 elist1.AddPattern( |
1252 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1280 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
1253 | 1281 |
1254 // Test that the host order does not matter. | 1282 // Test that the host order does not matter. |
1255 elist2.AddPattern( | 1283 elist2.AddPattern( |
1256 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1284 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
1257 elist2.AddPattern( | 1285 elist2.AddPattern( |
1258 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); | 1286 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); |
1259 | 1287 |
1260 set1 = new PermissionSet(empty_perms, elist1, slist1); | 1288 set1 = new PermissionSet(empty_perms, elist1, slist1); |
1261 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1289 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1262 | 1290 |
1263 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1291 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1264 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1292 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1265 | 1293 |
1266 // Test that paths are ignored. | 1294 // Test that paths are ignored. |
1267 elist2.ClearPatterns(); | 1295 elist2.ClearPatterns(); |
1268 elist2.AddPattern( | 1296 elist2.AddPattern( |
1269 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); | 1297 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); |
1270 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1298 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1271 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1299 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1272 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1300 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1273 | 1301 |
1274 // Test that RCDs are ignored. | 1302 // Test that RCDs are ignored. |
1275 elist2.ClearPatterns(); | 1303 elist2.ClearPatterns(); |
1276 elist2.AddPattern( | 1304 elist2.AddPattern( |
1277 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); | 1305 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); |
1278 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1306 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1279 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1307 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1280 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1308 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1281 | 1309 |
1282 // Test that subdomain wildcards are handled properly. | 1310 // Test that subdomain wildcards are handled properly. |
1283 elist2.ClearPatterns(); | 1311 elist2.ClearPatterns(); |
1284 elist2.AddPattern( | 1312 elist2.AddPattern( |
1285 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); | 1313 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); |
1286 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1314 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1287 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1315 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1288 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 | 1316 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 |
1289 // EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); | 1317 // EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1290 | 1318 |
1291 // Test that different domains count as different hosts. | 1319 // Test that different domains count as different hosts. |
1292 elist2.ClearPatterns(); | 1320 elist2.ClearPatterns(); |
1293 elist2.AddPattern( | 1321 elist2.AddPattern( |
1294 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1322 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
1295 elist2.AddPattern( | 1323 elist2.AddPattern( |
1296 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); | 1324 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); |
1297 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1325 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1298 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1326 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1299 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1327 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1300 | 1328 |
1301 // Test that different subdomains count as different hosts. | 1329 // Test that different subdomains count as different hosts. |
1302 elist2.ClearPatterns(); | 1330 elist2.ClearPatterns(); |
1303 elist2.AddPattern( | 1331 elist2.AddPattern( |
1304 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); | 1332 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); |
1305 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1333 set2 = new PermissionSet(empty_perms, elist2, slist2); |
1306 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1334 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1307 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1335 EXPECT_TRUE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1308 | 1336 |
1309 // Test that platform apps do not have host permissions increases. | 1337 // Test that platform apps do not have host permissions increases. |
1310 extension_type = Manifest::TYPE_PLATFORM_APP; | 1338 type = Manifest::TYPE_PLATFORM_APP; |
1311 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get(), extension_type)); | 1339 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
1312 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get(), extension_type)); | 1340 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
1313 } | 1341 } |
1314 | 1342 |
1315 TEST(PermissionsTest, GetAPIsAsStrings) { | 1343 TEST(PermissionsTest, GetAPIsAsStrings) { |
1316 APIPermissionSet apis; | 1344 APIPermissionSet apis; |
1317 URLPatternSet empty_set; | 1345 URLPatternSet empty_set; |
1318 | 1346 |
1319 apis.insert(APIPermission::kProxy); | 1347 apis.insert(APIPermission::kProxy); |
1320 apis.insert(APIPermission::kBackground); | 1348 apis.insert(APIPermission::kBackground); |
1321 apis.insert(APIPermission::kNotification); | 1349 apis.insert(APIPermission::kNotification); |
1322 apis.insert(APIPermission::kTab); | 1350 apis.insert(APIPermission::kTab); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 TEST(PermissionsTest, ChromeURLs) { | 1422 TEST(PermissionsTest, ChromeURLs) { |
1395 URLPatternSet allowed_hosts; | 1423 URLPatternSet allowed_hosts; |
1396 allowed_hosts.AddPattern( | 1424 allowed_hosts.AddPattern( |
1397 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); | 1425 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); |
1398 allowed_hosts.AddPattern( | 1426 allowed_hosts.AddPattern( |
1399 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); | 1427 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); |
1400 allowed_hosts.AddPattern( | 1428 allowed_hosts.AddPattern( |
1401 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); | 1429 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); |
1402 scoped_refptr<PermissionSet> permissions( | 1430 scoped_refptr<PermissionSet> permissions( |
1403 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); | 1431 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); |
1404 permissions->GetPermissionMessages(Manifest::TYPE_EXTENSION); | 1432 PermissionMessageProvider::Get()-> |
| 1433 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); |
1405 } | 1434 } |
1406 | 1435 |
1407 TEST(PermissionsTest, HasLessPrivilegesThan_DeclarativeWebRequest) { | 1436 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { |
1408 scoped_refptr<Extension> extension( | 1437 scoped_refptr<Extension> extension( |
1409 LoadManifest("permissions", "permissions_all_urls.json")); | 1438 LoadManifest("permissions", "permissions_all_urls.json")); |
1410 scoped_refptr<const PermissionSet> permissions( | 1439 scoped_refptr<const PermissionSet> permissions( |
1411 extension->GetActivePermissions()); | 1440 extension->GetActivePermissions()); |
1412 | 1441 |
1413 scoped_refptr<Extension> extension_dwr( | 1442 scoped_refptr<Extension> extension_dwr( |
1414 LoadManifest("permissions", "web_request_all_host_permissions.json")); | 1443 LoadManifest("permissions", "web_request_all_host_permissions.json")); |
1415 scoped_refptr<const PermissionSet> permissions_dwr( | 1444 scoped_refptr<const PermissionSet> permissions_dwr( |
1416 extension_dwr->GetActivePermissions()); | 1445 extension_dwr->GetActivePermissions()); |
1417 | 1446 |
1418 EXPECT_FALSE(permissions->HasLessPrivilegesThan(permissions_dwr.get(), | 1447 EXPECT_FALSE(PermissionMessageProvider::Get()-> |
1419 extension->GetType())); | 1448 IsPrivilegeIncrease(permissions.get(), |
| 1449 permissions_dwr.get(), |
| 1450 extension->GetType())); |
1420 } | 1451 } |
| 1452 |
1421 } // namespace extensions | 1453 } // namespace extensions |
OLD | NEW |