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

Side by Side Diff: chrome/browser/component_updater/test/component_unpacker_unittest.cc

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 7 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 (c) 2013 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 "chrome/browser/component_updater/test/component_unpacker_unittest.h"
6
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "base/values.h"
11 #include "chrome/browser/component_updater/component_updater_service.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 const char binary_output_hash[] =
16 "599aba6d15a7da390621ef1bacb66601ed6aed04dadc1f9b445dcfe31296142a";
17
18 base::FilePath test_file(const char* file);
19
20 class DummyInstaller : public ComponentInstaller {
21 public:
22 explicit DummyInstaller(const base::FilePath& installed_dir);
23
24 virtual void OnUpdateError(int error) OVERRIDE;
25
26 virtual bool Install(const base::DictionaryValue& manifest,
27 const base::FilePath& unpack_path) OVERRIDE;
28
29 virtual bool GetInstalledFile(const std::string& file,
30 base::FilePath* installed_file) OVERRIDE;
31
32 private:
33 base::FilePath installed_dir_;
34
35 DISALLOW_COPY_AND_ASSIGN(DummyInstaller);
36 };
37
38 class ComponentUnpackerOperationTest : public testing::Test {
39 public:
40 ComponentUnpackerOperationTest();
41
42 virtual ~ComponentUnpackerOperationTest();
43
44 protected:
45 base::FilePath input_dir_;
46 base::FilePath installed_dir_;
47 base::FilePath unpack_dir_;
48 scoped_ptr<DummyInstaller> installer_;
49 };
50
51 base::FilePath test_file(const char* file) {
52 base::FilePath path;
53 PathService::Get(chrome::DIR_TEST_DATA, &path);
54 return path.AppendASCII("components").AppendASCII(file);
55 }
56
57 ComponentUnpackerOperationTest::ComponentUnpackerOperationTest() {
58 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &unpack_dir_);
59 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &input_dir_);
60 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"),
61 &installed_dir_);
62 installer_.reset(new DummyInstaller(installed_dir_));
63 }
64
65 ComponentUnpackerOperationTest::~ComponentUnpackerOperationTest() {
66 file_util::Delete(unpack_dir_, true);
67 file_util::Delete(input_dir_, true);
68 file_util::Delete(installed_dir_, true);
69 }
70
71 DummyInstaller::DummyInstaller(const base::FilePath& installed_dir)
72 : installed_dir_(installed_dir) {
73 }
74
75 void DummyInstaller::OnUpdateError(int error) {}
76
77 bool DummyInstaller::Install(const base::DictionaryValue& manifest,
78 const base::FilePath& unpack_path) {
79 return false;
80 }
81
82 bool DummyInstaller::GetInstalledFile(const std::string& file,
83 base::FilePath* installed_file) {
84 *installed_file = installed_dir_.AppendASCII(file);
85 return true;
86 }
87
88 // Verify that a 'create' delta update operation works correctly.
89 TEST_F(ComponentUnpackerOperationTest, CheckCreateOperation) {
90 file_util::CopyFile(
91 test_file("binary_output.bin"),
92 input_dir_.Append(FILE_PATH_LITERAL("binary_output.bin")));
93
94 scoped_ptr<base::ListValue> command_args(new base::ListValue());
95 command_args->AppendString("output.bin");
96 command_args->AppendString(binary_output_hash);
97 command_args->AppendString("create");
98 command_args->AppendString("binary_output.bin");
99
100 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCreate());
101 DeltaUpdateResult result = op->Run(command_args.get(),
102 input_dir_,
103 unpack_dir_,
104 NULL);
105
106 EXPECT_EQ(DELTA_OK, result);
107 EXPECT_TRUE(file_util::ContentsEqual(
108 unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")),
109 test_file("binary_output.bin")));
110 }
111
112 // Verify that a 'copy' delta update operation works correctly.
113 TEST_F(ComponentUnpackerOperationTest, CheckCopyOperation) {
114 file_util::CopyFile(
115 test_file("binary_output.bin"),
116 installed_dir_.Append(FILE_PATH_LITERAL("binary_output.bin")));
117
118 scoped_ptr<base::ListValue> command_args(new base::ListValue());
119 command_args->AppendString("output.bin");
120 command_args->AppendString(binary_output_hash);
121 command_args->AppendString("copy");
122 command_args->AppendString("binary_output.bin");
123
124 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCopy());
125 DeltaUpdateResult result = op->Run(command_args.get(),
126 input_dir_,
127 unpack_dir_,
128 installer_.get());
129
130 EXPECT_EQ(DELTA_OK, result);
131 EXPECT_TRUE(file_util::ContentsEqual(
132 unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")),
133 test_file("binary_output.bin")));
134 }
135
136 // Verify that a 'courgette' delta update operation works correctly.
137 TEST_F(ComponentUnpackerOperationTest, CheckCourgetteOperation) {
138 file_util::CopyFile(
139 test_file("binary_input.bin"),
140 installed_dir_.Append(FILE_PATH_LITERAL("binary_input.bin")));
141 file_util::CopyFile(
142 test_file("binary_courgette_patch.bin"),
143 input_dir_.Append(FILE_PATH_LITERAL("binary_courgette_patch.bin")));
144
145 scoped_ptr<base::ListValue> command_args(new base::ListValue());
146 command_args->AppendString("output.bin");
147 command_args->AppendString(binary_output_hash);
148 command_args->AppendString("courgette");
149 command_args->AppendString("binary_input.bin");
150 command_args->AppendString("binary_courgette_patch.bin");
151
152 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchCourgette());
153 DeltaUpdateResult result = op->Run(command_args.get(),
154 input_dir_,
155 unpack_dir_,
156 installer_.get());
157
158 EXPECT_EQ(DELTA_OK, result);
159 EXPECT_TRUE(file_util::ContentsEqual(
160 unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")),
161 test_file("binary_output.bin")));
162 }
163
164 // Verify that a 'bsdiff' delta update operation works correctly.
165 TEST_F(ComponentUnpackerOperationTest, CheckBsdiffOperation) {
166 file_util::CopyFile(
167 test_file("binary_input.bin"),
168 installed_dir_.Append(FILE_PATH_LITERAL("binary_input.bin")));
169 file_util::CopyFile(
170 test_file("binary_bsdiff_patch.bin"),
171 input_dir_.Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")));
172
173 scoped_ptr<base::ListValue> command_args(new base::ListValue());
174 command_args->AppendString("output.bin");
175 command_args->AppendString(binary_output_hash);
176 command_args->AppendString("courgette");
177 command_args->AppendString("binary_input.bin");
178 command_args->AppendString("binary_bsdiff_patch.bin");
179
180 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchBsdiff());
181 DeltaUpdateResult result = op->Run(command_args.get(),
182 input_dir_,
183 unpack_dir_,
184 installer_.get());
185
186 EXPECT_EQ(DELTA_OK, result);
187 EXPECT_TRUE(file_util::ContentsEqual(
188 unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")),
189 test_file("binary_output.bin")));
190 }
191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698