| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/common/chrome_version_info.h" | 11 #include "chrome/common/chrome_version_info.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 14 #include "chrome/common/extensions/extension_test_util.h" | 14 #include "chrome/common/extensions/extension_test_util.h" |
| 15 #include "chrome/common/extensions/features/feature.h" | 15 #include "chrome/common/extensions/features/feature_channel.h" |
| 16 #include "chrome/common/extensions/permissions/api_permission.h" | 16 #include "chrome/common/extensions/permissions/api_permission.h" |
| 17 #include "chrome/common/extensions/permissions/permission_set.h" | 17 #include "chrome/common/extensions/permissions/permission_set.h" |
| 18 #include "chrome/common/extensions/permissions/permissions_data.h" | 18 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 19 #include "chrome/common/extensions/permissions/socket_permission.h" | 19 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 20 #include "content/public/common/socket_permission_request.h" | 20 #include "content/public/common/socket_permission_request.h" |
| 21 #include "extensions/common/error_utils.h" | 21 #include "extensions/common/error_utils.h" |
| 22 #include "extensions/common/id_util.h" | 22 #include "extensions/common/id_util.h" |
| 23 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
| 24 #include "extensions/common/url_pattern_set.h" | 24 #include "extensions/common/url_pattern_set.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 110 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
| 111 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 111 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); |
| 112 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); | 112 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); |
| 113 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); | 113 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); |
| 114 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 114 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
| 115 EXPECT_TRUE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 115 EXPECT_TRUE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST(ExtensionPermissionsTest, SocketPermissions) { | 118 TEST(ExtensionPermissionsTest, SocketPermissions) { |
| 119 // Set feature current channel to appropriate value. | 119 // Set feature current channel to appropriate value. |
| 120 Feature::ScopedCurrentChannel scoped_channel( | 120 ScopedCurrentChannel scoped_channel(chrome::VersionInfo::CHANNEL_DEV); |
| 121 chrome::VersionInfo::CHANNEL_DEV); | |
| 122 scoped_refptr<Extension> extension; | 121 scoped_refptr<Extension> extension; |
| 123 std::string error; | 122 std::string error; |
| 124 | 123 |
| 125 extension = LoadManifest("socket_permissions", "empty.json"); | 124 extension = LoadManifest("socket_permissions", "empty.json"); |
| 126 EXPECT_FALSE(CheckSocketPermission(extension, | 125 EXPECT_FALSE(CheckSocketPermission(extension, |
| 127 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 126 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 128 | 127 |
| 129 extension = LoadManifestUnchecked("socket_permissions", | 128 extension = LoadManifestUnchecked("socket_permissions", |
| 130 "socket1.json", | 129 "socket1.json", |
| 131 Manifest::INTERNAL, Extension::NO_FLAGS, | 130 Manifest::INTERNAL, Extension::NO_FLAGS, |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 PermissionsData::ClearTabSpecificPermissions(extension.get(), 1); | 611 PermissionsData::ClearTabSpecificPermissions(extension.get(), 1); |
| 613 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) | 612 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) |
| 614 .get()); | 613 .get()); |
| 615 | 614 |
| 616 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 615 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
| 617 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 616 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
| 618 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 617 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
| 619 } | 618 } |
| 620 | 619 |
| 621 } // namespace extensions | 620 } // namespace extensions |
| OLD | NEW |