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

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

Powered by Google App Engine
This is Rietveld 408576698