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

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

Issue 1547413002: Reland of Change extension icon load errors to warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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 <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
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 TEST_F(FileUtilTest, CheckZeroLengthIconFile) { 422 // Try to install an extension with a zero-length icon file.
423 TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) {
423 base::FilePath install_dir; 424 base::FilePath install_dir;
424 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); 425 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
425 426
426 // Try to install an extension with a zero-length icon file. 427 base::FilePath ext_dir =
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
427 base::FilePath ext_dir = 447 base::FilePath ext_dir =
428 install_dir.AppendASCII("file_util").AppendASCII("bad_icon"); 448 install_dir.AppendASCII("file_util").AppendASCII("bad_icon");
429 449
430 std::string error; 450 std::string error;
431 scoped_refptr<Extension> extension(file_util::LoadExtension( 451 scoped_refptr<Extension> extension(file_util::LoadExtension(
432 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); 452 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
433 EXPECT_TRUE(extension.get() == NULL); 453 EXPECT_FALSE(extension);
434 EXPECT_STREQ("Could not load extension icon 'icon.png'.", error.c_str()); 454 EXPECT_EQ("Could not load extension icon 'missing-icon.png'.", error);
435 } 455 }
436 456
437 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) { 457 TEST_F(FileUtilTest, ExtensionURLToRelativeFilePath) {
438 #define URL_PREFIX "chrome-extension://extension-id/" 458 #define URL_PREFIX "chrome-extension://extension-id/"
439 struct TestCase { 459 struct TestCase {
440 const char* url; 460 const char* url;
441 const char* expected_relative_path; 461 const char* expected_relative_path;
442 } test_cases[] = { 462 } test_cases[] = {
443 { URL_PREFIX "simple.html", 463 { URL_PREFIX "simple.html",
444 "simple.html" }, 464 "simple.html" },
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 base::FilePath actual_path = 557 base::FilePath actual_path =
538 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path); 558 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path);
539 EXPECT_EQ(expected_path.value(), actual_path.value()) << 559 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
540 " For the path " << url; 560 " For the path " << url;
541 } 561 }
542 // Remove temp files. 562 // Remove temp files.
543 ASSERT_TRUE(base::DeleteFile(root_path, true)); 563 ASSERT_TRUE(base::DeleteFile(root_path, true));
544 } 564 }
545 565
546 } // namespace extensions 566 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698