OLD | NEW |
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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 command_args->SetString("sha256", binary_output_hash); | 85 command_args->SetString("sha256", binary_output_hash); |
86 command_args->SetString("op", "create"); | 86 command_args->SetString("op", "create"); |
87 command_args->SetString("patch", "binary_output.bin"); | 87 command_args->SetString("patch", "binary_output.bin"); |
88 | 88 |
89 TestCallback callback; | 89 TestCallback callback; |
90 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); | 90 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); |
91 op->Run(command_args.get(), | 91 op->Run(command_args.get(), |
92 input_dir_.path(), | 92 input_dir_.path(), |
93 unpack_dir_.path(), | 93 unpack_dir_.path(), |
94 NULL, | 94 NULL, |
95 true, | |
96 base::Bind(&TestCallback::Set, base::Unretained(&callback)), | 95 base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
97 task_runner_); | 96 task_runner_); |
98 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
99 | 98 |
100 EXPECT_EQ(true, callback.called_); | 99 EXPECT_EQ(true, callback.called_); |
101 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); | 100 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
102 EXPECT_EQ(0, callback.extra_code_); | 101 EXPECT_EQ(0, callback.extra_code_); |
103 EXPECT_TRUE(base::ContentsEqual( | 102 EXPECT_TRUE(base::ContentsEqual( |
104 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), | 103 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
105 test_file("binary_output.bin"))); | 104 test_file("binary_output.bin"))); |
(...skipping 10 matching lines...) Expand all Loading... |
116 command_args->SetString("sha256", binary_output_hash); | 115 command_args->SetString("sha256", binary_output_hash); |
117 command_args->SetString("op", "copy"); | 116 command_args->SetString("op", "copy"); |
118 command_args->SetString("input", "binary_output.bin"); | 117 command_args->SetString("input", "binary_output.bin"); |
119 | 118 |
120 TestCallback callback; | 119 TestCallback callback; |
121 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); | 120 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); |
122 op->Run(command_args.get(), | 121 op->Run(command_args.get(), |
123 input_dir_.path(), | 122 input_dir_.path(), |
124 unpack_dir_.path(), | 123 unpack_dir_.path(), |
125 installer_.get(), | 124 installer_.get(), |
126 true, | |
127 base::Bind(&TestCallback::Set, base::Unretained(&callback)), | 125 base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
128 task_runner_); | 126 task_runner_); |
129 base::RunLoop().RunUntilIdle(); | 127 base::RunLoop().RunUntilIdle(); |
130 | 128 |
131 EXPECT_EQ(true, callback.called_); | 129 EXPECT_EQ(true, callback.called_); |
132 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); | 130 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
133 EXPECT_EQ(0, callback.extra_code_); | 131 EXPECT_EQ(0, callback.extra_code_); |
134 EXPECT_TRUE(base::ContentsEqual( | 132 EXPECT_TRUE(base::ContentsEqual( |
135 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), | 133 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
136 test_file("binary_output.bin"))); | 134 test_file("binary_output.bin"))); |
137 } | 135 } |
138 | 136 |
139 // Verify that a 'courgette' delta update operation works correctly. | 137 // Verify that a 'courgette' delta update operation works correctly. |
140 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { | 138 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { |
141 EXPECT_TRUE(base::CopyFile( | 139 EXPECT_TRUE(base::CopyFile( |
142 test_file("binary_input.bin"), | 140 test_file("binary_input.bin"), |
143 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); | 141 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); |
144 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"), | 142 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"), |
145 input_dir_.path().Append(FILE_PATH_LITERAL( | 143 input_dir_.path().Append(FILE_PATH_LITERAL( |
146 "binary_courgette_patch.bin")))); | 144 "binary_courgette_patch.bin")))); |
147 | 145 |
148 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); | 146 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); |
149 command_args->SetString("output", "output.bin"); | 147 command_args->SetString("output", "output.bin"); |
150 command_args->SetString("sha256", binary_output_hash); | 148 command_args->SetString("sha256", binary_output_hash); |
151 command_args->SetString("op", "courgette"); | 149 command_args->SetString("op", "courgette"); |
152 command_args->SetString("input", "binary_input.bin"); | 150 command_args->SetString("input", "binary_input.bin"); |
153 command_args->SetString("patch", "binary_courgette_patch.bin"); | 151 command_args->SetString("patch", "binary_courgette_patch.bin"); |
154 | 152 |
155 TestCallback callback; | 153 TestCallback callback; |
156 scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("courgette"); | 154 scoped_ptr<DeltaUpdateOpFactory> factory( |
| 155 CreateInProcessDeltaUpdateOpFactory()); |
| 156 scoped_refptr<DeltaUpdateOp> op = factory->CreateDeltaUpdateOp("courgette"); |
157 op->Run(command_args.get(), | 157 op->Run(command_args.get(), |
158 input_dir_.path(), | 158 input_dir_.path(), |
159 unpack_dir_.path(), | 159 unpack_dir_.path(), |
160 installer_.get(), | 160 installer_.get(), |
161 true, | |
162 base::Bind(&TestCallback::Set, base::Unretained(&callback)), | 161 base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
163 task_runner_); | 162 task_runner_); |
164 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
165 | 164 |
166 EXPECT_EQ(true, callback.called_); | 165 EXPECT_EQ(true, callback.called_); |
167 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); | 166 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
168 EXPECT_EQ(0, callback.extra_code_); | 167 EXPECT_EQ(0, callback.extra_code_); |
169 EXPECT_TRUE(base::ContentsEqual( | 168 EXPECT_TRUE(base::ContentsEqual( |
170 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), | 169 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
171 test_file("binary_output.bin"))); | 170 test_file("binary_output.bin"))); |
172 } | 171 } |
173 | 172 |
174 // Verify that a 'bsdiff' delta update operation works correctly. | 173 // Verify that a 'bsdiff' delta update operation works correctly. |
175 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { | 174 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { |
176 EXPECT_TRUE(base::CopyFile( | 175 EXPECT_TRUE(base::CopyFile( |
177 test_file("binary_input.bin"), | 176 test_file("binary_input.bin"), |
178 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); | 177 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); |
179 EXPECT_TRUE(base::CopyFile( | 178 EXPECT_TRUE(base::CopyFile( |
180 test_file("binary_bsdiff_patch.bin"), | 179 test_file("binary_bsdiff_patch.bin"), |
181 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")))); | 180 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")))); |
182 | 181 |
183 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); | 182 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); |
184 command_args->SetString("output", "output.bin"); | 183 command_args->SetString("output", "output.bin"); |
185 command_args->SetString("sha256", binary_output_hash); | 184 command_args->SetString("sha256", binary_output_hash); |
186 command_args->SetString("op", "courgette"); | 185 command_args->SetString("op", "courgette"); |
187 command_args->SetString("input", "binary_input.bin"); | 186 command_args->SetString("input", "binary_input.bin"); |
188 command_args->SetString("patch", "binary_bsdiff_patch.bin"); | 187 command_args->SetString("patch", "binary_bsdiff_patch.bin"); |
189 | 188 |
190 TestCallback callback; | 189 TestCallback callback; |
191 scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("bsdiff"); | 190 scoped_ptr<DeltaUpdateOpFactory> factory( |
| 191 CreateInProcessDeltaUpdateOpFactory()); |
| 192 scoped_refptr<DeltaUpdateOp> op = factory->CreateDeltaUpdateOp("bsdiff"); |
192 op->Run(command_args.get(), | 193 op->Run(command_args.get(), |
193 input_dir_.path(), | 194 input_dir_.path(), |
194 unpack_dir_.path(), | 195 unpack_dir_.path(), |
195 installer_.get(), | 196 installer_.get(), |
196 true, | |
197 base::Bind(&TestCallback::Set, base::Unretained(&callback)), | 197 base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
198 task_runner_); | 198 task_runner_); |
199 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
200 | 200 |
201 EXPECT_EQ(true, callback.called_); | 201 EXPECT_EQ(true, callback.called_); |
202 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); | 202 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
203 EXPECT_EQ(0, callback.extra_code_); | 203 EXPECT_EQ(0, callback.extra_code_); |
204 EXPECT_TRUE(base::ContentsEqual( | 204 EXPECT_TRUE(base::ContentsEqual( |
205 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), | 205 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
206 test_file("binary_output.bin"))); | 206 test_file("binary_output.bin"))); |
207 } | 207 } |
208 | 208 |
209 } // namespace component_updater | 209 } // namespace component_updater |
OLD | NEW |