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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 Manifest::TYPE_PLATFORM_APP)); | 903 Manifest::TYPE_PLATFORM_APP)); |
904 } | 904 } |
905 | 905 |
906 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { | 906 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { |
907 scoped_refptr<Extension> extension; | 907 scoped_refptr<Extension> extension; |
908 | 908 |
909 extension = LoadManifest("permissions", "many-hosts.json"); | 909 extension = LoadManifest("permissions", "many-hosts.json"); |
910 std::vector<base::string16> warnings = | 910 std::vector<base::string16> warnings = |
911 PermissionsData::GetPermissionMessageStrings(extension.get()); | 911 PermissionsData::GetPermissionMessageStrings(extension.get()); |
912 ASSERT_EQ(1u, warnings.size()); | 912 ASSERT_EQ(1u, warnings.size()); |
913 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", | 913 EXPECT_EQ( |
914 base::UTF16ToUTF8(warnings[0])); | 914 "Read and modify your data on encrypted.google.com and " |
| 915 "www.google.com", |
| 916 base::UTF16ToUTF8(warnings[0])); |
915 } | 917 } |
916 | 918 |
917 TEST(PermissionsTest, GetWarningMessages_Plugins) { | 919 TEST(PermissionsTest, GetWarningMessages_Plugins) { |
918 scoped_refptr<Extension> extension; | 920 scoped_refptr<Extension> extension; |
919 scoped_refptr<PermissionSet> permissions; | 921 scoped_refptr<PermissionSet> permissions; |
920 | 922 |
921 extension = LoadManifest("permissions", "plugins.json"); | 923 extension = LoadManifest("permissions", "plugins.json"); |
922 std::vector<base::string16> warnings = | 924 std::vector<base::string16> warnings = |
923 PermissionsData::GetPermissionMessageStrings(extension.get()); | 925 PermissionsData::GetPermissionMessageStrings(extension.get()); |
924 // We don't parse the plugins key on Chrome OS, so it should not ask for any | 926 // We don't parse the plugins key on Chrome OS, so it should not ask for any |
925 // permissions. | 927 // permissions. |
926 #if defined(OS_CHROMEOS) | 928 #if defined(OS_CHROMEOS) |
927 ASSERT_EQ(0u, warnings.size()); | 929 ASSERT_EQ(0u, warnings.size()); |
928 #else | 930 #else |
929 ASSERT_EQ(1u, warnings.size()); | 931 ASSERT_EQ(1u, warnings.size()); |
930 EXPECT_EQ("Access all data on your computer and the websites you visit", | 932 EXPECT_EQ( |
931 base::UTF16ToUTF8(warnings[0])); | 933 "Read and modify all your data on your computer and the websites " |
| 934 "you visit", |
| 935 base::UTF16ToUTF8(warnings[0])); |
932 #endif | 936 #endif |
933 } | 937 } |
934 | 938 |
935 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { | 939 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
936 // Both audio and video present. | 940 // Both audio and video present. |
937 scoped_refptr<Extension> extension = | 941 scoped_refptr<Extension> extension = |
938 LoadManifest("permissions", "audio-video.json"); | 942 LoadManifest("permissions", "audio-video.json"); |
939 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 943 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
940 PermissionSet* set = | 944 PermissionSet* set = |
941 const_cast<PermissionSet*>( | 945 const_cast<PermissionSet*>( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 | 982 |
979 // First verify that declarativeWebRequest produces a message when host | 983 // First verify that declarativeWebRequest produces a message when host |
980 // permissions do not cover all hosts. | 984 // permissions do not cover all hosts. |
981 scoped_refptr<Extension> extension = | 985 scoped_refptr<Extension> extension = |
982 LoadManifest("permissions", "web_request_not_all_host_permissions.json"); | 986 LoadManifest("permissions", "web_request_not_all_host_permissions.json"); |
983 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 987 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
984 const PermissionSet* set = extension->GetActivePermissions().get(); | 988 const PermissionSet* set = extension->GetActivePermissions().get(); |
985 std::vector<base::string16> warnings = | 989 std::vector<base::string16> warnings = |
986 provider->GetWarningMessages(set, extension->GetType()); | 990 provider->GetWarningMessages(set, extension->GetType()); |
987 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); | 991 EXPECT_TRUE(Contains(warnings, "Block parts of web pages")); |
988 EXPECT_FALSE(Contains(warnings, "Access your data on all websites")); | 992 EXPECT_FALSE(Contains(warnings, "Read and modify your data on all websites")); |
989 | 993 |
990 // Now verify that declarativeWebRequest does not produce a message when host | 994 // Now verify that declarativeWebRequest does not produce a message when host |
991 // permissions do cover all hosts. | 995 // permissions do cover all hosts. |
992 extension = | 996 extension = |
993 LoadManifest("permissions", "web_request_all_host_permissions.json"); | 997 LoadManifest("permissions", "web_request_all_host_permissions.json"); |
994 set = extension->GetActivePermissions().get(); | 998 set = extension->GetActivePermissions().get(); |
995 warnings = provider->GetWarningMessages(set, extension->GetType()); | 999 warnings = provider->GetWarningMessages(set, extension->GetType()); |
996 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); | 1000 EXPECT_FALSE(Contains(warnings, "Block parts of web pages")); |
997 EXPECT_TRUE(Contains(warnings, "Access your data on all websites")); | 1001 EXPECT_TRUE(Contains(warnings, "Read and modify your data on all websites")); |
998 } | 1002 } |
999 | 1003 |
1000 TEST(PermissionsTest, GetWarningMessages_Serial) { | 1004 TEST(PermissionsTest, GetWarningMessages_Serial) { |
1001 scoped_refptr<Extension> extension = | 1005 scoped_refptr<Extension> extension = |
1002 LoadManifest("permissions", "serial.json"); | 1006 LoadManifest("permissions", "serial.json"); |
1003 | 1007 |
1004 EXPECT_TRUE(extension->is_platform_app()); | 1008 EXPECT_TRUE(extension->is_platform_app()); |
1005 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); | 1009 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); |
1006 std::vector<base::string16> warnings = | 1010 std::vector<base::string16> warnings = |
1007 PermissionsData::GetPermissionMessageStrings(extension.get()); | 1011 PermissionsData::GetPermissionMessageStrings(extension.get()); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 scoped_refptr<const PermissionSet> permissions_dwr( | 1572 scoped_refptr<const PermissionSet> permissions_dwr( |
1569 extension_dwr->GetActivePermissions()); | 1573 extension_dwr->GetActivePermissions()); |
1570 | 1574 |
1571 EXPECT_FALSE(PermissionMessageProvider::Get()-> | 1575 EXPECT_FALSE(PermissionMessageProvider::Get()-> |
1572 IsPrivilegeIncrease(permissions.get(), | 1576 IsPrivilegeIncrease(permissions.get(), |
1573 permissions_dwr.get(), | 1577 permissions_dwr.get(), |
1574 extension->GetType())); | 1578 extension->GetType())); |
1575 } | 1579 } |
1576 | 1580 |
1577 } // namespace extensions | 1581 } // namespace extensions |
OLD | NEW |