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

Side by Side Diff: chrome/common/extensions/permissions/permission_set_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698