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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/api/commands/commands_handler.h" | 18 #include "chrome/common/extensions/api/commands/commands_handler.h" |
19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
20 #include "chrome/common/extensions/background_info.h" | 20 #include "chrome/common/extensions/background_info.h" |
21 #include "chrome/common/extensions/command.h" | 21 #include "chrome/common/extensions/command.h" |
22 #include "chrome/common/extensions/extension_file_util.h" | 22 #include "chrome/common/extensions/extension_file_util.h" |
23 #include "chrome/common/extensions/extension_manifest_constants.h" | 23 #include "chrome/common/extensions/extension_manifest_constants.h" |
24 #include "chrome/common/extensions/extension_resource.h" | |
25 #include "chrome/common/extensions/features/feature.h" | 24 #include "chrome/common/extensions/features/feature.h" |
26 #include "chrome/common/extensions/manifest.h" | 25 #include "chrome/common/extensions/manifest.h" |
27 #include "chrome/common/extensions/manifest_handler.h" | 26 #include "chrome/common/extensions/manifest_handler.h" |
28 #include "chrome/common/extensions/permissions/api_permission.h" | 27 #include "chrome/common/extensions/permissions/api_permission.h" |
29 #include "chrome/common/extensions/permissions/permission_set.h" | 28 #include "chrome/common/extensions/permissions/permission_set.h" |
30 #include "chrome/common/extensions/permissions/socket_permission.h" | 29 #include "chrome/common/extensions/permissions/socket_permission.h" |
31 #include "chrome/common/extensions/permissions/usb_device_permission.h" | 30 #include "chrome/common/extensions/permissions/usb_device_permission.h" |
32 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
33 #include "extensions/common/error_utils.h" | 32 #include "extensions/common/error_utils.h" |
| 33 #include "extensions/common/extension_resource.h" |
| 34 #include "extensions/common/id_util.h" |
34 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
35 #include "net/base/mime_sniffer.h" | 36 #include "net/base/mime_sniffer.h" |
36 #include "net/dns/mock_host_resolver.h" | 37 #include "net/dns/mock_host_resolver.h" |
37 #include "skia/ext/image_operations.h" | 38 #include "skia/ext/image_operations.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
40 #include "ui/gfx/codec/png_codec.h" | 41 #include "ui/gfx/codec/png_codec.h" |
41 | 42 |
42 using content::SocketPermissionRequest; | 43 using content::SocketPermissionRequest; |
43 | 44 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); | 208 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); |
208 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); | 209 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); |
209 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); | 210 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); |
210 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); | 211 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); |
211 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); | 212 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); |
212 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); | 213 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); |
213 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); | 214 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); |
214 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); | 215 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); |
215 } | 216 } |
216 | 217 |
217 TEST_F(ExtensionTest, GenerateID) { | |
218 const uint8 public_key_info[] = { | |
219 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, | |
220 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, | |
221 0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, 0x20, 0xdc, 0x7c, 0x9b, | |
222 0x0c, 0xdc, 0x51, 0x61, 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08, | |
223 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, 0x85, 0x7b, 0x0c, 0x04, | |
224 0x13, 0x3f, 0x8d, 0xf4, 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a, | |
225 0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f, 0x9e, 0x36, 0x74, 0x30, | |
226 0xda, 0x8a, 0x31, 0x4f, 0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17, | |
227 0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5, 0xb2, 0x65, 0x7a, 0x89, | |
228 0x4e, 0xb6, 0x47, 0xff, 0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85, | |
229 0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9, 0x96, 0xd0, 0xd6, 0x14, | |
230 0x6f, 0x13, 0x8d, 0xc5, 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18, | |
231 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93, 0xe7, 0x1f, 0x0f, 0xe6, | |
232 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01 | |
233 }; | |
234 | |
235 std::string extension_id; | |
236 EXPECT_TRUE( | |
237 Extension::GenerateId( | |
238 std::string(reinterpret_cast<const char*>(&public_key_info[0]), | |
239 arraysize(public_key_info)), | |
240 &extension_id)); | |
241 EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", extension_id); | |
242 } | |
243 | 218 |
244 // This test ensures that the mimetype sniffing code stays in sync with the | 219 // This test ensures that the mimetype sniffing code stays in sync with the |
245 // actual crx files that we test other parts of the system with. | 220 // actual crx files that we test other parts of the system with. |
246 TEST_F(ExtensionTest, MimeTypeSniffing) { | 221 TEST_F(ExtensionTest, MimeTypeSniffing) { |
247 base::FilePath path; | 222 base::FilePath path; |
248 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 223 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
249 path = path.AppendASCII("extensions").AppendASCII("good.crx"); | 224 path = path.AppendASCII("extensions").AppendASCII("good.crx"); |
250 | 225 |
251 std::string data; | 226 std::string data; |
252 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); | 227 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // methods of Extension for extensions with various permissions. | 539 // methods of Extension for extensions with various permissions. |
565 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { | 540 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { |
566 protected: | 541 protected: |
567 ExtensionScriptAndCaptureVisibleTest() | 542 ExtensionScriptAndCaptureVisibleTest() |
568 : http_url("http://www.google.com"), | 543 : http_url("http://www.google.com"), |
569 http_url_with_path("http://www.google.com/index.html"), | 544 http_url_with_path("http://www.google.com/index.html"), |
570 https_url("https://www.google.com"), | 545 https_url("https://www.google.com"), |
571 file_url("file:///foo/bar"), | 546 file_url("file:///foo/bar"), |
572 favicon_url("chrome://favicon/http://www.google.com"), | 547 favicon_url("chrome://favicon/http://www.google.com"), |
573 extension_url("chrome-extension://" + | 548 extension_url("chrome-extension://" + |
574 Extension::GenerateIdForPath( | 549 id_util::GenerateIdForPath( |
575 base::FilePath(FILE_PATH_LITERAL("foo")))), | 550 base::FilePath(FILE_PATH_LITERAL("foo")))), |
576 settings_url("chrome://settings"), | 551 settings_url("chrome://settings"), |
577 about_url("about:flags") { | 552 about_url("about:flags") { |
578 urls_.insert(http_url); | 553 urls_.insert(http_url); |
579 urls_.insert(http_url_with_path); | 554 urls_.insert(http_url_with_path); |
580 urls_.insert(https_url); | 555 urls_.insert(https_url); |
581 urls_.insert(file_url); | 556 urls_.insert(file_url); |
582 urls_.insert(favicon_url); | 557 urls_.insert(favicon_url); |
583 urls_.insert(extension_url); | 558 urls_.insert(extension_url); |
584 urls_.insert(settings_url); | 559 urls_.insert(settings_url); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); | 894 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); |
920 | 895 |
921 extension->ClearTabSpecificPermissions(1); | 896 extension->ClearTabSpecificPermissions(1); |
922 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); | 897 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); |
923 | 898 |
924 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); | 899 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); |
925 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); | 900 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); |
926 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); | 901 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); |
927 } | 902 } |
928 | 903 |
929 TEST_F(ExtensionTest, GenerateId) { | |
930 std::string result; | |
931 EXPECT_TRUE(Extension::GenerateId("", &result)); | |
932 | |
933 EXPECT_TRUE(Extension::GenerateId("test", &result)); | |
934 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); | |
935 | |
936 EXPECT_TRUE(Extension::GenerateId("_", &result)); | |
937 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); | |
938 | |
939 EXPECT_TRUE(Extension::GenerateId( | |
940 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); | |
941 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); | |
942 } | |
943 | |
944 namespace { | 904 namespace { |
945 enum SyncTestExtensionType { | 905 enum SyncTestExtensionType { |
946 EXTENSION, | 906 EXTENSION, |
947 APP, | 907 APP, |
948 USER_SCRIPT, | 908 USER_SCRIPT, |
949 THEME | 909 THEME |
950 }; | 910 }; |
951 | 911 |
952 static scoped_refptr<Extension> MakeSyncTestExtension( | 912 static scoped_refptr<Extension> MakeSyncTestExtension( |
953 SyncTestExtensionType type, | 913 SyncTestExtensionType type, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 scoped_refptr<Extension> extension( | 1146 scoped_refptr<Extension> extension( |
1187 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1147 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
1188 Manifest::INTERNAL, 2, base::FilePath(), | 1148 Manifest::INTERNAL, 2, base::FilePath(), |
1189 Extension::NO_FLAGS)); | 1149 Extension::NO_FLAGS)); |
1190 if (extension) | 1150 if (extension) |
1191 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1151 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
1192 } | 1152 } |
1193 #endif // !defined(OS_CHROMEOS) | 1153 #endif // !defined(OS_CHROMEOS) |
1194 | 1154 |
1195 } // namespace extensions | 1155 } // namespace extensions |
OLD | NEW |