| Index: chrome/browser/component_updater/test/component_unpacker_unittest.cc
|
| diff --git a/chrome/browser/component_updater/test/component_unpacker_unittest.cc b/chrome/browser/component_updater/test/component_unpacker_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a6d64b34d659206aa8f42ce4d77eac0926b97c74
|
| --- /dev/null
|
| +++ b/chrome/browser/component_updater/test/component_unpacker_unittest.cc
|
| @@ -0,0 +1,142 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/file_util.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/path_service.h"
|
| +#include "base/threading/sequenced_worker_pool.h"
|
| +#include "chrome/browser/component_updater/component_unpacker.h"
|
| +#include "chrome/browser/component_updater/default_component_installer.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +namespace component_updater {
|
| +
|
| +namespace {
|
| +
|
| +const uint8 kTestComponentSha2Hash[] = {
|
| + 0x0d, 0x0e, 0x0a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c,
|
| + 0xba, 0x22, 0x4b, 0x29, 0x12, 0xf3, 0x9e, 0x2c,
|
| + 0x88, 0x7a, 0x71, 0x4b, 0x0a, 0x7c, 0x80, 0x1c,
|
| + 0xcc, 0x29, 0x7c, 0x0a, 0x5f, 0xea, 0x67, 0xb7
|
| +};
|
| +
|
| +base::FilePath test_file(const char* file) {
|
| + base::FilePath path;
|
| + PathService::Get(chrome::DIR_TEST_DATA, &path);
|
| + return path.AppendASCII("components").AppendASCII(file);
|
| +}
|
| +
|
| +class DummyComponentInstallerTraits : public ComponentInstallerTraits {
|
| + public:
|
| + virtual bool VerifyInstallation(const base::FilePath& dir) const OVERRIDE {
|
| + return true;
|
| + }
|
| +
|
| + virtual bool CanAutoUpdate() const OVERRIDE {
|
| + return false;
|
| + }
|
| +
|
| + virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
|
| + const base::FilePath& install_dir) OVERRIDE {
|
| + return true;
|
| + }
|
| +
|
| + virtual void ComponentReady(
|
| + const base::Version& version,
|
| + const base::FilePath& install_dir,
|
| + scoped_ptr<base::DictionaryValue> manifest) OVERRIDE {
|
| + }
|
| +
|
| + virtual base::FilePath GetBaseDirectory() const OVERRIDE {
|
| + return base::FilePath();
|
| + }
|
| +
|
| + virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE {
|
| + }
|
| +
|
| + virtual std::string GetName() const OVERRIDE {
|
| + return "dummy component.";
|
| + }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +class ComponentUnpackerTest : public testing::Test {
|
| + public:
|
| + ComponentUnpackerTest();
|
| + virtual ~ComponentUnpackerTest();
|
| +
|
| + bool SaveInstallSource(scoped_refptr<ComponentUnpacker> unpacker,
|
| + const base::FilePath& backup_path) const {
|
| + return unpacker->SaveInstallSource(backup_path);
|
| + }
|
| +
|
| + bool DoUnpackersMatch(scoped_refptr<ComponentUnpacker> unpacker1,
|
| + scoped_refptr<ComponentUnpacker> unpacker2) const {
|
| + return base::ContentsEqual(unpacker1->path_, unpacker2->path_) &&
|
| + unpacker1->fingerprint_ == unpacker2->fingerprint_ &&
|
| + unpacker1->in_process_ == unpacker2->in_process_ &&
|
| + std::equal(unpacker1->pk_hash_.begin(), unpacker1->pk_hash_.end(),
|
| + &unpacker2->pk_hash_[0]);
|
| + }
|
| +
|
| + protected:
|
| + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
|
| +
|
| + private:
|
| +};
|
| +
|
| +ComponentUnpackerTest::ComponentUnpackerTest()
|
| + : blocking_task_runner_(BrowserThread::GetBlockingPool()->
|
| + GetSequencedTaskRunnerWithShutdownBehavior(
|
| + BrowserThread::GetBlockingPool()->GetSequenceToken(),
|
| + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {
|
| +}
|
| +
|
| +ComponentUnpackerTest::~ComponentUnpackerTest() {
|
| +}
|
| +
|
| +TEST_F(ComponentUnpackerTest, BackupAndReload) {
|
| + const std::string kFingerprint = "Test Fingerprint XYZ";
|
| + const bool kIsInProcess = true;
|
| +
|
| + scoped_ptr<ComponentInstallerTraits> dummy_installer_traits(
|
| + new DummyComponentInstallerTraits);
|
| + scoped_ptr<ComponentInstaller> dummy_installer(
|
| + new DefaultComponentInstaller(dummy_installer_traits.Pass()));
|
| +
|
| + std::vector<uint8> pk_hash;
|
| + pk_hash.assign(kTestComponentSha2Hash,
|
| + &kTestComponentSha2Hash[sizeof(kTestComponentSha2Hash)]);
|
| +
|
| + base::ScopedTempDir backup_dir;
|
| + EXPECT_TRUE(backup_dir.CreateUniqueTempDir());
|
| + scoped_refptr<ComponentUnpacker> unpacker = new ComponentUnpacker(
|
| + pk_hash,
|
| + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"),
|
| + kFingerprint,
|
| + dummy_installer.get(),
|
| + kIsInProcess,
|
| + blocking_task_runner_);
|
| + EXPECT_TRUE(SaveInstallSource(unpacker, backup_dir.path()));
|
| +
|
| + scoped_refptr<ComponentUnpacker> recreated_unpacker(
|
| + ComponentUnpacker::CreateFromBackup(backup_dir.path(),
|
| + dummy_installer.get(),
|
| + blocking_task_runner_));
|
| +
|
| + EXPECT_TRUE(DoUnpackersMatch(unpacker, recreated_unpacker));
|
| +}
|
| +
|
| +} // namespace component_updater
|
| +
|
|
|