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

Unified Diff: chrome/browser/component_updater/test/component_unpacker_unittest.cc

Issue 321473003: Elevated install of recovery component (component update part) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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..08c0d442b937d81fd7a955453a4afbf4c33e31e7
--- /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 "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, SaveAndReload) {
+ 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(),
+ pk_hash,
+ dummy_installer.get(),
+ blocking_task_runner_));
+
+ EXPECT_TRUE(DoUnpackersMatch(unpacker, recreated_unpacker));
+}
+
+} // namespace component_updater
+

Powered by Google App Engine
This is Rietveld 408576698