OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "extensions/common/file_util.h" | 5 #include "extensions/common/file_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 "the_id", | 407 "the_id", |
408 Manifest::EXTERNAL_PREF, | 408 Manifest::EXTERNAL_PREF, |
409 Extension::ERROR_ON_PRIVATE_KEY, | 409 Extension::ERROR_ON_PRIVATE_KEY, |
410 &error); | 410 &error); |
411 EXPECT_FALSE(extension.get()); | 411 EXPECT_FALSE(extension.get()); |
412 EXPECT_THAT(error, | 412 EXPECT_THAT(error, |
413 testing::ContainsRegex( | 413 testing::ContainsRegex( |
414 "extension includes the key file.*ext_root.a_key.pem")); | 414 "extension includes the key file.*ext_root.a_key.pem")); |
415 } | 415 } |
416 | 416 |
417 TEST_F(FileUtilTest, CheckZeroLengthIconFile) { | 417 // Try to install an extension with a zero-length icon file. |
| 418 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) { |
418 base::FilePath install_dir; | 419 base::FilePath install_dir; |
419 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); | 420 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); |
420 | 421 |
421 // Try to install an extension with a zero-length icon file. | 422 base::FilePath ext_dir = |
| 423 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); |
| 424 |
| 425 std::string error; |
| 426 scoped_refptr<Extension> extension(file_util::LoadExtension( |
| 427 ext_dir, Manifest::INTERNAL, Extension::NO_FLAGS, &error)); |
| 428 EXPECT_TRUE(extension); |
| 429 ASSERT_EQ(2U, extension->install_warnings().size()); |
| 430 |
| 431 EXPECT_EQ("Could not load extension icon 'missing-icon.png'.", |
| 432 extension->install_warnings()[0].message); |
| 433 EXPECT_EQ("Could not load extension icon 'icon.png'.", |
| 434 extension->install_warnings()[1].message); |
| 435 } |
| 436 |
| 437 // Try to install an unpacked extension with a zero-length icon file. |
| 438 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFileUnpacked) { |
| 439 base::FilePath install_dir; |
| 440 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); |
| 441 |
422 base::FilePath ext_dir = | 442 base::FilePath ext_dir = |
423 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); | 443 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); |
424 | 444 |
425 std::string error; | 445 std::string error; |
426 scoped_refptr<Extension> extension(file_util::LoadExtension( | 446 scoped_refptr<Extension> extension(file_util::LoadExtension( |
427 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); | 447 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
428 EXPECT_TRUE(extension.get() == NULL); | 448 EXPECT_FALSE(extension); |
429 EXPECT_STREQ("Could not load extension icon 'icon.png'.", error.c_str()); | 449 EXPECT_EQ("Could not load extension icon 'missing-icon.png'.", error); |
430 } | 450 } |
431 | 451 |
432 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { | 452 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { |
433 #define URL_PREFIX "chrome-extension://extension-id/" | 453 #define URL_PREFIX "chrome-extension://extension-id/" |
434 struct TestCase { | 454 struct TestCase { |
435 const char* url; | 455 const char* url; |
436 const char* expected_relative_path; | 456 const char* expected_relative_path; |
437 } test_cases[] = { | 457 } test_cases[] = { |
438 { URL_PREFIX "simple.html", | 458 { URL_PREFIX "simple.html", |
439 "simple.html" }, | 459 "simple.html" }, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 base::FilePath actual_path = | 552 base::FilePath actual_path = |
533 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); | 553 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); |
534 EXPECT_EQ(expected_path.value(), actual_path.value()) << | 554 EXPECT_EQ(expected_path.value(), actual_path.value()) << |
535 " For the path " << url; | 555 " For the path " << url; |
536 } | 556 } |
537 // Remove temp files. | 557 // Remove temp files. |
538 ASSERT_TRUE(base::DeleteFile(root_path, true)); | 558 ASSERT_TRUE(base::DeleteFile(root_path, true)); |
539 } | 559 } |
540 | 560 |
541 } // namespace extensions | 561 } // namespace extensions |
OLD | NEW |