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_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. | 521 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. |
522 extension = extension_file_util::LoadExtension( | 522 extension = extension_file_util::LoadExtension( |
523 ext_path, "the_id", Extension::EXTERNAL_PREF, | 523 ext_path, "the_id", Extension::EXTERNAL_PREF, |
524 Extension::ERROR_ON_PRIVATE_KEY, &error); | 524 Extension::ERROR_ON_PRIVATE_KEY, &error); |
525 EXPECT_FALSE(extension.get()); | 525 EXPECT_FALSE(extension.get()); |
526 EXPECT_THAT(error, | 526 EXPECT_THAT(error, |
527 testing::ContainsRegex( | 527 testing::ContainsRegex( |
528 "extension includes the key file.*ext_root.a_key.pem")); | 528 "extension includes the key file.*ext_root.a_key.pem")); |
529 } | 529 } |
530 | 530 |
| 531 TEST(ExtensionFileUtil, CheckZeroLengthImageFile) { |
| 532 FilePath install_dir; |
| 533 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 534 |
| 535 // Try to install an extension with a zero-length icon file. |
| 536 FilePath ext_dir = install_dir.AppendASCII("extensions") |
| 537 .AppendASCII("bad") |
| 538 .AppendASCII("Extensions") |
| 539 .AppendASCII("ffffffffffffffffffffffffffffffff"); |
| 540 |
| 541 std::string error; |
| 542 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 543 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 544 ASSERT_TRUE(extension == NULL); |
| 545 ASSERT_STREQ("Could not load extension icon 'icon.png'.", |
| 546 error.c_str()); |
| 547 |
| 548 // Try to install an extension with a zero-length browser action icon file. |
| 549 ext_dir = install_dir.AppendASCII("extensions") |
| 550 .AppendASCII("bad") |
| 551 .AppendASCII("Extensions") |
| 552 .AppendASCII("gggggggggggggggggggggggggggggggg"); |
| 553 |
| 554 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension( |
| 555 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 556 ASSERT_TRUE(extension2 == NULL); |
| 557 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.", |
| 558 error.c_str()); |
| 559 |
| 560 // Try to install an extension with a zero-length page action icon file. |
| 561 ext_dir = install_dir.AppendASCII("extensions") |
| 562 .AppendASCII("bad") |
| 563 .AppendASCII("Extensions") |
| 564 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); |
| 565 |
| 566 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( |
| 567 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 568 ASSERT_TRUE(extension3 == NULL); |
| 569 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", |
| 570 error.c_str()); |
| 571 } |
| 572 |
531 // TODO(aa): More tests as motivation allows. Maybe steal some from | 573 // TODO(aa): More tests as motivation allows. Maybe steal some from |
532 // ExtensionService? Many of them could probably be tested here without the | 574 // ExtensionService? Many of them could probably be tested here without the |
533 // MessageLoop shenanigans. | 575 // MessageLoop shenanigans. |
OLD | NEW |