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

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

Powered by Google App Engine
This is Rietveld 408576698