| 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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/common/extensions/permissions/socket_permission.h" | 24 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/mime_sniffer.h" | 27 #include "net/base/mime_sniffer.h" |
| 28 #include "skia/ext/image_operations.h" | 28 #include "skia/ext/image_operations.h" |
| 29 #include "net/base/mock_host_resolver.h" | 29 #include "net/base/mock_host_resolver.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 32 #include "ui/gfx/codec/png_codec.h" |
| 33 | 33 |
| 34 using content::SocketPermissionRequest; |
| 34 using extensions::APIPermission; | 35 using extensions::APIPermission; |
| 35 using extensions::APIPermissionSet; | 36 using extensions::APIPermissionSet; |
| 36 using extensions::Extension; | 37 using extensions::Extension; |
| 37 using extensions::Feature; | 38 using extensions::Feature; |
| 38 using extensions::PermissionSet; | 39 using extensions::PermissionSet; |
| 39 using extensions::SocketPermission; | 40 using extensions::SocketPermission; |
| 40 using extensions::SocketPermissionData; | |
| 41 | 41 |
| 42 namespace keys = extension_manifest_keys; | 42 namespace keys = extension_manifest_keys; |
| 43 namespace values = extension_manifest_values; | 43 namespace values = extension_manifest_values; |
| 44 namespace errors = extension_manifest_errors; | 44 namespace errors = extension_manifest_errors; |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 scoped_refptr<Extension> LoadManifestUnchecked( | 48 scoped_refptr<Extension> LoadManifestUnchecked( |
| 49 const std::string& dir, | 49 const std::string& dir, |
| 50 const std::string& test_file, | 50 const std::string& test_file, |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 442 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
| 443 hosts = extension->GetEffectiveHostPermissions(); | 443 hosts = extension->GetEffectiveHostPermissions(); |
| 444 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); | 444 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); |
| 445 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); | 445 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); |
| 446 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 446 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
| 447 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); | 447 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 static bool CheckSocketPermission(scoped_refptr<Extension> extension, | 450 static bool CheckSocketPermission(scoped_refptr<Extension> extension, |
| 451 SocketPermissionData::OperationType type, | 451 SocketPermissionRequest::OperationType type, |
| 452 const char* host, | 452 const char* host, |
| 453 int port) { | 453 int port) { |
| 454 SocketPermission::CheckParam param(type, host, port); | 454 SocketPermission::CheckParam param(type, host, port); |
| 455 return extension->CheckAPIPermissionWithParam( | 455 return extension->CheckAPIPermissionWithParam( |
| 456 APIPermission::kSocket, ¶m); | 456 APIPermission::kSocket, ¶m); |
| 457 } | 457 } |
| 458 | 458 |
| 459 TEST(ExtensionTest, SocketPermissions) { | 459 TEST(ExtensionTest, SocketPermissions) { |
| 460 // Set feature current channel to appropriate value. | 460 // Set feature current channel to appropriate value. |
| 461 Feature::ScopedCurrentChannel scoped_channel( | 461 Feature::ScopedCurrentChannel scoped_channel( |
| 462 chrome::VersionInfo::CHANNEL_DEV); | 462 chrome::VersionInfo::CHANNEL_DEV); |
| 463 scoped_refptr<Extension> extension; | 463 scoped_refptr<Extension> extension; |
| 464 std::string error; | 464 std::string error; |
| 465 | 465 |
| 466 extension = LoadManifest("socket_permissions", "empty.json"); | 466 extension = LoadManifest("socket_permissions", "empty.json"); |
| 467 EXPECT_FALSE(CheckSocketPermission( | 467 EXPECT_FALSE(CheckSocketPermission(extension, |
| 468 extension, SocketPermissionData::TCP_CONNECT, "www.example.com", 80)); | 468 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 469 | 469 |
| 470 extension = LoadManifestUnchecked("socket_permissions", | 470 extension = LoadManifestUnchecked("socket_permissions", |
| 471 "socket1.json", | 471 "socket1.json", |
| 472 Extension::INTERNAL, Extension::NO_FLAGS, | 472 Extension::INTERNAL, Extension::NO_FLAGS, |
| 473 &error); | 473 &error); |
| 474 EXPECT_TRUE(extension == NULL); | 474 EXPECT_TRUE(extension == NULL); |
| 475 ASSERT_EQ(ExtensionErrorUtils::FormatErrorMessage( | 475 ASSERT_EQ(ExtensionErrorUtils::FormatErrorMessage( |
| 476 errors::kInvalidPermission, "socket"), error); | 476 errors::kInvalidPermission, "socket"), error); |
| 477 | 477 |
| 478 extension = LoadManifest("socket_permissions", "socket2.json"); | 478 extension = LoadManifest("socket_permissions", "socket2.json"); |
| 479 EXPECT_TRUE(CheckSocketPermission(extension, |
| 480 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 481 EXPECT_FALSE(CheckSocketPermission( |
| 482 extension, SocketPermissionRequest::UDP_BIND, "", 80)); |
| 479 EXPECT_TRUE(CheckSocketPermission( | 483 EXPECT_TRUE(CheckSocketPermission( |
| 480 extension, SocketPermissionData::TCP_CONNECT, "www.example.com", 80)); | 484 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); |
| 481 EXPECT_FALSE(CheckSocketPermission( | |
| 482 extension, SocketPermissionData::UDP_BIND, "", 80)); | |
| 483 EXPECT_TRUE(CheckSocketPermission( | |
| 484 extension, SocketPermissionData::UDP_BIND, "", 8888)); | |
| 485 | 485 |
| 486 EXPECT_FALSE(CheckSocketPermission( | 486 EXPECT_FALSE(CheckSocketPermission( |
| 487 extension, SocketPermissionData::UDP_SEND_TO, "example.com", 1900)); | 487 extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900)); |
| 488 EXPECT_TRUE(CheckSocketPermission( | 488 EXPECT_TRUE(CheckSocketPermission( |
| 489 extension, SocketPermissionData::UDP_SEND_TO, "239.255.255.250", 1900)); | 489 extension, |
| 490 SocketPermissionRequest::UDP_SEND_TO, |
| 491 "239.255.255.250", 1900)); |
| 490 } | 492 } |
| 491 | 493 |
| 492 // Returns a copy of |source| resized to |size| x |size|. | 494 // Returns a copy of |source| resized to |size| x |size|. |
| 493 static SkBitmap ResizedCopy(const SkBitmap& source, int size) { | 495 static SkBitmap ResizedCopy(const SkBitmap& source, int size) { |
| 494 return skia::ImageOperations::Resize(source, | 496 return skia::ImageOperations::Resize(source, |
| 495 skia::ImageOperations::RESIZE_LANCZOS3, | 497 skia::ImageOperations::RESIZE_LANCZOS3, |
| 496 size, | 498 size, |
| 497 size); | 499 size); |
| 498 } | 500 } |
| 499 | 501 |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 | 1207 |
| 1206 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1208 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
| 1207 scoped_refptr<Extension> extension( | 1209 scoped_refptr<Extension> extension( |
| 1208 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1210 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1209 Extension::INTERNAL, 2, FilePath(), | 1211 Extension::INTERNAL, 2, FilePath(), |
| 1210 Extension::NO_FLAGS)); | 1212 Extension::NO_FLAGS)); |
| 1211 if (extension) | 1213 if (extension) |
| 1212 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1214 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1213 } | 1215 } |
| 1214 #endif // !defined(OS_CHROMEOS) | 1216 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |