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

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

Issue 22299009: Move channel-related (Chrome-specific) global state out of Feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_test_util.h" 13 #include "chrome/common/extensions/extension_test_util.h"
14 #include "chrome/common/extensions/features/feature.h" 14 #include "chrome/common/extensions/features/feature_channel.h"
15 #include "chrome/common/extensions/permissions/permission_set.h" 15 #include "chrome/common/extensions/permissions/permission_set.h"
16 #include "chrome/common/extensions/permissions/permissions_data.h" 16 #include "chrome/common/extensions/permissions/permissions_data.h"
17 #include "chrome/common/extensions/permissions/permissions_info.h" 17 #include "chrome/common/extensions/permissions/permissions_info.h"
18 #include "chrome/common/extensions/permissions/socket_permission.h" 18 #include "chrome/common/extensions/permissions/socket_permission.h"
19 #include "extensions/common/error_utils.h" 19 #include "extensions/common/error_utils.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 using extension_test_util::LoadManifest; 22 using extension_test_util::LoadManifest;
23 23
24 namespace extensions { 24 namespace extensions {
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXPECT_TRUE(extension->is_platform_app()); 828 EXPECT_TRUE(extension->is_platform_app());
829 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 829 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
830 std::vector<string16> warnings = 830 std::vector<string16> warnings =
831 PermissionsData::GetPermissionMessageStrings(extension.get()); 831 PermissionsData::GetPermissionMessageStrings(extension.get());
832 EXPECT_TRUE( 832 EXPECT_TRUE(
833 Contains(warnings, "Use serial devices attached to your computer")); 833 Contains(warnings, "Use serial devices attached to your computer"));
834 ASSERT_EQ(1u, warnings.size()); 834 ASSERT_EQ(1u, warnings.size());
835 } 835 }
836 836
837 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 837 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
838 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 838 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
839 839
840 scoped_refptr<Extension> extension = 840 scoped_refptr<Extension> extension =
841 LoadManifest("permissions", "socket_any_host.json"); 841 LoadManifest("permissions", "socket_any_host.json");
842 EXPECT_TRUE(extension->is_platform_app()); 842 EXPECT_TRUE(extension->is_platform_app());
843 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 843 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
844 std::vector<string16> warnings = 844 std::vector<string16> warnings =
845 PermissionsData::GetPermissionMessageStrings(extension.get()); 845 PermissionsData::GetPermissionMessageStrings(extension.get());
846 EXPECT_EQ(1u, warnings.size()); 846 EXPECT_EQ(1u, warnings.size());
847 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 847 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
848 "on the local network or internet")); 848 "on the local network or internet"));
849 } 849 }
850 850
851 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 851 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
852 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 852 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
853 853
854 scoped_refptr<Extension> extension = 854 scoped_refptr<Extension> extension =
855 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 855 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
856 EXPECT_TRUE(extension->is_platform_app()); 856 EXPECT_TRUE(extension->is_platform_app());
857 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 857 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
858 std::vector<string16> warnings = 858 std::vector<string16> warnings =
859 PermissionsData::GetPermissionMessageStrings(extension.get()); 859 PermissionsData::GetPermissionMessageStrings(extension.get());
860 860
861 // Verify the warnings, including support for unicode characters, the fact 861 // Verify the warnings, including support for unicode characters, the fact
862 // that domain host warnings come before specific host warnings, and the fact 862 // that domain host warnings come before specific host warnings, and the fact
863 // that domains and hostnames are in alphabetical order regardless of the 863 // that domains and hostnames are in alphabetical order regardless of the
864 // order in the manifest file. 864 // order in the manifest file.
865 EXPECT_EQ(2u, warnings.size()); 865 EXPECT_EQ(2u, warnings.size());
866 if (warnings.size() > 0) 866 if (warnings.size() > 0)
867 EXPECT_EQ(warnings[0], 867 EXPECT_EQ(warnings[0],
868 UTF8ToUTF16("Exchange data with any computer in the domain " 868 UTF8ToUTF16("Exchange data with any computer in the domain "
869 "example.org")); 869 "example.org"));
870 if (warnings.size() > 1) 870 if (warnings.size() > 1)
871 EXPECT_EQ(warnings[1], 871 EXPECT_EQ(warnings[1],
872 UTF8ToUTF16("Exchange data with the computers named: " 872 UTF8ToUTF16("Exchange data with the computers named: "
873 "b\xC3\xA5r.example.com foo.example.com")); 873 "b\xC3\xA5r.example.com foo.example.com"));
874 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 874 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
875 } 875 }
876 876
877 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 877 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
878 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 878 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
879 879
880 scoped_refptr<Extension> extension = 880 scoped_refptr<Extension> extension =
881 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 881 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
882 EXPECT_TRUE(extension->is_platform_app()); 882 EXPECT_TRUE(extension->is_platform_app());
883 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 883 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
884 std::vector<string16> warnings = 884 std::vector<string16> warnings =
885 PermissionsData::GetPermissionMessageStrings(extension.get()); 885 PermissionsData::GetPermissionMessageStrings(extension.get());
886 886
887 // Verify the warnings, including the fact that domain host warnings come 887 // Verify the warnings, including the fact that domain host warnings come
888 // before specific host warnings and the fact that domains and hostnames are 888 // before specific host warnings and the fact that domains and hostnames are
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 allowed_hosts.AddPattern( 1326 allowed_hosts.AddPattern(
1327 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); 1327 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/"));
1328 allowed_hosts.AddPattern( 1328 allowed_hosts.AddPattern(
1329 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); 1329 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/"));
1330 scoped_refptr<PermissionSet> permissions( 1330 scoped_refptr<PermissionSet> permissions(
1331 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); 1331 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet()));
1332 permissions->GetPermissionMessages(Manifest::TYPE_EXTENSION); 1332 permissions->GetPermissionMessages(Manifest::TYPE_EXTENSION);
1333 } 1333 }
1334 1334
1335 } // namespace extensions 1335 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698