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

Side by Side Diff: components/update_client/test/component_patcher_unittest.cc

Issue 808773005: Move most of the component updater artifacts to update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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
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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/component_updater/component_patcher.h" 16 #include "components/update_client/component_patcher.h"
17 #include "components/component_updater/component_patcher_operation.h" 17 #include "components/update_client/component_patcher_operation.h"
18 #include "components/component_updater/component_updater_service.h" 18 #include "components/update_client/test/component_patcher_unittest.h"
19 #include "components/component_updater/test/component_patcher_unittest.h" 19 #include "components/update_client/test/test_installer.h"
20 #include "components/component_updater/test/test_installer.h"
21 #include "courgette/courgette.h" 20 #include "courgette/courgette.h"
22 #include "courgette/third_party/bsdiff.h" 21 #include "courgette/third_party/bsdiff.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 23
25 namespace { 24 namespace {
26 25
27 class TestCallback { 26 class TestCallback {
28 public: 27 public:
29 TestCallback(); 28 TestCallback();
30 virtual ~TestCallback() {} 29 virtual ~TestCallback() {}
31 void Set(component_updater::ComponentUnpacker::Error error, int extra_code); 30 void Set(update_client::ComponentUnpacker::Error error, int extra_code);
32 31
33 int error_; 32 int error_;
34 int extra_code_; 33 int extra_code_;
35 bool called_; 34 bool called_;
36 35
37 private: 36 private:
38 DISALLOW_COPY_AND_ASSIGN(TestCallback); 37 DISALLOW_COPY_AND_ASSIGN(TestCallback);
39 }; 38 };
40 39
41 TestCallback::TestCallback() : error_(-1), extra_code_(-1), called_(false) { 40 TestCallback::TestCallback() : error_(-1), extra_code_(-1), called_(false) {
42 } 41 }
43 42
44 void TestCallback::Set(component_updater::ComponentUnpacker::Error error, 43 void TestCallback::Set(update_client::ComponentUnpacker::Error error,
45 int extra_code) { 44 int extra_code) {
46 error_ = error; 45 error_ = error;
47 extra_code_ = extra_code; 46 extra_code_ = extra_code;
48 called_ = true; 47 called_ = true;
49 } 48 }
50 49
51 } // namespace 50 } // namespace
52 51
53 namespace component_updater { 52 namespace update_client {
54 53
55 namespace { 54 namespace {
56 55
57 base::FilePath test_file(const char* file) { 56 base::FilePath test_file(const char* file) {
58 base::FilePath path; 57 base::FilePath path;
59 PathService::Get(base::DIR_SOURCE_ROOT, &path); 58 PathService::Get(base::DIR_SOURCE_ROOT, &path);
60 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") 59 return path.AppendASCII("components")
61 .AppendASCII("component_updater").AppendASCII(file); 60 .AppendASCII("test")
61 .AppendASCII("data")
62 .AppendASCII("update_client")
63 .AppendASCII(file);
62 } 64 }
63 65
64 } // namespace 66 } // namespace
65 67
66 ComponentPatcherOperationTest::ComponentPatcherOperationTest() { 68 ComponentPatcherOperationTest::ComponentPatcherOperationTest() {
67 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir()); 69 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
68 EXPECT_TRUE(input_dir_.CreateUniqueTempDir()); 70 EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
69 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir()); 71 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
70 installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path())); 72 installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path()));
71 task_runner_ = base::MessageLoop::current()->task_runner(); 73 task_runner_ = base::MessageLoop::current()->task_runner();
72 } 74 }
73 75
74 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() { 76 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() {
75 } 77 }
76 78
77 // Verify that a 'create' delta update operation works correctly. 79 // Verify that a 'create' delta update operation works correctly.
78 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { 80 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) {
79 EXPECT_TRUE(base::CopyFile( 81 EXPECT_TRUE(base::CopyFile(
80 test_file("binary_output.bin"), 82 test_file("binary_output.bin"),
81 input_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 83 input_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin"))));
82 84
83 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 85 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
84 command_args->SetString("output", "output.bin"); 86 command_args->SetString("output", "output.bin");
85 command_args->SetString("sha256", binary_output_hash); 87 command_args->SetString("sha256", binary_output_hash);
86 command_args->SetString("op", "create"); 88 command_args->SetString("op", "create");
87 command_args->SetString("patch", "binary_output.bin"); 89 command_args->SetString("patch", "binary_output.bin");
88 90
89 TestCallback callback; 91 TestCallback callback;
90 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); 92 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate();
91 op->Run(command_args.get(), 93 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(), NULL,
92 input_dir_.path(),
93 unpack_dir_.path(),
94 NULL,
95 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 94 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
96 task_runner_); 95 task_runner_);
97 base::RunLoop().RunUntilIdle(); 96 base::RunLoop().RunUntilIdle();
98 97
99 EXPECT_EQ(true, callback.called_); 98 EXPECT_EQ(true, callback.called_);
100 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 99 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
101 EXPECT_EQ(0, callback.extra_code_); 100 EXPECT_EQ(0, callback.extra_code_);
102 EXPECT_TRUE(base::ContentsEqual( 101 EXPECT_TRUE(base::ContentsEqual(
103 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 102 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
104 test_file("binary_output.bin"))); 103 test_file("binary_output.bin")));
105 } 104 }
106 105
107 // Verify that a 'copy' delta update operation works correctly. 106 // Verify that a 'copy' delta update operation works correctly.
108 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { 107 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) {
109 EXPECT_TRUE(base::CopyFile( 108 EXPECT_TRUE(base::CopyFile(
110 test_file("binary_output.bin"), 109 test_file("binary_output.bin"),
111 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 110 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin"))));
112 111
113 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 112 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
114 command_args->SetString("output", "output.bin"); 113 command_args->SetString("output", "output.bin");
115 command_args->SetString("sha256", binary_output_hash); 114 command_args->SetString("sha256", binary_output_hash);
116 command_args->SetString("op", "copy"); 115 command_args->SetString("op", "copy");
117 command_args->SetString("input", "binary_output.bin"); 116 command_args->SetString("input", "binary_output.bin");
118 117
119 TestCallback callback; 118 TestCallback callback;
120 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); 119 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy();
121 op->Run(command_args.get(), 120 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(),
122 input_dir_.path(),
123 unpack_dir_.path(),
124 installer_.get(), 121 installer_.get(),
125 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 122 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
126 task_runner_); 123 task_runner_);
127 base::RunLoop().RunUntilIdle(); 124 base::RunLoop().RunUntilIdle();
128 125
129 EXPECT_EQ(true, callback.called_); 126 EXPECT_EQ(true, callback.called_);
130 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 127 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
131 EXPECT_EQ(0, callback.extra_code_); 128 EXPECT_EQ(0, callback.extra_code_);
132 EXPECT_TRUE(base::ContentsEqual( 129 EXPECT_TRUE(base::ContentsEqual(
133 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 130 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
(...skipping 12 matching lines...) Expand all
146 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 143 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
147 command_args->SetString("output", "output.bin"); 144 command_args->SetString("output", "output.bin");
148 command_args->SetString("sha256", binary_output_hash); 145 command_args->SetString("sha256", binary_output_hash);
149 command_args->SetString("op", "courgette"); 146 command_args->SetString("op", "courgette");
150 command_args->SetString("input", "binary_input.bin"); 147 command_args->SetString("input", "binary_input.bin");
151 command_args->SetString("patch", "binary_courgette_patch.bin"); 148 command_args->SetString("patch", "binary_courgette_patch.bin");
152 149
153 TestCallback callback; 150 TestCallback callback;
154 scoped_refptr<DeltaUpdateOp> op = 151 scoped_refptr<DeltaUpdateOp> op =
155 CreateDeltaUpdateOp("courgette", NULL /* out_of_process_patcher */); 152 CreateDeltaUpdateOp("courgette", NULL /* out_of_process_patcher */);
156 op->Run(command_args.get(), 153 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(),
157 input_dir_.path(),
158 unpack_dir_.path(),
159 installer_.get(), 154 installer_.get(),
160 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 155 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
161 task_runner_); 156 task_runner_);
162 base::RunLoop().RunUntilIdle(); 157 base::RunLoop().RunUntilIdle();
163 158
164 EXPECT_EQ(true, callback.called_); 159 EXPECT_EQ(true, callback.called_);
165 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 160 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
166 EXPECT_EQ(0, callback.extra_code_); 161 EXPECT_EQ(0, callback.extra_code_);
167 EXPECT_TRUE(base::ContentsEqual( 162 EXPECT_TRUE(base::ContentsEqual(
168 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 163 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
(...skipping 12 matching lines...) Expand all
181 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 176 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
182 command_args->SetString("output", "output.bin"); 177 command_args->SetString("output", "output.bin");
183 command_args->SetString("sha256", binary_output_hash); 178 command_args->SetString("sha256", binary_output_hash);
184 command_args->SetString("op", "courgette"); 179 command_args->SetString("op", "courgette");
185 command_args->SetString("input", "binary_input.bin"); 180 command_args->SetString("input", "binary_input.bin");
186 command_args->SetString("patch", "binary_bsdiff_patch.bin"); 181 command_args->SetString("patch", "binary_bsdiff_patch.bin");
187 182
188 TestCallback callback; 183 TestCallback callback;
189 scoped_refptr<DeltaUpdateOp> op = 184 scoped_refptr<DeltaUpdateOp> op =
190 CreateDeltaUpdateOp("bsdiff", NULL /* out_of_process_patcher */); 185 CreateDeltaUpdateOp("bsdiff", NULL /* out_of_process_patcher */);
191 op->Run(command_args.get(), 186 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(),
192 input_dir_.path(),
193 unpack_dir_.path(),
194 installer_.get(), 187 installer_.get(),
195 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 188 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
196 task_runner_); 189 task_runner_);
197 base::RunLoop().RunUntilIdle(); 190 base::RunLoop().RunUntilIdle();
198 191
199 EXPECT_EQ(true, callback.called_); 192 EXPECT_EQ(true, callback.called_);
200 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 193 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
201 EXPECT_EQ(0, callback.extra_code_); 194 EXPECT_EQ(0, callback.extra_code_);
202 EXPECT_TRUE(base::ContentsEqual( 195 EXPECT_TRUE(base::ContentsEqual(
203 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 196 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
204 test_file("binary_output.bin"))); 197 test_file("binary_output.bin")));
205 } 198 }
206 199
207 } // namespace component_updater 200 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698