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

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

Issue 93793010: Update uses of UTF conversions in chrome/common to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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 18 matching lines...) Expand all
29 namespace { 29 namespace {
30 30
31 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 31 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
32 int schemes = URLPattern::SCHEME_ALL; 32 int schemes = URLPattern::SCHEME_ALL;
33 extent->AddPattern(URLPattern(schemes, pattern)); 33 extent->AddPattern(URLPattern(schemes, pattern));
34 } 34 }
35 35
36 size_t IndexOf(const std::vector<base::string16>& warnings, 36 size_t IndexOf(const std::vector<base::string16>& warnings,
37 const std::string& warning) { 37 const std::string& warning) {
38 for (size_t i = 0; i < warnings.size(); ++i) { 38 for (size_t i = 0; i < warnings.size(); ++i) {
39 if (warnings[i] == ASCIIToUTF16(warning)) 39 if (warnings[i] == base::ASCIIToUTF16(warning))
40 return i; 40 return i;
41 } 41 }
42 42
43 return warnings.size(); 43 return warnings.size();
44 } 44 }
45 45
46 bool Contains(const std::vector<base::string16>& warnings, 46 bool Contains(const std::vector<base::string16>& warnings,
47 const std::string& warning) { 47 const std::string& warning) {
48 return IndexOf(warnings, warning) != warnings.size(); 48 return IndexOf(warnings, warning) != warnings.size();
49 } 49 }
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 870 }
871 871
872 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 872 TEST(PermissionsTest, GetWarningMessages_ManyHosts) {
873 scoped_refptr<Extension> extension; 873 scoped_refptr<Extension> extension;
874 874
875 extension = LoadManifest("permissions", "many-hosts.json"); 875 extension = LoadManifest("permissions", "many-hosts.json");
876 std::vector<base::string16> warnings = 876 std::vector<base::string16> warnings =
877 PermissionsData::GetPermissionMessageStrings(extension.get()); 877 PermissionsData::GetPermissionMessageStrings(extension.get());
878 ASSERT_EQ(1u, warnings.size()); 878 ASSERT_EQ(1u, warnings.size());
879 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 879 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
880 UTF16ToUTF8(warnings[0])); 880 base::UTF16ToUTF8(warnings[0]));
881 } 881 }
882 882
883 TEST(PermissionsTest, GetWarningMessages_Plugins) { 883 TEST(PermissionsTest, GetWarningMessages_Plugins) {
884 scoped_refptr<Extension> extension; 884 scoped_refptr<Extension> extension;
885 scoped_refptr<PermissionSet> permissions; 885 scoped_refptr<PermissionSet> permissions;
886 886
887 extension = LoadManifest("permissions", "plugins.json"); 887 extension = LoadManifest("permissions", "plugins.json");
888 std::vector<base::string16> warnings = 888 std::vector<base::string16> warnings =
889 PermissionsData::GetPermissionMessageStrings(extension.get()); 889 PermissionsData::GetPermissionMessageStrings(extension.get());
890 // We don't parse the plugins key on Chrome OS, so it should not ask for any 890 // We don't parse the plugins key on Chrome OS, so it should not ask for any
891 // permissions. 891 // permissions.
892 #if defined(OS_CHROMEOS) 892 #if defined(OS_CHROMEOS)
893 ASSERT_EQ(0u, warnings.size()); 893 ASSERT_EQ(0u, warnings.size());
894 #else 894 #else
895 ASSERT_EQ(1u, warnings.size()); 895 ASSERT_EQ(1u, warnings.size());
896 EXPECT_EQ("Access all data on your computer and the websites you visit", 896 EXPECT_EQ("Access all data on your computer and the websites you visit",
897 UTF16ToUTF8(warnings[0])); 897 base::UTF16ToUTF8(warnings[0]));
898 #endif 898 #endif
899 } 899 }
900 900
901 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { 901 TEST(PermissionsTest, GetWarningMessages_AudioVideo) {
902 // Both audio and video present. 902 // Both audio and video present.
903 scoped_refptr<Extension> extension = 903 scoped_refptr<Extension> extension =
904 LoadManifest("permissions", "audio-video.json"); 904 LoadManifest("permissions", "audio-video.json");
905 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); 905 const PermissionMessageProvider* provider = PermissionMessageProvider::Get();
906 PermissionSet* set = 906 PermissionSet* set =
907 const_cast<PermissionSet*>( 907 const_cast<PermissionSet*>(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 std::vector<base::string16> warnings = 1000 std::vector<base::string16> warnings =
1001 PermissionsData::GetPermissionMessageStrings(extension.get()); 1001 PermissionsData::GetPermissionMessageStrings(extension.get());
1002 1002
1003 // Verify the warnings, including support for unicode characters, the fact 1003 // Verify the warnings, including support for unicode characters, the fact
1004 // that domain host warnings come before specific host warnings, and the fact 1004 // that domain host warnings come before specific host warnings, and the fact
1005 // that domains and hostnames are in alphabetical order regardless of the 1005 // that domains and hostnames are in alphabetical order regardless of the
1006 // order in the manifest file. 1006 // order in the manifest file.
1007 EXPECT_EQ(2u, warnings.size()); 1007 EXPECT_EQ(2u, warnings.size());
1008 if (warnings.size() > 0) 1008 if (warnings.size() > 0)
1009 EXPECT_EQ(warnings[0], 1009 EXPECT_EQ(warnings[0],
1010 UTF8ToUTF16("Exchange data with any computer in the domain " 1010 base::UTF8ToUTF16("Exchange data with any computer in the domain "
1011 "example.org")); 1011 "example.org"));
1012 if (warnings.size() > 1) 1012 if (warnings.size() > 1)
1013 EXPECT_EQ(warnings[1], 1013 EXPECT_EQ(warnings[1],
1014 UTF8ToUTF16("Exchange data with the computers named: " 1014 base::UTF8ToUTF16("Exchange data with the computers named: "
1015 "b\xC3\xA5r.example.com foo.example.com")); 1015 "b\xC3\xA5r.example.com foo.example.com"));
1016 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 1016 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
1017 } 1017 }
1018 1018
1019 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 1019 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
1020 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 1020 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
1021 1021
1022 scoped_refptr<Extension> extension = 1022 scoped_refptr<Extension> extension =
1023 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 1023 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
1024 EXPECT_TRUE(extension->is_platform_app()); 1024 EXPECT_TRUE(extension->is_platform_app());
1025 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1025 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1026 std::vector<base::string16> warnings = 1026 std::vector<base::string16> warnings =
1027 PermissionsData::GetPermissionMessageStrings(extension.get()); 1027 PermissionsData::GetPermissionMessageStrings(extension.get());
1028 1028
1029 // Verify the warnings, including the fact that domain host warnings come 1029 // Verify the warnings, including the fact that domain host warnings come
1030 // before specific host warnings and the fact that domains and hostnames are 1030 // before specific host warnings and the fact that domains and hostnames are
1031 // in alphabetical order regardless of the order in the manifest file. 1031 // in alphabetical order regardless of the order in the manifest file.
1032 EXPECT_EQ(2u, warnings.size()); 1032 EXPECT_EQ(2u, warnings.size());
1033 if (warnings.size() > 0) 1033 if (warnings.size() > 0)
1034 EXPECT_EQ(warnings[0], 1034 EXPECT_EQ(warnings[0],
1035 UTF8ToUTF16("Exchange data with any computer in the domains: " 1035 base::UTF8ToUTF16("Exchange data with any computer in the "
1036 "example.com foo.example.org")); 1036 "domains: example.com foo.example.org"));
1037 if (warnings.size() > 1) 1037 if (warnings.size() > 1)
1038 EXPECT_EQ(warnings[1], 1038 EXPECT_EQ(warnings[1],
1039 UTF8ToUTF16("Exchange data with the computer named " 1039 base::UTF8ToUTF16("Exchange data with the computer named "
1040 "bar.example.org")); 1040 "bar.example.org"));
1041 } 1041 }
1042 1042
1043 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 1043 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
1044 scoped_refptr<Extension> extension; 1044 scoped_refptr<Extension> extension;
1045 1045
1046 extension = LoadManifest("permissions", "platform_app_hosts.json"); 1046 extension = LoadManifest("permissions", "platform_app_hosts.json");
1047 EXPECT_TRUE(extension->is_platform_app()); 1047 EXPECT_TRUE(extension->is_platform_app());
1048 std::vector<base::string16> warnings = 1048 std::vector<base::string16> warnings =
1049 PermissionsData::GetPermissionMessageStrings(extension.get()); 1049 PermissionsData::GetPermissionMessageStrings(extension.get());
1050 ASSERT_EQ(0u, warnings.size()); 1050 ASSERT_EQ(0u, warnings.size());
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 scoped_refptr<const PermissionSet> permissions_dwr( 1486 scoped_refptr<const PermissionSet> permissions_dwr(
1487 extension_dwr->GetActivePermissions()); 1487 extension_dwr->GetActivePermissions());
1488 1488
1489 EXPECT_FALSE(PermissionMessageProvider::Get()-> 1489 EXPECT_FALSE(PermissionMessageProvider::Get()->
1490 IsPrivilegeIncrease(permissions.get(), 1490 IsPrivilegeIncrease(permissions.get(),
1491 permissions_dwr.get(), 1491 permissions_dwr.get(),
1492 extension->GetType())); 1492 extension->GetType()));
1493 } 1493 }
1494 1494
1495 } // namespace extensions 1495 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698