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

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: 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 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 "testing/gtest/include/gtest/gtest.h"
18
19 using content::BrowserThread;
20
21 namespace component_updater {
22
23 namespace {
24
25 const uint8 kTestComponentSha2Hash[] = {
26 0x0d, 0x0e, 0x0a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c,
27 0xba, 0x22, 0x4b, 0x29, 0x12, 0xf3, 0x9e, 0x2c,
28 0x88, 0x7a, 0x71, 0x4b, 0x0a, 0x7c, 0x80, 0x1c,
29 0xcc, 0x29, 0x7c, 0x0a, 0x5f, 0xea, 0x67, 0xb7
30 };
31
32 base::FilePath test_file(const char* file) {
33 base::FilePath path;
34 PathService::Get(chrome::DIR_TEST_DATA, &path);
35 return path.AppendASCII("components").AppendASCII(file);
36 }
37
38 class DummyComponentInstallerTraits : public ComponentInstallerTraits {
39 public:
40 virtual bool VerifyInstallation(const base::FilePath& dir) const OVERRIDE {
41 return true;
42 }
43
44 virtual bool CanAutoUpdate() const OVERRIDE {
45 return false;
46 }
47
48 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
49 const base::FilePath& install_dir) OVERRIDE {
50 return true;
51 }
52
53 virtual void ComponentReady(
54 const base::Version& version,
55 const base::FilePath& install_dir,
56 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE {
57 }
58
59 virtual base::FilePath GetBaseDirectory() const OVERRIDE {
60 return base::FilePath();
61 }
62
63 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE {
64 }
65
66 virtual std::string GetName() const OVERRIDE {
67 return "dummy component.";
68 }
69 };
70
71 } // namespace
72
73 class ComponentUnpackerTest : public testing::Test {
74 public:
75 ComponentUnpackerTest();
76 virtual ~ComponentUnpackerTest();
77
78 bool SaveInstallSource(scoped_refptr<ComponentUnpacker> unpacker,
79 const base::FilePath& backup_path) const {
80 return unpacker->SaveInstallSource(backup_path);
81 }
82
83 bool DoUnpackersMatch(scoped_refptr<ComponentUnpacker> unpacker1,
84 scoped_refptr<ComponentUnpacker> unpacker2) const {
85 return base::ContentsEqual(unpacker1->path_, unpacker2->path_) &&
86 unpacker1->fingerprint_ == unpacker2->fingerprint_ &&
87 unpacker1->in_process_ == unpacker2->in_process_ &&
88 std::equal(unpacker1->pk_hash_.begin(), unpacker1->pk_hash_.end(),
89 &unpacker2->pk_hash_[0]);
90 }
91
92 protected:
93 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
94
95 private:
96 };
97
98 ComponentUnpackerTest::ComponentUnpackerTest()
99 : blocking_task_runner_(BrowserThread::GetBlockingPool()->
100 GetSequencedTaskRunnerWithShutdownBehavior(
101 BrowserThread::GetBlockingPool()->GetSequenceToken(),
102 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {
103 }
104
105 ComponentUnpackerTest::~ComponentUnpackerTest() {
106 }
107
108 TEST_F(ComponentUnpackerTest, SaveAndReload) {
109 const std::string kFingerprint = "Test Fingerprint XYZ";
110 const bool kIsInProcess = true;
111
112 scoped_ptr<ComponentInstallerTraits> dummy_installer_traits(
113 new DummyComponentInstallerTraits);
114 scoped_ptr<ComponentInstaller> dummy_installer(
115 new DefaultComponentInstaller(dummy_installer_traits.Pass()));
116
117 std::vector<uint8> pk_hash;
118 pk_hash.assign(kTestComponentSha2Hash,
119 &kTestComponentSha2Hash[sizeof(kTestComponentSha2Hash)]);
120
121 base::ScopedTempDir backup_dir;
122 EXPECT_TRUE(backup_dir.CreateUniqueTempDir());
123 scoped_refptr<ComponentUnpacker> unpacker = new ComponentUnpacker(
124 pk_hash,
125 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"),
126 kFingerprint,
127 dummy_installer.get(),
128 kIsInProcess,
129 blocking_task_runner_);
130 EXPECT_TRUE(SaveInstallSource(unpacker, backup_dir.path()));
131
132 scoped_refptr<ComponentUnpacker> recreated_unpacker(
133 ComponentUnpacker::CreateFromBackup(backup_dir.path(),
134 pk_hash,
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