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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc

Issue 11530004: google_apis: DriveServiceInterface::GetResourceEntry() returns ResourceEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years 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 | Annotate | Revision Log
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/sync_file_system/drive_file_sync_client.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "chrome/browser/google_apis/drive_uploader.h" 10 #include "chrome/browser/google_apis/drive_uploader.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 }; 160 };
161 161
162 // Invokes |arg0| as a GetDataCallback. 162 // Invokes |arg0| as a GetDataCallback.
163 ACTION_P2(InvokeGetDataCallback0, error, result) { 163 ACTION_P2(InvokeGetDataCallback0, error, result) {
164 scoped_ptr<base::Value> value(result.Pass()); 164 scoped_ptr<base::Value> value(result.Pass());
165 base::MessageLoopProxy::current()->PostTask( 165 base::MessageLoopProxy::current()->PostTask(
166 FROM_HERE, 166 FROM_HERE,
167 base::Bind(arg0, error, base::Passed(&value))); 167 base::Bind(arg0, error, base::Passed(&value)));
168 } 168 }
169 169
170 // Invokes |arg1| as a GetDataCallback. 170 // Invokes |arg1| as a GetResourceEntryCallback.
171 ACTION_P2(InvokeGetDataCallback1, error, result) { 171 ACTION_P2(InvokeGetResourceEntryCallback1, error, result) {
172 scoped_ptr<base::Value> value(result.Pass()); 172 scoped_ptr<google_apis::ResourceEntry> entry(result.Pass());
173 base::MessageLoopProxy::current()->PostTask( 173 base::MessageLoopProxy::current()->PostTask(
174 FROM_HERE, 174 FROM_HERE,
175 base::Bind(arg1, error, base::Passed(&value))); 175 base::Bind(arg1, error, base::Passed(&entry)));
176 } 176 }
177 177
178 // Invokes |arg2| as a GetDataCallback. 178 // Invokes |arg2| as a GetDataCallback.
179 ACTION_P2(InvokeGetDataCallback2, error, result) { 179 ACTION_P2(InvokeGetDataCallback2, error, result) {
180 scoped_ptr<base::Value> value(result.Pass()); 180 scoped_ptr<base::Value> value(result.Pass());
181 base::MessageLoopProxy::current()->PostTask( 181 base::MessageLoopProxy::current()->PostTask(
182 FROM_HERE, 182 FROM_HERE,
183 base::Bind(arg2, error, base::Passed(&value))); 183 base::Bind(arg2, error, base::Passed(&value)));
184 } 184 }
185 185
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) { 384 TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) {
385 const std::string kParentResourceId("folder:sync_root_resource_id"); 385 const std::string kParentResourceId("folder:sync_root_resource_id");
386 const GURL kOrigin("chrome-extension://example"); 386 const GURL kOrigin("chrome-extension://example");
387 387
388 scoped_ptr<base::Value> not_found_result_value( 388 scoped_ptr<base::Value> not_found_result_value(
389 google_apis::test_util::LoadJSONFile( 389 google_apis::test_util::LoadJSONFile(
390 "sync_file_system/origin_directory_not_found.json").Pass()); 390 "sync_file_system/origin_directory_not_found.json").Pass());
391 scoped_ptr<google_apis::ResourceList> not_found_result = 391 scoped_ptr<google_apis::ResourceList> not_found_result =
392 google_apis::ResourceList::ExtractAndParse(*not_found_result_value); 392 google_apis::ResourceList::ExtractAndParse(*not_found_result_value);
393 393
394 scoped_ptr<base::Value> got_parent_result( 394 scoped_ptr<base::Value> got_parent_result_value(
395 google_apis::test_util::LoadJSONFile( 395 google_apis::test_util::LoadJSONFile(
396 "sync_file_system/origin_directory_get_parent.json").Pass()); 396 "sync_file_system/origin_directory_get_parent.json").Pass());
397 scoped_ptr<google_apis::ResourceEntry> got_parent_result
398 = google_apis::ResourceEntry::ExtractAndParse(*got_parent_result_value);
397 scoped_ptr<base::Value> created_result(google_apis::test_util::LoadJSONFile( 399 scoped_ptr<base::Value> created_result(google_apis::test_util::LoadJSONFile(
398 "sync_file_system/origin_directory_created.json").Pass()); 400 "sync_file_system/origin_directory_created.json").Pass());
399 401
400 testing::InSequence sequence; 402 testing::InSequence sequence;
401 403
402 // Expected to call GetResourceList from GetDriveDirectoryForOrigin. 404 // Expected to call GetResourceList from GetDriveDirectoryForOrigin.
403 EXPECT_CALL(*mock_drive_service(), 405 EXPECT_CALL(*mock_drive_service(),
404 GetResourceList(GURL(), // feed_url 406 GetResourceList(GURL(), // feed_url
405 0, // start_changestamp 407 0, // start_changestamp
406 FormatOriginQuery(kOrigin), 408 FormatOriginQuery(kOrigin),
407 false, // shared_with_me 409 false, // shared_with_me
408 kParentResourceId, // directory_resource_id 410 kParentResourceId, // directory_resource_id
409 _)) 411 _))
410 .WillOnce(InvokeGetResourceListCallback5( 412 .WillOnce(InvokeGetResourceListCallback5(
411 google_apis::HTTP_SUCCESS, 413 google_apis::HTTP_SUCCESS,
412 base::Passed(&not_found_result))); 414 base::Passed(&not_found_result)));
413 415
414 // Expected to call GetResourceEntry from GetDriveDirectoryForOrigin. 416 // Expected to call GetResourceEntry from GetDriveDirectoryForOrigin.
415 EXPECT_CALL(*mock_drive_service(), 417 EXPECT_CALL(*mock_drive_service(),
416 GetResourceEntry(kParentResourceId, _)) 418 GetResourceEntry(kParentResourceId, _))
417 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 419 .WillOnce(InvokeGetResourceEntryCallback1(
418 base::Passed(&got_parent_result))); 420 google_apis::HTTP_SUCCESS,
421 base::Passed(&got_parent_result)));
419 422
420 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); 423 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
421 // Expected to call AddNewDirectory from GetDriveDirectoryForOrigin. 424 // Expected to call AddNewDirectory from GetDriveDirectoryForOrigin.
422 EXPECT_CALL(*mock_drive_service(), 425 EXPECT_CALL(*mock_drive_service(),
423 AddNewDirectory(GURL("https://sync_root_content_url"), 426 AddNewDirectory(GURL("https://sync_root_content_url"),
424 FilePath().AppendASCII(dir_title).value(), 427 FilePath().AppendASCII(dir_title).value(),
425 _)) 428 _))
426 .WillOnce(InvokeGetDataCallback2(google_apis::HTTP_CREATED, 429 .WillOnce(InvokeGetDataCallback2(google_apis::HTTP_CREATED,
427 base::Passed(&created_result))); 430 base::Passed(&created_result)));
428 431
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_FALSE(document_feed->entries().empty()); 605 EXPECT_FALSE(document_feed->entries().empty());
603 } 606 }
604 607
605 TEST_F(DriveFileSyncClientTest, DownloadFile) { 608 TEST_F(DriveFileSyncClientTest, DownloadFile) {
606 const std::string kResourceId = "file:resource_id"; 609 const std::string kResourceId = "file:resource_id";
607 const std::string kLocalFileMD5 = "123456"; 610 const std::string kLocalFileMD5 = "123456";
608 const FilePath kLocalFilePath(FPL("/tmp/dir/file")); 611 const FilePath kLocalFilePath(FPL("/tmp/dir/file"));
609 612
610 scoped_ptr<base::Value> file_entry_data( 613 scoped_ptr<base::Value> file_entry_data(
611 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 614 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
612 scoped_ptr<ResourceEntry> entry( 615 scoped_ptr<ResourceEntry> file_entry(
616 ResourceEntry::ExtractAndParse(*file_entry_data));
617 // We need another copy as |file_entry| will be passed to
618 // InvokeGetResourceEntryCallback1.
619 scoped_ptr<ResourceEntry> file_entry_copy(
613 ResourceEntry::ExtractAndParse(*file_entry_data)); 620 ResourceEntry::ExtractAndParse(*file_entry_data));
614 621
615 testing::InSequence sequence; 622 testing::InSequence sequence;
616 623
617 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile. 624 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile.
618 EXPECT_CALL(*mock_drive_service(), 625 EXPECT_CALL(*mock_drive_service(),
619 GetResourceEntry(kResourceId, _)) 626 GetResourceEntry(kResourceId, _))
620 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 627 .WillOnce(InvokeGetResourceEntryCallback1(
621 base::Passed(&file_entry_data))) 628 google_apis::HTTP_SUCCESS,
629 base::Passed(&file_entry)))
622 .RetiresOnSaturation(); 630 .RetiresOnSaturation();
623 631
624 // Expected to call DriveUploaderInterface::DownloadFile from 632 // Expected to call DriveUploaderInterface::DownloadFile from
625 // DidGetResourceEntryForDownloadFile. 633 // DidGetResourceEntryForDownloadFile.
626 EXPECT_CALL(*mock_drive_service(), 634 EXPECT_CALL(*mock_drive_service(),
627 DownloadFile(_, // drive_path 635 DownloadFile(_, // drive_path
628 kLocalFilePath, 636 kLocalFilePath,
629 entry->content_url(), 637 file_entry_copy->content_url(),
630 _, _)) 638 _, _))
631 .WillOnce(InvokeDownloadActionCallback3(google_apis::HTTP_SUCCESS, 639 .WillOnce(InvokeDownloadActionCallback3(google_apis::HTTP_SUCCESS,
632 kLocalFilePath)) 640 kLocalFilePath))
633 .RetiresOnSaturation(); 641 .RetiresOnSaturation();
634 642
635 bool done = false; 643 bool done = false;
636 std::string file_md5; 644 std::string file_md5;
637 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 645 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
638 sync_client()->DownloadFile(kResourceId, 646 sync_client()->DownloadFile(kResourceId,
639 kLocalFileMD5, 647 kLocalFileMD5,
640 kLocalFilePath, 648 kLocalFilePath,
641 base::Bind(&DidDownloadFile, 649 base::Bind(&DidDownloadFile,
642 &done, &file_md5, &error)); 650 &done, &file_md5, &error));
643 message_loop()->RunUntilIdle(); 651 message_loop()->RunUntilIdle();
644 652
645 EXPECT_TRUE(done); 653 EXPECT_TRUE(done);
646 EXPECT_EQ(entry->file_md5(), file_md5); 654 EXPECT_EQ(file_entry_copy->file_md5(), file_md5);
647 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); 655 EXPECT_EQ(google_apis::HTTP_SUCCESS, error);
648 } 656 }
649 657
650 TEST_F(DriveFileSyncClientTest, DownloadFileInNotModified) { 658 TEST_F(DriveFileSyncClientTest, DownloadFileInNotModified) {
651 const std::string kResourceId = "file:resource_id"; 659 const std::string kResourceId = "file:resource_id";
652 const FilePath kLocalFilePath(FPL("/tmp/dir/file")); 660 const FilePath kLocalFilePath(FPL("/tmp/dir/file"));
653 661
654 scoped_ptr<base::Value> file_entry_data( 662 scoped_ptr<base::Value> file_entry_data(
655 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 663 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
656 scoped_ptr<ResourceEntry> entry( 664 scoped_ptr<ResourceEntry> file_entry(
665 ResourceEntry::ExtractAndParse(*file_entry_data));
666 // We need another copy as |file_entry| will be passed to
667 // InvokeGetResourceEntryCallback1.
668 scoped_ptr<ResourceEntry> file_entry_copy(
657 ResourceEntry::ExtractAndParse(*file_entry_data)); 669 ResourceEntry::ExtractAndParse(*file_entry_data));
658 670
659 // Since local file's hash value is equal to remote file's one, it is expected 671 // Since local file's hash value is equal to remote file's one, it is expected
660 // to cancel download the file and to return NOT_MODIFIED status code. 672 // to cancel download the file and to return NOT_MODIFIED status code.
661 const std::string kLocalFileMD5 = entry->file_md5(); 673 const std::string kLocalFileMD5 = file_entry_copy->file_md5();
662 674
663 testing::InSequence sequence; 675 testing::InSequence sequence;
664 676
665 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile. 677 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile.
666 EXPECT_CALL(*mock_drive_service(), 678 EXPECT_CALL(*mock_drive_service(),
667 GetResourceEntry(kResourceId, _)) 679 GetResourceEntry(kResourceId, _))
668 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 680 .WillOnce(InvokeGetResourceEntryCallback1(
669 base::Passed(&file_entry_data))) 681 google_apis::HTTP_SUCCESS,
682 base::Passed(&file_entry)))
670 .RetiresOnSaturation(); 683 .RetiresOnSaturation();
671 684
672 bool done = false; 685 bool done = false;
673 std::string file_md5; 686 std::string file_md5;
674 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 687 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
675 sync_client()->DownloadFile(kResourceId, 688 sync_client()->DownloadFile(kResourceId,
676 kLocalFileMD5, 689 kLocalFileMD5,
677 kLocalFilePath, 690 kLocalFilePath,
678 base::Bind(&DidDownloadFile, 691 base::Bind(&DidDownloadFile,
679 &done, &file_md5, &error)); 692 &done, &file_md5, &error));
680 message_loop()->RunUntilIdle(); 693 message_loop()->RunUntilIdle();
681 694
682 EXPECT_TRUE(done); 695 EXPECT_TRUE(done);
683 EXPECT_EQ(entry->file_md5(), file_md5); 696 EXPECT_EQ(file_entry_copy->file_md5(), file_md5);
684 EXPECT_EQ(google_apis::HTTP_NOT_MODIFIED, error); 697 EXPECT_EQ(google_apis::HTTP_NOT_MODIFIED, error);
685 } 698 }
686 699
687 TEST_F(DriveFileSyncClientTest, UploadNewFile) { 700 TEST_F(DriveFileSyncClientTest, UploadNewFile) {
688 const std::string kDirectoryResourceId = "folder:directory_resource_id"; 701 const std::string kDirectoryResourceId = "folder:directory_resource_id";
689 const FilePath kLocalFilePath(FPL("/tmp/dir/file")); 702 const FilePath kLocalFilePath(FPL("/tmp/dir/file"));
690 const std::string kTitle("testfile"); 703 const std::string kTitle("testfile");
691 int64 kFileSize = 1024; 704 int64 kFileSize = 1024;
692 705
693 scoped_ptr<base::Value> dir_entry_data(google_apis::test_util::LoadJSONFile( 706 scoped_ptr<base::Value> dir_entry_data(google_apis::test_util::LoadJSONFile(
694 "gdata/directory_entry.json").Pass()); 707 "gdata/directory_entry.json").Pass());
695 scoped_ptr<ResourceEntry> dir_entry( 708 scoped_ptr<ResourceEntry> dir_entry(
696 ResourceEntry::ExtractAndParse(*dir_entry_data)); 709 ResourceEntry::ExtractAndParse(*dir_entry_data));
697 const GURL link_url = 710 const GURL link_url =
698 dir_entry->GetLinkByType(Link::LINK_RESUMABLE_CREATE_MEDIA)->href(); 711 dir_entry->GetLinkByType(Link::LINK_RESUMABLE_CREATE_MEDIA)->href();
699 712
700 testing::InSequence sequence; 713 testing::InSequence sequence;
701 714
702 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile. 715 // Expected to call GetResourceEntry from DriveFileSyncClient::UploadNewFile.
703 EXPECT_CALL(*mock_drive_service(), 716 EXPECT_CALL(*mock_drive_service(),
704 GetResourceEntry(kDirectoryResourceId, _)) 717 GetResourceEntry(kDirectoryResourceId, _))
705 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 718 .WillOnce(InvokeGetResourceEntryCallback1(
706 base::Passed(&dir_entry_data))) 719 google_apis::HTTP_SUCCESS,
720 base::Passed(&dir_entry)))
707 .RetiresOnSaturation(); 721 .RetiresOnSaturation();
708 722
709 bool done = false; 723 bool done = false;
710 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 724 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
711 std::string resource_id; 725 std::string resource_id;
712 sync_client()->UploadNewFile(kDirectoryResourceId, 726 sync_client()->UploadNewFile(kDirectoryResourceId,
713 kLocalFilePath, 727 kLocalFilePath,
714 kTitle, 728 kTitle,
715 kFileSize, 729 kFileSize,
716 base::Bind(&DidUploadFile, 730 base::Bind(&DidUploadFile,
717 &done, &error, &resource_id)); 731 &done, &error, &resource_id));
718 message_loop()->RunUntilIdle(); 732 message_loop()->RunUntilIdle();
719 733
720 EXPECT_TRUE(done); 734 EXPECT_TRUE(done);
721 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); 735 EXPECT_EQ(google_apis::HTTP_SUCCESS, error);
722 } 736 }
723 737
724 TEST_F(DriveFileSyncClientTest, UploadExistingFile) { 738 TEST_F(DriveFileSyncClientTest, UploadExistingFile) {
725 const std::string kResourceId = "file:resource_id"; 739 const std::string kResourceId = "file:resource_id";
726 const FilePath kLocalFilePath(FPL("/tmp/dir/file")); 740 const FilePath kLocalFilePath(FPL("/tmp/dir/file"));
727 int64 kFileSize = 1024; 741 int64 kFileSize = 1024;
728 742
729 scoped_ptr<base::Value> file_entry_data( 743 scoped_ptr<base::Value> file_entry_data(
730 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 744 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
731 scoped_ptr<ResourceEntry> entry( 745 scoped_ptr<ResourceEntry> file_entry(
732 ResourceEntry::ExtractAndParse(*file_entry_data)); 746 ResourceEntry::ExtractAndParse(*file_entry_data));
733 const std::string expected_remote_file_md5 = entry->file_md5(); 747 const std::string expected_remote_file_md5 = file_entry->file_md5();
734 const GURL link_url = 748 const GURL link_url =
735 entry->GetLinkByType(Link::LINK_RESUMABLE_EDIT_MEDIA)->href(); 749 file_entry->GetLinkByType(Link::LINK_RESUMABLE_EDIT_MEDIA)->href();
736 750
737 testing::InSequence sequence; 751 testing::InSequence sequence;
738 752
739 // Expected to call GetResourceEntry from 753 // Expected to call GetResourceEntry from
740 // DriveFileSyncClient::UploadExistingFile. 754 // DriveFileSyncClient::UploadExistingFile.
741 EXPECT_CALL(*mock_drive_service(), 755 EXPECT_CALL(*mock_drive_service(),
742 GetResourceEntry(kResourceId, _)) 756 GetResourceEntry(kResourceId, _))
743 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 757 .WillOnce(InvokeGetResourceEntryCallback1(
744 base::Passed(&file_entry_data))) 758 google_apis::HTTP_SUCCESS,
759 base::Passed(&file_entry)))
745 .RetiresOnSaturation(); 760 .RetiresOnSaturation();
746 761
747 bool done = false; 762 bool done = false;
748 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 763 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
749 std::string resource_id; 764 std::string resource_id;
750 sync_client()->UploadExistingFile(kResourceId, 765 sync_client()->UploadExistingFile(kResourceId,
751 expected_remote_file_md5, 766 expected_remote_file_md5,
752 kLocalFilePath, 767 kLocalFilePath,
753 kFileSize, 768 kFileSize,
754 base::Bind(&DidUploadFile, 769 base::Bind(&DidUploadFile,
755 &done, &error, &resource_id)); 770 &done, &error, &resource_id));
756 message_loop()->RunUntilIdle(); 771 message_loop()->RunUntilIdle();
757 772
758 EXPECT_TRUE(done); 773 EXPECT_TRUE(done);
759 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); 774 EXPECT_EQ(google_apis::HTTP_SUCCESS, error);
760 } 775 }
761 776
762 TEST_F(DriveFileSyncClientTest, UploadExistingFileInConflict) { 777 TEST_F(DriveFileSyncClientTest, UploadExistingFileInConflict) {
763 const std::string kResourceId = "file:resource_id"; 778 const std::string kResourceId = "file:resource_id";
764 const FilePath kLocalFilePath(FPL("/tmp/dir/file")); 779 const FilePath kLocalFilePath(FPL("/tmp/dir/file"));
765 int64 kFileSize = 1024; 780 int64 kFileSize = 1024;
766 781
767 // Since remote file's hash value is different from the expected one, it is 782 // Since remote file's hash value is different from the expected one, it is
768 // expected to cancel upload the file and to return CONFLICT status code. 783 // expected to cancel upload the file and to return CONFLICT status code.
769 const std::string kExpectedRemoteFileMD5 = "123456"; 784 const std::string kExpectedRemoteFileMD5 = "123456";
770 785
771 scoped_ptr<base::Value> file_entry_data( 786 scoped_ptr<base::Value> file_entry_data(
772 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 787 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
773 scoped_ptr<ResourceEntry> entry( 788 scoped_ptr<ResourceEntry> file_entry(
774 ResourceEntry::ExtractAndParse(*file_entry_data)); 789 ResourceEntry::ExtractAndParse(*file_entry_data));
775 790
776 testing::InSequence sequence; 791 testing::InSequence sequence;
777 792
778 // Expected to call GetResourceEntry from 793 // Expected to call GetResourceEntry from
779 // DriveFileSyncClient::UploadExistingFile. 794 // DriveFileSyncClient::UploadExistingFile.
780 EXPECT_CALL(*mock_drive_service(), 795 EXPECT_CALL(*mock_drive_service(),
781 GetResourceEntry(kResourceId, _)) 796 GetResourceEntry(kResourceId, _))
782 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 797 .WillOnce(InvokeGetResourceEntryCallback1(
783 base::Passed(&file_entry_data))) 798 google_apis::HTTP_SUCCESS,
799 base::Passed(&file_entry)))
784 .RetiresOnSaturation(); 800 .RetiresOnSaturation();
785 801
786 bool done = false; 802 bool done = false;
787 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 803 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
788 std::string resource_id; 804 std::string resource_id;
789 sync_client()->UploadExistingFile(kResourceId, 805 sync_client()->UploadExistingFile(kResourceId,
790 kExpectedRemoteFileMD5, 806 kExpectedRemoteFileMD5,
791 kLocalFilePath, 807 kLocalFilePath,
792 kFileSize, 808 kFileSize,
793 base::Bind(&DidUploadFile, 809 base::Bind(&DidUploadFile,
794 &done, &error, &resource_id)); 810 &done, &error, &resource_id));
795 message_loop()->RunUntilIdle(); 811 message_loop()->RunUntilIdle();
796 812
797 EXPECT_TRUE(done); 813 EXPECT_TRUE(done);
798 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); 814 EXPECT_EQ(google_apis::HTTP_CONFLICT, error);
799 } 815 }
800 816
801 TEST_F(DriveFileSyncClientTest, DeleteFile) { 817 TEST_F(DriveFileSyncClientTest, DeleteFile) {
802 const std::string kResourceId = "file:resource_id"; 818 const std::string kResourceId = "file:resource_id";
803 819
804 scoped_ptr<base::Value> file_entry_data( 820 scoped_ptr<base::Value> file_entry_data(
805 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 821 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
806 scoped_ptr<ResourceEntry> entry( 822 scoped_ptr<ResourceEntry> file_entry(
807 ResourceEntry::ExtractAndParse(*file_entry_data)); 823 ResourceEntry::ExtractAndParse(*file_entry_data));
808 const std::string kExpectedRemoteFileMD5 = entry->file_md5(); 824 // We need another copy as |file_entry| will be passed to
825 // InvokeGetResourceEntryCallback1.
826 scoped_ptr<ResourceEntry> file_entry_copy(
827 ResourceEntry::ExtractAndParse(*file_entry_data));
828 const std::string kExpectedRemoteFileMD5 = file_entry_copy->file_md5();
809 829
810 testing::InSequence sequence; 830 testing::InSequence sequence;
811 831
812 // Expected to call GetResourceEntry from DriveFileSyncClient::DeleteFile. 832 // Expected to call GetResourceEntry from DriveFileSyncClient::DeleteFile.
813 EXPECT_CALL(*mock_drive_service(), GetResourceEntry(kResourceId, _)) 833 EXPECT_CALL(*mock_drive_service(), GetResourceEntry(kResourceId, _))
814 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 834 .WillOnce(InvokeGetResourceEntryCallback1(
815 base::Passed(&file_entry_data))) 835 google_apis::HTTP_SUCCESS,
836 base::Passed(&file_entry)))
816 .RetiresOnSaturation(); 837 .RetiresOnSaturation();
817 838
818 // Expected to call DriveUploaderInterface::DeleteResource from 839 // Expected to call DriveUploaderInterface::DeleteResource from
819 // DidGetResourceEntryForDeleteFile. 840 // DidGetResourceEntryForDeleteFile.
820 EXPECT_CALL(*mock_drive_service(), 841 EXPECT_CALL(*mock_drive_service(),
821 DeleteResource(entry->GetLinkByType(Link::LINK_SELF)->href(), _)) 842 DeleteResource(
843 file_entry_copy->GetLinkByType(Link::LINK_SELF)->href(), _))
822 .WillOnce(InvokeEntryActionCallback2(google_apis::HTTP_SUCCESS)) 844 .WillOnce(InvokeEntryActionCallback2(google_apis::HTTP_SUCCESS))
823 .RetiresOnSaturation(); 845 .RetiresOnSaturation();
824 846
825 bool done = false; 847 bool done = false;
826 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 848 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
827 std::string resource_id; 849 std::string resource_id;
828 sync_client()->DeleteFile(kResourceId, 850 sync_client()->DeleteFile(kResourceId,
829 kExpectedRemoteFileMD5, 851 kExpectedRemoteFileMD5,
830 base::Bind(&DidDeleteFile, &done, &error)); 852 base::Bind(&DidDeleteFile, &done, &error));
831 message_loop()->RunUntilIdle(); 853 message_loop()->RunUntilIdle();
832 854
833 EXPECT_TRUE(done); 855 EXPECT_TRUE(done);
834 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); 856 EXPECT_EQ(google_apis::HTTP_SUCCESS, error);
835 } 857 }
836 858
837 TEST_F(DriveFileSyncClientTest, DeleteFileInConflict) { 859 TEST_F(DriveFileSyncClientTest, DeleteFileInConflict) {
838 const std::string kResourceId = "file:resource_id"; 860 const std::string kResourceId = "file:resource_id";
839 861
840 // Since remote file's hash value is different from the expected one, it is 862 // Since remote file's hash value is different from the expected one, it is
841 // expected to cancel delete the file and to return CONFLICT status code. 863 // expected to cancel delete the file and to return CONFLICT status code.
842 const std::string kExpectedRemoteFileMD5 = "123456"; 864 const std::string kExpectedRemoteFileMD5 = "123456";
843 865
844 scoped_ptr<base::Value> file_entry_data( 866 scoped_ptr<base::Value> file_entry_data(
845 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass()); 867 google_apis::test_util::LoadJSONFile("gdata/file_entry.json").Pass());
846 scoped_ptr<ResourceEntry> entry( 868 scoped_ptr<ResourceEntry> file_entry(
847 ResourceEntry::ExtractAndParse(*file_entry_data)); 869 ResourceEntry::ExtractAndParse(*file_entry_data));
848 870
849 testing::InSequence sequence; 871 testing::InSequence sequence;
850 872
851 // Expected to call GetResourceEntry from DriveFileSyncClient::DeleteFile. 873 // Expected to call GetResourceEntry from DriveFileSyncClient::DeleteFile.
852 EXPECT_CALL(*mock_drive_service(), GetResourceEntry(kResourceId, _)) 874 EXPECT_CALL(*mock_drive_service(), GetResourceEntry(kResourceId, _))
853 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, 875 .WillOnce(InvokeGetResourceEntryCallback1(
854 base::Passed(&file_entry_data))) 876 google_apis::HTTP_SUCCESS,
877 base::Passed(&file_entry)))
855 .RetiresOnSaturation(); 878 .RetiresOnSaturation();
856 879
857 bool done = false; 880 bool done = false;
858 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 881 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
859 std::string resource_id; 882 std::string resource_id;
860 sync_client()->DeleteFile(kResourceId, 883 sync_client()->DeleteFile(kResourceId,
861 kExpectedRemoteFileMD5, 884 kExpectedRemoteFileMD5,
862 base::Bind(&DidDeleteFile, &done, &error)); 885 base::Bind(&DidDeleteFile, &done, &error));
863 message_loop()->RunUntilIdle(); 886 message_loop()->RunUntilIdle();
864 887
865 EXPECT_TRUE(done); 888 EXPECT_TRUE(done);
866 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); 889 EXPECT_EQ(google_apis::HTTP_CONFLICT, error);
867 } 890 }
868 891
869 #endif // !defined(OS_ANDROID) 892 #endif // !defined(OS_ANDROID)
870 893
871 } // namespace sync_file_system 894 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698