| 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 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) { |
| 418 base::FilePath install_dir; | 418 base::FilePath install_dir; |
| 419 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); | 419 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); |
| 420 | 420 |
| 421 // Try to install an extension with a zero-length icon file. | 421 // Try to install an extension with a zero-length icon file. |
| 422 base::FilePath ext_dir = | 422 base::FilePath ext_dir = |
| 423 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); | 423 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); |
| 424 | 424 |
| 425 std::string error; | 425 std::string error; |
| 426 scoped_refptr<Extension> extension(file_util::LoadExtension( | 426 scoped_refptr<Extension> extension(file_util::LoadExtension( |
| 427 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); | 427 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
| 428 EXPECT_TRUE(extension.get() == NULL); | 428 EXPECT_TRUE(extension.get()); |
| 429 EXPECT_STREQ("Could not load extension icon 'icon.png'.", error.c_str()); | 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); |
| 430 } | 435 } |
| 431 | 436 |
| 432 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { | 437 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { |
| 433 #define URL_PREFIX "chrome-extension://extension-id/" | 438 #define URL_PREFIX "chrome-extension://extension-id/" |
| 434 struct TestCase { | 439 struct TestCase { |
| 435 const char* url; | 440 const char* url; |
| 436 const char* expected_relative_path; | 441 const char* expected_relative_path; |
| 437 } test_cases[] = { | 442 } test_cases[] = { |
| 438 { URL_PREFIX "simple.html", | 443 { URL_PREFIX "simple.html", |
| 439 "simple.html" }, | 444 "simple.html" }, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 base::FilePath actual_path = | 537 base::FilePath actual_path = |
| 533 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); | 538 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); |
| 534 EXPECT_EQ(expected_path.value(), actual_path.value()) << | 539 EXPECT_EQ(expected_path.value(), actual_path.value()) << |
| 535 " For the path " << url; | 540 " For the path " << url; |
| 536 } | 541 } |
| 537 // Remove temp files. | 542 // Remove temp files. |
| 538 ASSERT_TRUE(base::DeleteFile(root_path, true)); | 543 ASSERT_TRUE(base::DeleteFile(root_path, true)); |
| 539 } | 544 } |
| 540 | 545 |
| 541 } // namespace extensions | 546 } // namespace extensions |
| OLD | NEW |