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

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

Issue 315573003: Remove PermissionsData::ForExtension() completely (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 info->GetByName("unlimited_storage")->id()); 126 info->GetByName("unlimited_storage")->id());
127 } 127 }
128 128
129 TEST(PermissionsTest, EffectiveHostPermissions) { 129 TEST(PermissionsTest, EffectiveHostPermissions) {
130 scoped_refptr<Extension> extension; 130 scoped_refptr<Extension> extension;
131 scoped_refptr<const PermissionSet> permissions; 131 scoped_refptr<const PermissionSet> permissions;
132 132
133 extension = LoadManifest("effective_host_permissions", "empty.json"); 133 extension = LoadManifest("effective_host_permissions", "empty.json");
134 permissions = extension->GetActivePermissions(); 134 permissions = extension->GetActivePermissions();
135 EXPECT_EQ(0u, 135 EXPECT_EQ(0u,
136 PermissionsData::ForExtension(extension) 136 extension->permissions_data()
137 ->GetEffectiveHostPermissions() 137 ->GetEffectiveHostPermissions()
138 .patterns() 138 .patterns()
139 .size()); 139 .size());
140 EXPECT_FALSE( 140 EXPECT_FALSE(
141 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 141 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
142 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 142 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
143 143
144 extension = LoadManifest("effective_host_permissions", "one_host.json"); 144 extension = LoadManifest("effective_host_permissions", "one_host.json");
145 permissions = extension->GetActivePermissions(); 145 permissions = extension->GetActivePermissions();
146 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 146 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions, 907 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions,
908 write_directory_permissions, 908 write_directory_permissions,
909 Manifest::TYPE_PLATFORM_APP)); 909 Manifest::TYPE_PLATFORM_APP));
910 } 910 }
911 911
912 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 912 TEST(PermissionsTest, GetWarningMessages_ManyHosts) {
913 scoped_refptr<Extension> extension; 913 scoped_refptr<Extension> extension;
914 914
915 extension = LoadManifest("permissions", "many-hosts.json"); 915 extension = LoadManifest("permissions", "many-hosts.json");
916 std::vector<base::string16> warnings = 916 std::vector<base::string16> warnings =
917 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 917 extension->permissions_data()->GetPermissionMessageStrings();
918 ASSERT_EQ(1u, warnings.size()); 918 ASSERT_EQ(1u, warnings.size());
919 EXPECT_EQ( 919 EXPECT_EQ(
920 "Read and modify your data on encrypted.google.com and " 920 "Read and modify your data on encrypted.google.com and "
921 "www.google.com", 921 "www.google.com",
922 base::UTF16ToUTF8(warnings[0])); 922 base::UTF16ToUTF8(warnings[0]));
923 } 923 }
924 924
925 TEST(PermissionsTest, GetWarningMessages_Plugins) { 925 TEST(PermissionsTest, GetWarningMessages_Plugins) {
926 scoped_refptr<Extension> extension; 926 scoped_refptr<Extension> extension;
927 scoped_refptr<PermissionSet> permissions; 927 scoped_refptr<PermissionSet> permissions;
928 928
929 extension = LoadManifest("permissions", "plugins.json"); 929 extension = LoadManifest("permissions", "plugins.json");
930 std::vector<base::string16> warnings = 930 std::vector<base::string16> warnings =
931 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 931 extension->permissions_data()->GetPermissionMessageStrings();
932 // We don't parse the plugins key on Chrome OS, so it should not ask for any 932 // We don't parse the plugins key on Chrome OS, so it should not ask for any
933 // permissions. 933 // permissions.
934 #if defined(OS_CHROMEOS) 934 #if defined(OS_CHROMEOS)
935 ASSERT_EQ(0u, warnings.size()); 935 ASSERT_EQ(0u, warnings.size());
936 #else 936 #else
937 ASSERT_EQ(1u, warnings.size()); 937 ASSERT_EQ(1u, warnings.size());
938 EXPECT_EQ( 938 EXPECT_EQ(
939 "Read and modify all your data on your computer and the websites " 939 "Read and modify all your data on your computer and the websites "
940 "you visit", 940 "you visit",
941 base::UTF16ToUTF8(warnings[0])); 941 base::UTF16ToUTF8(warnings[0]));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 warnings, "Read and modify all your data on the websites you visit")); 1009 warnings, "Read and modify all your data on the websites you visit"));
1010 } 1010 }
1011 1011
1012 TEST(PermissionsTest, GetWarningMessages_Serial) { 1012 TEST(PermissionsTest, GetWarningMessages_Serial) {
1013 scoped_refptr<Extension> extension = 1013 scoped_refptr<Extension> extension =
1014 LoadManifest("permissions", "serial.json"); 1014 LoadManifest("permissions", "serial.json");
1015 1015
1016 EXPECT_TRUE(extension->is_platform_app()); 1016 EXPECT_TRUE(extension->is_platform_app());
1017 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 1017 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
1018 std::vector<base::string16> warnings = 1018 std::vector<base::string16> warnings =
1019 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1019 extension->permissions_data()->GetPermissionMessageStrings();
1020 EXPECT_TRUE( 1020 EXPECT_TRUE(
1021 Contains(warnings, "Use serial devices attached to your computer")); 1021 Contains(warnings, "Use serial devices attached to your computer"));
1022 ASSERT_EQ(1u, warnings.size()); 1022 ASSERT_EQ(1u, warnings.size());
1023 } 1023 }
1024 1024
1025 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 1025 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
1026 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 1026 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
1027 1027
1028 scoped_refptr<Extension> extension = 1028 scoped_refptr<Extension> extension =
1029 LoadManifest("permissions", "socket_any_host.json"); 1029 LoadManifest("permissions", "socket_any_host.json");
1030 EXPECT_TRUE(extension->is_platform_app()); 1030 EXPECT_TRUE(extension->is_platform_app());
1031 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1031 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1032 std::vector<base::string16> warnings = 1032 std::vector<base::string16> warnings =
1033 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1033 extension->permissions_data()->GetPermissionMessageStrings();
1034 EXPECT_EQ(1u, warnings.size()); 1034 EXPECT_EQ(1u, warnings.size());
1035 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 1035 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
1036 "on the local network or internet")); 1036 "on the local network or internet"));
1037 } 1037 }
1038 1038
1039 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 1039 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
1040 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 1040 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
1041 1041
1042 scoped_refptr<Extension> extension = 1042 scoped_refptr<Extension> extension =
1043 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 1043 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
1044 EXPECT_TRUE(extension->is_platform_app()); 1044 EXPECT_TRUE(extension->is_platform_app());
1045 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1045 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1046 std::vector<base::string16> warnings = 1046 std::vector<base::string16> warnings =
1047 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1047 extension->permissions_data()->GetPermissionMessageStrings();
1048 1048
1049 // Verify the warnings, including support for unicode characters, the fact 1049 // Verify the warnings, including support for unicode characters, the fact
1050 // that domain host warnings come before specific host warnings, and the fact 1050 // that domain host warnings come before specific host warnings, and the fact
1051 // that domains and hostnames are in alphabetical order regardless of the 1051 // that domains and hostnames are in alphabetical order regardless of the
1052 // order in the manifest file. 1052 // order in the manifest file.
1053 EXPECT_EQ(2u, warnings.size()); 1053 EXPECT_EQ(2u, warnings.size());
1054 if (warnings.size() > 0) 1054 if (warnings.size() > 0)
1055 EXPECT_EQ(warnings[0], 1055 EXPECT_EQ(warnings[0],
1056 base::UTF8ToUTF16("Exchange data with any computer in the domain " 1056 base::UTF8ToUTF16("Exchange data with any computer in the domain "
1057 "example.org")); 1057 "example.org"));
1058 if (warnings.size() > 1) 1058 if (warnings.size() > 1)
1059 EXPECT_EQ(warnings[1], 1059 EXPECT_EQ(warnings[1],
1060 base::UTF8ToUTF16("Exchange data with the computers named: " 1060 base::UTF8ToUTF16("Exchange data with the computers named: "
1061 "b\xC3\xA5r.example.com foo.example.com")); 1061 "b\xC3\xA5r.example.com foo.example.com"));
1062 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 1062 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
1063 } 1063 }
1064 1064
1065 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 1065 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
1066 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 1066 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
1067 1067
1068 scoped_refptr<Extension> extension = 1068 scoped_refptr<Extension> extension =
1069 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 1069 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
1070 EXPECT_TRUE(extension->is_platform_app()); 1070 EXPECT_TRUE(extension->is_platform_app());
1071 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1071 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1072 std::vector<base::string16> warnings = 1072 std::vector<base::string16> warnings =
1073 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1073 extension->permissions_data()->GetPermissionMessageStrings();
1074 1074
1075 // Verify the warnings, including the fact that domain host warnings come 1075 // Verify the warnings, including the fact that domain host warnings come
1076 // before specific host warnings and the fact that domains and hostnames are 1076 // before specific host warnings and the fact that domains and hostnames are
1077 // in alphabetical order regardless of the order in the manifest file. 1077 // in alphabetical order regardless of the order in the manifest file.
1078 EXPECT_EQ(2u, warnings.size()); 1078 EXPECT_EQ(2u, warnings.size());
1079 if (warnings.size() > 0) 1079 if (warnings.size() > 0)
1080 EXPECT_EQ(warnings[0], 1080 EXPECT_EQ(warnings[0],
1081 base::UTF8ToUTF16("Exchange data with any computer in the " 1081 base::UTF8ToUTF16("Exchange data with any computer in the "
1082 "domains: example.com foo.example.org")); 1082 "domains: example.com foo.example.org"));
1083 if (warnings.size() > 1) 1083 if (warnings.size() > 1)
1084 EXPECT_EQ(warnings[1], 1084 EXPECT_EQ(warnings[1],
1085 base::UTF8ToUTF16("Exchange data with the computer named " 1085 base::UTF8ToUTF16("Exchange data with the computer named "
1086 "bar.example.org")); 1086 "bar.example.org"));
1087 } 1087 }
1088 1088
1089 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 1089 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
1090 scoped_refptr<Extension> extension; 1090 scoped_refptr<Extension> extension;
1091 1091
1092 extension = LoadManifest("permissions", "platform_app_hosts.json"); 1092 extension = LoadManifest("permissions", "platform_app_hosts.json");
1093 EXPECT_TRUE(extension->is_platform_app()); 1093 EXPECT_TRUE(extension->is_platform_app());
1094 std::vector<base::string16> warnings = 1094 std::vector<base::string16> warnings =
1095 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1095 extension->permissions_data()->GetPermissionMessageStrings();
1096 ASSERT_EQ(0u, warnings.size()); 1096 ASSERT_EQ(0u, warnings.size());
1097 1097
1098 extension = LoadManifest("permissions", "platform_app_all_urls.json"); 1098 extension = LoadManifest("permissions", "platform_app_all_urls.json");
1099 EXPECT_TRUE(extension->is_platform_app()); 1099 EXPECT_TRUE(extension->is_platform_app());
1100 warnings = 1100 warnings = extension->permissions_data()->GetPermissionMessageStrings();
1101 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings();
1102 ASSERT_EQ(0u, warnings.size()); 1101 ASSERT_EQ(0u, warnings.size());
1103 } 1102 }
1104 1103
1105 bool ShowsAllHostsWarning(const std::string& pattern) { 1104 bool ShowsAllHostsWarning(const std::string& pattern) {
1106 scoped_refptr<Extension> extension = 1105 scoped_refptr<Extension> extension =
1107 ExtensionBuilder() 1106 ExtensionBuilder()
1108 .SetManifest(DictionaryBuilder() 1107 .SetManifest(DictionaryBuilder()
1109 .Set("name", "TLDWildCardTest") 1108 .Set("name", "TLDWildCardTest")
1110 .Set("version", "0.1.0") 1109 .Set("version", "0.1.0")
1111 .Set("permissions", ListBuilder().Append(pattern)) 1110 .Set("permissions", ListBuilder().Append(pattern))
1112 .Build()) 1111 .Build())
1113 .Build(); 1112 .Build();
1114 1113
1115 std::vector<base::string16> warnings = 1114 std::vector<base::string16> warnings =
1116 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1115 extension->permissions_data()->GetPermissionMessageStrings();
1117 1116
1118 if (warnings.empty()) 1117 if (warnings.empty())
1119 return false; 1118 return false;
1120 1119
1121 if (warnings[0] != 1120 if (warnings[0] !=
1122 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS)) { 1121 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS)) {
1123 return false; 1122 return false;
1124 } 1123 }
1125 1124
1126 return true; 1125 return true;
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1538 }
1540 1539
1541 TEST(PermissionsTest, SyncFileSystemPermission) { 1540 TEST(PermissionsTest, SyncFileSystemPermission) {
1542 scoped_refptr<Extension> extension = LoadManifest( 1541 scoped_refptr<Extension> extension = LoadManifest(
1543 "permissions", "sync_file_system.json"); 1542 "permissions", "sync_file_system.json");
1544 APIPermissionSet apis; 1543 APIPermissionSet apis;
1545 apis.insert(APIPermission::kSyncFileSystem); 1544 apis.insert(APIPermission::kSyncFileSystem);
1546 EXPECT_TRUE(extension->is_platform_app()); 1545 EXPECT_TRUE(extension->is_platform_app());
1547 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); 1546 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem));
1548 std::vector<base::string16> warnings = 1547 std::vector<base::string16> warnings =
1549 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); 1548 extension->permissions_data()->GetPermissionMessageStrings();
1550 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); 1549 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account"));
1551 ASSERT_EQ(1u, warnings.size()); 1550 ASSERT_EQ(1u, warnings.size());
1552 } 1551 }
1553 1552
1554 // Make sure that we don't crash when we're trying to show the permissions 1553 // Make sure that we don't crash when we're trying to show the permissions
1555 // even though chrome://thumb (and everything that's not chrome://favicon with 1554 // even though chrome://thumb (and everything that's not chrome://favicon with
1556 // a chrome:// scheme) is not a valid permission. 1555 // a chrome:// scheme) is not a valid permission.
1557 // More details here: crbug/246314. 1556 // More details here: crbug/246314.
1558 TEST(PermissionsTest, ChromeURLs) { 1557 TEST(PermissionsTest, ChromeURLs) {
1559 URLPatternSet allowed_hosts; 1558 URLPatternSet allowed_hosts;
(...skipping 21 matching lines...) Expand all
1581 scoped_refptr<const PermissionSet> permissions_dwr( 1580 scoped_refptr<const PermissionSet> permissions_dwr(
1582 extension_dwr->GetActivePermissions()); 1581 extension_dwr->GetActivePermissions());
1583 1582
1584 EXPECT_FALSE(PermissionMessageProvider::Get()-> 1583 EXPECT_FALSE(PermissionMessageProvider::Get()->
1585 IsPrivilegeIncrease(permissions.get(), 1584 IsPrivilegeIncrease(permissions.get(),
1586 permissions_dwr.get(), 1585 permissions_dwr.get(),
1587 extension->GetType())); 1586 extension->GetType()));
1588 } 1587 }
1589 1588
1590 } // namespace extensions 1589 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698