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

Side by Side 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: Initial upload Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/file_util.h"
7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/component_updater/component_unpacker.h"
14 #include "chrome/browser/component_updater/default_component_installer.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using content::BrowserThread;
21
22 namespace component_updater {
23
24 namespace {
25
26 const uint8 kTestComponentSha2Hash[] = {
27 0x0d, 0x0e, 0x0a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c,
28 0xba, 0x22, 0x4b, 0x29, 0x12, 0xf3, 0x9e, 0x2c,
29 0x88, 0x7a, 0x71, 0x4b, 0x0a, 0x7c, 0x80, 0x1c,
30 0xcc, 0x29, 0x7c, 0x0a, 0x5f, 0xea, 0x67, 0xb7
31 };
32
33 base::FilePath test_file(const char* file) {
34 base::FilePath path;
35 PathService::Get(chrome::DIR_TEST_DATA, &path);
36 return path.AppendASCII("components").AppendASCII(file);
37 }
38
39 class DummyComponentInstallerTraits : public ComponentInstallerTraits {
40 public:
41 virtual bool VerifyInstallation(const base::FilePath& dir) const OVERRIDE {
42 return true;
43 }
44
45 virtual bool CanAutoUpdate() const OVERRIDE {
46 return false;
47 }
48
49 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
50 const base::FilePath& install_dir) OVERRIDE {
51 return true;
52 }
53
54 virtual void ComponentReady(
55 const base::Version& version,
56 const base::FilePath& install_dir,
57 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE {
58 }
59
60 virtual base::FilePath GetBaseDirectory() const OVERRIDE {
61 return base::FilePath();
62 }
63
64 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE {
65 }
66
67 virtual std::string GetName() const OVERRIDE {
68 return "dummy component.";
69 }
70 };
71
72 } // namespace
73
74 class ComponentUnpackerTest : public testing::Test {
75 public:
76 ComponentUnpackerTest();
77 virtual ~ComponentUnpackerTest();
78
79 bool SaveInstallSource(scoped_refptr<ComponentUnpacker> unpacker,
80 const base::FilePath& backup_path) const {
81 return unpacker->SaveInstallSource(backup_path);
82 }
83
84 bool DoUnpackersMatch(scoped_refptr<ComponentUnpacker> unpacker1,
85 scoped_refptr<ComponentUnpacker> unpacker2) const {
86 return base::ContentsEqual(unpacker1->path_, unpacker2->path_) &&
87 unpacker1->fingerprint_ == unpacker2->fingerprint_ &&
88 unpacker1->in_process_ == unpacker2->in_process_ &&
89 std::equal(unpacker1->pk_hash_.begin(), unpacker1->pk_hash_.end(),
90 &unpacker2->pk_hash_[0]);
91 }
92
93 protected:
94 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
95
96 private:
97 };
98
99 ComponentUnpackerTest::ComponentUnpackerTest()
100 : blocking_task_runner_(BrowserThread::GetBlockingPool()->
101 GetSequencedTaskRunnerWithShutdownBehavior(
102 BrowserThread::GetBlockingPool()->GetSequenceToken(),
103 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {
104 }
105
106 ComponentUnpackerTest::~ComponentUnpackerTest() {
107 }
108
109 TEST_F(ComponentUnpackerTest, BackupAndReload) {
110 const std::string kFingerprint = "Test Fingerprint XYZ";
111 const bool kIsInProcess = true;
112
113 scoped_ptr<ComponentInstallerTraits> dummy_installer_traits(
114 new DummyComponentInstallerTraits);
115 scoped_ptr<ComponentInstaller> dummy_installer(
116 new DefaultComponentInstaller(dummy_installer_traits.Pass()));
117
118 std::vector<uint8> pk_hash;
119 pk_hash.assign(kTestComponentSha2Hash,
120 &kTestComponentSha2Hash[sizeof(kTestComponentSha2Hash)]);
121
122 base::ScopedTempDir backup_dir;
123 EXPECT_TRUE(backup_dir.CreateUniqueTempDir());
124 scoped_refptr<ComponentUnpacker> unpacker = new ComponentUnpacker(
125 pk_hash,
126 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"),
127 kFingerprint,
128 dummy_installer.get(),
129 kIsInProcess,
130 blocking_task_runner_);
131 EXPECT_TRUE(SaveInstallSource(unpacker, backup_dir.path()));
132
133 scoped_refptr<ComponentUnpacker> recreated_unpacker(
134 ComponentUnpacker::CreateFromBackup(backup_dir.path(),
135 dummy_installer.get(),
136 blocking_task_runner_));
137
138 EXPECT_TRUE(DoUnpackersMatch(unpacker, recreated_unpacker));
139 }
140
141 } // namespace component_updater
142
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698