OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 info->GetByName("unlimitedStorage")->id()); | 124 info->GetByName("unlimitedStorage")->id()); |
125 EXPECT_EQ(APIPermission::kUnlimitedStorage, | 125 EXPECT_EQ(APIPermission::kUnlimitedStorage, |
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->permissions_data()->active_permissions(); |
135 EXPECT_EQ(0u, | 135 EXPECT_EQ(0u, |
136 extension->permissions_data() | 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->permissions_data()->active_permissions(); |
146 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 146 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
147 GURL("http://www.google.com"))); | 147 GURL("http://www.google.com"))); |
148 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( | 148 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( |
149 GURL("https://www.google.com"))); | 149 GURL("https://www.google.com"))); |
150 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 150 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
151 | 151 |
152 extension = LoadManifest("effective_host_permissions", | 152 extension = LoadManifest("effective_host_permissions", |
153 "one_host_wildcard.json"); | 153 "one_host_wildcard.json"); |
154 permissions = extension->GetActivePermissions(); | 154 permissions = extension->permissions_data()->active_permissions(); |
155 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); | 155 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); |
156 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 156 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
157 GURL("http://foo.google.com"))); | 157 GURL("http://foo.google.com"))); |
158 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 158 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
159 | 159 |
160 extension = LoadManifest("effective_host_permissions", "two_hosts.json"); | 160 extension = LoadManifest("effective_host_permissions", "two_hosts.json"); |
161 permissions = extension->GetActivePermissions(); | 161 permissions = extension->permissions_data()->active_permissions(); |
162 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 162 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
163 GURL("http://www.google.com"))); | 163 GURL("http://www.google.com"))); |
164 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 164 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
165 GURL("http://www.reddit.com"))); | 165 GURL("http://www.reddit.com"))); |
166 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 166 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
167 | 167 |
168 extension = LoadManifest("effective_host_permissions", | 168 extension = LoadManifest("effective_host_permissions", |
169 "https_not_considered.json"); | 169 "https_not_considered.json"); |
170 permissions = extension->GetActivePermissions(); | 170 permissions = extension->permissions_data()->active_permissions(); |
171 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); | 171 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); |
172 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://google.com"))); | 172 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://google.com"))); |
173 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 173 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
174 | 174 |
175 extension = LoadManifest("effective_host_permissions", | 175 extension = LoadManifest("effective_host_permissions", |
176 "two_content_scripts.json"); | 176 "two_content_scripts.json"); |
177 permissions = extension->GetActivePermissions(); | 177 permissions = extension->permissions_data()->active_permissions(); |
178 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); | 178 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); |
179 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 179 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
180 GURL("http://www.reddit.com"))); | 180 GURL("http://www.reddit.com"))); |
181 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( | 181 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( |
182 GURL("http://news.ycombinator.com"))); | 182 GURL("http://news.ycombinator.com"))); |
183 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 183 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
184 | 184 |
185 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); | 185 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); |
186 permissions = extension->GetActivePermissions(); | 186 permissions = extension->permissions_data()->active_permissions(); |
187 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); | 187 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); |
188 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); | 188 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); |
189 EXPECT_TRUE( | 189 EXPECT_TRUE( |
190 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); | 190 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); |
191 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 191 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
192 | 192 |
193 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); | 193 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); |
194 permissions = extension->GetActivePermissions(); | 194 permissions = extension->permissions_data()->active_permissions(); |
195 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); | 195 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); |
196 EXPECT_TRUE( | 196 EXPECT_TRUE( |
197 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); | 197 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); |
198 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 198 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
199 | 199 |
200 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 200 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
201 permissions = extension->GetActivePermissions(); | 201 permissions = extension->permissions_data()->active_permissions(); |
202 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); | 202 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); |
203 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); | 203 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); |
204 EXPECT_TRUE( | 204 EXPECT_TRUE( |
205 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); | 205 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); |
206 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 206 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
207 } | 207 } |
208 | 208 |
209 TEST(PermissionsTest, ExplicitAccessToOrigin) { | 209 TEST(PermissionsTest, ExplicitAccessToOrigin) { |
210 APIPermissionSet apis; | 210 APIPermissionSet apis; |
211 ManifestPermissionSet manifest_permissions; | 211 ManifestPermissionSet manifest_permissions; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 std::string(kTests[i].base_name) + "_old.json")); | 616 std::string(kTests[i].base_name) + "_old.json")); |
617 scoped_refptr<Extension> new_extension( | 617 scoped_refptr<Extension> new_extension( |
618 LoadManifest("allow_silent_upgrade", | 618 LoadManifest("allow_silent_upgrade", |
619 std::string(kTests[i].base_name) + "_new.json")); | 619 std::string(kTests[i].base_name) + "_new.json")); |
620 | 620 |
621 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; | 621 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; |
622 if (!new_extension.get()) | 622 if (!new_extension.get()) |
623 continue; | 623 continue; |
624 | 624 |
625 scoped_refptr<const PermissionSet> old_p( | 625 scoped_refptr<const PermissionSet> old_p( |
626 old_extension->GetActivePermissions()); | 626 old_extension->permissions_data()->active_permissions()); |
627 scoped_refptr<const PermissionSet> new_p( | 627 scoped_refptr<const PermissionSet> new_p( |
628 new_extension->GetActivePermissions()); | 628 new_extension->permissions_data()->active_permissions()); |
629 Manifest::Type extension_type = old_extension->GetType(); | 629 Manifest::Type extension_type = old_extension->GetType(); |
630 | 630 |
631 bool increased = PermissionMessageProvider::Get()->IsPrivilegeIncrease( | 631 bool increased = PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
632 old_p.get(), new_p.get(), extension_type); | 632 old_p.get(), new_p.get(), extension_type); |
633 EXPECT_EQ(kTests[i].expect_increase, increased) << kTests[i].base_name; | 633 EXPECT_EQ(kTests[i].expect_increase, increased) << kTests[i].base_name; |
634 } | 634 } |
635 } | 635 } |
636 | 636 |
637 TEST(PermissionsTest, PermissionMessages) { | 637 TEST(PermissionsTest, PermissionMessages) { |
638 // Ensure that all permissions that needs to show install UI actually have | 638 // Ensure that all permissions that needs to show install UI actually have |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 "you visit", | 940 "you visit", |
941 base::UTF16ToUTF8(warnings[0])); | 941 base::UTF16ToUTF8(warnings[0])); |
942 #endif | 942 #endif |
943 } | 943 } |
944 | 944 |
945 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { | 945 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
946 // Both audio and video present. | 946 // Both audio and video present. |
947 scoped_refptr<Extension> extension = | 947 scoped_refptr<Extension> extension = |
948 LoadManifest("permissions", "audio-video.json"); | 948 LoadManifest("permissions", "audio-video.json"); |
949 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 949 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
950 PermissionSet* set = | 950 PermissionSet* set = const_cast<PermissionSet*>( |
951 const_cast<PermissionSet*>( | 951 extension->permissions_data()->active_permissions().get()); |
952 extension->GetActivePermissions().get()); | |
953 std::vector<base::string16> warnings = | 952 std::vector<base::string16> warnings = |
954 provider->GetWarningMessages(set, extension->GetType()); | 953 provider->GetWarningMessages(set, extension->GetType()); |
955 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 954 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
956 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 955 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
957 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); | 956 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); |
958 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); | 957 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); |
959 size_t combined_size = warnings.size(); | 958 size_t combined_size = warnings.size(); |
960 | 959 |
961 // Just audio present. | 960 // Just audio present. |
962 set->apis_.erase(APIPermission::kVideoCapture); | 961 set->apis_.erase(APIPermission::kVideoCapture); |
(...skipping 21 matching lines...) Expand all Loading... |
984 | 983 |
985 // Until Declarative Web Request is in stable, let's make sure it is enabled | 984 // Until Declarative Web Request is in stable, let's make sure it is enabled |
986 // on the current channel. | 985 // on the current channel. |
987 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY); | 986 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY); |
988 | 987 |
989 // First verify that declarativeWebRequest produces a message when host | 988 // First verify that declarativeWebRequest produces a message when host |
990 // permissions do not cover all hosts. | 989 // permissions do not cover all hosts. |
991 scoped_refptr<Extension> extension = | 990 scoped_refptr<Extension> extension = |
992 LoadManifest("permissions", "web_request_not_all_host_permissions.json"); | 991 LoadManifest("permissions", "web_request_not_all_host_permissions.json"); |
993 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 992 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
994 const PermissionSet* set = extension->GetActivePermissions().get(); | 993 const PermissionSet* set = |
| 994 extension->permissions_data()->active_permissions().get(); |
995 std::vector<base::string16> warnings = | 995 std::vector<base::string16> warnings = |
996 provider->GetWarningMessages(set, extension->GetType()); | 996 provider->GetWarningMessages(set, extension->GetType()); |
997 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); | 997 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); |
998 EXPECT_FALSE(Contains( | 998 EXPECT_FALSE(Contains( |
999 warnings, "Read and modify all your data on the websites you visit")); | 999 warnings, "Read and modify all your data on the websites you visit")); |
1000 | 1000 |
1001 // Now verify that declarativeWebRequest does not produce a message when host | 1001 // Now verify that declarativeWebRequest does not produce a message when host |
1002 // permissions do cover all hosts. | 1002 // permissions do cover all hosts. |
1003 extension = | 1003 extension = |
1004 LoadManifest("permissions", "web_request_all_host_permissions.json"); | 1004 LoadManifest("permissions", "web_request_all_host_permissions.json"); |
1005 set = extension->GetActivePermissions().get(); | 1005 set = extension->permissions_data()->active_permissions().get(); |
1006 warnings = provider->GetWarningMessages(set, extension->GetType()); | 1006 warnings = provider->GetWarningMessages(set, extension->GetType()); |
1007 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); | 1007 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); |
1008 EXPECT_TRUE(Contains( | 1008 EXPECT_TRUE(Contains( |
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( |
| 1018 extension->permissions_data()->HasAPIPermission(APIPermission::kSerial)); |
1018 std::vector<base::string16> warnings = | 1019 std::vector<base::string16> warnings = |
1019 extension->permissions_data()->GetPermissionMessageStrings(); | 1020 extension->permissions_data()->GetPermissionMessageStrings(); |
1020 EXPECT_TRUE( | 1021 EXPECT_TRUE( |
1021 Contains(warnings, "Use serial devices attached to your computer")); | 1022 Contains(warnings, "Use serial devices attached to your computer")); |
1022 ASSERT_EQ(1u, warnings.size()); | 1023 ASSERT_EQ(1u, warnings.size()); |
1023 } | 1024 } |
1024 | 1025 |
1025 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { | 1026 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { |
1026 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 1027 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
1027 | 1028 |
1028 scoped_refptr<Extension> extension = | 1029 scoped_refptr<Extension> extension = |
1029 LoadManifest("permissions", "socket_any_host.json"); | 1030 LoadManifest("permissions", "socket_any_host.json"); |
1030 EXPECT_TRUE(extension->is_platform_app()); | 1031 EXPECT_TRUE(extension->is_platform_app()); |
1031 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 1032 EXPECT_TRUE( |
| 1033 extension->permissions_data()->HasAPIPermission(APIPermission::kSocket)); |
1032 std::vector<base::string16> warnings = | 1034 std::vector<base::string16> warnings = |
1033 extension->permissions_data()->GetPermissionMessageStrings(); | 1035 extension->permissions_data()->GetPermissionMessageStrings(); |
1034 EXPECT_EQ(1u, warnings.size()); | 1036 EXPECT_EQ(1u, warnings.size()); |
1035 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " | 1037 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " |
1036 "on the local network or internet")); | 1038 "on the local network or internet")); |
1037 } | 1039 } |
1038 | 1040 |
1039 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { | 1041 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { |
1040 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 1042 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
1041 | 1043 |
1042 scoped_refptr<Extension> extension = | 1044 scoped_refptr<Extension> extension = |
1043 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); | 1045 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); |
1044 EXPECT_TRUE(extension->is_platform_app()); | 1046 EXPECT_TRUE(extension->is_platform_app()); |
1045 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 1047 EXPECT_TRUE( |
| 1048 extension->permissions_data()->HasAPIPermission(APIPermission::kSocket)); |
1046 std::vector<base::string16> warnings = | 1049 std::vector<base::string16> warnings = |
1047 extension->permissions_data()->GetPermissionMessageStrings(); | 1050 extension->permissions_data()->GetPermissionMessageStrings(); |
1048 | 1051 |
1049 // Verify the warnings, including support for unicode characters, the fact | 1052 // Verify the warnings, including support for unicode characters, the fact |
1050 // that domain host warnings come before specific host warnings, and the fact | 1053 // that domain host warnings come before specific host warnings, and the fact |
1051 // that domains and hostnames are in alphabetical order regardless of the | 1054 // that domains and hostnames are in alphabetical order regardless of the |
1052 // order in the manifest file. | 1055 // order in the manifest file. |
1053 EXPECT_EQ(2u, warnings.size()); | 1056 EXPECT_EQ(2u, warnings.size()); |
1054 if (warnings.size() > 0) | 1057 if (warnings.size() > 0) |
1055 EXPECT_EQ(warnings[0], | 1058 EXPECT_EQ(warnings[0], |
1056 base::UTF8ToUTF16("Exchange data with any computer in the domain " | 1059 base::UTF8ToUTF16("Exchange data with any computer in the domain " |
1057 "example.org")); | 1060 "example.org")); |
1058 if (warnings.size() > 1) | 1061 if (warnings.size() > 1) |
1059 EXPECT_EQ(warnings[1], | 1062 EXPECT_EQ(warnings[1], |
1060 base::UTF8ToUTF16("Exchange data with the computers named: " | 1063 base::UTF8ToUTF16("Exchange data with the computers named: " |
1061 "b\xC3\xA5r.example.com foo.example.com")); | 1064 "b\xC3\xA5r.example.com foo.example.com")); |
1062 // "\xC3\xA5" = UTF-8 for lowercase A with ring above | 1065 // "\xC3\xA5" = UTF-8 for lowercase A with ring above |
1063 } | 1066 } |
1064 | 1067 |
1065 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { | 1068 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { |
1066 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 1069 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
1067 | 1070 |
1068 scoped_refptr<Extension> extension = | 1071 scoped_refptr<Extension> extension = |
1069 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); | 1072 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); |
1070 EXPECT_TRUE(extension->is_platform_app()); | 1073 EXPECT_TRUE(extension->is_platform_app()); |
1071 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 1074 EXPECT_TRUE( |
| 1075 extension->permissions_data()->HasAPIPermission(APIPermission::kSocket)); |
1072 std::vector<base::string16> warnings = | 1076 std::vector<base::string16> warnings = |
1073 extension->permissions_data()->GetPermissionMessageStrings(); | 1077 extension->permissions_data()->GetPermissionMessageStrings(); |
1074 | 1078 |
1075 // Verify the warnings, including the fact that domain host warnings come | 1079 // Verify the warnings, including the fact that domain host warnings come |
1076 // before specific host warnings and the fact that domains and hostnames are | 1080 // before specific host warnings and the fact that domains and hostnames are |
1077 // in alphabetical order regardless of the order in the manifest file. | 1081 // in alphabetical order regardless of the order in the manifest file. |
1078 EXPECT_EQ(2u, warnings.size()); | 1082 EXPECT_EQ(2u, warnings.size()); |
1079 if (warnings.size() > 0) | 1083 if (warnings.size() > 0) |
1080 EXPECT_EQ(warnings[0], | 1084 EXPECT_EQ(warnings[0], |
1081 base::UTF8ToUTF16("Exchange data with any computer in the " | 1085 base::UTF8ToUTF16("Exchange data with any computer in the " |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 empty_extent, empty_extent); | 1540 empty_extent, empty_extent); |
1537 EXPECT_EQ(2U, perm_set->apis().size()); | 1541 EXPECT_EQ(2U, perm_set->apis().size()); |
1538 } | 1542 } |
1539 | 1543 |
1540 TEST(PermissionsTest, SyncFileSystemPermission) { | 1544 TEST(PermissionsTest, SyncFileSystemPermission) { |
1541 scoped_refptr<Extension> extension = LoadManifest( | 1545 scoped_refptr<Extension> extension = LoadManifest( |
1542 "permissions", "sync_file_system.json"); | 1546 "permissions", "sync_file_system.json"); |
1543 APIPermissionSet apis; | 1547 APIPermissionSet apis; |
1544 apis.insert(APIPermission::kSyncFileSystem); | 1548 apis.insert(APIPermission::kSyncFileSystem); |
1545 EXPECT_TRUE(extension->is_platform_app()); | 1549 EXPECT_TRUE(extension->is_platform_app()); |
1546 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); | 1550 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 1551 APIPermission::kSyncFileSystem)); |
1547 std::vector<base::string16> warnings = | 1552 std::vector<base::string16> warnings = |
1548 extension->permissions_data()->GetPermissionMessageStrings(); | 1553 extension->permissions_data()->GetPermissionMessageStrings(); |
1549 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); | 1554 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); |
1550 ASSERT_EQ(1u, warnings.size()); | 1555 ASSERT_EQ(1u, warnings.size()); |
1551 } | 1556 } |
1552 | 1557 |
1553 // Make sure that we don't crash when we're trying to show the permissions | 1558 // Make sure that we don't crash when we're trying to show the permissions |
1554 // even though chrome://thumb (and everything that's not chrome://favicon with | 1559 // even though chrome://thumb (and everything that's not chrome://favicon with |
1555 // a chrome:// scheme) is not a valid permission. | 1560 // a chrome:// scheme) is not a valid permission. |
1556 // More details here: crbug/246314. | 1561 // More details here: crbug/246314. |
1557 TEST(PermissionsTest, ChromeURLs) { | 1562 TEST(PermissionsTest, ChromeURLs) { |
1558 URLPatternSet allowed_hosts; | 1563 URLPatternSet allowed_hosts; |
1559 allowed_hosts.AddPattern( | 1564 allowed_hosts.AddPattern( |
1560 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); | 1565 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); |
1561 allowed_hosts.AddPattern( | 1566 allowed_hosts.AddPattern( |
1562 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); | 1567 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); |
1563 allowed_hosts.AddPattern( | 1568 allowed_hosts.AddPattern( |
1564 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); | 1569 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); |
1565 scoped_refptr<PermissionSet> permissions( | 1570 scoped_refptr<PermissionSet> permissions( |
1566 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), | 1571 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), |
1567 allowed_hosts, URLPatternSet())); | 1572 allowed_hosts, URLPatternSet())); |
1568 PermissionMessageProvider::Get()-> | 1573 PermissionMessageProvider::Get()-> |
1569 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); | 1574 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); |
1570 } | 1575 } |
1571 | 1576 |
1572 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { | 1577 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { |
1573 scoped_refptr<Extension> extension( | 1578 scoped_refptr<Extension> extension( |
1574 LoadManifest("permissions", "permissions_all_urls.json")); | 1579 LoadManifest("permissions", "permissions_all_urls.json")); |
1575 scoped_refptr<const PermissionSet> permissions( | 1580 scoped_refptr<const PermissionSet> permissions( |
1576 extension->GetActivePermissions()); | 1581 extension->permissions_data()->active_permissions()); |
1577 | 1582 |
1578 scoped_refptr<Extension> extension_dwr( | 1583 scoped_refptr<Extension> extension_dwr( |
1579 LoadManifest("permissions", "web_request_all_host_permissions.json")); | 1584 LoadManifest("permissions", "web_request_all_host_permissions.json")); |
1580 scoped_refptr<const PermissionSet> permissions_dwr( | 1585 scoped_refptr<const PermissionSet> permissions_dwr( |
1581 extension_dwr->GetActivePermissions()); | 1586 extension_dwr->permissions_data()->active_permissions()); |
1582 | 1587 |
1583 EXPECT_FALSE(PermissionMessageProvider::Get()-> | 1588 EXPECT_FALSE(PermissionMessageProvider::Get()-> |
1584 IsPrivilegeIncrease(permissions.get(), | 1589 IsPrivilegeIncrease(permissions.get(), |
1585 permissions_dwr.get(), | 1590 permissions_dwr.get(), |
1586 extension->GetType())); | 1591 extension->GetType())); |
1587 } | 1592 } |
1588 | 1593 |
1589 } // namespace extensions | 1594 } // namespace extensions |
OLD | NEW |