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