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" | |
14 #include "chrome/common/extensions/extension_test_util.h" | 13 #include "chrome/common/extensions/extension_test_util.h" |
15 #include "chrome/common/extensions/features/feature_channel.h" | 14 #include "chrome/common/extensions/features/feature_channel.h" |
16 #include "chrome/common/extensions/permissions/api_permission.h" | 15 #include "chrome/common/extensions/permissions/api_permission.h" |
17 #include "chrome/common/extensions/permissions/permission_set.h" | 16 #include "chrome/common/extensions/permissions/permission_set.h" |
18 #include "chrome/common/extensions/permissions/permissions_data.h" | 17 #include "chrome/common/extensions/permissions/permissions_data.h" |
19 #include "chrome/common/extensions/permissions/socket_permission.h" | 18 #include "chrome/common/extensions/permissions/socket_permission.h" |
20 #include "content/public/common/socket_permission_request.h" | 19 #include "content/public/common/socket_permission_request.h" |
21 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
22 #include "extensions/common/id_util.h" | 21 #include "extensions/common/id_util.h" |
| 22 #include "extensions/common/manifest_constants.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" |
26 | 26 |
27 using content::SocketPermissionRequest; | 27 using content::SocketPermissionRequest; |
28 using extension_test_util::LoadManifest; | 28 using extension_test_util::LoadManifest; |
29 using extension_test_util::LoadManifestUnchecked; | 29 using extension_test_util::LoadManifestUnchecked; |
30 using extension_test_util::LoadManifestStrict; | 30 using extension_test_util::LoadManifestStrict; |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 extension = LoadManifest("socket_permissions", "empty.json"); | 124 extension = LoadManifest("socket_permissions", "empty.json"); |
125 EXPECT_FALSE(CheckSocketPermission(extension, | 125 EXPECT_FALSE(CheckSocketPermission(extension, |
126 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 126 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
127 | 127 |
128 extension = LoadManifestUnchecked("socket_permissions", | 128 extension = LoadManifestUnchecked("socket_permissions", |
129 "socket1.json", | 129 "socket1.json", |
130 Manifest::INTERNAL, Extension::NO_FLAGS, | 130 Manifest::INTERNAL, Extension::NO_FLAGS, |
131 &error); | 131 &error); |
132 EXPECT_TRUE(extension.get() == NULL); | 132 EXPECT_TRUE(extension.get() == NULL); |
133 ASSERT_EQ(ErrorUtils::FormatErrorMessage( | 133 ASSERT_EQ(ErrorUtils::FormatErrorMessage( |
134 extension_manifest_errors::kInvalidPermission, "socket"), | 134 manifest_errors::kInvalidPermission, "socket"), |
135 error); | 135 error); |
136 | 136 |
137 extension = LoadManifest("socket_permissions", "socket2.json"); | 137 extension = LoadManifest("socket_permissions", "socket2.json"); |
138 EXPECT_TRUE(CheckSocketPermission(extension, | 138 EXPECT_TRUE(CheckSocketPermission(extension, |
139 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 139 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
140 EXPECT_FALSE(CheckSocketPermission( | 140 EXPECT_FALSE(CheckSocketPermission( |
141 extension, SocketPermissionRequest::UDP_BIND, "", 80)); | 141 extension, SocketPermissionRequest::UDP_BIND, "", 80)); |
142 EXPECT_TRUE(CheckSocketPermission( | 142 EXPECT_TRUE(CheckSocketPermission( |
143 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); | 143 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); |
144 | 144 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // Having chrome://*/ should not work for regular extensions. Note that | 368 // Having chrome://*/ should not work for regular extensions. Note that |
369 // for favicon access, we require the explicit pattern chrome://favicon/*. | 369 // for favicon access, we require the explicit pattern chrome://favicon/*. |
370 std::string error; | 370 std::string error; |
371 extension = LoadManifestUnchecked("script_and_capture", | 371 extension = LoadManifestUnchecked("script_and_capture", |
372 "extension_wildcard_chrome.json", | 372 "extension_wildcard_chrome.json", |
373 Manifest::INTERNAL, Extension::NO_FLAGS, | 373 Manifest::INTERNAL, Extension::NO_FLAGS, |
374 &error); | 374 &error); |
375 std::vector<InstallWarning> warnings = extension->install_warnings(); | 375 std::vector<InstallWarning> warnings = extension->install_warnings(); |
376 EXPECT_FALSE(warnings.empty()); | 376 EXPECT_FALSE(warnings.empty()); |
377 EXPECT_EQ(ErrorUtils::FormatErrorMessage( | 377 EXPECT_EQ(ErrorUtils::FormatErrorMessage( |
378 extension_manifest_errors::kInvalidPermissionScheme, | 378 manifest_errors::kInvalidPermissionScheme, |
379 "chrome://*/"), | 379 "chrome://*/"), |
380 warnings[0].message); | 380 warnings[0].message); |
381 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 381 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
382 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 382 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
383 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 383 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
384 | 384 |
385 // Having chrome://favicon/* should not give you chrome://* | 385 // Having chrome://favicon/* should not give you chrome://* |
386 extension = LoadManifestStrict("script_and_capture", | 386 extension = LoadManifestStrict("script_and_capture", |
387 "extension_chrome_favicon_wildcard.json"); | 387 "extension_chrome_favicon_wildcard.json"); |
388 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 388 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 PermissionsData::ClearTabSpecificPermissions(extension.get(), 1); | 608 PermissionsData::ClearTabSpecificPermissions(extension.get(), 1); |
609 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) | 609 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) |
610 .get()); | 610 .get()); |
611 | 611 |
612 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 612 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
613 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 613 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
614 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 614 EXPECT_TRUE(AllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
615 } | 615 } |
616 | 616 |
617 } // namespace extensions | 617 } // namespace extensions |
OLD | NEW |