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

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

Issue 420503002: Componentize component_updater: Decouple in-process DeltaUpdateOp from out-of-process version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/component_updater/component_patcher.h" 14 #include "chrome/browser/component_updater/component_patcher.h"
15 #include "chrome/browser/component_updater/component_patcher_operation.h" 15 #include "chrome/browser/component_updater/component_patcher_operation.h"
16 #include "chrome/browser/component_updater/component_patcher_operation_factory.h "
16 #include "chrome/browser/component_updater/component_updater_service.h" 17 #include "chrome/browser/component_updater/component_updater_service.h"
17 #include "chrome/browser/component_updater/test/component_patcher_unittest.h" 18 #include "chrome/browser/component_updater/test/component_patcher_unittest.h"
18 #include "chrome/browser/component_updater/test/test_installer.h" 19 #include "chrome/browser/component_updater/test/test_installer.h"
19 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "courgette/courgette.h" 22 #include "courgette/courgette.h"
22 #include "courgette/third_party/bsdiff.h" 23 #include "courgette/third_party/bsdiff.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace { 26 namespace {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 command_args->SetString("sha256", binary_output_hash); 86 command_args->SetString("sha256", binary_output_hash);
86 command_args->SetString("op", "create"); 87 command_args->SetString("op", "create");
87 command_args->SetString("patch", "binary_output.bin"); 88 command_args->SetString("patch", "binary_output.bin");
88 89
89 TestCallback callback; 90 TestCallback callback;
90 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); 91 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate();
91 op->Run(command_args.get(), 92 op->Run(command_args.get(),
92 input_dir_.path(), 93 input_dir_.path(),
93 unpack_dir_.path(), 94 unpack_dir_.path(),
94 NULL, 95 NULL,
95 true,
96 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 96 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
97 task_runner_); 97 task_runner_);
98 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
99 99
100 EXPECT_EQ(true, callback.called_); 100 EXPECT_EQ(true, callback.called_);
101 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 101 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
102 EXPECT_EQ(0, callback.extra_code_); 102 EXPECT_EQ(0, callback.extra_code_);
103 EXPECT_TRUE(base::ContentsEqual( 103 EXPECT_TRUE(base::ContentsEqual(
104 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 104 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
105 test_file("binary_output.bin"))); 105 test_file("binary_output.bin")));
(...skipping 10 matching lines...) Expand all
116 command_args->SetString("sha256", binary_output_hash); 116 command_args->SetString("sha256", binary_output_hash);
117 command_args->SetString("op", "copy"); 117 command_args->SetString("op", "copy");
118 command_args->SetString("input", "binary_output.bin"); 118 command_args->SetString("input", "binary_output.bin");
119 119
120 TestCallback callback; 120 TestCallback callback;
121 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); 121 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy();
122 op->Run(command_args.get(), 122 op->Run(command_args.get(),
123 input_dir_.path(), 123 input_dir_.path(),
124 unpack_dir_.path(), 124 unpack_dir_.path(),
125 installer_.get(), 125 installer_.get(),
126 true,
127 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 126 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
128 task_runner_); 127 task_runner_);
129 base::RunLoop().RunUntilIdle(); 128 base::RunLoop().RunUntilIdle();
130 129
131 EXPECT_EQ(true, callback.called_); 130 EXPECT_EQ(true, callback.called_);
132 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 131 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
133 EXPECT_EQ(0, callback.extra_code_); 132 EXPECT_EQ(0, callback.extra_code_);
134 EXPECT_TRUE(base::ContentsEqual( 133 EXPECT_TRUE(base::ContentsEqual(
135 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 134 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
136 test_file("binary_output.bin"))); 135 test_file("binary_output.bin")));
137 } 136 }
138 137
139 // Verify that a 'courgette' delta update operation works correctly. 138 // Verify that a 'courgette' delta update operation works correctly.
140 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { 139 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) {
141 EXPECT_TRUE(base::CopyFile( 140 EXPECT_TRUE(base::CopyFile(
142 test_file("binary_input.bin"), 141 test_file("binary_input.bin"),
143 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 142 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin"))));
144 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"), 143 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"),
145 input_dir_.path().Append(FILE_PATH_LITERAL( 144 input_dir_.path().Append(FILE_PATH_LITERAL(
146 "binary_courgette_patch.bin")))); 145 "binary_courgette_patch.bin"))));
147 146
148 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 147 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
149 command_args->SetString("output", "output.bin"); 148 command_args->SetString("output", "output.bin");
150 command_args->SetString("sha256", binary_output_hash); 149 command_args->SetString("sha256", binary_output_hash);
151 command_args->SetString("op", "courgette"); 150 command_args->SetString("op", "courgette");
152 command_args->SetString("input", "binary_input.bin"); 151 command_args->SetString("input", "binary_input.bin");
153 command_args->SetString("patch", "binary_courgette_patch.bin"); 152 command_args->SetString("patch", "binary_courgette_patch.bin");
154 153
155 TestCallback callback; 154 TestCallback callback;
156 scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("courgette"); 155 scoped_ptr<DeltaUpdateOpFactory> factory(
156 CreateDeltaUpdateOpFactory(true /* in_process */));
waffles 2014/07/31 21:54:27 Am I correct in thinking that this true no longer
tommycli 2014/08/04 20:25:14 Done.
157 scoped_refptr<DeltaUpdateOp> op = factory->CreateDeltaUpdateOp("courgette");
157 op->Run(command_args.get(), 158 op->Run(command_args.get(),
158 input_dir_.path(), 159 input_dir_.path(),
159 unpack_dir_.path(), 160 unpack_dir_.path(),
160 installer_.get(), 161 installer_.get(),
161 true,
162 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 162 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
163 task_runner_); 163 task_runner_);
164 base::RunLoop().RunUntilIdle(); 164 base::RunLoop().RunUntilIdle();
165 165
166 EXPECT_EQ(true, callback.called_); 166 EXPECT_EQ(true, callback.called_);
167 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 167 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
168 EXPECT_EQ(0, callback.extra_code_); 168 EXPECT_EQ(0, callback.extra_code_);
169 EXPECT_TRUE(base::ContentsEqual( 169 EXPECT_TRUE(base::ContentsEqual(
170 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 170 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
171 test_file("binary_output.bin"))); 171 test_file("binary_output.bin")));
172 } 172 }
173 173
174 // Verify that a 'bsdiff' delta update operation works correctly. 174 // Verify that a 'bsdiff' delta update operation works correctly.
175 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { 175 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) {
176 EXPECT_TRUE(base::CopyFile( 176 EXPECT_TRUE(base::CopyFile(
177 test_file("binary_input.bin"), 177 test_file("binary_input.bin"),
178 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 178 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin"))));
179 EXPECT_TRUE(base::CopyFile( 179 EXPECT_TRUE(base::CopyFile(
180 test_file("binary_bsdiff_patch.bin"), 180 test_file("binary_bsdiff_patch.bin"),
181 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")))); 181 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin"))));
182 182
183 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 183 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
184 command_args->SetString("output", "output.bin"); 184 command_args->SetString("output", "output.bin");
185 command_args->SetString("sha256", binary_output_hash); 185 command_args->SetString("sha256", binary_output_hash);
186 command_args->SetString("op", "courgette"); 186 command_args->SetString("op", "courgette");
187 command_args->SetString("input", "binary_input.bin"); 187 command_args->SetString("input", "binary_input.bin");
188 command_args->SetString("patch", "binary_bsdiff_patch.bin"); 188 command_args->SetString("patch", "binary_bsdiff_patch.bin");
189 189
190 TestCallback callback; 190 TestCallback callback;
191 scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("bsdiff"); 191 scoped_ptr<DeltaUpdateOpFactory> factory(
192 CreateDeltaUpdateOpFactory(true /* in_process */));
193 scoped_refptr<DeltaUpdateOp> op = factory->CreateDeltaUpdateOp("bsdiff");
192 op->Run(command_args.get(), 194 op->Run(command_args.get(),
193 input_dir_.path(), 195 input_dir_.path(),
194 unpack_dir_.path(), 196 unpack_dir_.path(),
195 installer_.get(), 197 installer_.get(),
196 true,
197 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 198 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
198 task_runner_); 199 task_runner_);
199 base::RunLoop().RunUntilIdle(); 200 base::RunLoop().RunUntilIdle();
200 201
201 EXPECT_EQ(true, callback.called_); 202 EXPECT_EQ(true, callback.called_);
202 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 203 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
203 EXPECT_EQ(0, callback.extra_code_); 204 EXPECT_EQ(0, callback.extra_code_);
204 EXPECT_TRUE(base::ContentsEqual( 205 EXPECT_TRUE(base::ContentsEqual(
205 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 206 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
206 test_file("binary_output.bin"))); 207 test_file("binary_output.bin")));
207 } 208 }
208 209
209 } // namespace component_updater 210 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698