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 "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" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 return &mock_file_status_observer_; | 442 return &mock_file_status_observer_; |
443 } | 443 } |
444 | 444 |
445 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { | 445 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { |
446 return &mock_remote_processor_; | 446 return &mock_remote_processor_; |
447 } | 447 } |
448 | 448 |
449 MessageLoop* message_loop() { return &message_loop_; } | 449 MessageLoop* message_loop() { return &message_loop_; } |
450 DriveFileSyncService* sync_service() { return sync_service_.get(); } | 450 DriveFileSyncService* sync_service() { return sync_service_.get(); } |
451 | 451 |
452 std::string FormatTitleQuery(const std::string& title) { | |
453 return DriveFileSyncClient::FormatTitleQuery(title); | |
454 } | |
455 | |
456 const DriveFileSyncService::PendingChangeQueue& pending_changes() const { | 452 const DriveFileSyncService::PendingChangeQueue& pending_changes() const { |
457 return sync_service_->pending_changes_; | 453 return sync_service_->pending_changes_; |
458 } | 454 } |
459 | 455 |
460 fileapi::FileSystemURL CreateURL(const GURL& origin, | 456 fileapi::FileSystemURL CreateURL(const GURL& origin, |
461 const base::FilePath::StringType& path) { | 457 const base::FilePath::StringType& path) { |
462 return CreateSyncableFileSystemURL( | 458 return CreateSyncableFileSystemURL( |
463 origin, kServiceName, base::FilePath(path)); | 459 origin, kServiceName, base::FilePath(path)); |
464 } | 460 } |
465 | 461 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 const std::string& resource_id, | 510 const std::string& resource_id, |
515 int64 changestamp, | 511 int64 changestamp, |
516 const std::string& remote_file_md5) { | 512 const std::string& remote_file_md5) { |
517 return sync_service_->AppendRemoteChangeInternal( | 513 return sync_service_->AppendRemoteChangeInternal( |
518 origin, path, is_deleted, resource_id, | 514 origin, path, is_deleted, resource_id, |
519 changestamp, remote_file_md5, base::Time(), | 515 changestamp, remote_file_md5, base::Time(), |
520 DriveFileSyncService::REMOTE_SYNC_TYPE_INCREMENTAL); | 516 DriveFileSyncService::REMOTE_SYNC_TYPE_INCREMENTAL); |
521 } | 517 } |
522 | 518 |
523 // Mock setup helpers ------------------------------------------------------ | 519 // Mock setup helpers ------------------------------------------------------ |
524 void SetUpDriveServiceExpectCallsForSearchInDirectory( | 520 void SetUpDriveServiceExpectCallsForSearchByTitle( |
525 const std::string& result_mock_json_name, | 521 const std::string& result_mock_json_name, |
526 const std::string& query, | 522 const std::string& title, |
527 const std::string& search_directory) { | 523 const std::string& search_directory) { |
528 scoped_ptr<Value> result_value(LoadJSONFile( | 524 scoped_ptr<Value> result_value(LoadJSONFile( |
529 result_mock_json_name)); | 525 result_mock_json_name)); |
530 scoped_ptr<google_apis::ResourceList> result( | 526 scoped_ptr<google_apis::ResourceList> result( |
531 google_apis::ResourceList::ExtractAndParse(*result_value)); | 527 google_apis::ResourceList::ExtractAndParse(*result_value)); |
532 EXPECT_CALL(*mock_drive_service(), | 528 EXPECT_CALL(*mock_drive_service(), |
533 SearchInDirectory(query, search_directory, _)) | 529 SearchByTitle(title, search_directory, _)) |
534 .WillOnce(InvokeGetResourceListCallback2( | 530 .WillOnce(InvokeGetResourceListCallback2( |
535 google_apis::HTTP_SUCCESS, | 531 google_apis::HTTP_SUCCESS, |
536 base::Passed(&result))) | 532 base::Passed(&result))) |
537 .RetiresOnSaturation(); | 533 .RetiresOnSaturation(); |
538 } | 534 } |
539 | 535 |
540 void SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | 536 void SetUpDriveServiceExpectCallsForGetResourceListInDirectory( |
541 const std::string& result_mock_json_name, | 537 const std::string& result_mock_json_name, |
542 const std::string& search_directory) { | 538 const std::string& search_directory) { |
543 scoped_ptr<Value> result_value(LoadJSONFile( | 539 scoped_ptr<Value> result_value(LoadJSONFile( |
(...skipping 19 matching lines...) Expand all Loading... | |
563 base::Passed(&result))) | 559 base::Passed(&result))) |
564 .RetiresOnSaturation(); | 560 .RetiresOnSaturation(); |
565 } | 561 } |
566 | 562 |
567 void SetUpDriveServiceExpectCallsForGetSyncRoot() { | 563 void SetUpDriveServiceExpectCallsForGetSyncRoot() { |
568 scoped_ptr<Value> result_value(LoadJSONFile( | 564 scoped_ptr<Value> result_value(LoadJSONFile( |
569 "chromeos/sync_file_system/sync_root_found.json")); | 565 "chromeos/sync_file_system/sync_root_found.json")); |
570 scoped_ptr<google_apis::ResourceList> result( | 566 scoped_ptr<google_apis::ResourceList> result( |
571 google_apis::ResourceList::ExtractAndParse(*result_value)); | 567 google_apis::ResourceList::ExtractAndParse(*result_value)); |
572 EXPECT_CALL(*mock_drive_service(), | 568 EXPECT_CALL(*mock_drive_service(), |
573 Search(FormatTitleQuery(kSyncRootDirectoryName), _)) | 569 SearchByTitle(kSyncRootDirectoryName, "", _)) |
tzik
2013/04/18 14:26:23
ditto
hidehiko
2013/04/22 04:24:45
Done.
| |
574 .Times(AtMost(1)) | 570 .Times(AtMost(1)) |
575 .WillOnce(InvokeGetResourceListCallback1( | 571 .WillOnce(InvokeGetResourceListCallback2( |
576 google_apis::HTTP_SUCCESS, | 572 google_apis::HTTP_SUCCESS, |
577 base::Passed(&result))) | 573 base::Passed(&result))) |
578 .RetiresOnSaturation(); | 574 .RetiresOnSaturation(); |
579 } | 575 } |
580 | 576 |
581 void SetUpDriveServiceExpectCallsForGetAboutResource() { | 577 void SetUpDriveServiceExpectCallsForGetAboutResource() { |
582 scoped_ptr<Value> account_metadata_value(LoadJSONFile( | 578 scoped_ptr<Value> account_metadata_value(LoadJSONFile( |
583 "chromeos/gdata/account_metadata.json")); | 579 "chromeos/gdata/account_metadata.json")); |
584 scoped_ptr<google_apis::AboutResource> about_resource( | 580 scoped_ptr<google_apis::AboutResource> about_resource( |
585 google_apis::AboutResource::CreateFromAccountMetadata( | 581 google_apis::AboutResource::CreateFromAccountMetadata( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 EXPECT_CALL(*mock_remote_observer(), | 713 EXPECT_CALL(*mock_remote_observer(), |
718 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 714 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
719 .Times(AtLeast(1)); | 715 .Times(AtLeast(1)); |
720 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) | 716 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
721 .Times(AnyNumber()); | 717 .Times(AnyNumber()); |
722 | 718 |
723 // Expect to call GetResourceList for the sync root from | 719 // Expect to call GetResourceList for the sync root from |
724 // RegisterOriginForTrackingChanges. | 720 // RegisterOriginForTrackingChanges. |
725 SetUpDriveServiceExpectCallsForGetSyncRoot(); | 721 SetUpDriveServiceExpectCallsForGetSyncRoot(); |
726 | 722 |
727 SetUpDriveServiceExpectCallsForSearchInDirectory( | 723 SetUpDriveServiceExpectCallsForSearchByTitle( |
728 "chromeos/sync_file_system/origin_directory_found.json", | 724 "chromeos/sync_file_system/origin_directory_found.json", |
729 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), | 725 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin), |
730 kSyncRootResourceId); | 726 kSyncRootResourceId); |
731 SetUpDriveServiceExpectCallsForSearchInDirectory( | 727 SetUpDriveServiceExpectCallsForSearchByTitle( |
732 "chromeos/sync_file_system/origin_directory_not_found.json", | 728 "chromeos/sync_file_system/origin_directory_not_found.json", |
733 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), | 729 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin), |
734 kSyncRootResourceId); | 730 kSyncRootResourceId); |
735 | 731 |
736 // If the directory for the origin is missing, DriveFileSyncService should | 732 // If the directory for the origin is missing, DriveFileSyncService should |
737 // attempt to create it. | 733 // attempt to create it. |
738 SetUpDriveServiceExpectCallsForAddNewDirectory( | 734 SetUpDriveServiceExpectCallsForAddNewDirectory( |
739 kSyncRootResourceId, | 735 kSyncRootResourceId, |
740 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); | 736 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); |
741 | 737 |
742 // Once the directory is created GetAboutResource should be called to get | 738 // Once the directory is created GetAboutResource should be called to get |
743 // the largest changestamp for the origin as a prepariation of the batch sync. | 739 // the largest changestamp for the origin as a prepariation of the batch sync. |
(...skipping 27 matching lines...) Expand all Loading... | |
771 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 767 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
772 .Times(AnyNumber()); | 768 .Times(AnyNumber()); |
773 | 769 |
774 InSequence sequence; | 770 InSequence sequence; |
775 | 771 |
776 // Expect to call GetResourceList for the sync root from | 772 // Expect to call GetResourceList for the sync root from |
777 // RegisterOriginForTrackingChanges. | 773 // RegisterOriginForTrackingChanges. |
778 SetUpDriveServiceExpectCallsForGetSyncRoot(); | 774 SetUpDriveServiceExpectCallsForGetSyncRoot(); |
779 | 775 |
780 // We already have a directory for the origin. | 776 // We already have a directory for the origin. |
781 SetUpDriveServiceExpectCallsForSearchInDirectory( | 777 SetUpDriveServiceExpectCallsForSearchByTitle( |
782 "chromeos/sync_file_system/origin_directory_found.json", | 778 "chromeos/sync_file_system/origin_directory_found.json", |
783 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), | 779 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin), |
784 kSyncRootResourceId); | 780 kSyncRootResourceId); |
785 | 781 |
786 SetUpDriveServiceExpectCallsForGetAboutResource(); | 782 SetUpDriveServiceExpectCallsForGetAboutResource(); |
787 | 783 |
788 // DriveFileSyncService should fetch the list of the directory content | 784 // DriveFileSyncService should fetch the list of the directory content |
789 // to start the batch sync. | 785 // to start the batch sync. |
790 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | 786 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( |
791 "chromeos/sync_file_system/listing_files_in_directory.json", | 787 "chromeos/sync_file_system/listing_files_in_directory.json", |
792 kDirectoryResourceId); | 788 kDirectoryResourceId); |
793 | 789 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 .Times(AtLeast(1)); | 1167 .Times(AtLeast(1)); |
1172 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) | 1168 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
1173 .Times(AnyNumber()); | 1169 .Times(AnyNumber()); |
1174 | 1170 |
1175 InSequence sequence; | 1171 InSequence sequence; |
1176 | 1172 |
1177 // Expect to call GetResourceList for the sync root from | 1173 // Expect to call GetResourceList for the sync root from |
1178 // RegisterOriginForTrackingChanges. | 1174 // RegisterOriginForTrackingChanges. |
1179 SetUpDriveServiceExpectCallsForGetSyncRoot(); | 1175 SetUpDriveServiceExpectCallsForGetSyncRoot(); |
1180 | 1176 |
1181 SetUpDriveServiceExpectCallsForSearchInDirectory( | 1177 SetUpDriveServiceExpectCallsForSearchByTitle( |
1182 "chromeos/sync_file_system/origin_directory_found.json", | 1178 "chromeos/sync_file_system/origin_directory_found.json", |
1183 FormatTitleQuery(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)), | 1179 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin), |
1184 kSyncRootResourceId); | 1180 kSyncRootResourceId); |
1185 | 1181 |
1186 // Usually the sync service starts batch sync here, but since we're | 1182 // Usually the sync service starts batch sync here, but since we're |
1187 // setting up a drive service with sync disabled batch sync doesn't | 1183 // setting up a drive service with sync disabled batch sync doesn't |
1188 // start (while register origin should still return OK). | 1184 // start (while register origin should still return OK). |
1189 | 1185 |
1190 SetUpDriveSyncService(false); | 1186 SetUpDriveSyncService(false); |
1191 bool done = false; | 1187 bool done = false; |
1192 sync_service()->RegisterOriginForTrackingChanges( | 1188 sync_service()->RegisterOriginForTrackingChanges( |
1193 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 1189 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1286 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); | 1282 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); |
1287 | 1283 |
1288 // Expect to drop this change for file. | 1284 // Expect to drop this change for file. |
1289 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( | 1285 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( |
1290 kOrigin, *entry, 1)); | 1286 kOrigin, *entry, 1)); |
1291 } | 1287 } |
1292 | 1288 |
1293 #endif // !defined(OS_ANDROID) | 1289 #endif // !defined(OS_ANDROID) |
1294 | 1290 |
1295 } // namespace sync_file_system | 1291 } // namespace sync_file_system |
OLD | NEW |