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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation_unittest.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 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/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 10 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Unizpping a non-zip should do nothing. 112 // Unizpping a non-zip should do nothing.
113 TEST_F(ImageWriterOperationTest, UnzipNonZipFile) { 113 TEST_F(ImageWriterOperationTest, UnzipNonZipFile) {
114 EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0); 114 EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0);
115 115
116 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); 116 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0);
117 EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0); 117 EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0);
118 EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0); 118 EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0);
119 119
120 operation_->Start(); 120 operation_->Start();
121 content::BrowserThread::PostTask( 121 content::BrowserThread::PostTask(
122 content::BrowserThread::FILE, 122 content::BrowserThread::FILE, FROM_HERE,
123 FROM_HERE, 123 base::BindOnce(&OperationForTest::Unzip, operation_,
124 base::Bind( 124 base::Bind(&base::DoNothing)));
125 &OperationForTest::Unzip, operation_, base::Bind(&base::DoNothing)));
126 125
127 base::RunLoop().RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
128 } 127 }
129 128
130 TEST_F(ImageWriterOperationTest, UnzipZipFile) { 129 TEST_F(ImageWriterOperationTest, UnzipZipFile) {
131 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); 130 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0);
132 EXPECT_CALL(manager_, 131 EXPECT_CALL(manager_,
133 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, _)) 132 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, _))
134 .Times(AtLeast(1)); 133 .Times(AtLeast(1));
135 EXPECT_CALL(manager_, 134 EXPECT_CALL(manager_,
136 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, 0)) 135 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, 0))
137 .Times(AtLeast(1)); 136 .Times(AtLeast(1));
138 EXPECT_CALL(manager_, 137 EXPECT_CALL(manager_,
139 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, 100)) 138 OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, 100))
140 .Times(AtLeast(1)); 139 .Times(AtLeast(1));
141 140
142 operation_->SetImagePath(zip_file_); 141 operation_->SetImagePath(zip_file_);
143 142
144 operation_->Start(); 143 operation_->Start();
145 content::BrowserThread::PostTask( 144 content::BrowserThread::PostTask(
146 content::BrowserThread::FILE, 145 content::BrowserThread::FILE, FROM_HERE,
147 FROM_HERE, 146 base::BindOnce(&OperationForTest::Unzip, operation_,
148 base::Bind( 147 base::Bind(&base::DoNothing)));
149 &OperationForTest::Unzip, operation_, base::Bind(&base::DoNothing)));
150 148
151 base::RunLoop().RunUntilIdle(); 149 base::RunLoop().RunUntilIdle();
152 150
153 EXPECT_TRUE(base::ContentsEqual(image_path_, operation_->GetImagePath())); 151 EXPECT_TRUE(base::ContentsEqual(image_path_, operation_->GetImagePath()));
154 } 152 }
155 153
156 #if defined(OS_LINUX) 154 #if defined(OS_LINUX)
157 TEST_F(ImageWriterOperationTest, WriteImageToDevice) { 155 TEST_F(ImageWriterOperationTest, WriteImageToDevice) {
158 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); 156 EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0);
159 EXPECT_CALL(manager_, 157 EXPECT_CALL(manager_,
160 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, _)) 158 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, _))
161 .Times(AtLeast(1)); 159 .Times(AtLeast(1));
162 EXPECT_CALL(manager_, 160 EXPECT_CALL(manager_,
163 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0)) 161 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0))
164 .Times(AtLeast(1)); 162 .Times(AtLeast(1));
165 EXPECT_CALL(manager_, 163 EXPECT_CALL(manager_,
166 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100)) 164 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100))
167 .Times(AtLeast(1)); 165 .Times(AtLeast(1));
168 166
169 operation_->Start(); 167 operation_->Start();
170 content::BrowserThread::PostTask( 168 content::BrowserThread::PostTask(
171 content::BrowserThread::FILE, 169 content::BrowserThread::FILE, FROM_HERE,
172 FROM_HERE, 170 base::BindOnce(&OperationForTest::Write, operation_,
173 base::Bind( 171 base::Bind(&base::DoNothing)));
174 &OperationForTest::Write, operation_, base::Bind(&base::DoNothing)));
175 172
176 base::RunLoop().RunUntilIdle(); 173 base::RunLoop().RunUntilIdle();
177 174
178 #if !defined(OS_CHROMEOS) 175 #if !defined(OS_CHROMEOS)
179 test_utils_.GetUtilityClient()->Progress(0); 176 test_utils_.GetUtilityClient()->Progress(0);
180 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2); 177 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
181 test_utils_.GetUtilityClient()->Progress(kTestFileSize); 178 test_utils_.GetUtilityClient()->Progress(kTestFileSize);
182 test_utils_.GetUtilityClient()->Success(); 179 test_utils_.GetUtilityClient()->Success();
183 180
184 base::RunLoop().RunUntilIdle(); 181 base::RunLoop().RunUntilIdle();
(...skipping 17 matching lines...) Expand all
202 .Times(AtLeast(1)); 199 .Times(AtLeast(1));
203 EXPECT_CALL( 200 EXPECT_CALL(
204 manager_, 201 manager_,
205 OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, 100)) 202 OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, 100))
206 .Times(AtLeast(1)); 203 .Times(AtLeast(1));
207 204
208 test_utils_.FillFile( 205 test_utils_.FillFile(
209 test_utils_.GetDevicePath(), kImagePattern, kTestFileSize); 206 test_utils_.GetDevicePath(), kImagePattern, kTestFileSize);
210 207
211 operation_->Start(); 208 operation_->Start();
212 content::BrowserThread::PostTask(content::BrowserThread::FILE, 209 content::BrowserThread::PostTask(
213 FROM_HERE, 210 content::BrowserThread::FILE, FROM_HERE,
214 base::Bind(&OperationForTest::VerifyWrite, 211 base::BindOnce(&OperationForTest::VerifyWrite, operation_,
215 operation_, 212 base::Bind(&base::DoNothing)));
216 base::Bind(&base::DoNothing)));
217 213
218 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
219 215
220 #if !defined(OS_CHROMEOS) 216 #if !defined(OS_CHROMEOS)
221 test_utils_.GetUtilityClient()->Progress(0); 217 test_utils_.GetUtilityClient()->Progress(0);
222 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2); 218 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
223 test_utils_.GetUtilityClient()->Progress(kTestFileSize); 219 test_utils_.GetUtilityClient()->Progress(kTestFileSize);
224 test_utils_.GetUtilityClient()->Success(); 220 test_utils_.GetUtilityClient()->Success();
225 #endif 221 #endif
226 222
(...skipping 12 matching lines...) Expand all
239 EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0); 235 EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0);
240 EXPECT_CALL( 236 EXPECT_CALL(
241 manager_, 237 manager_,
242 OnError(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _, _)) 238 OnError(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _, _))
243 .Times(1); 239 .Times(1);
244 240
245 test_utils_.FillFile( 241 test_utils_.FillFile(
246 test_utils_.GetDevicePath(), kDevicePattern, kTestFileSize); 242 test_utils_.GetDevicePath(), kDevicePattern, kTestFileSize);
247 243
248 operation_->Start(); 244 operation_->Start();
249 content::BrowserThread::PostTask(content::BrowserThread::FILE, 245 content::BrowserThread::PostTask(
250 FROM_HERE, 246 content::BrowserThread::FILE, FROM_HERE,
251 base::Bind(&OperationForTest::VerifyWrite, 247 base::BindOnce(&OperationForTest::VerifyWrite, operation_,
252 operation_, 248 base::Bind(&base::DoNothing)));
253 base::Bind(&base::DoNothing)));
254 249
255 base::RunLoop().RunUntilIdle(); 250 base::RunLoop().RunUntilIdle();
256 251
257 test_utils_.GetUtilityClient()->Progress(0); 252 test_utils_.GetUtilityClient()->Progress(0);
258 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2); 253 test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
259 test_utils_.GetUtilityClient()->Error(error::kVerificationFailed); 254 test_utils_.GetUtilityClient()->Error(error::kVerificationFailed);
260 255
261 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
262 } 257 }
263 #endif 258 #endif
264 259
265 // Tests that on creation the operation_ has the expected state. 260 // Tests that on creation the operation_ has the expected state.
266 TEST_F(ImageWriterOperationTest, Creation) { 261 TEST_F(ImageWriterOperationTest, Creation) {
267 EXPECT_EQ(0, operation_->GetProgress()); 262 EXPECT_EQ(0, operation_->GetProgress());
268 EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, operation_->GetStage()); 263 EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, operation_->GetStage());
269 } 264 }
270 265
271 } // namespace image_writer 266 } // namespace image_writer
272 } // namespace extensions 267 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698