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

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

Issue 18854021: Making the extension permissions dialog scrollable, when needed (adding expandable sections for thi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polishing Created 7 years, 5 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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 EXPECT_EQ(kTests[i].expect_success, 819 EXPECT_EQ(kTests[i].expect_success,
820 empty->HasAnyAccessToAPI(kTests[i].api_name)); 820 empty->HasAnyAccessToAPI(kTests[i].api_name));
821 } 821 }
822 } 822 }
823 823
824 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 824 TEST(PermissionsTest, GetWarningMessages_ManyHosts) {
825 scoped_refptr<Extension> extension; 825 scoped_refptr<Extension> extension;
826 826
827 extension = LoadManifest("permissions", "many-hosts.json"); 827 extension = LoadManifest("permissions", "many-hosts.json");
828 std::vector<string16> warnings = 828 std::vector<string16> warnings =
829 PermissionsData::GetPermissionMessageStrings(extension.get()); 829 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
830 ASSERT_EQ(1u, warnings.size()); 830 ASSERT_EQ(1u, warnings.size());
831 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 831 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
832 UTF16ToUTF8(warnings[0])); 832 UTF16ToUTF8(warnings[0]));
833 } 833 }
834 834
835 TEST(PermissionsTest, GetWarningMessages_Plugins) { 835 TEST(PermissionsTest, GetWarningMessages_Plugins) {
836 scoped_refptr<Extension> extension; 836 scoped_refptr<Extension> extension;
837 scoped_refptr<PermissionSet> permissions; 837 scoped_refptr<PermissionSet> permissions;
838 838
839 extension = LoadManifest("permissions", "plugins.json"); 839 extension = LoadManifest("permissions", "plugins.json");
840 std::vector<string16> warnings = 840 std::vector<string16> warnings =
841 PermissionsData::GetPermissionMessageStrings(extension.get()); 841 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
842 // We don't parse the plugins key on Chrome OS, so it should not ask for any 842 // We don't parse the plugins key on Chrome OS, so it should not ask for any
843 // permissions. 843 // permissions.
844 #if defined(OS_CHROMEOS) 844 #if defined(OS_CHROMEOS)
845 ASSERT_EQ(0u, warnings.size()); 845 ASSERT_EQ(0u, warnings.size());
846 #else 846 #else
847 ASSERT_EQ(1u, warnings.size()); 847 ASSERT_EQ(1u, warnings.size());
848 EXPECT_EQ("Access all data on your computer and the websites you visit", 848 EXPECT_EQ("Access all data on your computer and the websites you visit",
849 UTF16ToUTF8(warnings[0])); 849 UTF16ToUTF8(warnings[0]));
850 #endif 850 #endif
851 } 851 }
852 852
853 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { 853 TEST(PermissionsTest, GetWarningMessages_AudioVideo) {
854 // Both audio and video present. 854 // Both audio and video present.
855 scoped_refptr<Extension> extension = 855 scoped_refptr<Extension> extension =
856 LoadManifest("permissions", "audio-video.json"); 856 LoadManifest("permissions", "audio-video.json");
857 PermissionSet* set = 857 PermissionSet* set =
858 const_cast<PermissionSet*>( 858 const_cast<PermissionSet*>(
859 extension->GetActivePermissions().get()); 859 extension->GetActivePermissions().get());
860 std::vector<string16> warnings = 860 std::vector<string16> warnings =
861 set->GetWarningMessages(extension->GetType()); 861 set->GetWarningMessages(extension->GetType(), false);
862 EXPECT_FALSE(Contains(warnings, "Use your microphone")); 862 EXPECT_FALSE(Contains(warnings, "Use your microphone"));
863 EXPECT_FALSE(Contains(warnings, "Use your camera")); 863 EXPECT_FALSE(Contains(warnings, "Use your camera"));
864 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera")); 864 EXPECT_TRUE(Contains(warnings, "Use your microphone and camera"));
865 size_t combined_index = IndexOf(warnings, "Use your microphone and camera"); 865 size_t combined_index = IndexOf(warnings, "Use your microphone and camera");
866 size_t combined_size = warnings.size(); 866 size_t combined_size = warnings.size();
867 867
868 // Just audio present. 868 // Just audio present.
869 set->apis_.erase(APIPermission::kVideoCapture); 869 set->apis_.erase(APIPermission::kVideoCapture);
870 warnings = set->GetWarningMessages(extension->GetType()); 870 warnings = set->GetWarningMessages(extension->GetType(), false);
871 EXPECT_EQ(combined_size, warnings.size()); 871 EXPECT_EQ(combined_size, warnings.size());
872 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone")); 872 EXPECT_EQ(combined_index, IndexOf(warnings, "Use your microphone"));
873 EXPECT_FALSE(Contains(warnings, "Use your camera")); 873 EXPECT_FALSE(Contains(warnings, "Use your camera"));
874 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); 874 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera"));
875 875
876 // Just video present. 876 // Just video present.
877 set->apis_.erase(APIPermission::kAudioCapture); 877 set->apis_.erase(APIPermission::kAudioCapture);
878 set->apis_.insert(APIPermission::kVideoCapture); 878 set->apis_.insert(APIPermission::kVideoCapture);
879 warnings = set->GetWarningMessages(extension->GetType()); 879 warnings = set->GetWarningMessages(extension->GetType(), false);
880 EXPECT_EQ(combined_size, warnings.size()); 880 EXPECT_EQ(combined_size, warnings.size());
881 EXPECT_FALSE(Contains(warnings, "Use your microphone")); 881 EXPECT_FALSE(Contains(warnings, "Use your microphone"));
882 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); 882 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera"));
883 EXPECT_TRUE(Contains(warnings, "Use your camera")); 883 EXPECT_TRUE(Contains(warnings, "Use your camera"));
884 } 884 }
885 885
886 TEST(PermissionsTest, GetWarningMessages_Serial) { 886 TEST(PermissionsTest, GetWarningMessages_Serial) {
887 scoped_refptr<Extension> extension = 887 scoped_refptr<Extension> extension =
888 LoadManifest("permissions", "serial.json"); 888 LoadManifest("permissions", "serial.json");
889 889
890 EXPECT_TRUE(extension->is_platform_app()); 890 EXPECT_TRUE(extension->is_platform_app());
891 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 891 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
892 std::vector<string16> warnings = 892 std::vector<string16> warnings =
893 PermissionsData::GetPermissionMessageStrings(extension.get()); 893 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
894 EXPECT_TRUE( 894 EXPECT_TRUE(
895 Contains(warnings, "Use serial devices attached to your computer")); 895 Contains(warnings, "Use serial devices attached to your computer"));
896 ASSERT_EQ(1u, warnings.size()); 896 ASSERT_EQ(1u, warnings.size());
897 } 897 }
898 898
899 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 899 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
900 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 900 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
901 901
902 scoped_refptr<Extension> extension = 902 scoped_refptr<Extension> extension =
903 LoadManifest("permissions", "socket_any_host.json"); 903 LoadManifest("permissions", "socket_any_host.json");
904 EXPECT_TRUE(extension->is_platform_app()); 904 EXPECT_TRUE(extension->is_platform_app());
905 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 905 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
906 std::vector<string16> warnings = 906 std::vector<string16> warnings =
907 PermissionsData::GetPermissionMessageStrings(extension.get()); 907 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
908 EXPECT_EQ(1u, warnings.size()); 908 EXPECT_EQ(1u, warnings.size());
909 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 909 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
910 "on the local network or internet")); 910 "on the local network or internet"));
911 } 911 }
912 912
913 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 913 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
914 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 914 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
915 915
916 scoped_refptr<Extension> extension = 916 scoped_refptr<Extension> extension =
917 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 917 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
918 EXPECT_TRUE(extension->is_platform_app()); 918 EXPECT_TRUE(extension->is_platform_app());
919 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 919 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
920 std::vector<string16> warnings = 920 std::vector<string16> warnings =
921 PermissionsData::GetPermissionMessageStrings(extension.get()); 921 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
922 922
923 // Verify the warnings, including support for unicode characters, the fact 923 // Verify the warnings, including support for unicode characters, the fact
924 // that domain host warnings come before specific host warnings, and the fact 924 // that domain host warnings come before specific host warnings, and the fact
925 // that domains and hostnames are in alphabetical order regardless of the 925 // that domains and hostnames are in alphabetical order regardless of the
926 // order in the manifest file. 926 // order in the manifest file.
927 EXPECT_EQ(2u, warnings.size()); 927 EXPECT_EQ(2u, warnings.size());
928 if (warnings.size() > 0) 928 if (warnings.size() > 0)
929 EXPECT_EQ(warnings[0], 929 EXPECT_EQ(warnings[0],
930 UTF8ToUTF16("Exchange data with any computer in the domain " 930 UTF8ToUTF16("Exchange data with any computer in the domain "
931 "example.org")); 931 "example.org"));
932 if (warnings.size() > 1) 932 if (warnings.size() > 1)
933 EXPECT_EQ(warnings[1], 933 EXPECT_EQ(warnings[1],
934 UTF8ToUTF16("Exchange data with the computers named: " 934 UTF8ToUTF16("Exchange data with the computers named: "
935 "b\xC3\xA5r.example.com foo.example.com")); 935 "b\xC3\xA5r.example.com foo.example.com"));
936 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 936 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
937 } 937 }
938 938
939 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 939 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
940 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 940 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
941 941
942 scoped_refptr<Extension> extension = 942 scoped_refptr<Extension> extension =
943 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 943 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
944 EXPECT_TRUE(extension->is_platform_app()); 944 EXPECT_TRUE(extension->is_platform_app());
945 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 945 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
946 std::vector<string16> warnings = 946 std::vector<string16> warnings =
947 PermissionsData::GetPermissionMessageStrings(extension.get()); 947 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
948 948
949 // Verify the warnings, including the fact that domain host warnings come 949 // Verify the warnings, including the fact that domain host warnings come
950 // before specific host warnings and the fact that domains and hostnames are 950 // before specific host warnings and the fact that domains and hostnames are
951 // in alphabetical order regardless of the order in the manifest file. 951 // in alphabetical order regardless of the order in the manifest file.
952 EXPECT_EQ(2u, warnings.size()); 952 EXPECT_EQ(2u, warnings.size());
953 if (warnings.size() > 0) 953 if (warnings.size() > 0)
954 EXPECT_EQ(warnings[0], 954 EXPECT_EQ(warnings[0],
955 UTF8ToUTF16("Exchange data with any computer in the domains: " 955 UTF8ToUTF16("Exchange data with any computer in the domains: "
956 "example.com foo.example.org")); 956 "example.com foo.example.org"));
957 if (warnings.size() > 1) 957 if (warnings.size() > 1)
958 EXPECT_EQ(warnings[1], 958 EXPECT_EQ(warnings[1],
959 UTF8ToUTF16("Exchange data with the computer named " 959 UTF8ToUTF16("Exchange data with the computer named "
960 "bar.example.org")); 960 "bar.example.org"));
961 } 961 }
962 962
963 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 963 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
964 scoped_refptr<Extension> extension; 964 scoped_refptr<Extension> extension;
965 965
966 extension = LoadManifest("permissions", "platform_app_hosts.json"); 966 extension = LoadManifest("permissions", "platform_app_hosts.json");
967 EXPECT_TRUE(extension->is_platform_app()); 967 EXPECT_TRUE(extension->is_platform_app());
968 std::vector<string16> warnings = 968 std::vector<string16> warnings =
969 PermissionsData::GetPermissionMessageStrings(extension.get()); 969 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
970 ASSERT_EQ(0u, warnings.size()); 970 ASSERT_EQ(0u, warnings.size());
971 971
972 extension = LoadManifest("permissions", "platform_app_all_urls.json"); 972 extension = LoadManifest("permissions", "platform_app_all_urls.json");
973 EXPECT_TRUE(extension->is_platform_app()); 973 EXPECT_TRUE(extension->is_platform_app());
974 warnings = PermissionsData::GetPermissionMessageStrings(extension.get()); 974 warnings = PermissionsData::GetPermissionMessageStrings(
975 extension.get(), false);
975 ASSERT_EQ(0u, warnings.size()); 976 ASSERT_EQ(0u, warnings.size());
976 } 977 }
977 978
978 TEST(PermissionsTest, GetDistinctHostsForDisplay) { 979 TEST(PermissionsTest, GetDistinctHostsForDisplay) {
979 scoped_refptr<PermissionSet> perm_set; 980 scoped_refptr<PermissionSet> perm_set;
980 APIPermissionSet empty_perms; 981 APIPermissionSet empty_perms;
981 std::set<std::string> expected; 982 std::set<std::string> expected;
982 expected.insert("www.foo.com"); 983 expected.insert("www.foo.com");
983 expected.insert("www.bar.com"); 984 expected.insert("www.bar.com");
984 expected.insert("www.baz.com"); 985 expected.insert("www.baz.com");
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 } 1366 }
1366 1367
1367 TEST(PermissionsTest, SyncFileSystemPermission) { 1368 TEST(PermissionsTest, SyncFileSystemPermission) {
1368 scoped_refptr<Extension> extension = LoadManifest( 1369 scoped_refptr<Extension> extension = LoadManifest(
1369 "permissions", "sync_file_system.json"); 1370 "permissions", "sync_file_system.json");
1370 APIPermissionSet apis; 1371 APIPermissionSet apis;
1371 apis.insert(APIPermission::kSyncFileSystem); 1372 apis.insert(APIPermission::kSyncFileSystem);
1372 EXPECT_TRUE(extension->is_platform_app()); 1373 EXPECT_TRUE(extension->is_platform_app());
1373 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); 1374 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem));
1374 std::vector<string16> warnings = 1375 std::vector<string16> warnings =
1375 PermissionsData::GetPermissionMessageStrings(extension.get()); 1376 PermissionsData::GetPermissionMessageStrings(extension.get(), false);
1376 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); 1377 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account"));
1377 ASSERT_EQ(1u, warnings.size()); 1378 ASSERT_EQ(1u, warnings.size());
1378 } 1379 }
1379 1380
1380 // Make sure that we don't crash when we're trying to show the permissions 1381 // Make sure that we don't crash when we're trying to show the permissions
1381 // even though chrome://thumb (and everything that's not chrome://favicon with 1382 // even though chrome://thumb (and everything that's not chrome://favicon with
1382 // a chrome:// scheme) is not a valid permission. 1383 // a chrome:// scheme) is not a valid permission.
1383 // More details here: crbug/246314. 1384 // More details here: crbug/246314.
1384 TEST(PermissionsTest, ChromeURLs) { 1385 TEST(PermissionsTest, ChromeURLs) {
1385 URLPatternSet allowed_hosts; 1386 URLPatternSet allowed_hosts;
1386 allowed_hosts.AddPattern( 1387 allowed_hosts.AddPattern(
1387 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); 1388 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/"));
1388 allowed_hosts.AddPattern( 1389 allowed_hosts.AddPattern(
1389 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); 1390 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/"));
1390 allowed_hosts.AddPattern( 1391 allowed_hosts.AddPattern(
1391 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); 1392 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/"));
1392 scoped_refptr<PermissionSet> permissions( 1393 scoped_refptr<PermissionSet> permissions(
1393 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); 1394 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet()));
1394 permissions->GetPermissionMessages(Manifest::TYPE_EXTENSION); 1395 permissions->GetPermissionMessages(Manifest::TYPE_EXTENSION, false);
1395 } 1396 }
1396 1397
1397 } // namespace extensions 1398 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698