| Index: chrome/browser/extensions/sandboxed_unpacker_unittest.cc
|
| diff --git a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
|
| index 8b70ccf7c5a8f9ee1c3a57bed025b21c440f33c4..090e32ea3ddfa5fc3823458c5a8520871dbf2304 100644
|
| --- a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
|
| +++ b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
|
| @@ -3,6 +3,7 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/files/file_util.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/message_loop/message_loop.h"
|
| @@ -16,6 +17,7 @@
|
| #include "content/public/test/test_utils.h"
|
| #include "extensions/common/constants.h"
|
| #include "extensions/common/extension.h"
|
| +#include "extensions/common/switches.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
|
|
| @@ -32,6 +34,7 @@ class MockSandboxedUnpackerClient : public SandboxedUnpackerClient {
|
| }
|
|
|
| base::FilePath temp_dir() const { return temp_dir_; }
|
| + base::string16 unpack_err() const { return error_; }
|
|
|
| private:
|
| ~MockSandboxedUnpackerClient() override {}
|
| @@ -43,13 +46,14 @@ class MockSandboxedUnpackerClient : public SandboxedUnpackerClient {
|
| const SkBitmap& install_icon) override {
|
| temp_dir_ = temp_dir;
|
| quit_closure_.Run();
|
| -
|
| }
|
|
|
| void OnUnpackFailure(const base::string16& error) override {
|
| - ASSERT_TRUE(false);
|
| + error_ = error;
|
| + quit_closure_.Run();
|
| }
|
|
|
| + base::string16 error_;
|
| base::Closure quit_closure_;
|
| base::FilePath temp_dir_;
|
| };
|
| @@ -73,7 +77,8 @@ class SandboxedUnpackerTest : public testing::Test {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| - void SetupUnpacker(const std::string& crx_name) {
|
| + void SetupUnpacker(const std::string& crx_name,
|
| + const std::string& package_hash) {
|
| base::FilePath original_path;
|
| ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
|
| original_path = original_path.AppendASCII("extensions")
|
| @@ -82,12 +87,8 @@ class SandboxedUnpackerTest : public testing::Test {
|
| ASSERT_TRUE(base::PathExists(original_path)) << original_path.value();
|
|
|
| sandboxed_unpacker_ = new SandboxedUnpacker(
|
| - original_path,
|
| - Manifest::INTERNAL,
|
| - Extension::NO_FLAGS,
|
| - extensions_dir_.path(),
|
| - base::MessageLoopProxy::current(),
|
| - client_);
|
| + original_path, package_hash, Manifest::INTERNAL, Extension::NO_FLAGS,
|
| + extensions_dir_.path(), base::MessageLoopProxy::current(), client_);
|
|
|
| base::MessageLoopProxy::current()->PostTask(
|
| FROM_HERE,
|
| @@ -99,6 +100,10 @@ class SandboxedUnpackerTest : public testing::Test {
|
| return client_->temp_dir().AppendASCII(kTempExtensionName);
|
| }
|
|
|
| + base::string16 GetInstallError() {
|
| + return client_->unpack_err();
|
| + }
|
| +
|
| protected:
|
| base::ScopedTempDir extensions_dir_;
|
| MockSandboxedUnpackerClient* client_;
|
| @@ -109,7 +114,7 @@ class SandboxedUnpackerTest : public testing::Test {
|
| };
|
|
|
| TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) {
|
| - SetupUnpacker("no_l10n.crx");
|
| + SetupUnpacker("no_l10n.crx", "");
|
| // Check that there is no _locales folder.
|
| base::FilePath install_path =
|
| GetInstallPath().Append(kLocaleFolder);
|
| @@ -117,11 +122,34 @@ TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) {
|
| }
|
|
|
| TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) {
|
| - SetupUnpacker("good_l10n.crx");
|
| + SetupUnpacker("good_l10n.crx", "");
|
| // Check that there is _locales folder.
|
| base::FilePath install_path =
|
| GetInstallPath().Append(kLocaleFolder);
|
| EXPECT_TRUE(base::PathExists(install_path));
|
| }
|
|
|
| +TEST_F(SandboxedUnpackerTest, FailHashCheck) {
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + extensions::switches::kEnableCrxHashCheck);
|
| + SetupUnpacker("good_l10n.crx", "badhash");
|
| + // Check that there is an error message.
|
| + EXPECT_NE(base::string16(), GetInstallError());
|
| +}
|
| +
|
| +TEST_F(SandboxedUnpackerTest, PassHashCheck) {
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + extensions::switches::kEnableCrxHashCheck);
|
| + SetupUnpacker("good_l10n.crx",
|
| + "6fa171c726373785aa4fcd2df448c3db0420a95d5044fbee831f089b979c4068");
|
| + // Check that there is no error message.
|
| + EXPECT_EQ(base::string16(), GetInstallError());
|
| +}
|
| +
|
| +TEST_F(SandboxedUnpackerTest, SkipHashCheck) {
|
| + SetupUnpacker("good_l10n.crx", "badhash");
|
| + // Check that there is no error message.
|
| + EXPECT_EQ(base::string16(), GetInstallError());
|
| +}
|
| +
|
| } // namespace extensions
|
|
|