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

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

Issue 105473003: Add explicit base namespace to string16 users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 15 matching lines...) Expand all
26 26
27 namespace extensions { 27 namespace extensions {
28 28
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<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] == 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<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 }
50 50
51 } // namespace 51 } // namespace
52 52
53 // Tests GetByID. 53 // Tests GetByID.
54 TEST(PermissionsTest, GetByID) { 54 TEST(PermissionsTest, GetByID) {
55 PermissionsInfo* info = PermissionsInfo::GetInstance(); 55 PermissionsInfo* info = PermissionsInfo::GetInstance();
56 APIPermissionSet apis = info->GetAll(); 56 APIPermissionSet apis = info->GetAll();
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 Manifest::TYPE_PLATFORM_APP)); 868 Manifest::TYPE_PLATFORM_APP));
869 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions, 869 EXPECT_TRUE(provider->IsPrivilegeIncrease(directory_permissions,
870 write_directory_permissions, 870 write_directory_permissions,
871 Manifest::TYPE_PLATFORM_APP)); 871 Manifest::TYPE_PLATFORM_APP));
872 } 872 }
873 873
874 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 874 TEST(PermissionsTest, GetWarningMessages_ManyHosts) {
875 scoped_refptr<Extension> extension; 875 scoped_refptr<Extension> extension;
876 876
877 extension = LoadManifest("permissions", "many-hosts.json"); 877 extension = LoadManifest("permissions", "many-hosts.json");
878 std::vector<string16> warnings = 878 std::vector<base::string16> warnings =
879 PermissionsData::GetPermissionMessageStrings(extension.get()); 879 PermissionsData::GetPermissionMessageStrings(extension.get());
880 ASSERT_EQ(1u, warnings.size()); 880 ASSERT_EQ(1u, warnings.size());
881 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 881 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
882 UTF16ToUTF8(warnings[0])); 882 UTF16ToUTF8(warnings[0]));
883 } 883 }
884 884
885 TEST(PermissionsTest, GetWarningMessages_Plugins) { 885 TEST(PermissionsTest, GetWarningMessages_Plugins) {
886 scoped_refptr<Extension> extension; 886 scoped_refptr<Extension> extension;
887 scoped_refptr<PermissionSet> permissions; 887 scoped_refptr<PermissionSet> permissions;
888 888
889 extension = LoadManifest("permissions", "plugins.json"); 889 extension = LoadManifest("permissions", "plugins.json");
890 std::vector<string16> warnings = 890 std::vector<base::string16> warnings =
891 PermissionsData::GetPermissionMessageStrings(extension.get()); 891 PermissionsData::GetPermissionMessageStrings(extension.get());
892 // We don't parse the plugins key on Chrome OS, so it should not ask for any 892 // We don't parse the plugins key on Chrome OS, so it should not ask for any
893 // permissions. 893 // permissions.
894 #if defined(OS_CHROMEOS) 894 #if defined(OS_CHROMEOS)
895 ASSERT_EQ(0u, warnings.size()); 895 ASSERT_EQ(0u, warnings.size());
896 #else 896 #else
897 ASSERT_EQ(1u, warnings.size()); 897 ASSERT_EQ(1u, warnings.size());
898 EXPECT_EQ("Access all data on your computer and the websites you visit", 898 EXPECT_EQ("Access all data on your computer and the websites you visit",
899 UTF16ToUTF8(warnings[0])); 899 UTF16ToUTF8(warnings[0]));
900 #endif 900 #endif
901 } 901 }
902 902
903 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { 903 TEST(PermissionsTest, GetWarningMessages_AudioVideo) {
904 // Both audio and video present. 904 // Both audio and video present.
905 scoped_refptr<Extension> extension = 905 scoped_refptr<Extension> extension =
906 LoadManifest("permissions", "audio-video.json"); 906 LoadManifest("permissions", "audio-video.json");
907 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); 907 const PermissionMessageProvider* provider = PermissionMessageProvider::Get();
908 PermissionSet* set = 908 PermissionSet* set =
909 const_cast<PermissionSet*>( 909 const_cast<PermissionSet*>(
910 extension->GetActivePermissions().get()); 910 extension->GetActivePermissions().get());
911 std::vector<string16> warnings = 911 std::vector<base::string16> warnings =
912 provider->GetWarningMessages(set, extension->GetType()); 912 provider->GetWarningMessages(set, extension->GetType());
913 EXPECT_FALSE(Contains(warnings, "Use your microphone")); 913 EXPECT_FALSE(Contains(warnings, "Use your microphone"));
914 EXPECT_FALSE(Contains(warnings, "Use your camera")); 914 EXPECT_FALSE(Contains(warnings, "Use your camera"));
915 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); 915 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera"));
916 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); 916 size_t combined_index = IndexOf(warnings, "Use your microphone and camera");
917 size_t combined_size = warnings.size(); 917 size_t combined_size = warnings.size();
918 918
919 // Just audio present. 919 // Just audio present.
920 set->apis_.erase(APIPermission::kVideoCapture); 920 set->apis_.erase(APIPermission::kVideoCapture);
921 warnings = provider->GetWarningMessages(set, extension->GetType()); 921 warnings = provider->GetWarningMessages(set, extension->GetType());
(...skipping 21 matching lines...) Expand all
943 // Until Declarative Web Request is in stable, let's make sure it is enabled 943 // Until Declarative Web Request is in stable, let's make sure it is enabled
944 // on the current channel. 944 // on the current channel.
945 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY); 945 ScopedCurrentChannel sc(chrome::VersionInfo::CHANNEL_CANARY);
946 946
947 // First verify that declarativeWebRequest produces a message when host 947 // First verify that declarativeWebRequest produces a message when host
948 // permissions do not cover all hosts. 948 // permissions do not cover all hosts.
949 scoped_refptr<Extension> extension = 949 scoped_refptr<Extension> extension =
950 LoadManifest("permissions", "web_request_com_host_permissions.json"); 950 LoadManifest("permissions", "web_request_com_host_permissions.json");
951 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); 951 const PermissionMessageProvider* provider = PermissionMessageProvider::Get();
952 const PermissionSet* set = extension->GetActivePermissions().get(); 952 const PermissionSet* set = extension->GetActivePermissions().get();
953 std::vector<string16> warnings = 953 std::vector<base::string16> warnings =
954 provider->GetWarningMessages(set, extension->GetType()); 954 provider->GetWarningMessages(set, extension->GetType());
955 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); 955 EXPECT_TRUE(Contains(warnings, "Block parts of web pages"));
956 EXPECT_FALSE(Contains(warnings, "Access your data on all websites")); 956 EXPECT_FALSE(Contains(warnings, "Access your data on all websites"));
957 957
958 // Now verify that declarativeWebRequest does not produce a message when host 958 // Now verify that declarativeWebRequest does not produce a message when host
959 // permissions do cover all hosts. 959 // permissions do cover all hosts.
960 extension = 960 extension =
961 LoadManifest("permissions", "web_request_all_host_permissions.json"); 961 LoadManifest("permissions", "web_request_all_host_permissions.json");
962 set = extension->GetActivePermissions().get(); 962 set = extension->GetActivePermissions().get();
963 warnings = provider->GetWarningMessages(set, extension->GetType()); 963 warnings = provider->GetWarningMessages(set, extension->GetType());
964 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); 964 EXPECT_FALSE(Contains(warnings, "Block parts of web pages"));
965 EXPECT_TRUE(Contains(warnings, "Access your data on all websites")); 965 EXPECT_TRUE(Contains(warnings, "Access your data on all websites"));
966 } 966 }
967 967
968 TEST(PermissionsTest, GetWarningMessages_Serial) { 968 TEST(PermissionsTest, GetWarningMessages_Serial) {
969 scoped_refptr<Extension> extension = 969 scoped_refptr<Extension> extension =
970 LoadManifest("permissions", "serial.json"); 970 LoadManifest("permissions", "serial.json");
971 971
972 EXPECT_TRUE(extension->is_platform_app()); 972 EXPECT_TRUE(extension->is_platform_app());
973 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 973 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
974 std::vector<string16> warnings = 974 std::vector<base::string16> warnings =
975 PermissionsData::GetPermissionMessageStrings(extension.get()); 975 PermissionsData::GetPermissionMessageStrings(extension.get());
976 EXPECT_TRUE( 976 EXPECT_TRUE(
977 Contains(warnings, "Use serial devices attached to your computer")); 977 Contains(warnings, "Use serial devices attached to your computer"));
978 ASSERT_EQ(1u, warnings.size()); 978 ASSERT_EQ(1u, warnings.size());
979 } 979 }
980 980
981 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 981 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
982 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 982 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
983 983
984 scoped_refptr<Extension> extension = 984 scoped_refptr<Extension> extension =
985 LoadManifest("permissions", "socket_any_host.json"); 985 LoadManifest("permissions", "socket_any_host.json");
986 EXPECT_TRUE(extension->is_platform_app()); 986 EXPECT_TRUE(extension->is_platform_app());
987 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 987 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
988 std::vector<string16> warnings = 988 std::vector<base::string16> warnings =
989 PermissionsData::GetPermissionMessageStrings(extension.get()); 989 PermissionsData::GetPermissionMessageStrings(extension.get());
990 EXPECT_EQ(1u, warnings.size()); 990 EXPECT_EQ(1u, warnings.size());
991 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 991 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
992 "on the local network or internet")); 992 "on the local network or internet"));
993 } 993 }
994 994
995 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 995 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
996 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 996 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
997 997
998 scoped_refptr<Extension> extension = 998 scoped_refptr<Extension> extension =
999 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 999 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
1000 EXPECT_TRUE(extension->is_platform_app()); 1000 EXPECT_TRUE(extension->is_platform_app());
1001 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1001 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1002 std::vector<string16> warnings = 1002 std::vector<base::string16> warnings =
1003 PermissionsData::GetPermissionMessageStrings(extension.get()); 1003 PermissionsData::GetPermissionMessageStrings(extension.get());
1004 1004
1005 // Verify the warnings, including support for unicode characters, the fact 1005 // Verify the warnings, including support for unicode characters, the fact
1006 // that domain host warnings come before specific host warnings, and the fact 1006 // that domain host warnings come before specific host warnings, and the fact
1007 // that domains and hostnames are in alphabetical order regardless of the 1007 // that domains and hostnames are in alphabetical order regardless of the
1008 // order in the manifest file. 1008 // order in the manifest file.
1009 EXPECT_EQ(2u, warnings.size()); 1009 EXPECT_EQ(2u, warnings.size());
1010 if (warnings.size() > 0) 1010 if (warnings.size() > 0)
1011 EXPECT_EQ(warnings[0], 1011 EXPECT_EQ(warnings[0],
1012 UTF8ToUTF16("Exchange data with any computer in the domain " 1012 UTF8ToUTF16("Exchange data with any computer in the domain "
1013 "example.org")); 1013 "example.org"));
1014 if (warnings.size() > 1) 1014 if (warnings.size() > 1)
1015 EXPECT_EQ(warnings[1], 1015 EXPECT_EQ(warnings[1],
1016 UTF8ToUTF16("Exchange data with the computers named: " 1016 UTF8ToUTF16("Exchange data with the computers named: "
1017 "b\xC3\xA5r.example.com foo.example.com")); 1017 "b\xC3\xA5r.example.com foo.example.com"));
1018 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 1018 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
1019 } 1019 }
1020 1020
1021 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 1021 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
1022 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 1022 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
1023 1023
1024 scoped_refptr<Extension> extension = 1024 scoped_refptr<Extension> extension =
1025 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 1025 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
1026 EXPECT_TRUE(extension->is_platform_app()); 1026 EXPECT_TRUE(extension->is_platform_app());
1027 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 1027 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
1028 std::vector<string16> warnings = 1028 std::vector<base::string16> warnings =
1029 PermissionsData::GetPermissionMessageStrings(extension.get()); 1029 PermissionsData::GetPermissionMessageStrings(extension.get());
1030 1030
1031 // Verify the warnings, including the fact that domain host warnings come 1031 // Verify the warnings, including the fact that domain host warnings come
1032 // before specific host warnings and the fact that domains and hostnames are 1032 // before specific host warnings and the fact that domains and hostnames are
1033 // in alphabetical order regardless of the order in the manifest file. 1033 // in alphabetical order regardless of the order in the manifest file.
1034 EXPECT_EQ(2u, warnings.size()); 1034 EXPECT_EQ(2u, warnings.size());
1035 if (warnings.size() > 0) 1035 if (warnings.size() > 0)
1036 EXPECT_EQ(warnings[0], 1036 EXPECT_EQ(warnings[0],
1037 UTF8ToUTF16("Exchange data with any computer in the domains: " 1037 UTF8ToUTF16("Exchange data with any computer in the domains: "
1038 "example.com foo.example.org")); 1038 "example.com foo.example.org"));
1039 if (warnings.size() > 1) 1039 if (warnings.size() > 1)
1040 EXPECT_EQ(warnings[1], 1040 EXPECT_EQ(warnings[1],
1041 UTF8ToUTF16("Exchange data with the computer named " 1041 UTF8ToUTF16("Exchange data with the computer named "
1042 "bar.example.org")); 1042 "bar.example.org"));
1043 } 1043 }
1044 1044
1045 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 1045 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
1046 scoped_refptr<Extension> extension; 1046 scoped_refptr<Extension> extension;
1047 1047
1048 extension = LoadManifest("permissions", "platform_app_hosts.json"); 1048 extension = LoadManifest("permissions", "platform_app_hosts.json");
1049 EXPECT_TRUE(extension->is_platform_app()); 1049 EXPECT_TRUE(extension->is_platform_app());
1050 std::vector<string16> warnings = 1050 std::vector<base::string16> warnings =
1051 PermissionsData::GetPermissionMessageStrings(extension.get()); 1051 PermissionsData::GetPermissionMessageStrings(extension.get());
1052 ASSERT_EQ(0u, warnings.size()); 1052 ASSERT_EQ(0u, warnings.size());
1053 1053
1054 extension = LoadManifest("permissions", "platform_app_all_urls.json"); 1054 extension = LoadManifest("permissions", "platform_app_all_urls.json");
1055 EXPECT_TRUE(extension->is_platform_app()); 1055 EXPECT_TRUE(extension->is_platform_app());
1056 warnings = PermissionsData::GetPermissionMessageStrings(extension.get()); 1056 warnings = PermissionsData::GetPermissionMessageStrings(extension.get());
1057 ASSERT_EQ(0u, warnings.size()); 1057 ASSERT_EQ(0u, warnings.size());
1058 } 1058 }
1059 1059
1060 TEST(PermissionsTest, GetDistinctHosts) { 1060 TEST(PermissionsTest, GetDistinctHosts) {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 EXPECT_EQ(4U, perm_set->apis().size()); 1445 EXPECT_EQ(4U, perm_set->apis().size());
1446 } 1446 }
1447 1447
1448 TEST(PermissionsTest, SyncFileSystemPermission) { 1448 TEST(PermissionsTest, SyncFileSystemPermission) {
1449 scoped_refptr<Extension> extension = LoadManifest( 1449 scoped_refptr<Extension> extension = LoadManifest(
1450 "permissions", "sync_file_system.json"); 1450 "permissions", "sync_file_system.json");
1451 APIPermissionSet apis; 1451 APIPermissionSet apis;
1452 apis.insert(APIPermission::kSyncFileSystem); 1452 apis.insert(APIPermission::kSyncFileSystem);
1453 EXPECT_TRUE(extension->is_platform_app()); 1453 EXPECT_TRUE(extension->is_platform_app());
1454 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); 1454 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem));
1455 std::vector<string16> warnings = 1455 std::vector<base::string16> warnings =
1456 PermissionsData::GetPermissionMessageStrings(extension.get()); 1456 PermissionsData::GetPermissionMessageStrings(extension.get());
1457 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); 1457 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account"));
1458 ASSERT_EQ(1u, warnings.size()); 1458 ASSERT_EQ(1u, warnings.size());
1459 } 1459 }
1460 1460
1461 // Make sure that we don't crash when we're trying to show the permissions 1461 // Make sure that we don't crash when we're trying to show the permissions
1462 // even though chrome://thumb (and everything that's not chrome://favicon with 1462 // even though chrome://thumb (and everything that's not chrome://favicon with
1463 // a chrome:// scheme) is not a valid permission. 1463 // a chrome:// scheme) is not a valid permission.
1464 // More details here: crbug/246314. 1464 // More details here: crbug/246314.
1465 TEST(PermissionsTest, ChromeURLs) { 1465 TEST(PermissionsTest, ChromeURLs) {
(...skipping 22 matching lines...) Expand all
1488 scoped_refptr<const PermissionSet> permissions_dwr( 1488 scoped_refptr<const PermissionSet> permissions_dwr(
1489 extension_dwr->GetActivePermissions()); 1489 extension_dwr->GetActivePermissions());
1490 1490
1491 EXPECT_FALSE(PermissionMessageProvider::Get()-> 1491 EXPECT_FALSE(PermissionMessageProvider::Get()->
1492 IsPrivilegeIncrease(permissions.get(), 1492 IsPrivilegeIncrease(permissions.get(),
1493 permissions_dwr.get(), 1493 permissions_dwr.get(),
1494 extension->GetType())); 1494 extension->GetType()));
1495 } 1495 }
1496 1496
1497 } // namespace extensions 1497 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698