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

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

Issue 881403003: Rename gdata_errorcode.h to drive_api_error_codes.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos in BUILD.gn Created 5 years, 10 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 (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/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/drive/dummy_drive_service.h" 16 #include "chrome/browser/drive/dummy_drive_service.h"
17 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
18 #include "google_apis/drive/test_util.h" 18 #include "google_apis/drive/test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using google_apis::CancelCallback; 21 using google_apis::CancelCallback;
22 using google_apis::FileResource; 22 using google_apis::FileResource;
23 using google_apis::GDataErrorCode; 23 using google_apis::DriveApiErrorCode;
mtomasz 2015/01/29 06:18:02 nit: ditto
24 using google_apis::GDATA_NO_CONNECTION; 24 using google_apis::DRIVE_NO_CONNECTION;
25 using google_apis::GDATA_OTHER_ERROR; 25 using google_apis::DRIVE_OTHER_ERROR;
26 using google_apis::HTTP_CONFLICT; 26 using google_apis::HTTP_CONFLICT;
27 using google_apis::HTTP_CREATED; 27 using google_apis::HTTP_CREATED;
28 using google_apis::HTTP_NOT_FOUND; 28 using google_apis::HTTP_NOT_FOUND;
29 using google_apis::HTTP_PRECONDITION; 29 using google_apis::HTTP_PRECONDITION;
30 using google_apis::HTTP_RESUME_INCOMPLETE; 30 using google_apis::HTTP_RESUME_INCOMPLETE;
31 using google_apis::HTTP_SUCCESS; 31 using google_apis::HTTP_SUCCESS;
32 using google_apis::InitiateUploadCallback; 32 using google_apis::InitiateUploadCallback;
33 using google_apis::ProgressCallback; 33 using google_apis::ProgressCallback;
34 using google_apis::UploadRangeResponse; 34 using google_apis::UploadRangeResponse;
35 using google_apis::drive::UploadRangeCallback; 35 using google_apis::drive::UploadRangeCallback;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return CancelCallback(); 177 return CancelCallback();
178 } 178 }
179 179
180 // Runs |callback| with the current upload status. 180 // Runs |callback| with the current upload status.
181 void SendUploadRangeResponse(const GURL& upload_location, 181 void SendUploadRangeResponse(const GURL& upload_location,
182 const UploadRangeCallback& callback) { 182 const UploadRangeCallback& callback) {
183 // Callback with response. 183 // Callback with response.
184 UploadRangeResponse response; 184 UploadRangeResponse response;
185 scoped_ptr<FileResource> entry; 185 scoped_ptr<FileResource> entry;
186 if (received_bytes_ == expected_content_length_) { 186 if (received_bytes_ == expected_content_length_) {
187 GDataErrorCode response_code = 187 DriveApiErrorCode response_code =
188 upload_location == GURL(kTestUploadNewFileURL) ? 188 upload_location == GURL(kTestUploadNewFileURL) ?
189 HTTP_CREATED : HTTP_SUCCESS; 189 HTTP_CREATED : HTTP_SUCCESS;
190 response = UploadRangeResponse(response_code, -1, -1); 190 response = UploadRangeResponse(response_code, -1, -1);
191 191
192 entry.reset(new FileResource); 192 entry.reset(new FileResource);
193 entry->set_md5_checksum(kTestDummyMd5); 193 entry->set_md5_checksum(kTestDummyMd5);
194 } else { 194 } else {
195 response = UploadRangeResponse( 195 response = UploadRangeResponse(
196 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); 196 HTTP_RESUME_INCOMPLETE, 0, received_bytes_);
197 } 197 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 base::Bind(callback, HTTP_PRECONDITION, 238 base::Bind(callback, HTTP_PRECONDITION,
239 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 239 base::Passed(make_scoped_ptr<FileResource>(NULL))));
240 return CancelCallback(); 240 return CancelCallback();
241 } 241 }
242 242
243 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback, 243 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback,
244 progress_callback); 244 progress_callback);
245 } 245 }
246 246
247 CancelCallback SendMultipartUploadResult( 247 CancelCallback SendMultipartUploadResult(
248 GDataErrorCode response_code, 248 DriveApiErrorCode response_code,
249 int64 content_length, 249 int64 content_length,
250 const google_apis::FileResourceCallback& callback, 250 const google_apis::FileResourceCallback& callback,
251 const google_apis::ProgressCallback& progress_callback) { 251 const google_apis::ProgressCallback& progress_callback) {
252 received_bytes_ = content_length; 252 received_bytes_ = content_length;
253 multipart_upload_call_count_++; 253 multipart_upload_call_count_++;
254 254
255 // Callback progress 255 // Callback progress
256 if (!progress_callback.is_null()) { 256 if (!progress_callback.is_null()) {
257 // For the testing purpose, it always notifies the progress at the end of 257 // For the testing purpose, it always notifies the progress at the end of
258 // whole file uploading. 258 // whole file uploading.
(...skipping 23 matching lines...) Expand all
282 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { 282 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService {
283 // Returns error. 283 // Returns error.
284 CancelCallback InitiateUploadNewFile( 284 CancelCallback InitiateUploadNewFile(
285 const std::string& content_type, 285 const std::string& content_type,
286 int64 content_length, 286 int64 content_length,
287 const std::string& parent_resource_id, 287 const std::string& parent_resource_id,
288 const std::string& title, 288 const std::string& title,
289 const UploadNewFileOptions& options, 289 const UploadNewFileOptions& options,
290 const InitiateUploadCallback& callback) override { 290 const InitiateUploadCallback& callback) override {
291 base::MessageLoop::current()->PostTask(FROM_HERE, 291 base::MessageLoop::current()->PostTask(FROM_HERE,
292 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 292 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
293 return CancelCallback(); 293 return CancelCallback();
294 } 294 }
295 295
296 CancelCallback InitiateUploadExistingFile( 296 CancelCallback InitiateUploadExistingFile(
297 const std::string& content_type, 297 const std::string& content_type,
298 int64 content_length, 298 int64 content_length,
299 const std::string& resource_id, 299 const std::string& resource_id,
300 const UploadExistingFileOptions& options, 300 const UploadExistingFileOptions& options,
301 const InitiateUploadCallback& callback) override { 301 const InitiateUploadCallback& callback) override {
302 base::MessageLoop::current()->PostTask(FROM_HERE, 302 base::MessageLoop::current()->PostTask(FROM_HERE,
303 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); 303 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
304 return CancelCallback(); 304 return CancelCallback();
305 } 305 }
306 306
307 // Should not be used. 307 // Should not be used.
308 CancelCallback ResumeUpload( 308 CancelCallback ResumeUpload(
309 const GURL& upload_url, 309 const GURL& upload_url,
310 int64 start_position, 310 int64 start_position,
311 int64 end_position, 311 int64 end_position,
312 int64 content_length, 312 int64 content_length,
313 const std::string& content_type, 313 const std::string& content_type,
314 const base::FilePath& local_file_path, 314 const base::FilePath& local_file_path,
315 const UploadRangeCallback& callback, 315 const UploadRangeCallback& callback,
316 const ProgressCallback& progress_callback) override { 316 const ProgressCallback& progress_callback) override {
317 NOTREACHED(); 317 NOTREACHED();
318 return CancelCallback(); 318 return CancelCallback();
319 } 319 }
320 320
321 CancelCallback MultipartUploadNewFile( 321 CancelCallback MultipartUploadNewFile(
322 const std::string& content_type, 322 const std::string& content_type,
323 int64 content_length, 323 int64 content_length,
324 const std::string& parent_resource_id, 324 const std::string& parent_resource_id,
325 const std::string& title, 325 const std::string& title,
326 const base::FilePath& local_file_path, 326 const base::FilePath& local_file_path,
327 const UploadNewFileOptions& options, 327 const UploadNewFileOptions& options,
328 const google_apis::FileResourceCallback& callback, 328 const google_apis::FileResourceCallback& callback,
329 const google_apis::ProgressCallback& progress_callback) override { 329 const google_apis::ProgressCallback& progress_callback) override {
330 base::MessageLoop::current()->PostTask( 330 base::MessageLoop::current()->PostTask(
331 FROM_HERE, 331 FROM_HERE,
332 base::Bind(callback, GDATA_NO_CONNECTION, 332 base::Bind(callback, DRIVE_NO_CONNECTION,
333 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 333 base::Passed(make_scoped_ptr<FileResource>(NULL))));
334 return CancelCallback(); 334 return CancelCallback();
335 } 335 }
336 336
337 CancelCallback MultipartUploadExistingFile( 337 CancelCallback MultipartUploadExistingFile(
338 const std::string& content_type, 338 const std::string& content_type,
339 int64 content_length, 339 int64 content_length,
340 const std::string& resource_id, 340 const std::string& resource_id,
341 const base::FilePath& local_file_path, 341 const base::FilePath& local_file_path,
342 const UploadExistingFileOptions& options, 342 const UploadExistingFileOptions& options,
343 const google_apis::FileResourceCallback& callback, 343 const google_apis::FileResourceCallback& callback,
344 const google_apis::ProgressCallback& progress_callback) override { 344 const google_apis::ProgressCallback& progress_callback) override {
345 base::MessageLoop::current()->PostTask( 345 base::MessageLoop::current()->PostTask(
346 FROM_HERE, 346 FROM_HERE,
347 base::Bind(callback, GDATA_NO_CONNECTION, 347 base::Bind(callback, DRIVE_NO_CONNECTION,
348 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 348 base::Passed(make_scoped_ptr<FileResource>(NULL))));
349 return CancelCallback(); 349 return CancelCallback();
350 } 350 }
351 }; 351 };
352 352
353 // Mock DriveService that returns a failure at ResumeUpload(). 353 // Mock DriveService that returns a failure at ResumeUpload().
354 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { 354 class MockDriveServiceNoConnectionAtResume : public DummyDriveService {
355 // Succeeds and returns an upload location URL. 355 // Succeeds and returns an upload location URL.
356 CancelCallback InitiateUploadNewFile( 356 CancelCallback InitiateUploadNewFile(
357 const std::string& content_type, 357 const std::string& content_type,
(...skipping 23 matching lines...) Expand all
381 const GURL& upload_url, 381 const GURL& upload_url,
382 int64 start_position, 382 int64 start_position,
383 int64 end_position, 383 int64 end_position,
384 int64 content_length, 384 int64 content_length,
385 const std::string& content_type, 385 const std::string& content_type,
386 const base::FilePath& local_file_path, 386 const base::FilePath& local_file_path,
387 const UploadRangeCallback& callback, 387 const UploadRangeCallback& callback,
388 const ProgressCallback& progress_callback) override { 388 const ProgressCallback& progress_callback) override {
389 base::MessageLoop::current()->PostTask(FROM_HERE, 389 base::MessageLoop::current()->PostTask(FROM_HERE,
390 base::Bind(callback, 390 base::Bind(callback,
391 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), 391 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
392 base::Passed(scoped_ptr<FileResource>()))); 392 base::Passed(scoped_ptr<FileResource>())));
393 return CancelCallback(); 393 return CancelCallback();
394 } 394 }
395 }; 395 };
396 396
397 // Mock DriveService that returns a failure at GetUploadStatus(). 397 // Mock DriveService that returns a failure at GetUploadStatus().
398 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService { 398 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
399 // Returns error. 399 // Returns error.
400 CancelCallback GetUploadStatus(const GURL& upload_url, 400 CancelCallback GetUploadStatus(const GURL& upload_url,
401 int64 content_length, 401 int64 content_length,
402 const UploadRangeCallback& callback) override { 402 const UploadRangeCallback& callback) override {
403 base::MessageLoop::current()->PostTask(FROM_HERE, 403 base::MessageLoop::current()->PostTask(FROM_HERE,
404 base::Bind(callback, 404 base::Bind(callback,
405 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), 405 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
406 base::Passed(scoped_ptr<FileResource>()))); 406 base::Passed(scoped_ptr<FileResource>())));
407 return CancelCallback(); 407 return CancelCallback();
408 } 408 }
409 }; 409 };
410 410
411 class DriveUploaderTest : public testing::Test { 411 class DriveUploaderTest : public testing::Test {
412 public: 412 public:
413 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 413 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
414 414
415 protected: 415 protected:
416 base::MessageLoop message_loop_; 416 base::MessageLoop message_loop_;
417 base::ScopedTempDir temp_dir_; 417 base::ScopedTempDir temp_dir_;
418 }; 418 };
419 419
420 } // namespace 420 } // namespace
421 421
422 TEST_F(DriveUploaderTest, UploadExisting0KB) { 422 TEST_F(DriveUploaderTest, UploadExisting0KB) {
423 base::FilePath local_path; 423 base::FilePath local_path;
424 std::string data; 424 std::string data;
425 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 425 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
426 temp_dir_.path(), 0, &local_path, &data)); 426 temp_dir_.path(), 0, &local_path, &data));
427 427
428 GDataErrorCode error = GDATA_OTHER_ERROR; 428 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
429 GURL upload_location; 429 GURL upload_location;
430 scoped_ptr<FileResource> entry; 430 scoped_ptr<FileResource> entry;
431 431
432 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 432 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
433 DriveUploader uploader(&mock_service, 433 DriveUploader uploader(&mock_service,
434 base::MessageLoopProxy::current().get()); 434 base::MessageLoopProxy::current().get());
435 std::vector<test_util::ProgressInfo> upload_progress_values; 435 std::vector<test_util::ProgressInfo> upload_progress_values;
436 uploader.UploadExistingFile( 436 uploader.UploadExistingFile(
437 kTestInitiateUploadResourceId, 437 kTestInitiateUploadResourceId,
438 local_path, 438 local_path,
(...skipping 15 matching lines...) Expand all
454 ASSERT_EQ(1U, upload_progress_values.size()); 454 ASSERT_EQ(1U, upload_progress_values.size());
455 EXPECT_EQ(test_util::ProgressInfo(0, 0), upload_progress_values[0]); 455 EXPECT_EQ(test_util::ProgressInfo(0, 0), upload_progress_values[0]);
456 } 456 }
457 457
458 TEST_F(DriveUploaderTest, UploadExisting512KB) { 458 TEST_F(DriveUploaderTest, UploadExisting512KB) {
459 base::FilePath local_path; 459 base::FilePath local_path;
460 std::string data; 460 std::string data;
461 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 461 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
462 temp_dir_.path(), 512 * 1024, &local_path, &data)); 462 temp_dir_.path(), 512 * 1024, &local_path, &data));
463 463
464 GDataErrorCode error = GDATA_OTHER_ERROR; 464 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
465 GURL upload_location; 465 GURL upload_location;
466 scoped_ptr<FileResource> entry; 466 scoped_ptr<FileResource> entry;
467 467
468 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 468 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
469 DriveUploader uploader(&mock_service, 469 DriveUploader uploader(&mock_service,
470 base::MessageLoopProxy::current().get()); 470 base::MessageLoopProxy::current().get());
471 std::vector<test_util::ProgressInfo> upload_progress_values; 471 std::vector<test_util::ProgressInfo> upload_progress_values;
472 uploader.UploadExistingFile( 472 uploader.UploadExistingFile(
473 kTestInitiateUploadResourceId, 473 kTestInitiateUploadResourceId,
474 local_path, 474 local_path,
(...skipping 17 matching lines...) Expand all
492 EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 512 * 1024), 492 EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 512 * 1024),
493 upload_progress_values[0]); 493 upload_progress_values[0]);
494 } 494 }
495 495
496 TEST_F(DriveUploaderTest, UploadExisting2MB) { 496 TEST_F(DriveUploaderTest, UploadExisting2MB) {
497 base::FilePath local_path; 497 base::FilePath local_path;
498 std::string data; 498 std::string data;
499 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 499 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
500 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 500 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
501 501
502 GDataErrorCode error = GDATA_OTHER_ERROR; 502 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
503 GURL upload_location; 503 GURL upload_location;
504 scoped_ptr<FileResource> entry; 504 scoped_ptr<FileResource> entry;
505 505
506 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 506 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
507 DriveUploader uploader(&mock_service, 507 DriveUploader uploader(&mock_service,
508 base::MessageLoopProxy::current().get()); 508 base::MessageLoopProxy::current().get());
509 std::vector<test_util::ProgressInfo> upload_progress_values; 509 std::vector<test_util::ProgressInfo> upload_progress_values;
510 uploader.UploadExistingFile( 510 uploader.UploadExistingFile(
511 kTestInitiateUploadResourceId, local_path, kTestMimeType, 511 kTestInitiateUploadResourceId, local_path, kTestMimeType,
512 DriveUploader::UploadExistingFileOptions(), 512 DriveUploader::UploadExistingFileOptions(),
(...skipping 14 matching lines...) Expand all
527 EXPECT_EQ(test_util::ProgressInfo(2 * 1024 * 1024, 2 * 1024 * 1024), 527 EXPECT_EQ(test_util::ProgressInfo(2 * 1024 * 1024, 2 * 1024 * 1024),
528 upload_progress_values[0]); 528 upload_progress_values[0]);
529 } 529 }
530 530
531 TEST_F(DriveUploaderTest, InitiateUploadFail) { 531 TEST_F(DriveUploaderTest, InitiateUploadFail) {
532 base::FilePath local_path; 532 base::FilePath local_path;
533 std::string data; 533 std::string data;
534 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 534 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
535 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 535 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
536 536
537 GDataErrorCode error = HTTP_SUCCESS; 537 DriveApiErrorCode error = HTTP_SUCCESS;
538 GURL upload_location; 538 GURL upload_location;
539 scoped_ptr<FileResource> entry; 539 scoped_ptr<FileResource> entry;
540 540
541 MockDriveServiceNoConnectionAtInitiate mock_service; 541 MockDriveServiceNoConnectionAtInitiate mock_service;
542 DriveUploader uploader(&mock_service, 542 DriveUploader uploader(&mock_service,
543 base::MessageLoopProxy::current().get()); 543 base::MessageLoopProxy::current().get());
544 uploader.UploadExistingFile( 544 uploader.UploadExistingFile(
545 kTestInitiateUploadResourceId, local_path, kTestMimeType, 545 kTestInitiateUploadResourceId, local_path, kTestMimeType,
546 DriveUploader::UploadExistingFileOptions(), 546 DriveUploader::UploadExistingFileOptions(),
547 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 547 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
548 google_apis::ProgressCallback()); 548 google_apis::ProgressCallback());
549 base::RunLoop().RunUntilIdle(); 549 base::RunLoop().RunUntilIdle();
550 550
551 EXPECT_EQ(GDATA_NO_CONNECTION, error); 551 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
552 EXPECT_TRUE(upload_location.is_empty()); 552 EXPECT_TRUE(upload_location.is_empty());
553 EXPECT_FALSE(entry); 553 EXPECT_FALSE(entry);
554 } 554 }
555 555
556 TEST_F(DriveUploaderTest, MultipartUploadFail) { 556 TEST_F(DriveUploaderTest, MultipartUploadFail) {
557 base::FilePath local_path; 557 base::FilePath local_path;
558 std::string data; 558 std::string data;
559 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024, 559 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024,
560 &local_path, &data)); 560 &local_path, &data));
561 561
562 GDataErrorCode error = HTTP_SUCCESS; 562 DriveApiErrorCode error = HTTP_SUCCESS;
563 GURL upload_location; 563 GURL upload_location;
564 scoped_ptr<FileResource> entry; 564 scoped_ptr<FileResource> entry;
565 565
566 MockDriveServiceNoConnectionAtInitiate mock_service; 566 MockDriveServiceNoConnectionAtInitiate mock_service;
567 DriveUploader uploader(&mock_service, 567 DriveUploader uploader(&mock_service,
568 base::MessageLoopProxy::current().get()); 568 base::MessageLoopProxy::current().get());
569 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 569 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
570 local_path, 570 local_path,
571 kTestMimeType, 571 kTestMimeType,
572 DriveUploader::UploadExistingFileOptions(), 572 DriveUploader::UploadExistingFileOptions(),
573 test_util::CreateCopyResultCallback( 573 test_util::CreateCopyResultCallback(
574 &error, &upload_location, &entry), 574 &error, &upload_location, &entry),
575 google_apis::ProgressCallback()); 575 google_apis::ProgressCallback());
576 base::RunLoop().RunUntilIdle(); 576 base::RunLoop().RunUntilIdle();
577 577
578 EXPECT_EQ(GDATA_NO_CONNECTION, error); 578 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
579 EXPECT_TRUE(upload_location.is_empty()); 579 EXPECT_TRUE(upload_location.is_empty());
580 EXPECT_FALSE(entry); 580 EXPECT_FALSE(entry);
581 } 581 }
582 582
583 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { 583 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) {
584 base::FilePath local_path; 584 base::FilePath local_path;
585 std::string data; 585 std::string data;
586 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 586 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
587 temp_dir_.path(), 512 * 1024, &local_path, &data)); 587 temp_dir_.path(), 512 * 1024, &local_path, &data));
588 588
589 GDataErrorCode error = GDATA_OTHER_ERROR; 589 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
590 GURL upload_location; 590 GURL upload_location;
591 scoped_ptr<FileResource> entry; 591 scoped_ptr<FileResource> entry;
592 592
593 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 593 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
594 DriveUploader uploader(&mock_service, 594 DriveUploader uploader(&mock_service,
595 base::MessageLoopProxy::current().get()); 595 base::MessageLoopProxy::current().get());
596 DriveUploader::UploadExistingFileOptions options; 596 DriveUploader::UploadExistingFileOptions options;
597 options.etag = kTestETag; 597 options.etag = kTestETag;
598 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 598 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
599 local_path, 599 local_path,
600 kTestMimeType, 600 kTestMimeType,
601 options, 601 options,
602 test_util::CreateCopyResultCallback( 602 test_util::CreateCopyResultCallback(
603 &error, &upload_location, &entry), 603 &error, &upload_location, &entry),
604 google_apis::ProgressCallback()); 604 google_apis::ProgressCallback());
605 base::RunLoop().RunUntilIdle(); 605 base::RunLoop().RunUntilIdle();
606 606
607 EXPECT_EQ(HTTP_SUCCESS, error); 607 EXPECT_EQ(HTTP_SUCCESS, error);
608 EXPECT_TRUE(upload_location.is_empty()); 608 EXPECT_TRUE(upload_location.is_empty());
609 } 609 }
610 610
611 TEST_F(DriveUploaderTest, MultipartUploadConflict) { 611 TEST_F(DriveUploaderTest, MultipartUploadConflict) {
612 base::FilePath local_path; 612 base::FilePath local_path;
613 std::string data; 613 std::string data;
614 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 614 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
615 temp_dir_.path(), 512 * 1024, &local_path, &data)); 615 temp_dir_.path(), 512 * 1024, &local_path, &data));
616 const std::string kDestinationETag("destination_etag"); 616 const std::string kDestinationETag("destination_etag");
617 617
618 GDataErrorCode error = GDATA_OTHER_ERROR; 618 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
619 GURL upload_location; 619 GURL upload_location;
620 scoped_ptr<FileResource> entry; 620 scoped_ptr<FileResource> entry;
621 621
622 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 622 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
623 DriveUploader uploader(&mock_service, 623 DriveUploader uploader(&mock_service,
624 base::MessageLoopProxy::current().get()); 624 base::MessageLoopProxy::current().get());
625 DriveUploader::UploadExistingFileOptions options; 625 DriveUploader::UploadExistingFileOptions options;
626 options.etag = kDestinationETag; 626 options.etag = kDestinationETag;
627 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 627 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
628 local_path, 628 local_path,
629 kTestMimeType, 629 kTestMimeType,
630 options, 630 options,
631 test_util::CreateCopyResultCallback( 631 test_util::CreateCopyResultCallback(
632 &error, &upload_location, &entry), 632 &error, &upload_location, &entry),
633 google_apis::ProgressCallback()); 633 google_apis::ProgressCallback());
634 base::RunLoop().RunUntilIdle(); 634 base::RunLoop().RunUntilIdle();
635 635
636 EXPECT_EQ(HTTP_CONFLICT, error); 636 EXPECT_EQ(HTTP_CONFLICT, error);
637 EXPECT_TRUE(upload_location.is_empty()); 637 EXPECT_TRUE(upload_location.is_empty());
638 } 638 }
639 639
640 TEST_F(DriveUploaderTest, InitiateUploadConflict) { 640 TEST_F(DriveUploaderTest, InitiateUploadConflict) {
641 base::FilePath local_path; 641 base::FilePath local_path;
642 std::string data; 642 std::string data;
643 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 643 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
644 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 644 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
645 const std::string kDestinationETag("destination_etag"); 645 const std::string kDestinationETag("destination_etag");
646 646
647 GDataErrorCode error = GDATA_OTHER_ERROR; 647 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
648 GURL upload_location; 648 GURL upload_location;
649 scoped_ptr<FileResource> entry; 649 scoped_ptr<FileResource> entry;
650 650
651 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 651 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
652 DriveUploader uploader(&mock_service, 652 DriveUploader uploader(&mock_service,
653 base::MessageLoopProxy::current().get()); 653 base::MessageLoopProxy::current().get());
654 DriveUploader::UploadExistingFileOptions options; 654 DriveUploader::UploadExistingFileOptions options;
655 options.etag = kDestinationETag; 655 options.etag = kDestinationETag;
656 uploader.UploadExistingFile( 656 uploader.UploadExistingFile(
657 kTestInitiateUploadResourceId, local_path, kTestMimeType, options, 657 kTestInitiateUploadResourceId, local_path, kTestMimeType, options,
658 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 658 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
659 google_apis::ProgressCallback()); 659 google_apis::ProgressCallback());
660 base::RunLoop().RunUntilIdle(); 660 base::RunLoop().RunUntilIdle();
661 661
662 EXPECT_EQ(HTTP_CONFLICT, error); 662 EXPECT_EQ(HTTP_CONFLICT, error);
663 EXPECT_TRUE(upload_location.is_empty()); 663 EXPECT_TRUE(upload_location.is_empty());
664 } 664 }
665 665
666 TEST_F(DriveUploaderTest, ResumeUploadFail) { 666 TEST_F(DriveUploaderTest, ResumeUploadFail) {
667 base::FilePath local_path; 667 base::FilePath local_path;
668 std::string data; 668 std::string data;
669 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 669 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
670 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 670 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
671 671
672 GDataErrorCode error = HTTP_SUCCESS; 672 DriveApiErrorCode error = HTTP_SUCCESS;
673 GURL upload_location; 673 GURL upload_location;
674 scoped_ptr<FileResource> entry; 674 scoped_ptr<FileResource> entry;
675 675
676 MockDriveServiceNoConnectionAtResume mock_service; 676 MockDriveServiceNoConnectionAtResume mock_service;
677 DriveUploader uploader(&mock_service, 677 DriveUploader uploader(&mock_service,
678 base::MessageLoopProxy::current().get()); 678 base::MessageLoopProxy::current().get());
679 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 679 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
680 local_path, 680 local_path,
681 kTestMimeType, 681 kTestMimeType,
682 DriveUploader::UploadExistingFileOptions(), 682 DriveUploader::UploadExistingFileOptions(),
683 test_util::CreateCopyResultCallback( 683 test_util::CreateCopyResultCallback(
684 &error, &upload_location, &entry), 684 &error, &upload_location, &entry),
685 google_apis::ProgressCallback()); 685 google_apis::ProgressCallback());
686 base::RunLoop().RunUntilIdle(); 686 base::RunLoop().RunUntilIdle();
687 687
688 EXPECT_EQ(GDATA_NO_CONNECTION, error); 688 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
689 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); 689 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location);
690 } 690 }
691 691
692 TEST_F(DriveUploaderTest, GetUploadStatusFail) { 692 TEST_F(DriveUploaderTest, GetUploadStatusFail) {
693 base::FilePath local_path; 693 base::FilePath local_path;
694 std::string data; 694 std::string data;
695 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 695 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
696 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 696 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
697 697
698 GDataErrorCode error = HTTP_SUCCESS; 698 DriveApiErrorCode error = HTTP_SUCCESS;
699 GURL upload_location; 699 GURL upload_location;
700 scoped_ptr<FileResource> entry; 700 scoped_ptr<FileResource> entry;
701 701
702 MockDriveServiceNoConnectionAtGetUploadStatus mock_service; 702 MockDriveServiceNoConnectionAtGetUploadStatus mock_service;
703 DriveUploader uploader(&mock_service, 703 DriveUploader uploader(&mock_service,
704 base::MessageLoopProxy::current().get()); 704 base::MessageLoopProxy::current().get());
705 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL), 705 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL),
706 local_path, 706 local_path,
707 kTestMimeType, 707 kTestMimeType,
708 test_util::CreateCopyResultCallback( 708 test_util::CreateCopyResultCallback(
709 &error, &upload_location, &entry), 709 &error, &upload_location, &entry),
710 google_apis::ProgressCallback()); 710 google_apis::ProgressCallback());
711 base::RunLoop().RunUntilIdle(); 711 base::RunLoop().RunUntilIdle();
712 712
713 EXPECT_EQ(GDATA_NO_CONNECTION, error); 713 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
714 EXPECT_TRUE(upload_location.is_empty()); 714 EXPECT_TRUE(upload_location.is_empty());
715 } 715 }
716 716
717 TEST_F(DriveUploaderTest, NonExistingSourceFile) { 717 TEST_F(DriveUploaderTest, NonExistingSourceFile) {
718 GDataErrorCode error = GDATA_OTHER_ERROR; 718 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
719 GURL upload_location; 719 GURL upload_location;
720 scoped_ptr<FileResource> entry; 720 scoped_ptr<FileResource> entry;
721 721
722 DriveUploader uploader(NULL, // NULL, the service won't be used. 722 DriveUploader uploader(NULL, // NULL, the service won't be used.
723 base::MessageLoopProxy::current().get()); 723 base::MessageLoopProxy::current().get());
724 uploader.UploadExistingFile( 724 uploader.UploadExistingFile(
725 kTestInitiateUploadResourceId, 725 kTestInitiateUploadResourceId,
726 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), 726 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"),
727 kTestMimeType, 727 kTestMimeType,
728 DriveUploader::UploadExistingFileOptions(), 728 DriveUploader::UploadExistingFileOptions(),
729 test_util::CreateCopyResultCallback( 729 test_util::CreateCopyResultCallback(
730 &error, &upload_location, &entry), 730 &error, &upload_location, &entry),
731 google_apis::ProgressCallback()); 731 google_apis::ProgressCallback());
732 base::RunLoop().RunUntilIdle(); 732 base::RunLoop().RunUntilIdle();
733 733
734 // Should return failure without doing any attempt to connect to the server. 734 // Should return failure without doing any attempt to connect to the server.
735 EXPECT_EQ(HTTP_NOT_FOUND, error); 735 EXPECT_EQ(HTTP_NOT_FOUND, error);
736 EXPECT_TRUE(upload_location.is_empty()); 736 EXPECT_TRUE(upload_location.is_empty());
737 } 737 }
738 738
739 TEST_F(DriveUploaderTest, ResumeUpload) { 739 TEST_F(DriveUploaderTest, ResumeUpload) {
740 base::FilePath local_path; 740 base::FilePath local_path;
741 std::string data; 741 std::string data;
742 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 742 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
743 temp_dir_.path(), 1024 * 1024, &local_path, &data)); 743 temp_dir_.path(), 1024 * 1024, &local_path, &data));
744 744
745 GDataErrorCode error = GDATA_OTHER_ERROR; 745 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
746 GURL upload_location; 746 GURL upload_location;
747 scoped_ptr<FileResource> entry; 747 scoped_ptr<FileResource> entry;
748 748
749 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 749 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
750 DriveUploader uploader(&mock_service, 750 DriveUploader uploader(&mock_service,
751 base::MessageLoopProxy::current().get()); 751 base::MessageLoopProxy::current().get());
752 // Emulate the situation that the only first part is successfully uploaded, 752 // Emulate the situation that the only first part is successfully uploaded,
753 // but not the latter half. 753 // but not the latter half.
754 mock_service.set_received_bytes(512 * 1024); 754 mock_service.set_received_bytes(512 * 1024);
755 755
(...skipping 13 matching lines...) Expand all
769 EXPECT_EQ(HTTP_SUCCESS, error); 769 EXPECT_EQ(HTTP_SUCCESS, error);
770 EXPECT_TRUE(upload_location.is_empty()); 770 EXPECT_TRUE(upload_location.is_empty());
771 ASSERT_TRUE(entry); 771 ASSERT_TRUE(entry);
772 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); 772 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum());
773 ASSERT_EQ(1U, upload_progress_values.size()); 773 ASSERT_EQ(1U, upload_progress_values.size());
774 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 774 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
775 upload_progress_values[0]); 775 upload_progress_values[0]);
776 } 776 }
777 777
778 } // namespace drive 778 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698