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

Side by Side Diff: chrome/browser/drive/drive_uploader_unittest.cc

Issue 1115573002: [chrome/browser/drive] Avoid use of MessageLoopProxy by TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed UnitTest comments Created 5 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/drive/fake_drive_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/drive/drive_uploader.h" 5 #include "chrome/browser/drive/drive_uploader.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/thread_task_runner_handle.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/drive/dummy_drive_service.h" 17 #include "chrome/browser/drive/dummy_drive_service.h"
17 #include "google_apis/drive/drive_api_parser.h" 18 #include "google_apis/drive/drive_api_parser.h"
18 #include "google_apis/drive/test_util.h" 19 #include "google_apis/drive/test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using google_apis::CancelCallback; 22 using google_apis::CancelCallback;
22 using google_apis::FileResource; 23 using google_apis::FileResource;
23 using google_apis::DriveApiErrorCode; 24 using google_apis::DriveApiErrorCode;
24 using google_apis::DRIVE_NO_CONNECTION; 25 using google_apis::DRIVE_NO_CONNECTION;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const std::string& title, 86 const std::string& title,
86 const UploadNewFileOptions& options, 87 const UploadNewFileOptions& options,
87 const InitiateUploadCallback& callback) override { 88 const InitiateUploadCallback& callback) override {
88 EXPECT_EQ(kTestDocumentTitle, title); 89 EXPECT_EQ(kTestDocumentTitle, title);
89 EXPECT_EQ(kTestMimeType, content_type); 90 EXPECT_EQ(kTestMimeType, content_type);
90 EXPECT_EQ(expected_content_length_, content_length); 91 EXPECT_EQ(expected_content_length_, content_length);
91 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id); 92 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id);
92 93
93 // Calls back the upload URL for subsequent ResumeUpload requests. 94 // Calls back the upload URL for subsequent ResumeUpload requests.
94 // InitiateUpload is an asynchronous function, so don't callback directly. 95 // InitiateUpload is an asynchronous function, so don't callback directly.
95 base::MessageLoop::current()->PostTask(FROM_HERE, 96 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
96 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 97 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
97 return CancelCallback(); 98 return CancelCallback();
98 } 99 }
99 100
100 CancelCallback InitiateUploadExistingFile( 101 CancelCallback InitiateUploadExistingFile(
101 const std::string& content_type, 102 const std::string& content_type,
102 int64 content_length, 103 int64 content_length,
103 const std::string& resource_id, 104 const std::string& resource_id,
104 const UploadExistingFileOptions& options, 105 const UploadExistingFileOptions& options,
105 const InitiateUploadCallback& callback) override { 106 const InitiateUploadCallback& callback) override {
106 EXPECT_EQ(kTestMimeType, content_type); 107 EXPECT_EQ(kTestMimeType, content_type);
107 EXPECT_EQ(expected_content_length_, content_length); 108 EXPECT_EQ(expected_content_length_, content_length);
108 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 109 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
109 110
110 if (!options.etag.empty() && options.etag != kTestETag) { 111 if (!options.etag.empty() && options.etag != kTestETag) {
111 base::MessageLoop::current()->PostTask(FROM_HERE, 112 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
112 base::Bind(callback, HTTP_PRECONDITION, GURL())); 113 base::Bind(callback, HTTP_PRECONDITION, GURL()));
113 return CancelCallback(); 114 return CancelCallback();
114 } 115 }
115 116
116 // Calls back the upload URL for subsequent ResumeUpload requests. 117 // Calls back the upload URL for subsequent ResumeUpload requests.
117 // InitiateUpload is an asynchronous function, so don't callback directly. 118 // InitiateUpload is an asynchronous function, so don't callback directly.
118 base::MessageLoop::current()->PostTask(FROM_HERE, 119 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
119 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 120 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
120 return CancelCallback(); 121 return CancelCallback();
121 } 122 }
122 123
123 // Handles a request for uploading a chunk of bytes. 124 // Handles a request for uploading a chunk of bytes.
124 CancelCallback ResumeUpload( 125 CancelCallback ResumeUpload(
125 const GURL& upload_location, 126 const GURL& upload_location,
126 int64 start_position, 127 int64 start_position,
127 int64 end_position, 128 int64 end_position,
128 int64 content_length, 129 int64 content_length,
(...skipping 20 matching lines...) Expand all
149 150
150 // Update the internal status of the current upload session. 151 // Update the internal status of the current upload session.
151 resume_upload_call_count_++; 152 resume_upload_call_count_++;
152 received_bytes_ = end_position; 153 received_bytes_ = end_position;
153 154
154 // Callback progress 155 // Callback progress
155 if (!progress_callback.is_null()) { 156 if (!progress_callback.is_null()) {
156 // For the testing purpose, it always notifies the progress at the end of 157 // For the testing purpose, it always notifies the progress at the end of
157 // each chunk uploading. 158 // each chunk uploading.
158 int64 chunk_size = end_position - start_position; 159 int64 chunk_size = end_position - start_position;
159 base::MessageLoop::current()->PostTask(FROM_HERE, 160 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
160 base::Bind(progress_callback, chunk_size, chunk_size)); 161 base::Bind(progress_callback, chunk_size, chunk_size));
161 } 162 }
162 163
163 SendUploadRangeResponse(upload_location, callback); 164 SendUploadRangeResponse(upload_location, callback);
164 return CancelCallback(); 165 return CancelCallback();
165 } 166 }
166 167
167 // Handles a request to fetch the current upload status. 168 // Handles a request to fetch the current upload status.
168 CancelCallback GetUploadStatus(const GURL& upload_location, 169 CancelCallback GetUploadStatus(const GURL& upload_location,
169 int64 content_length, 170 int64 content_length,
(...skipping 19 matching lines...) Expand all
189 HTTP_CREATED : HTTP_SUCCESS; 190 HTTP_CREATED : HTTP_SUCCESS;
190 response = UploadRangeResponse(response_code, -1, -1); 191 response = UploadRangeResponse(response_code, -1, -1);
191 192
192 entry.reset(new FileResource); 193 entry.reset(new FileResource);
193 entry->set_md5_checksum(kTestDummyMd5); 194 entry->set_md5_checksum(kTestDummyMd5);
194 } else { 195 } else {
195 response = UploadRangeResponse( 196 response = UploadRangeResponse(
196 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); 197 HTTP_RESUME_INCOMPLETE, 0, received_bytes_);
197 } 198 }
198 // ResumeUpload is an asynchronous function, so don't callback directly. 199 // ResumeUpload is an asynchronous function, so don't callback directly.
199 base::MessageLoop::current()->PostTask(FROM_HERE, 200 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
200 base::Bind(callback, response, base::Passed(&entry))); 201 base::Bind(callback, response, base::Passed(&entry)));
201 } 202 }
202 203
203 CancelCallback MultipartUploadNewFile( 204 CancelCallback MultipartUploadNewFile(
204 const std::string& content_type, 205 const std::string& content_type,
205 int64 content_length, 206 int64 content_length,
206 const std::string& parent_resource_id, 207 const std::string& parent_resource_id,
207 const std::string& title, 208 const std::string& title,
208 const base::FilePath& local_file_path, 209 const base::FilePath& local_file_path,
209 const UploadNewFileOptions& options, 210 const UploadNewFileOptions& options,
(...skipping 16 matching lines...) Expand all
226 const base::FilePath& local_file_path, 227 const base::FilePath& local_file_path,
227 const UploadExistingFileOptions& options, 228 const UploadExistingFileOptions& options,
228 const google_apis::FileResourceCallback& callback, 229 const google_apis::FileResourceCallback& callback,
229 const google_apis::ProgressCallback& progress_callback) override { 230 const google_apis::ProgressCallback& progress_callback) override {
230 EXPECT_EQ(kTestMimeType, content_type); 231 EXPECT_EQ(kTestMimeType, content_type);
231 EXPECT_EQ(expected_content_length_, content_length); 232 EXPECT_EQ(expected_content_length_, content_length);
232 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 233 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
233 EXPECT_EQ(expected_upload_file_, local_file_path); 234 EXPECT_EQ(expected_upload_file_, local_file_path);
234 235
235 if (!options.etag.empty() && options.etag != kTestETag) { 236 if (!options.etag.empty() && options.etag != kTestETag) {
236 base::MessageLoop::current()->PostTask( 237 base::ThreadTaskRunnerHandle::Get()->PostTask(
237 FROM_HERE, 238 FROM_HERE,
238 base::Bind(callback, HTTP_PRECONDITION, 239 base::Bind(callback, HTTP_PRECONDITION,
239 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 240 base::Passed(make_scoped_ptr<FileResource>(NULL))));
240 return CancelCallback(); 241 return CancelCallback();
241 } 242 }
242 243
243 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback, 244 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback,
244 progress_callback); 245 progress_callback);
245 } 246 }
246 247
247 CancelCallback SendMultipartUploadResult( 248 CancelCallback SendMultipartUploadResult(
248 DriveApiErrorCode response_code, 249 DriveApiErrorCode response_code,
249 int64 content_length, 250 int64 content_length,
250 const google_apis::FileResourceCallback& callback, 251 const google_apis::FileResourceCallback& callback,
251 const google_apis::ProgressCallback& progress_callback) { 252 const google_apis::ProgressCallback& progress_callback) {
252 received_bytes_ = content_length; 253 received_bytes_ = content_length;
253 multipart_upload_call_count_++; 254 multipart_upload_call_count_++;
254 255
255 // Callback progress 256 // Callback progress
256 if (!progress_callback.is_null()) { 257 if (!progress_callback.is_null()) {
257 // For the testing purpose, it always notifies the progress at the end of 258 // For the testing purpose, it always notifies the progress at the end of
258 // whole file uploading. 259 // whole file uploading.
259 base::MessageLoop::current()->PostTask( 260 base::ThreadTaskRunnerHandle::Get()->PostTask(
260 FROM_HERE, 261 FROM_HERE,
261 base::Bind(progress_callback, content_length, content_length)); 262 base::Bind(progress_callback, content_length, content_length));
262 } 263 }
263 264
264 // MultipartUploadXXXFile is an asynchronous function, so don't callback 265 // MultipartUploadXXXFile is an asynchronous function, so don't callback
265 // directly. 266 // directly.
266 scoped_ptr<FileResource> entry; 267 scoped_ptr<FileResource> entry;
267 entry.reset(new FileResource); 268 entry.reset(new FileResource);
268 entry->set_md5_checksum(kTestDummyMd5); 269 entry->set_md5_checksum(kTestDummyMd5);
269 base::MessageLoop::current()->PostTask( 270 base::ThreadTaskRunnerHandle::Get()->PostTask(
270 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry))); 271 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry)));
271 return CancelCallback(); 272 return CancelCallback();
272 } 273 }
273 274
274 const base::FilePath expected_upload_file_; 275 const base::FilePath expected_upload_file_;
275 const int64 expected_content_length_; 276 const int64 expected_content_length_;
276 int64 received_bytes_; 277 int64 received_bytes_;
277 int64 resume_upload_call_count_; 278 int64 resume_upload_call_count_;
278 int64 multipart_upload_call_count_; 279 int64 multipart_upload_call_count_;
279 }; 280 };
280 281
281 // Mock DriveService that returns a failure at InitiateUpload(). 282 // Mock DriveService that returns a failure at InitiateUpload().
282 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { 283 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService {
283 // Returns error. 284 // Returns error.
284 CancelCallback InitiateUploadNewFile( 285 CancelCallback InitiateUploadNewFile(
285 const std::string& content_type, 286 const std::string& content_type,
286 int64 content_length, 287 int64 content_length,
287 const std::string& parent_resource_id, 288 const std::string& parent_resource_id,
288 const std::string& title, 289 const std::string& title,
289 const UploadNewFileOptions& options, 290 const UploadNewFileOptions& options,
290 const InitiateUploadCallback& callback) override { 291 const InitiateUploadCallback& callback) override {
291 base::MessageLoop::current()->PostTask(FROM_HERE, 292 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
292 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 293 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
293 return CancelCallback(); 294 return CancelCallback();
294 } 295 }
295 296
296 CancelCallback InitiateUploadExistingFile( 297 CancelCallback InitiateUploadExistingFile(
297 const std::string& content_type, 298 const std::string& content_type,
298 int64 content_length, 299 int64 content_length,
299 const std::string& resource_id, 300 const std::string& resource_id,
300 const UploadExistingFileOptions& options, 301 const UploadExistingFileOptions& options,
301 const InitiateUploadCallback& callback) override { 302 const InitiateUploadCallback& callback) override {
302 base::MessageLoop::current()->PostTask(FROM_HERE, 303 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
303 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 304 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
304 return CancelCallback(); 305 return CancelCallback();
305 } 306 }
306 307
307 // Should not be used. 308 // Should not be used.
308 CancelCallback ResumeUpload( 309 CancelCallback ResumeUpload(
309 const GURL& upload_url, 310 const GURL& upload_url,
310 int64 start_position, 311 int64 start_position,
311 int64 end_position, 312 int64 end_position,
312 int64 content_length, 313 int64 content_length,
313 const std::string& content_type, 314 const std::string& content_type,
314 const base::FilePath& local_file_path, 315 const base::FilePath& local_file_path,
315 const UploadRangeCallback& callback, 316 const UploadRangeCallback& callback,
316 const ProgressCallback& progress_callback) override { 317 const ProgressCallback& progress_callback) override {
317 NOTREACHED(); 318 NOTREACHED();
318 return CancelCallback(); 319 return CancelCallback();
319 } 320 }
320 321
321 CancelCallback MultipartUploadNewFile( 322 CancelCallback MultipartUploadNewFile(
322 const std::string& content_type, 323 const std::string& content_type,
323 int64 content_length, 324 int64 content_length,
324 const std::string& parent_resource_id, 325 const std::string& parent_resource_id,
325 const std::string& title, 326 const std::string& title,
326 const base::FilePath& local_file_path, 327 const base::FilePath& local_file_path,
327 const UploadNewFileOptions& options, 328 const UploadNewFileOptions& options,
328 const google_apis::FileResourceCallback& callback, 329 const google_apis::FileResourceCallback& callback,
329 const google_apis::ProgressCallback& progress_callback) override { 330 const google_apis::ProgressCallback& progress_callback) override {
330 base::MessageLoop::current()->PostTask( 331 base::ThreadTaskRunnerHandle::Get()->PostTask(
331 FROM_HERE, 332 FROM_HERE,
332 base::Bind(callback, DRIVE_NO_CONNECTION, 333 base::Bind(callback, DRIVE_NO_CONNECTION,
333 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 334 base::Passed(make_scoped_ptr<FileResource>(NULL))));
334 return CancelCallback(); 335 return CancelCallback();
335 } 336 }
336 337
337 CancelCallback MultipartUploadExistingFile( 338 CancelCallback MultipartUploadExistingFile(
338 const std::string& content_type, 339 const std::string& content_type,
339 int64 content_length, 340 int64 content_length,
340 const std::string& resource_id, 341 const std::string& resource_id,
341 const base::FilePath& local_file_path, 342 const base::FilePath& local_file_path,
342 const UploadExistingFileOptions& options, 343 const UploadExistingFileOptions& options,
343 const google_apis::FileResourceCallback& callback, 344 const google_apis::FileResourceCallback& callback,
344 const google_apis::ProgressCallback& progress_callback) override { 345 const google_apis::ProgressCallback& progress_callback) override {
345 base::MessageLoop::current()->PostTask( 346 base::ThreadTaskRunnerHandle::Get()->PostTask(
346 FROM_HERE, 347 FROM_HERE,
347 base::Bind(callback, DRIVE_NO_CONNECTION, 348 base::Bind(callback, DRIVE_NO_CONNECTION,
348 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 349 base::Passed(make_scoped_ptr<FileResource>(NULL))));
349 return CancelCallback(); 350 return CancelCallback();
350 } 351 }
351 }; 352 };
352 353
353 // Mock DriveService that returns a failure at ResumeUpload(). 354 // Mock DriveService that returns a failure at ResumeUpload().
354 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { 355 class MockDriveServiceNoConnectionAtResume : public DummyDriveService {
355 // Succeeds and returns an upload location URL. 356 // Succeeds and returns an upload location URL.
356 CancelCallback InitiateUploadNewFile( 357 CancelCallback InitiateUploadNewFile(
357 const std::string& content_type, 358 const std::string& content_type,
358 int64 content_length, 359 int64 content_length,
359 const std::string& parent_resource_id, 360 const std::string& parent_resource_id,
360 const std::string& title, 361 const std::string& title,
361 const UploadNewFileOptions& options, 362 const UploadNewFileOptions& options,
362 const InitiateUploadCallback& callback) override { 363 const InitiateUploadCallback& callback) override {
363 base::MessageLoop::current()->PostTask(FROM_HERE, 364 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
364 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 365 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
365 return CancelCallback(); 366 return CancelCallback();
366 } 367 }
367 368
368 CancelCallback InitiateUploadExistingFile( 369 CancelCallback InitiateUploadExistingFile(
369 const std::string& content_type, 370 const std::string& content_type,
370 int64 content_length, 371 int64 content_length,
371 const std::string& resource_id, 372 const std::string& resource_id,
372 const UploadExistingFileOptions& options, 373 const UploadExistingFileOptions& options,
373 const InitiateUploadCallback& callback) override { 374 const InitiateUploadCallback& callback) override {
374 base::MessageLoop::current()->PostTask(FROM_HERE, 375 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
375 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 376 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
376 return CancelCallback(); 377 return CancelCallback();
377 } 378 }
378 379
379 // Returns error. 380 // Returns error.
380 CancelCallback ResumeUpload( 381 CancelCallback ResumeUpload(
381 const GURL& upload_url, 382 const GURL& upload_url,
382 int64 start_position, 383 int64 start_position,
383 int64 end_position, 384 int64 end_position,
384 int64 content_length, 385 int64 content_length,
385 const std::string& content_type, 386 const std::string& content_type,
386 const base::FilePath& local_file_path, 387 const base::FilePath& local_file_path,
387 const UploadRangeCallback& callback, 388 const UploadRangeCallback& callback,
388 const ProgressCallback& progress_callback) override { 389 const ProgressCallback& progress_callback) override {
389 base::MessageLoop::current()->PostTask(FROM_HERE, 390 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
390 base::Bind(callback, 391 base::Bind(callback,
391 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 392 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
392 base::Passed(scoped_ptr<FileResource>()))); 393 base::Passed(scoped_ptr<FileResource>())));
393 return CancelCallback(); 394 return CancelCallback();
394 } 395 }
395 }; 396 };
396 397
397 // Mock DriveService that returns a failure at GetUploadStatus(). 398 // Mock DriveService that returns a failure at GetUploadStatus().
398 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService { 399 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
399 // Returns error. 400 // Returns error.
400 CancelCallback GetUploadStatus(const GURL& upload_url, 401 CancelCallback GetUploadStatus(const GURL& upload_url,
401 int64 content_length, 402 int64 content_length,
402 const UploadRangeCallback& callback) override { 403 const UploadRangeCallback& callback) override {
403 base::MessageLoop::current()->PostTask(FROM_HERE, 404 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
404 base::Bind(callback, 405 base::Bind(callback,
405 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 406 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
406 base::Passed(scoped_ptr<FileResource>()))); 407 base::Passed(scoped_ptr<FileResource>())));
407 return CancelCallback(); 408 return CancelCallback();
408 } 409 }
409 }; 410 };
410 411
411 class DriveUploaderTest : public testing::Test { 412 class DriveUploaderTest : public testing::Test {
412 public: 413 public:
413 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 414 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
(...skipping 10 matching lines...) Expand all
424 std::string data; 425 std::string data;
425 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 426 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
426 temp_dir_.path(), 0, &local_path, &data)); 427 temp_dir_.path(), 0, &local_path, &data));
427 428
428 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 429 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
429 GURL upload_location; 430 GURL upload_location;
430 scoped_ptr<FileResource> entry; 431 scoped_ptr<FileResource> entry;
431 432
432 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 433 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
433 DriveUploader uploader(&mock_service, 434 DriveUploader uploader(&mock_service,
434 base::MessageLoopProxy::current().get()); 435 base::ThreadTaskRunnerHandle::Get().get());
435 std::vector<test_util::ProgressInfo> upload_progress_values; 436 std::vector<test_util::ProgressInfo> upload_progress_values;
436 uploader.UploadExistingFile( 437 uploader.UploadExistingFile(
437 kTestInitiateUploadResourceId, local_path, kTestMimeType, 438 kTestInitiateUploadResourceId, local_path, kTestMimeType,
438 UploadExistingFileOptions(), 439 UploadExistingFileOptions(),
439 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 440 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
440 base::Bind(&test_util::AppendProgressCallbackResult, 441 base::Bind(&test_util::AppendProgressCallbackResult,
441 &upload_progress_values)); 442 &upload_progress_values));
442 base::RunLoop().RunUntilIdle(); 443 base::RunLoop().RunUntilIdle();
443 444
444 EXPECT_EQ(0, mock_service.resume_upload_call_count()); 445 EXPECT_EQ(0, mock_service.resume_upload_call_count());
(...skipping 12 matching lines...) Expand all
457 std::string data; 458 std::string data;
458 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 459 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
459 temp_dir_.path(), 512 * 1024, &local_path, &data)); 460 temp_dir_.path(), 512 * 1024, &local_path, &data));
460 461
461 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 462 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
462 GURL upload_location; 463 GURL upload_location;
463 scoped_ptr<FileResource> entry; 464 scoped_ptr<FileResource> entry;
464 465
465 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 466 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
466 DriveUploader uploader(&mock_service, 467 DriveUploader uploader(&mock_service,
467 base::MessageLoopProxy::current().get()); 468 base::ThreadTaskRunnerHandle::Get().get());
468 std::vector<test_util::ProgressInfo> upload_progress_values; 469 std::vector<test_util::ProgressInfo> upload_progress_values;
469 uploader.UploadExistingFile( 470 uploader.UploadExistingFile(
470 kTestInitiateUploadResourceId, local_path, kTestMimeType, 471 kTestInitiateUploadResourceId, local_path, kTestMimeType,
471 UploadExistingFileOptions(), 472 UploadExistingFileOptions(),
472 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 473 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
473 base::Bind(&test_util::AppendProgressCallbackResult, 474 base::Bind(&test_util::AppendProgressCallbackResult,
474 &upload_progress_values)); 475 &upload_progress_values));
475 base::RunLoop().RunUntilIdle(); 476 base::RunLoop().RunUntilIdle();
476 477
477 // 512KB upload should be uploaded as multipart body. 478 // 512KB upload should be uploaded as multipart body.
(...skipping 14 matching lines...) Expand all
492 std::string data; 493 std::string data;
493 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 494 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
494 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 495 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
495 496
496 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 497 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
497 GURL upload_location; 498 GURL upload_location;
498 scoped_ptr<FileResource> entry; 499 scoped_ptr<FileResource> entry;
499 500
500 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 501 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
501 DriveUploader uploader(&mock_service, 502 DriveUploader uploader(&mock_service,
502 base::MessageLoopProxy::current().get()); 503 base::ThreadTaskRunnerHandle::Get().get());
503 std::vector<test_util::ProgressInfo> upload_progress_values; 504 std::vector<test_util::ProgressInfo> upload_progress_values;
504 uploader.UploadExistingFile( 505 uploader.UploadExistingFile(
505 kTestInitiateUploadResourceId, local_path, kTestMimeType, 506 kTestInitiateUploadResourceId, local_path, kTestMimeType,
506 UploadExistingFileOptions(), 507 UploadExistingFileOptions(),
507 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 508 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
508 base::Bind(&test_util::AppendProgressCallbackResult, 509 base::Bind(&test_util::AppendProgressCallbackResult,
509 &upload_progress_values)); 510 &upload_progress_values));
510 base::RunLoop().RunUntilIdle(); 511 base::RunLoop().RunUntilIdle();
511 512
512 // 2MB upload should not be split into multiple chunks. 513 // 2MB upload should not be split into multiple chunks.
(...skipping 14 matching lines...) Expand all
527 std::string data; 528 std::string data;
528 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 529 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
529 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 530 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
530 531
531 DriveApiErrorCode error = HTTP_SUCCESS; 532 DriveApiErrorCode error = HTTP_SUCCESS;
532 GURL upload_location; 533 GURL upload_location;
533 scoped_ptr<FileResource> entry; 534 scoped_ptr<FileResource> entry;
534 535
535 MockDriveServiceNoConnectionAtInitiate mock_service; 536 MockDriveServiceNoConnectionAtInitiate mock_service;
536 DriveUploader uploader(&mock_service, 537 DriveUploader uploader(&mock_service,
537 base::MessageLoopProxy::current().get()); 538 base::ThreadTaskRunnerHandle::Get().get());
538 uploader.UploadExistingFile( 539 uploader.UploadExistingFile(
539 kTestInitiateUploadResourceId, local_path, kTestMimeType, 540 kTestInitiateUploadResourceId, local_path, kTestMimeType,
540 UploadExistingFileOptions(), 541 UploadExistingFileOptions(),
541 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 542 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
542 google_apis::ProgressCallback()); 543 google_apis::ProgressCallback());
543 base::RunLoop().RunUntilIdle(); 544 base::RunLoop().RunUntilIdle();
544 545
545 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 546 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
546 EXPECT_TRUE(upload_location.is_empty()); 547 EXPECT_TRUE(upload_location.is_empty());
547 EXPECT_FALSE(entry); 548 EXPECT_FALSE(entry);
548 } 549 }
549 550
550 TEST_F(DriveUploaderTest, MultipartUploadFail) { 551 TEST_F(DriveUploaderTest, MultipartUploadFail) {
551 base::FilePath local_path; 552 base::FilePath local_path;
552 std::string data; 553 std::string data;
553 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024, 554 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024,
554 &local_path, &data)); 555 &local_path, &data));
555 556
556 DriveApiErrorCode error = HTTP_SUCCESS; 557 DriveApiErrorCode error = HTTP_SUCCESS;
557 GURL upload_location; 558 GURL upload_location;
558 scoped_ptr<FileResource> entry; 559 scoped_ptr<FileResource> entry;
559 560
560 MockDriveServiceNoConnectionAtInitiate mock_service; 561 MockDriveServiceNoConnectionAtInitiate mock_service;
561 DriveUploader uploader(&mock_service, 562 DriveUploader uploader(&mock_service,
562 base::MessageLoopProxy::current().get()); 563 base::ThreadTaskRunnerHandle::Get().get());
563 uploader.UploadExistingFile( 564 uploader.UploadExistingFile(
564 kTestInitiateUploadResourceId, local_path, kTestMimeType, 565 kTestInitiateUploadResourceId, local_path, kTestMimeType,
565 UploadExistingFileOptions(), 566 UploadExistingFileOptions(),
566 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 567 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
567 google_apis::ProgressCallback()); 568 google_apis::ProgressCallback());
568 base::RunLoop().RunUntilIdle(); 569 base::RunLoop().RunUntilIdle();
569 570
570 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 571 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
571 EXPECT_TRUE(upload_location.is_empty()); 572 EXPECT_TRUE(upload_location.is_empty());
572 EXPECT_FALSE(entry); 573 EXPECT_FALSE(entry);
573 } 574 }
574 575
575 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { 576 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) {
576 base::FilePath local_path; 577 base::FilePath local_path;
577 std::string data; 578 std::string data;
578 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 579 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
579 temp_dir_.path(), 512 * 1024, &local_path, &data)); 580 temp_dir_.path(), 512 * 1024, &local_path, &data));
580 581
581 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 582 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
582 GURL upload_location; 583 GURL upload_location;
583 scoped_ptr<FileResource> entry; 584 scoped_ptr<FileResource> entry;
584 585
585 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 586 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
586 DriveUploader uploader(&mock_service, 587 DriveUploader uploader(&mock_service,
587 base::MessageLoopProxy::current().get()); 588 base::ThreadTaskRunnerHandle::Get().get());
588 UploadExistingFileOptions options; 589 UploadExistingFileOptions options;
589 options.etag = kTestETag; 590 options.etag = kTestETag;
590 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 591 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
591 local_path, 592 local_path,
592 kTestMimeType, 593 kTestMimeType,
593 options, 594 options,
594 test_util::CreateCopyResultCallback( 595 test_util::CreateCopyResultCallback(
595 &error, &upload_location, &entry), 596 &error, &upload_location, &entry),
596 google_apis::ProgressCallback()); 597 google_apis::ProgressCallback());
597 base::RunLoop().RunUntilIdle(); 598 base::RunLoop().RunUntilIdle();
598 599
599 EXPECT_EQ(HTTP_SUCCESS, error); 600 EXPECT_EQ(HTTP_SUCCESS, error);
600 EXPECT_TRUE(upload_location.is_empty()); 601 EXPECT_TRUE(upload_location.is_empty());
601 } 602 }
602 603
603 TEST_F(DriveUploaderTest, MultipartUploadConflict) { 604 TEST_F(DriveUploaderTest, MultipartUploadConflict) {
604 base::FilePath local_path; 605 base::FilePath local_path;
605 std::string data; 606 std::string data;
606 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 607 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
607 temp_dir_.path(), 512 * 1024, &local_path, &data)); 608 temp_dir_.path(), 512 * 1024, &local_path, &data));
608 const std::string kDestinationETag("destination_etag"); 609 const std::string kDestinationETag("destination_etag");
609 610
610 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 611 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
611 GURL upload_location; 612 GURL upload_location;
612 scoped_ptr<FileResource> entry; 613 scoped_ptr<FileResource> entry;
613 614
614 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 615 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
615 DriveUploader uploader(&mock_service, 616 DriveUploader uploader(&mock_service,
616 base::MessageLoopProxy::current().get()); 617 base::ThreadTaskRunnerHandle::Get().get());
617 UploadExistingFileOptions options; 618 UploadExistingFileOptions options;
618 options.etag = kDestinationETag; 619 options.etag = kDestinationETag;
619 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 620 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
620 local_path, 621 local_path,
621 kTestMimeType, 622 kTestMimeType,
622 options, 623 options,
623 test_util::CreateCopyResultCallback( 624 test_util::CreateCopyResultCallback(
624 &error, &upload_location, &entry), 625 &error, &upload_location, &entry),
625 google_apis::ProgressCallback()); 626 google_apis::ProgressCallback());
626 base::RunLoop().RunUntilIdle(); 627 base::RunLoop().RunUntilIdle();
627 628
628 EXPECT_EQ(HTTP_CONFLICT, error); 629 EXPECT_EQ(HTTP_CONFLICT, error);
629 EXPECT_TRUE(upload_location.is_empty()); 630 EXPECT_TRUE(upload_location.is_empty());
630 } 631 }
631 632
632 TEST_F(DriveUploaderTest, InitiateUploadConflict) { 633 TEST_F(DriveUploaderTest, InitiateUploadConflict) {
633 base::FilePath local_path; 634 base::FilePath local_path;
634 std::string data; 635 std::string data;
635 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 636 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
636 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 637 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
637 const std::string kDestinationETag("destination_etag"); 638 const std::string kDestinationETag("destination_etag");
638 639
639 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 640 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
640 GURL upload_location; 641 GURL upload_location;
641 scoped_ptr<FileResource> entry; 642 scoped_ptr<FileResource> entry;
642 643
643 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 644 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
644 DriveUploader uploader(&mock_service, 645 DriveUploader uploader(&mock_service,
645 base::MessageLoopProxy::current().get()); 646 base::ThreadTaskRunnerHandle::Get().get());
646 UploadExistingFileOptions options; 647 UploadExistingFileOptions options;
647 options.etag = kDestinationETag; 648 options.etag = kDestinationETag;
648 uploader.UploadExistingFile( 649 uploader.UploadExistingFile(
649 kTestInitiateUploadResourceId, local_path, kTestMimeType, options, 650 kTestInitiateUploadResourceId, local_path, kTestMimeType, options,
650 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 651 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
651 google_apis::ProgressCallback()); 652 google_apis::ProgressCallback());
652 base::RunLoop().RunUntilIdle(); 653 base::RunLoop().RunUntilIdle();
653 654
654 EXPECT_EQ(HTTP_CONFLICT, error); 655 EXPECT_EQ(HTTP_CONFLICT, error);
655 EXPECT_TRUE(upload_location.is_empty()); 656 EXPECT_TRUE(upload_location.is_empty());
656 } 657 }
657 658
658 TEST_F(DriveUploaderTest, ResumeUploadFail) { 659 TEST_F(DriveUploaderTest, ResumeUploadFail) {
659 base::FilePath local_path; 660 base::FilePath local_path;
660 std::string data; 661 std::string data;
661 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 662 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
662 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 663 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
663 664
664 DriveApiErrorCode error = HTTP_SUCCESS; 665 DriveApiErrorCode error = HTTP_SUCCESS;
665 GURL upload_location; 666 GURL upload_location;
666 scoped_ptr<FileResource> entry; 667 scoped_ptr<FileResource> entry;
667 668
668 MockDriveServiceNoConnectionAtResume mock_service; 669 MockDriveServiceNoConnectionAtResume mock_service;
669 DriveUploader uploader(&mock_service, 670 DriveUploader uploader(&mock_service,
670 base::MessageLoopProxy::current().get()); 671 base::ThreadTaskRunnerHandle::Get().get());
671 uploader.UploadExistingFile( 672 uploader.UploadExistingFile(
672 kTestInitiateUploadResourceId, local_path, kTestMimeType, 673 kTestInitiateUploadResourceId, local_path, kTestMimeType,
673 UploadExistingFileOptions(), 674 UploadExistingFileOptions(),
674 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 675 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
675 google_apis::ProgressCallback()); 676 google_apis::ProgressCallback());
676 base::RunLoop().RunUntilIdle(); 677 base::RunLoop().RunUntilIdle();
677 678
678 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 679 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
679 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); 680 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location);
680 } 681 }
681 682
682 TEST_F(DriveUploaderTest, GetUploadStatusFail) { 683 TEST_F(DriveUploaderTest, GetUploadStatusFail) {
683 base::FilePath local_path; 684 base::FilePath local_path;
684 std::string data; 685 std::string data;
685 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 686 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
686 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 687 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
687 688
688 DriveApiErrorCode error = HTTP_SUCCESS; 689 DriveApiErrorCode error = HTTP_SUCCESS;
689 GURL upload_location; 690 GURL upload_location;
690 scoped_ptr<FileResource> entry; 691 scoped_ptr<FileResource> entry;
691 692
692 MockDriveServiceNoConnectionAtGetUploadStatus mock_service; 693 MockDriveServiceNoConnectionAtGetUploadStatus mock_service;
693 DriveUploader uploader(&mock_service, 694 DriveUploader uploader(&mock_service,
694 base::MessageLoopProxy::current().get()); 695 base::ThreadTaskRunnerHandle::Get().get());
695 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL), 696 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL),
696 local_path, 697 local_path,
697 kTestMimeType, 698 kTestMimeType,
698 test_util::CreateCopyResultCallback( 699 test_util::CreateCopyResultCallback(
699 &error, &upload_location, &entry), 700 &error, &upload_location, &entry),
700 google_apis::ProgressCallback()); 701 google_apis::ProgressCallback());
701 base::RunLoop().RunUntilIdle(); 702 base::RunLoop().RunUntilIdle();
702 703
703 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 704 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
704 EXPECT_TRUE(upload_location.is_empty()); 705 EXPECT_TRUE(upload_location.is_empty());
705 } 706 }
706 707
707 TEST_F(DriveUploaderTest, NonExistingSourceFile) { 708 TEST_F(DriveUploaderTest, NonExistingSourceFile) {
708 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 709 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
709 GURL upload_location; 710 GURL upload_location;
710 scoped_ptr<FileResource> entry; 711 scoped_ptr<FileResource> entry;
711 712
712 DriveUploader uploader(NULL, // NULL, the service won't be used. 713 DriveUploader uploader(NULL, // NULL, the service won't be used.
713 base::MessageLoopProxy::current().get()); 714 base::ThreadTaskRunnerHandle::Get().get());
714 uploader.UploadExistingFile( 715 uploader.UploadExistingFile(
715 kTestInitiateUploadResourceId, 716 kTestInitiateUploadResourceId,
716 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), 717 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"),
717 kTestMimeType, UploadExistingFileOptions(), 718 kTestMimeType, UploadExistingFileOptions(),
718 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 719 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
719 google_apis::ProgressCallback()); 720 google_apis::ProgressCallback());
720 base::RunLoop().RunUntilIdle(); 721 base::RunLoop().RunUntilIdle();
721 722
722 // Should return failure without doing any attempt to connect to the server. 723 // Should return failure without doing any attempt to connect to the server.
723 EXPECT_EQ(HTTP_NOT_FOUND, error); 724 EXPECT_EQ(HTTP_NOT_FOUND, error);
724 EXPECT_TRUE(upload_location.is_empty()); 725 EXPECT_TRUE(upload_location.is_empty());
725 } 726 }
726 727
727 TEST_F(DriveUploaderTest, ResumeUpload) { 728 TEST_F(DriveUploaderTest, ResumeUpload) {
728 base::FilePath local_path; 729 base::FilePath local_path;
729 std::string data; 730 std::string data;
730 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 731 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
731 temp_dir_.path(), 1024 * 1024, &local_path, &data)); 732 temp_dir_.path(), 1024 * 1024, &local_path, &data));
732 733
733 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 734 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
734 GURL upload_location; 735 GURL upload_location;
735 scoped_ptr<FileResource> entry; 736 scoped_ptr<FileResource> entry;
736 737
737 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 738 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
738 DriveUploader uploader(&mock_service, 739 DriveUploader uploader(&mock_service,
739 base::MessageLoopProxy::current().get()); 740 base::ThreadTaskRunnerHandle::Get().get());
740 // Emulate the situation that the only first part is successfully uploaded, 741 // Emulate the situation that the only first part is successfully uploaded,
741 // but not the latter half. 742 // but not the latter half.
742 mock_service.set_received_bytes(512 * 1024); 743 mock_service.set_received_bytes(512 * 1024);
743 744
744 std::vector<test_util::ProgressInfo> upload_progress_values; 745 std::vector<test_util::ProgressInfo> upload_progress_values;
745 uploader.ResumeUploadFile( 746 uploader.ResumeUploadFile(
746 GURL(kTestUploadExistingFileURL), 747 GURL(kTestUploadExistingFileURL),
747 local_path, 748 local_path,
748 kTestMimeType, 749 kTestMimeType,
749 test_util::CreateCopyResultCallback( 750 test_util::CreateCopyResultCallback(
750 &error, &upload_location, &entry), 751 &error, &upload_location, &entry),
751 base::Bind(&test_util::AppendProgressCallbackResult, 752 base::Bind(&test_util::AppendProgressCallbackResult,
752 &upload_progress_values)); 753 &upload_progress_values));
753 base::RunLoop().RunUntilIdle(); 754 base::RunLoop().RunUntilIdle();
754 755
755 EXPECT_EQ(1, mock_service.resume_upload_call_count()); 756 EXPECT_EQ(1, mock_service.resume_upload_call_count());
756 EXPECT_EQ(1024 * 1024, mock_service.received_bytes()); 757 EXPECT_EQ(1024 * 1024, mock_service.received_bytes());
757 EXPECT_EQ(HTTP_SUCCESS, error); 758 EXPECT_EQ(HTTP_SUCCESS, error);
758 EXPECT_TRUE(upload_location.is_empty()); 759 EXPECT_TRUE(upload_location.is_empty());
759 ASSERT_TRUE(entry); 760 ASSERT_TRUE(entry);
760 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); 761 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum());
761 ASSERT_EQ(1U, upload_progress_values.size()); 762 ASSERT_EQ(1U, upload_progress_values.size());
762 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 763 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
763 upload_progress_values[0]); 764 upload_progress_values[0]);
764 } 765 }
765 766
766 } // namespace drive 767 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/drive/fake_drive_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698