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

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

Issue 12385081: Replace GetAccountMetadata by GetAboutResource in sync_file_system. (Closed) Base URL: http://git.chromium.org/chromium/src.git@b174237_gdata_wapi_get_about_resource_impl4
Patch Set: Created 7 years, 9 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 | « chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc ('k') | no next file » | 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/sync_file_system/drive_file_sync_service.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "chrome/browser/extensions/test_extension_service.h" 12 #include "chrome/browser/extensions/test_extension_service.h"
13 #include "chrome/browser/extensions/test_extension_system.h" 13 #include "chrome/browser/extensions/test_extension_system.h"
14 #include "chrome/browser/google_apis/drive_api_parser.h"
14 #include "chrome/browser/google_apis/drive_uploader.h" 15 #include "chrome/browser/google_apis/drive_uploader.h"
15 #include "chrome/browser/google_apis/gdata_errorcode.h" 16 #include "chrome/browser/google_apis/gdata_errorcode.h"
16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
17 #include "chrome/browser/google_apis/mock_drive_service.h" 18 #include "chrome/browser/google_apis/mock_drive_service.h"
18 #include "chrome/browser/google_apis/test_util.h" 19 #include "chrome/browser/google_apis/test_util.h"
19 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" 20 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
20 #include "chrome/browser/sync_file_system/drive_metadata_store.h" 21 #include "chrome/browser/sync_file_system/drive_metadata_store.h"
21 #include "chrome/browser/sync_file_system/file_status_observer.h" 22 #include "chrome/browser/sync_file_system/file_status_observer.h"
22 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h" 23 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h"
23 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" 24 #include "chrome/browser/sync_file_system/sync_file_system.pb.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 GURL ExtensionNameToGURL(const base::FilePath::StringType& extension_name) { 102 GURL ExtensionNameToGURL(const base::FilePath::StringType& extension_name) {
102 std::string id = Extension::GenerateIdForPath(base::FilePath(extension_name)); 103 std::string id = Extension::GenerateIdForPath(base::FilePath(extension_name));
103 return extensions::Extension::GetBaseURLFromExtensionId(id); 104 return extensions::Extension::GetBaseURLFromExtensionId(id);
104 } 105 }
105 106
106 ACTION(InvokeCompletionCallback) { 107 ACTION(InvokeCompletionCallback) {
107 base::MessageLoopProxy::current()->PostTask(FROM_HERE, arg1); 108 base::MessageLoopProxy::current()->PostTask(FROM_HERE, arg1);
108 } 109 }
109 110
110 // Invokes |arg0| as a GetDataCallback. 111 // Invokes |arg0| as a GetDataCallback.
111 ACTION_P2(InvokeGetAccountMetadataCallback0, error, result) { 112 ACTION_P2(InvokeGetAboutResourceCallback0, error, result) {
112 scoped_ptr<google_apis::AccountMetadata> account_metadata(result.Pass()); 113 scoped_ptr<google_apis::AboutResource> about_resource(result.Pass());
113 base::MessageLoopProxy::current()->PostTask( 114 base::MessageLoopProxy::current()->PostTask(
114 FROM_HERE, 115 FROM_HERE,
115 base::Bind(arg0, error, base::Passed(&account_metadata))); 116 base::Bind(arg0, error, base::Passed(&about_resource)));
116 } 117 }
117 118
118 // Invokes |arg1| as a GetResourceEntryCallback. 119 // Invokes |arg1| as a GetResourceEntryCallback.
119 ACTION_P2(InvokeGetResourceEntryCallback1, error, result) { 120 ACTION_P2(InvokeGetResourceEntryCallback1, error, result) {
120 scoped_ptr<google_apis::ResourceEntry> entry(result.Pass()); 121 scoped_ptr<google_apis::ResourceEntry> entry(result.Pass());
121 base::MessageLoopProxy::current()->PostTask( 122 base::MessageLoopProxy::current()->PostTask(
122 FROM_HERE, 123 FROM_HERE,
123 base::Bind(arg1, error, base::Passed(&entry))); 124 base::Bind(arg1, error, base::Passed(&entry)));
124 } 125 }
125 126
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 .RetiresOnSaturation(); 462 .RetiresOnSaturation();
462 } 463 }
463 464
464 void SetUpDriveServiceExpectCallsForGetSyncRoot() { 465 void SetUpDriveServiceExpectCallsForGetSyncRoot() {
465 SetUpDriveServiceExpectCallsForGetResourceList( 466 SetUpDriveServiceExpectCallsForGetResourceList(
466 "sync_file_system/sync_root_found.json", 467 "sync_file_system/sync_root_found.json",
467 FormatTitleQuery(kSyncRootDirectoryName), 468 FormatTitleQuery(kSyncRootDirectoryName),
468 std::string()); 469 std::string());
469 } 470 }
470 471
471 void SetUpDriveServiceExpectCallsForGetAccountMetadata() { 472 void SetUpDriveServiceExpectCallsForGetAboutResource() {
472 scoped_ptr<Value> account_metadata_value(LoadJSONFile( 473 scoped_ptr<Value> account_metadata_value(LoadJSONFile(
473 "gdata/account_metadata.json")); 474 "gdata/account_metadata.json"));
474 scoped_ptr<google_apis::AccountMetadata> account_metadata( 475 scoped_ptr<google_apis::AboutResource> about_resource(
475 google_apis::AccountMetadata::CreateFrom(*account_metadata_value)); 476 google_apis::AboutResource::CreateFromAccountMetadata(
476 EXPECT_CALL(*mock_drive_service(), 477 *google_apis::AccountMetadata::CreateFrom(*account_metadata_value),
477 GetAccountMetadata(_)) 478 "folder:root"));
478 .WillOnce(InvokeGetAccountMetadataCallback0( 479 EXPECT_CALL(*mock_drive_service(), GetAboutResource(_))
480 .WillOnce(InvokeGetAboutResourceCallback0(
479 google_apis::HTTP_SUCCESS, 481 google_apis::HTTP_SUCCESS,
480 base::Passed(&account_metadata))) 482 base::Passed(&about_resource)))
481 .RetiresOnSaturation(); 483 .RetiresOnSaturation();
482 } 484 }
483 485
484 void SetUpDriveServiceExpectCallsForDownloadFile( 486 void SetUpDriveServiceExpectCallsForDownloadFile(
485 const std::string& file_resource_id) { 487 const std::string& file_resource_id) {
486 scoped_ptr<Value> file_entry_value( 488 scoped_ptr<Value> file_entry_value(
487 LoadJSONFile("gdata/file_entry.json").Pass()); 489 LoadJSONFile("gdata/file_entry.json").Pass());
488 scoped_ptr<google_apis::ResourceEntry> file_entry 490 scoped_ptr<google_apis::ResourceEntry> file_entry
489 = google_apis::ResourceEntry::ExtractAndParse(*file_entry_value); 491 = google_apis::ResourceEntry::ExtractAndParse(*file_entry_value);
490 EXPECT_CALL(*mock_drive_service(), 492 EXPECT_CALL(*mock_drive_service(),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); 580 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
579 581
580 Sequence change_queue_seq; 582 Sequence change_queue_seq;
581 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) 583 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0))
582 .InSequence(change_queue_seq); 584 .InSequence(change_queue_seq);
583 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(3)) 585 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(3))
584 .InSequence(change_queue_seq); 586 .InSequence(change_queue_seq);
585 587
586 InSequence sequence; 588 InSequence sequence;
587 589
588 SetUpDriveServiceExpectCallsForGetAccountMetadata(); 590 SetUpDriveServiceExpectCallsForGetAboutResource();
589 SetUpDriveServiceExpectCallsForGetResourceList( 591 SetUpDriveServiceExpectCallsForGetResourceList(
590 "sync_file_system/listing_files_in_directory.json", 592 "sync_file_system/listing_files_in_directory.json",
591 std::string(), 593 std::string(),
592 kDirectoryResourceId1); 594 kDirectoryResourceId1);
593 595
594 EXPECT_CALL(*mock_remote_observer(), 596 EXPECT_CALL(*mock_remote_observer(),
595 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) 597 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _))
596 .Times(1); 598 .Times(1);
597 599
598 SetUpDriveSyncService(true); 600 SetUpDriveSyncService(true);
(...skipping 30 matching lines...) Expand all
629 "sync_file_system/origin_directory_not_found.json", 631 "sync_file_system/origin_directory_not_found.json",
630 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), 632 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)),
631 kSyncRootResourceId); 633 kSyncRootResourceId);
632 634
633 // If the directory for the origin is missing, DriveFileSyncService should 635 // If the directory for the origin is missing, DriveFileSyncService should
634 // attempt to create it. 636 // attempt to create it.
635 SetUpDriveServiceExpectCallsForAddNewDirectory( 637 SetUpDriveServiceExpectCallsForAddNewDirectory(
636 kSyncRootResourceId, 638 kSyncRootResourceId,
637 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); 639 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
638 640
639 // Once the directory is created GetAccountMetadata should be called to get 641 // Once the directory is created GetAboutResource should be called to get
640 // the largest changestamp for the origin as a prepariation of the batch sync. 642 // the largest changestamp for the origin as a prepariation of the batch sync.
641 SetUpDriveServiceExpectCallsForGetAccountMetadata(); 643 SetUpDriveServiceExpectCallsForGetAboutResource();
642 644
643 SetUpDriveServiceExpectCallsForGetResourceList( 645 SetUpDriveServiceExpectCallsForGetResourceList(
644 "sync_file_system/listing_files_in_empty_directory.json", 646 "sync_file_system/listing_files_in_empty_directory.json",
645 std::string(), 647 std::string(),
646 kDirectoryResourceId); 648 kDirectoryResourceId);
647 649
648 SetUpDriveSyncService(true); 650 SetUpDriveSyncService(true);
649 bool done = false; 651 bool done = false;
650 sync_service()->RegisterOriginForTrackingChanges( 652 sync_service()->RegisterOriginForTrackingChanges(
651 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 653 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
(...skipping 19 matching lines...) Expand all
671 .Times(AnyNumber()); 673 .Times(AnyNumber());
672 674
673 InSequence sequence; 675 InSequence sequence;
674 676
675 // We already have a directory for the origin. 677 // We already have a directory for the origin.
676 SetUpDriveServiceExpectCallsForGetResourceList( 678 SetUpDriveServiceExpectCallsForGetResourceList(
677 "sync_file_system/origin_directory_found.json", 679 "sync_file_system/origin_directory_found.json",
678 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), 680 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)),
679 kSyncRootResourceId); 681 kSyncRootResourceId);
680 682
681 SetUpDriveServiceExpectCallsForGetAccountMetadata(); 683 SetUpDriveServiceExpectCallsForGetAboutResource();
682 684
683 // DriveFileSyncService should fetch the list of the directory content 685 // DriveFileSyncService should fetch the list of the directory content
684 // to start the batch sync. 686 // to start the batch sync.
685 SetUpDriveServiceExpectCallsForGetResourceList( 687 SetUpDriveServiceExpectCallsForGetResourceList(
686 "sync_file_system/listing_files_in_directory.json", 688 "sync_file_system/listing_files_in_directory.json",
687 std::string(), 689 std::string(),
688 kDirectoryResourceId); 690 kDirectoryResourceId);
689 691
690 SetUpDriveSyncService(true); 692 SetUpDriveSyncService(true);
691 bool done = false; 693 bool done = false;
(...skipping 25 matching lines...) Expand all
717 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); 719 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
718 720
719 EXPECT_CALL(*mock_remote_observer(), 721 EXPECT_CALL(*mock_remote_observer(),
720 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) 722 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _))
721 .Times(AtLeast(1)); 723 .Times(AtLeast(1));
722 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 724 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
723 .Times(AnyNumber()); 725 .Times(AnyNumber());
724 726
725 InSequence sequence; 727 InSequence sequence;
726 728
727 SetUpDriveServiceExpectCallsForGetAccountMetadata(); 729 SetUpDriveServiceExpectCallsForGetAboutResource();
728 SetUpDriveServiceExpectCallsForGetResourceList( 730 SetUpDriveServiceExpectCallsForGetResourceList(
729 "sync_file_system/listing_files_in_directory.json", 731 "sync_file_system/listing_files_in_directory.json",
730 std::string(), 732 std::string(),
731 kDirectoryResourceId1); 733 kDirectoryResourceId1);
732 734
733 SetUpDriveSyncService(true); 735 SetUpDriveSyncService(true);
734 message_loop()->RunUntilIdle(); 736 message_loop()->RunUntilIdle();
735 737
736 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size()); 738 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size());
737 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size()); 739 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size());
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); 1099 entry->set_kind(google_apis::ENTRY_KIND_FOLDER);
1098 1100
1099 // Expect to drop this change for file. 1101 // Expect to drop this change for file.
1100 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( 1102 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry(
1101 kOrigin, *entry, 1)); 1103 kOrigin, *entry, 1));
1102 } 1104 }
1103 1105
1104 #endif // !defined(OS_ANDROID) 1106 #endif // !defined(OS_ANDROID)
1105 1107
1106 } // namespace sync_file_system 1108 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698