| OLD | NEW |
| 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 "components/drive/drive_uploader.h" | 5 #include "components/drive/drive_uploader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 protected: | 422 protected: |
| 423 base::MessageLoop message_loop_; | 423 base::MessageLoop message_loop_; |
| 424 base::ScopedTempDir temp_dir_; | 424 base::ScopedTempDir temp_dir_; |
| 425 }; | 425 }; |
| 426 | 426 |
| 427 } // namespace | 427 } // namespace |
| 428 | 428 |
| 429 TEST_F(DriveUploaderTest, UploadExisting0KB) { | 429 TEST_F(DriveUploaderTest, UploadExisting0KB) { |
| 430 base::FilePath local_path; | 430 base::FilePath local_path; |
| 431 std::string data; | 431 std::string data; |
| 432 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 432 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.GetPath(), 0, |
| 433 temp_dir_.path(), 0, &local_path, &data)); | 433 &local_path, &data)); |
| 434 | 434 |
| 435 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 435 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 436 GURL upload_location; | 436 GURL upload_location; |
| 437 std::unique_ptr<FileResource> entry; | 437 std::unique_ptr<FileResource> entry; |
| 438 | 438 |
| 439 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 439 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 440 DriveUploader uploader(&mock_service, | 440 DriveUploader uploader(&mock_service, |
| 441 base::ThreadTaskRunnerHandle::Get().get()); | 441 base::ThreadTaskRunnerHandle::Get().get()); |
| 442 std::vector<test_util::ProgressInfo> upload_progress_values; | 442 std::vector<test_util::ProgressInfo> upload_progress_values; |
| 443 uploader.UploadExistingFile( | 443 uploader.UploadExistingFile( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 456 ASSERT_TRUE(entry); | 456 ASSERT_TRUE(entry); |
| 457 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); | 457 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); |
| 458 ASSERT_EQ(1U, upload_progress_values.size()); | 458 ASSERT_EQ(1U, upload_progress_values.size()); |
| 459 EXPECT_EQ(test_util::ProgressInfo(0, 0), upload_progress_values[0]); | 459 EXPECT_EQ(test_util::ProgressInfo(0, 0), upload_progress_values[0]); |
| 460 } | 460 } |
| 461 | 461 |
| 462 TEST_F(DriveUploaderTest, UploadExisting512KB) { | 462 TEST_F(DriveUploaderTest, UploadExisting512KB) { |
| 463 base::FilePath local_path; | 463 base::FilePath local_path; |
| 464 std::string data; | 464 std::string data; |
| 465 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 465 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 466 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 466 temp_dir_.GetPath(), 512 * 1024, &local_path, &data)); |
| 467 | 467 |
| 468 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 468 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 469 GURL upload_location; | 469 GURL upload_location; |
| 470 std::unique_ptr<FileResource> entry; | 470 std::unique_ptr<FileResource> entry; |
| 471 | 471 |
| 472 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 472 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 473 DriveUploader uploader(&mock_service, | 473 DriveUploader uploader(&mock_service, |
| 474 base::ThreadTaskRunnerHandle::Get().get()); | 474 base::ThreadTaskRunnerHandle::Get().get()); |
| 475 std::vector<test_util::ProgressInfo> upload_progress_values; | 475 std::vector<test_util::ProgressInfo> upload_progress_values; |
| 476 uploader.UploadExistingFile( | 476 uploader.UploadExistingFile( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 491 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); | 491 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); |
| 492 ASSERT_EQ(1U, upload_progress_values.size()); | 492 ASSERT_EQ(1U, upload_progress_values.size()); |
| 493 EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 512 * 1024), | 493 EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 512 * 1024), |
| 494 upload_progress_values[0]); | 494 upload_progress_values[0]); |
| 495 } | 495 } |
| 496 | 496 |
| 497 TEST_F(DriveUploaderTest, UploadExisting2MB) { | 497 TEST_F(DriveUploaderTest, UploadExisting2MB) { |
| 498 base::FilePath local_path; | 498 base::FilePath local_path; |
| 499 std::string data; | 499 std::string data; |
| 500 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 500 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 501 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); | 501 temp_dir_.GetPath(), 2 * 1024 * 1024, &local_path, &data)); |
| 502 | 502 |
| 503 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 503 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 504 GURL upload_location; | 504 GURL upload_location; |
| 505 std::unique_ptr<FileResource> entry; | 505 std::unique_ptr<FileResource> entry; |
| 506 | 506 |
| 507 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 507 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 508 DriveUploader uploader(&mock_service, | 508 DriveUploader uploader(&mock_service, |
| 509 base::ThreadTaskRunnerHandle::Get().get()); | 509 base::ThreadTaskRunnerHandle::Get().get()); |
| 510 std::vector<test_util::ProgressInfo> upload_progress_values; | 510 std::vector<test_util::ProgressInfo> upload_progress_values; |
| 511 uploader.UploadExistingFile( | 511 uploader.UploadExistingFile( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 526 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); | 526 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); |
| 527 ASSERT_EQ(1U, upload_progress_values.size()); | 527 ASSERT_EQ(1U, upload_progress_values.size()); |
| 528 EXPECT_EQ(test_util::ProgressInfo(2 * 1024 * 1024, 2 * 1024 * 1024), | 528 EXPECT_EQ(test_util::ProgressInfo(2 * 1024 * 1024, 2 * 1024 * 1024), |
| 529 upload_progress_values[0]); | 529 upload_progress_values[0]); |
| 530 } | 530 } |
| 531 | 531 |
| 532 TEST_F(DriveUploaderTest, InitiateUploadFail) { | 532 TEST_F(DriveUploaderTest, InitiateUploadFail) { |
| 533 base::FilePath local_path; | 533 base::FilePath local_path; |
| 534 std::string data; | 534 std::string data; |
| 535 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 535 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 536 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); | 536 temp_dir_.GetPath(), 2 * 1024 * 1024, &local_path, &data)); |
| 537 | 537 |
| 538 DriveApiErrorCode error = HTTP_SUCCESS; | 538 DriveApiErrorCode error = HTTP_SUCCESS; |
| 539 GURL upload_location; | 539 GURL upload_location; |
| 540 std::unique_ptr<FileResource> entry; | 540 std::unique_ptr<FileResource> entry; |
| 541 | 541 |
| 542 MockDriveServiceNoConnectionAtInitiate mock_service; | 542 MockDriveServiceNoConnectionAtInitiate mock_service; |
| 543 DriveUploader uploader(&mock_service, | 543 DriveUploader uploader(&mock_service, |
| 544 base::ThreadTaskRunnerHandle::Get().get()); | 544 base::ThreadTaskRunnerHandle::Get().get()); |
| 545 uploader.UploadExistingFile( | 545 uploader.UploadExistingFile( |
| 546 kTestInitiateUploadResourceId, local_path, kTestMimeType, | 546 kTestInitiateUploadResourceId, local_path, kTestMimeType, |
| 547 UploadExistingFileOptions(), | 547 UploadExistingFileOptions(), |
| 548 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), | 548 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), |
| 549 google_apis::ProgressCallback()); | 549 google_apis::ProgressCallback()); |
| 550 base::RunLoop().RunUntilIdle(); | 550 base::RunLoop().RunUntilIdle(); |
| 551 | 551 |
| 552 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 552 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 553 EXPECT_TRUE(upload_location.is_empty()); | 553 EXPECT_TRUE(upload_location.is_empty()); |
| 554 EXPECT_FALSE(entry); | 554 EXPECT_FALSE(entry); |
| 555 } | 555 } |
| 556 | 556 |
| 557 TEST_F(DriveUploaderTest, MultipartUploadFail) { | 557 TEST_F(DriveUploaderTest, MultipartUploadFail) { |
| 558 base::FilePath local_path; | 558 base::FilePath local_path; |
| 559 std::string data; | 559 std::string data; |
| 560 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024, | 560 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 561 &local_path, &data)); | 561 temp_dir_.GetPath(), 512 * 1024, &local_path, &data)); |
| 562 | 562 |
| 563 DriveApiErrorCode error = HTTP_SUCCESS; | 563 DriveApiErrorCode error = HTTP_SUCCESS; |
| 564 GURL upload_location; | 564 GURL upload_location; |
| 565 std::unique_ptr<FileResource> entry; | 565 std::unique_ptr<FileResource> entry; |
| 566 | 566 |
| 567 MockDriveServiceNoConnectionAtInitiate mock_service; | 567 MockDriveServiceNoConnectionAtInitiate mock_service; |
| 568 DriveUploader uploader(&mock_service, | 568 DriveUploader uploader(&mock_service, |
| 569 base::ThreadTaskRunnerHandle::Get().get()); | 569 base::ThreadTaskRunnerHandle::Get().get()); |
| 570 uploader.UploadExistingFile( | 570 uploader.UploadExistingFile( |
| 571 kTestInitiateUploadResourceId, local_path, kTestMimeType, | 571 kTestInitiateUploadResourceId, local_path, kTestMimeType, |
| 572 UploadExistingFileOptions(), | 572 UploadExistingFileOptions(), |
| 573 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), | 573 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), |
| 574 google_apis::ProgressCallback()); | 574 google_apis::ProgressCallback()); |
| 575 base::RunLoop().RunUntilIdle(); | 575 base::RunLoop().RunUntilIdle(); |
| 576 | 576 |
| 577 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 577 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 578 EXPECT_TRUE(upload_location.is_empty()); | 578 EXPECT_TRUE(upload_location.is_empty()); |
| 579 EXPECT_FALSE(entry); | 579 EXPECT_FALSE(entry); |
| 580 } | 580 } |
| 581 | 581 |
| 582 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { | 582 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { |
| 583 base::FilePath local_path; | 583 base::FilePath local_path; |
| 584 std::string data; | 584 std::string data; |
| 585 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 585 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 586 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 586 temp_dir_.GetPath(), 512 * 1024, &local_path, &data)); |
| 587 | 587 |
| 588 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 588 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 589 GURL upload_location; | 589 GURL upload_location; |
| 590 std::unique_ptr<FileResource> entry; | 590 std::unique_ptr<FileResource> entry; |
| 591 | 591 |
| 592 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 592 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 593 DriveUploader uploader(&mock_service, | 593 DriveUploader uploader(&mock_service, |
| 594 base::ThreadTaskRunnerHandle::Get().get()); | 594 base::ThreadTaskRunnerHandle::Get().get()); |
| 595 UploadExistingFileOptions options; | 595 UploadExistingFileOptions options; |
| 596 options.etag = kTestETag; | 596 options.etag = kTestETag; |
| 597 uploader.UploadExistingFile(kTestInitiateUploadResourceId, | 597 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
| 598 local_path, | 598 local_path, |
| 599 kTestMimeType, | 599 kTestMimeType, |
| 600 options, | 600 options, |
| 601 test_util::CreateCopyResultCallback( | 601 test_util::CreateCopyResultCallback( |
| 602 &error, &upload_location, &entry), | 602 &error, &upload_location, &entry), |
| 603 google_apis::ProgressCallback()); | 603 google_apis::ProgressCallback()); |
| 604 base::RunLoop().RunUntilIdle(); | 604 base::RunLoop().RunUntilIdle(); |
| 605 | 605 |
| 606 EXPECT_EQ(HTTP_SUCCESS, error); | 606 EXPECT_EQ(HTTP_SUCCESS, error); |
| 607 EXPECT_TRUE(upload_location.is_empty()); | 607 EXPECT_TRUE(upload_location.is_empty()); |
| 608 } | 608 } |
| 609 | 609 |
| 610 TEST_F(DriveUploaderTest, MultipartUploadConflict) { | 610 TEST_F(DriveUploaderTest, MultipartUploadConflict) { |
| 611 base::FilePath local_path; | 611 base::FilePath local_path; |
| 612 std::string data; | 612 std::string data; |
| 613 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 613 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 614 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 614 temp_dir_.GetPath(), 512 * 1024, &local_path, &data)); |
| 615 const std::string kDestinationETag("destination_etag"); | 615 const std::string kDestinationETag("destination_etag"); |
| 616 | 616 |
| 617 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 617 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 618 GURL upload_location; | 618 GURL upload_location; |
| 619 std::unique_ptr<FileResource> entry; | 619 std::unique_ptr<FileResource> entry; |
| 620 | 620 |
| 621 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 621 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 622 DriveUploader uploader(&mock_service, | 622 DriveUploader uploader(&mock_service, |
| 623 base::ThreadTaskRunnerHandle::Get().get()); | 623 base::ThreadTaskRunnerHandle::Get().get()); |
| 624 UploadExistingFileOptions options; | 624 UploadExistingFileOptions options; |
| 625 options.etag = kDestinationETag; | 625 options.etag = kDestinationETag; |
| 626 uploader.UploadExistingFile(kTestInitiateUploadResourceId, | 626 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
| 627 local_path, | 627 local_path, |
| 628 kTestMimeType, | 628 kTestMimeType, |
| 629 options, | 629 options, |
| 630 test_util::CreateCopyResultCallback( | 630 test_util::CreateCopyResultCallback( |
| 631 &error, &upload_location, &entry), | 631 &error, &upload_location, &entry), |
| 632 google_apis::ProgressCallback()); | 632 google_apis::ProgressCallback()); |
| 633 base::RunLoop().RunUntilIdle(); | 633 base::RunLoop().RunUntilIdle(); |
| 634 | 634 |
| 635 EXPECT_EQ(HTTP_CONFLICT, error); | 635 EXPECT_EQ(HTTP_CONFLICT, error); |
| 636 EXPECT_TRUE(upload_location.is_empty()); | 636 EXPECT_TRUE(upload_location.is_empty()); |
| 637 } | 637 } |
| 638 | 638 |
| 639 TEST_F(DriveUploaderTest, InitiateUploadConflict) { | 639 TEST_F(DriveUploaderTest, InitiateUploadConflict) { |
| 640 base::FilePath local_path; | 640 base::FilePath local_path; |
| 641 std::string data; | 641 std::string data; |
| 642 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 642 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 643 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); | 643 temp_dir_.GetPath(), 2 * 1024 * 1024, &local_path, &data)); |
| 644 const std::string kDestinationETag("destination_etag"); | 644 const std::string kDestinationETag("destination_etag"); |
| 645 | 645 |
| 646 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 646 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 647 GURL upload_location; | 647 GURL upload_location; |
| 648 std::unique_ptr<FileResource> entry; | 648 std::unique_ptr<FileResource> entry; |
| 649 | 649 |
| 650 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 650 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 651 DriveUploader uploader(&mock_service, | 651 DriveUploader uploader(&mock_service, |
| 652 base::ThreadTaskRunnerHandle::Get().get()); | 652 base::ThreadTaskRunnerHandle::Get().get()); |
| 653 UploadExistingFileOptions options; | 653 UploadExistingFileOptions options; |
| 654 options.etag = kDestinationETag; | 654 options.etag = kDestinationETag; |
| 655 uploader.UploadExistingFile( | 655 uploader.UploadExistingFile( |
| 656 kTestInitiateUploadResourceId, local_path, kTestMimeType, options, | 656 kTestInitiateUploadResourceId, local_path, kTestMimeType, options, |
| 657 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), | 657 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), |
| 658 google_apis::ProgressCallback()); | 658 google_apis::ProgressCallback()); |
| 659 base::RunLoop().RunUntilIdle(); | 659 base::RunLoop().RunUntilIdle(); |
| 660 | 660 |
| 661 EXPECT_EQ(HTTP_CONFLICT, error); | 661 EXPECT_EQ(HTTP_CONFLICT, error); |
| 662 EXPECT_TRUE(upload_location.is_empty()); | 662 EXPECT_TRUE(upload_location.is_empty()); |
| 663 } | 663 } |
| 664 | 664 |
| 665 TEST_F(DriveUploaderTest, ResumeUploadFail) { | 665 TEST_F(DriveUploaderTest, ResumeUploadFail) { |
| 666 base::FilePath local_path; | 666 base::FilePath local_path; |
| 667 std::string data; | 667 std::string data; |
| 668 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 668 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 669 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); | 669 temp_dir_.GetPath(), 2 * 1024 * 1024, &local_path, &data)); |
| 670 | 670 |
| 671 DriveApiErrorCode error = HTTP_SUCCESS; | 671 DriveApiErrorCode error = HTTP_SUCCESS; |
| 672 GURL upload_location; | 672 GURL upload_location; |
| 673 std::unique_ptr<FileResource> entry; | 673 std::unique_ptr<FileResource> entry; |
| 674 | 674 |
| 675 MockDriveServiceNoConnectionAtResume mock_service; | 675 MockDriveServiceNoConnectionAtResume mock_service; |
| 676 DriveUploader uploader(&mock_service, | 676 DriveUploader uploader(&mock_service, |
| 677 base::ThreadTaskRunnerHandle::Get().get()); | 677 base::ThreadTaskRunnerHandle::Get().get()); |
| 678 uploader.UploadExistingFile( | 678 uploader.UploadExistingFile( |
| 679 kTestInitiateUploadResourceId, local_path, kTestMimeType, | 679 kTestInitiateUploadResourceId, local_path, kTestMimeType, |
| 680 UploadExistingFileOptions(), | 680 UploadExistingFileOptions(), |
| 681 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), | 681 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), |
| 682 google_apis::ProgressCallback()); | 682 google_apis::ProgressCallback()); |
| 683 base::RunLoop().RunUntilIdle(); | 683 base::RunLoop().RunUntilIdle(); |
| 684 | 684 |
| 685 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 685 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 686 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); | 686 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); |
| 687 } | 687 } |
| 688 | 688 |
| 689 TEST_F(DriveUploaderTest, GetUploadStatusFail) { | 689 TEST_F(DriveUploaderTest, GetUploadStatusFail) { |
| 690 base::FilePath local_path; | 690 base::FilePath local_path; |
| 691 std::string data; | 691 std::string data; |
| 692 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 692 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 693 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); | 693 temp_dir_.GetPath(), 2 * 1024 * 1024, &local_path, &data)); |
| 694 | 694 |
| 695 DriveApiErrorCode error = HTTP_SUCCESS; | 695 DriveApiErrorCode error = HTTP_SUCCESS; |
| 696 GURL upload_location; | 696 GURL upload_location; |
| 697 std::unique_ptr<FileResource> entry; | 697 std::unique_ptr<FileResource> entry; |
| 698 | 698 |
| 699 MockDriveServiceNoConnectionAtGetUploadStatus mock_service; | 699 MockDriveServiceNoConnectionAtGetUploadStatus mock_service; |
| 700 DriveUploader uploader(&mock_service, | 700 DriveUploader uploader(&mock_service, |
| 701 base::ThreadTaskRunnerHandle::Get().get()); | 701 base::ThreadTaskRunnerHandle::Get().get()); |
| 702 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL), | 702 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL), |
| 703 local_path, | 703 local_path, |
| 704 kTestMimeType, | 704 kTestMimeType, |
| 705 test_util::CreateCopyResultCallback( | 705 test_util::CreateCopyResultCallback( |
| 706 &error, &upload_location, &entry), | 706 &error, &upload_location, &entry), |
| 707 google_apis::ProgressCallback()); | 707 google_apis::ProgressCallback()); |
| 708 base::RunLoop().RunUntilIdle(); | 708 base::RunLoop().RunUntilIdle(); |
| 709 | 709 |
| 710 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 710 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 711 EXPECT_TRUE(upload_location.is_empty()); | 711 EXPECT_TRUE(upload_location.is_empty()); |
| 712 } | 712 } |
| 713 | 713 |
| 714 TEST_F(DriveUploaderTest, NonExistingSourceFile) { | 714 TEST_F(DriveUploaderTest, NonExistingSourceFile) { |
| 715 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 715 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 716 GURL upload_location; | 716 GURL upload_location; |
| 717 std::unique_ptr<FileResource> entry; | 717 std::unique_ptr<FileResource> entry; |
| 718 | 718 |
| 719 DriveUploader uploader(NULL, // NULL, the service won't be used. | 719 DriveUploader uploader(NULL, // NULL, the service won't be used. |
| 720 base::ThreadTaskRunnerHandle::Get().get()); | 720 base::ThreadTaskRunnerHandle::Get().get()); |
| 721 uploader.UploadExistingFile( | 721 uploader.UploadExistingFile( |
| 722 kTestInitiateUploadResourceId, | 722 kTestInitiateUploadResourceId, |
| 723 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), | 723 temp_dir_.GetPath().AppendASCII("_this_path_should_not_exist_"), |
| 724 kTestMimeType, UploadExistingFileOptions(), | 724 kTestMimeType, UploadExistingFileOptions(), |
| 725 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), | 725 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), |
| 726 google_apis::ProgressCallback()); | 726 google_apis::ProgressCallback()); |
| 727 base::RunLoop().RunUntilIdle(); | 727 base::RunLoop().RunUntilIdle(); |
| 728 | 728 |
| 729 // Should return failure without doing any attempt to connect to the server. | 729 // Should return failure without doing any attempt to connect to the server. |
| 730 EXPECT_EQ(HTTP_NOT_FOUND, error); | 730 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 731 EXPECT_TRUE(upload_location.is_empty()); | 731 EXPECT_TRUE(upload_location.is_empty()); |
| 732 } | 732 } |
| 733 | 733 |
| 734 TEST_F(DriveUploaderTest, ResumeUpload) { | 734 TEST_F(DriveUploaderTest, ResumeUpload) { |
| 735 base::FilePath local_path; | 735 base::FilePath local_path; |
| 736 std::string data; | 736 std::string data; |
| 737 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 737 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 738 temp_dir_.path(), 1024 * 1024, &local_path, &data)); | 738 temp_dir_.GetPath(), 1024 * 1024, &local_path, &data)); |
| 739 | 739 |
| 740 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 740 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 741 GURL upload_location; | 741 GURL upload_location; |
| 742 std::unique_ptr<FileResource> entry; | 742 std::unique_ptr<FileResource> entry; |
| 743 | 743 |
| 744 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 744 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
| 745 DriveUploader uploader(&mock_service, | 745 DriveUploader uploader(&mock_service, |
| 746 base::ThreadTaskRunnerHandle::Get().get()); | 746 base::ThreadTaskRunnerHandle::Get().get()); |
| 747 // Emulate the situation that the only first part is successfully uploaded, | 747 // Emulate the situation that the only first part is successfully uploaded, |
| 748 // but not the latter half. | 748 // but not the latter half. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 std::vector<UploadFileInfo> files; | 856 std::vector<UploadFileInfo> files; |
| 857 bool committed; | 857 bool committed; |
| 858 }; | 858 }; |
| 859 | 859 |
| 860 TEST_F(DriveUploaderTest, BatchProcessing) { | 860 TEST_F(DriveUploaderTest, BatchProcessing) { |
| 861 // Preapre test file. | 861 // Preapre test file. |
| 862 const size_t kTestFileSize = 1024 * 512; | 862 const size_t kTestFileSize = 1024 * 512; |
| 863 base::FilePath local_path; | 863 base::FilePath local_path; |
| 864 std::string data; | 864 std::string data; |
| 865 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 865 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
| 866 temp_dir_.path(), kTestFileSize, &local_path, &data)); | 866 temp_dir_.GetPath(), kTestFileSize, &local_path, &data)); |
| 867 | 867 |
| 868 // Prepare test target. | 868 // Prepare test target. |
| 869 MockDriveServiceForBatchProcessing service; | 869 MockDriveServiceForBatchProcessing service; |
| 870 DriveUploader uploader(&service, base::ThreadTaskRunnerHandle::Get().get()); | 870 DriveUploader uploader(&service, base::ThreadTaskRunnerHandle::Get().get()); |
| 871 | 871 |
| 872 struct { | 872 struct { |
| 873 DriveApiErrorCode error; | 873 DriveApiErrorCode error; |
| 874 GURL resume_url; | 874 GURL resume_url; |
| 875 std::unique_ptr<FileResource> file; | 875 std::unique_ptr<FileResource> file; |
| 876 UploadCompletionCallback callback() { | 876 UploadCompletionCallback callback() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 951 |
| 952 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error); | 952 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error); |
| 953 EXPECT_TRUE(results[0].resume_url.is_empty()); | 953 EXPECT_TRUE(results[0].resume_url.is_empty()); |
| 954 EXPECT_FALSE(results[0].file); | 954 EXPECT_FALSE(results[0].file); |
| 955 | 955 |
| 956 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error); | 956 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error); |
| 957 EXPECT_TRUE(results[1].resume_url.is_empty()); | 957 EXPECT_TRUE(results[1].resume_url.is_empty()); |
| 958 EXPECT_FALSE(results[1].file); | 958 EXPECT_FALSE(results[1].file); |
| 959 } | 959 } |
| 960 } // namespace drive | 960 } // namespace drive |
| OLD | NEW |