Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Side by Side Diff: extensions/common/file_util_unittest.cc

Issue 1537473003: Change extension icon load errors to warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ultimate weirdness Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 "the_id", 409 "the_id",
410 Manifest::EXTERNAL_PREF, 410 Manifest::EXTERNAL_PREF,
411 Extension::ERROR_ON_PRIVATE_KEY, 411 Extension::ERROR_ON_PRIVATE_KEY,
412 &error); 412 &error);
413 EXPECT_FALSE(extension.get()); 413 EXPECT_FALSE(extension.get());
414 EXPECT_THAT(error, 414 EXPECT_THAT(error,
415 testing::ContainsRegex( 415 testing::ContainsRegex(
416 "extension includes the key file.*ext_root.a_key.pem")); 416 "extension includes the key file.*ext_root.a_key.pem"));
417 } 417 }
418 418
419 TEST_F(FileUtilTest, CheckZeroLengthIconFile) { 419 // Try to install an extension with a zero-length icon file.
420 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) {
420 base::FilePath install_dir; 421 base::FilePath install_dir;
421 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); 422 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
422 423
423 // Try to install an extension with a zero-length icon file. 424 base::FilePath ext_dir =
425 install_dir.AppendASCII("file_util").AppendASCII("bad_icon");
426
427 std::string error;
428 scoped_refptr<Extension> extension(file_util::LoadExtension(
429 ext_dir, Manifest::INTERNAL, Extension::NO_FLAGS, &error));
430 EXPECT_TRUE(extension);
431 ASSERT_EQ(2U, extension->install_warnings().size());
432
433 EXPECT_EQ("Could not load extension icon 'missing-icon.png'.",
434 extension->install_warnings()[0].message);
435 EXPECT_EQ("Could not load extension icon 'icon.png'.",
436 extension->install_warnings()[1].message);
437 }
438
439 // Try to install an unpacked extension with a zero-length icon file.
440 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFileUnpacked) {
441 base::FilePath install_dir;
442 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
443
424 base::FilePath ext_dir = 444 base::FilePath ext_dir =
425 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); 445 install_dir.AppendASCII("file_util").AppendASCII("bad_icon");
426 446
427 std::string error; 447 std::string error;
428 scoped_refptr<Extension> extension(file_util::LoadExtension( 448 scoped_refptr<Extension> extension(file_util::LoadExtension(
429 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); 449 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
430 EXPECT_TRUE(extension.get() == NULL); 450 EXPECT_FALSE(extension);
431 EXPECT_STREQ("Could not load extension icon 'icon.png'.", error.c_str()); 451 EXPECT_EQ("Could not load extension icon 'missing-icon.png'.", error);
432 } 452 }
433 453
434 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { 454 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) {
435 #define URL_PREFIX "chrome-extension://extension-id/" 455 #define URL_PREFIX "chrome-extension://extension-id/"
436 struct TestCase { 456 struct TestCase {
437 const char* url; 457 const char* url;
438 const char* expected_relative_path; 458 const char* expected_relative_path;
439 } test_cases[] = { 459 } test_cases[] = {
440 { URL_PREFIX "simple.html", 460 { URL_PREFIX "simple.html",
441 "simple.html" }, 461 "simple.html" },
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 base::FilePath actual_path = 554 base::FilePath actual_path =
535 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); 555 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path);
536 EXPECT_EQ(expected_path.value(), actual_path.value()) << 556 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
537 " For the path " << url; 557 " For the path " << url;
538 } 558 }
539 // Remove temp files. 559 // Remove temp files.
540 ASSERT_TRUE(base::DeleteFile(root_path, true)); 560 ASSERT_TRUE(base::DeleteFile(root_path, true));
541 } 561 }
542 562
543 } // namespace extensions 563 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698