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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 class MockRemoteServiceObserver : public RemoteFileSyncService::Observer { | 71 class MockRemoteServiceObserver : public RemoteFileSyncService::Observer { |
72 public: | 72 public: |
73 MockRemoteServiceObserver() {} | 73 MockRemoteServiceObserver() {} |
74 virtual ~MockRemoteServiceObserver() {} | 74 virtual ~MockRemoteServiceObserver() {} |
75 | 75 |
76 // LocalChangeProcessor override. | 76 // LocalChangeProcessor override. |
77 MOCK_METHOD1(OnRemoteChangeAvailable, | 77 MOCK_METHOD1(OnRemoteChangeQueueUpdated, |
78 void(int64 pending_changes)); | 78 void(int64 pending_changes)); |
79 MOCK_METHOD2(OnRemoteServiceStateUpdated, | 79 MOCK_METHOD2(OnRemoteServiceStateUpdated, |
80 void(RemoteServiceState state, | 80 void(RemoteServiceState state, |
81 const std::string& description)); | 81 const std::string& description)); |
82 }; | 82 }; |
83 | 83 |
84 class DriveFileSyncServiceTest : public testing::Test { | 84 class DriveFileSyncServiceTest : public testing::Test { |
85 public: | 85 public: |
86 DriveFileSyncServiceTest() | 86 DriveFileSyncServiceTest() |
87 : file_thread_(content::BrowserThread::FILE, &message_loop_), | 87 : file_thread_(content::BrowserThread::FILE, &message_loop_), |
88 mock_drive_service_(NULL) { | 88 mock_drive_service_(NULL) { |
89 } | 89 } |
90 | 90 |
91 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() OVERRIDE { |
92 ASSERT_TRUE(fileapi::RegisterSyncableFileSystem( | 92 ASSERT_TRUE(fileapi::RegisterSyncableFileSystem( |
93 DriveFileSyncService::kServiceName)); | 93 DriveFileSyncService::kServiceName)); |
94 | 94 |
95 mock_drive_service_ = new StrictMock<google_apis::MockDriveService>; | 95 mock_drive_service_ = new StrictMock<google_apis::MockDriveService>; |
96 | 96 |
97 EXPECT_CALL(*mock_drive_service(), Initialize(&profile_)); | 97 EXPECT_CALL(*mock_drive_service(), Initialize(&profile_)); |
98 EXPECT_CALL(*mock_drive_service(), AddObserver(_)); | 98 EXPECT_CALL(*mock_drive_service(), AddObserver(_)); |
99 | 99 |
100 sync_client_ = DriveFileSyncClient::CreateForTesting( | 100 sync_client_ = DriveFileSyncClient::CreateForTesting( |
101 &profile_, | 101 &profile_, |
| 102 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
102 scoped_ptr<DriveServiceInterface>(mock_drive_service_), | 103 scoped_ptr<DriveServiceInterface>(mock_drive_service_), |
103 scoped_ptr<DriveUploaderInterface>()).Pass(); | 104 scoped_ptr<DriveUploaderInterface>()).Pass(); |
104 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); | 105 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); |
105 metadata_store_.reset(new DriveMetadataStore( | 106 metadata_store_.reset(new DriveMetadataStore( |
106 base_dir_.path(), base::MessageLoopProxy::current())); | 107 base_dir_.path(), base::MessageLoopProxy::current())); |
107 | 108 |
108 bool done = false; | 109 bool done = false; |
109 metadata_store_->Initialize(base::Bind(&DidInitialize, &done)); | 110 metadata_store_->Initialize(base::Bind(&DidInitialize, &done)); |
110 message_loop_.RunUntilIdle(); | 111 message_loop_.RunUntilIdle(); |
111 EXPECT_TRUE(done); | 112 EXPECT_TRUE(done); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 fileapi::SyncOperationType* operation_out, | 254 fileapi::SyncOperationType* operation_out, |
254 fileapi::SyncStatusCode status, | 255 fileapi::SyncStatusCode status, |
255 const fileapi::FileSystemURL& url, | 256 const fileapi::FileSystemURL& url, |
256 fileapi::SyncOperationType operation) { | 257 fileapi::SyncOperationType operation) { |
257 *status_out = status; | 258 *status_out = status; |
258 *url_out = url; | 259 *url_out = url; |
259 *operation_out = operation; | 260 *operation_out = operation; |
260 } | 261 } |
261 | 262 |
262 void AppendIncrementalRemoteChange(const GURL& origin, | 263 void AppendIncrementalRemoteChange(const GURL& origin, |
263 google_apis::DocumentEntry* entry, | 264 const google_apis::DocumentEntry& entry, |
264 int64 changestamp) { | 265 int64 changestamp) { |
265 sync_service_->AppendNewRemoteChange( | 266 sync_service_->AppendNewRemoteChange( |
266 origin, entry, changestamp, | 267 origin, entry, changestamp, |
267 DriveFileSyncService::REMOTE_SYNC_TYPE_INCREMENTAL); | 268 DriveFileSyncService::REMOTE_SYNC_TYPE_INCREMENTAL); |
268 } | 269 } |
269 | 270 |
270 private: | 271 private: |
271 MessageLoop message_loop_; | 272 MessageLoop message_loop_; |
272 content::TestBrowserThread file_thread_; | 273 content::TestBrowserThread file_thread_; |
273 | 274 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 std::string query = FormatTitleQuery(kSyncRootDirectoryName); | 367 std::string query = FormatTitleQuery(kSyncRootDirectoryName); |
367 EXPECT_CALL(*mock_drive_service(), | 368 EXPECT_CALL(*mock_drive_service(), |
368 GetDocuments(GURL(), 0, query, false, std::string(), _)) | 369 GetDocuments(GURL(), 0, query, false, std::string(), _)) |
369 .WillOnce(InvokeGetDataCallback5( | 370 .WillOnce(InvokeGetDataCallback5( |
370 google_apis::HTTP_SUCCESS, | 371 google_apis::HTTP_SUCCESS, |
371 base::Passed(&sync_root_found))); | 372 base::Passed(&sync_root_found))); |
372 | 373 |
373 EXPECT_CALL(*mock_remote_observer(), | 374 EXPECT_CALL(*mock_remote_observer(), |
374 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 375 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
375 .Times(1); | 376 .Times(1); |
376 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(0)) | 377 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
377 .Times(AnyNumber()); | 378 .Times(AnyNumber()); |
378 | 379 |
379 SetUpDriveSyncService(); | 380 SetUpDriveSyncService(); |
380 message_loop()->RunUntilIdle(); | 381 message_loop()->RunUntilIdle(); |
381 | 382 |
382 EXPECT_EQ("folder:sync_root_resource_id", | 383 EXPECT_EQ("folder:sync_root_resource_id", |
383 metadata_store()->sync_root_directory()); | 384 metadata_store()->sync_root_directory()); |
384 | 385 |
385 EXPECT_EQ(0u, metadata_store()->batch_sync_origins().size()); | 386 EXPECT_EQ(0u, metadata_store()->batch_sync_origins().size()); |
386 EXPECT_EQ(0u, metadata_store()->incremental_sync_origins().size()); | 387 EXPECT_EQ(0u, metadata_store()->incremental_sync_origins().size()); |
387 EXPECT_EQ(0u, pending_changes().size()); | 388 EXPECT_EQ(0u, pending_changes().size()); |
388 } | 389 } |
389 | 390 |
390 TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) { | 391 TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) { |
391 const GURL kOrigin1("chrome-extension://example"); | 392 const GURL kOrigin1("chrome-extension://example"); |
392 const GURL kOrigin2("chrome-extension://example2"); | 393 const GURL kOrigin2("chrome-extension://example2"); |
393 const std::string kDirectoryResourceId1( | 394 const std::string kDirectoryResourceId1( |
394 "folder:origin_directory_resource_id"); | 395 "folder:origin_directory_resource_id"); |
395 const std::string kDirectoryResourceId2( | 396 const std::string kDirectoryResourceId2( |
396 "folder:origin_directory_resource_id2"); | 397 "folder:origin_directory_resource_id2"); |
397 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 398 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
398 | 399 |
399 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 400 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
400 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | 401 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); |
401 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | 402 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); |
402 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | 403 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); |
403 | 404 |
404 EXPECT_CALL(*mock_remote_observer(), | 405 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(4)) |
405 OnRemoteChangeAvailable(4)) | |
406 .Times(AnyNumber()); | 406 .Times(AnyNumber()); |
407 | 407 |
408 InSequence sequence; | 408 InSequence sequence; |
409 | 409 |
410 scoped_ptr<Value> account_metadata(LoadJSONFile( | 410 scoped_ptr<Value> account_metadata(LoadJSONFile( |
411 "gdata/account_metadata.json")); | 411 "gdata/account_metadata.json")); |
412 EXPECT_CALL(*mock_drive_service(), | 412 EXPECT_CALL(*mock_drive_service(), |
413 GetAccountMetadata(_)) | 413 GetAccountMetadata(_)) |
414 .WillOnce(InvokeGetDataCallback0( | 414 .WillOnce(InvokeGetDataCallback0( |
415 google_apis::HTTP_SUCCESS, | 415 google_apis::HTTP_SUCCESS, |
(...skipping 28 matching lines...) Expand all Loading... |
444 const GURL kOrigin("chrome-extension://example"); | 444 const GURL kOrigin("chrome-extension://example"); |
445 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 445 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
446 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 446 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
447 const GURL kSyncRootContentURL("https://sync_root_content_url/"); | 447 const GURL kSyncRootContentURL("https://sync_root_content_url/"); |
448 | 448 |
449 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 449 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
450 | 450 |
451 EXPECT_CALL(*mock_remote_observer(), | 451 EXPECT_CALL(*mock_remote_observer(), |
452 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 452 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
453 .Times(AtLeast(1)); | 453 .Times(AtLeast(1)); |
454 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(0)) | 454 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
455 .Times(AnyNumber()); | 455 .Times(AnyNumber()); |
456 | 456 |
457 InSequence sequence; | 457 InSequence sequence; |
458 | 458 |
459 scoped_ptr<Value> origin_directory_not_found(LoadJSONFile( | 459 scoped_ptr<Value> origin_directory_not_found(LoadJSONFile( |
460 "sync_file_system/origin_directory_not_found.json")); | 460 "sync_file_system/origin_directory_not_found.json")); |
461 std::string query = FormatTitleQuery( | 461 std::string query = FormatTitleQuery( |
462 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); | 462 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); |
463 | 463 |
464 EXPECT_CALL(*mock_drive_service(), | 464 EXPECT_CALL(*mock_drive_service(), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) { | 525 TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) { |
526 const GURL kOrigin("chrome-extension://example"); | 526 const GURL kOrigin("chrome-extension://example"); |
527 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 527 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
528 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 528 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
529 | 529 |
530 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 530 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
531 | 531 |
532 EXPECT_CALL(*mock_remote_observer(), | 532 EXPECT_CALL(*mock_remote_observer(), |
533 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 533 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
534 .Times(AtLeast(1)); | 534 .Times(AtLeast(1)); |
535 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(4)) | 535 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
536 .Times(AnyNumber()); | 536 .Times(AnyNumber()); |
537 | 537 |
538 InSequence sequence; | 538 InSequence sequence; |
539 | 539 |
540 scoped_ptr<Value> origin_directory_found(LoadJSONFile( | 540 scoped_ptr<Value> origin_directory_found(LoadJSONFile( |
541 "sync_file_system/origin_directory_found.json")); | 541 "sync_file_system/origin_directory_found.json")); |
542 std::string query = FormatTitleQuery( | 542 std::string query = FormatTitleQuery( |
543 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); | 543 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); |
544 EXPECT_CALL(*mock_drive_service(), | 544 EXPECT_CALL(*mock_drive_service(), |
545 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _)) | 545 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _)) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 591 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
592 | 592 |
593 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 593 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
594 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | 594 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); |
595 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | 595 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); |
596 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | 596 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); |
597 | 597 |
598 EXPECT_CALL(*mock_remote_observer(), | 598 EXPECT_CALL(*mock_remote_observer(), |
599 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 599 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
600 .Times(AtLeast(1)); | 600 .Times(AtLeast(1)); |
601 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(_)) | 601 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
602 .Times(AnyNumber()); | 602 .Times(AnyNumber()); |
603 | 603 |
604 InSequence sequence; | 604 InSequence sequence; |
605 | 605 |
606 scoped_ptr<Value> account_metadata(LoadJSONFile( | 606 scoped_ptr<Value> account_metadata(LoadJSONFile( |
607 "gdata/account_metadata.json")); | 607 "gdata/account_metadata.json")); |
608 EXPECT_CALL(*mock_drive_service(), | 608 EXPECT_CALL(*mock_drive_service(), |
609 GetAccountMetadata(_)) | 609 GetAccountMetadata(_)) |
610 .WillOnce(InvokeGetDataCallback0( | 610 .WillOnce(InvokeGetDataCallback0( |
611 google_apis::HTTP_SUCCESS, | 611 google_apis::HTTP_SUCCESS, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 std::string query = FormatTitleQuery(kSyncRootDirectoryName); | 651 std::string query = FormatTitleQuery(kSyncRootDirectoryName); |
652 EXPECT_CALL(*mock_drive_service(), | 652 EXPECT_CALL(*mock_drive_service(), |
653 GetDocuments(GURL(), 0, query, false, std::string(), _)) | 653 GetDocuments(GURL(), 0, query, false, std::string(), _)) |
654 .WillOnce(InvokeGetDataCallback5( | 654 .WillOnce(InvokeGetDataCallback5( |
655 google_apis::HTTP_SUCCESS, | 655 google_apis::HTTP_SUCCESS, |
656 base::Passed(&sync_root_found))); | 656 base::Passed(&sync_root_found))); |
657 | 657 |
658 EXPECT_CALL(*mock_remote_observer(), | 658 EXPECT_CALL(*mock_remote_observer(), |
659 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 659 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
660 .Times(1); | 660 .Times(1); |
| 661 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
| 662 .Times(AnyNumber()); |
661 | 663 |
662 SetUpDriveSyncService(); | 664 SetUpDriveSyncService(); |
663 message_loop()->RunUntilIdle(); | 665 message_loop()->RunUntilIdle(); |
664 | 666 |
665 const fileapi::FileChange local_add_or_update_change( | 667 const fileapi::FileChange local_add_or_update_change( |
666 fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 668 fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
667 fileapi::SYNC_FILE_TYPE_FILE); | 669 fileapi::SYNC_FILE_TYPE_FILE); |
668 const fileapi::FileChange local_delete_change( | 670 const fileapi::FileChange local_delete_change( |
669 fileapi::FileChange::FILE_CHANGE_DELETE, | 671 fileapi::FileChange::FILE_CHANGE_DELETE, |
670 fileapi::SYNC_FILE_TYPE_FILE); | 672 fileapi::SYNC_FILE_TYPE_FILE); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 } | 719 } |
718 | 720 |
719 TEST_F(DriveFileSyncServiceTest, RemoteChange_NoChange) { | 721 TEST_F(DriveFileSyncServiceTest, RemoteChange_NoChange) { |
720 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 722 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
721 | 723 |
722 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 724 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
723 | 725 |
724 EXPECT_CALL(*mock_remote_observer(), | 726 EXPECT_CALL(*mock_remote_observer(), |
725 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 727 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
726 .Times(AnyNumber()); | 728 .Times(AnyNumber()); |
727 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(_)) | 729 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
728 .Times(AnyNumber()); | 730 .Times(AnyNumber()); |
729 | 731 |
730 SetUpDriveSyncService(); | 732 SetUpDriveSyncService(); |
731 | 733 |
732 ProcessRemoteChange(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC, | 734 ProcessRemoteChange(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC, |
733 fileapi::FileSystemURL(), | 735 fileapi::FileSystemURL(), |
734 fileapi::SYNC_OPERATION_NONE); | 736 fileapi::SYNC_OPERATION_NONE); |
735 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty()); | 737 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty()); |
736 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty()); | 738 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty()); |
737 EXPECT_TRUE(pending_changes().empty()); | 739 EXPECT_TRUE(pending_changes().empty()); |
738 } | 740 } |
739 | 741 |
740 TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) { | 742 TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) { |
741 const GURL kOrigin("chrome-extension://example"); | 743 const GURL kOrigin("chrome-extension://example"); |
742 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 744 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
743 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 745 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
744 const FilePath::StringType kFileName(FPL("File 1.mp3")); | 746 const FilePath::StringType kFileName(FPL("File 1.mp3")); |
745 | 747 |
746 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 748 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
747 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); | 749 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); |
748 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); | 750 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); |
749 | 751 |
750 EXPECT_CALL(*mock_remote_observer(), | 752 EXPECT_CALL(*mock_remote_observer(), |
751 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 753 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
752 .Times(AnyNumber()); | 754 .Times(AnyNumber()); |
753 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(_)) | 755 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
754 .Times(AnyNumber()); | 756 .Times(AnyNumber()); |
755 | 757 |
756 EXPECT_CALL(*mock_remote_processor(), | 758 EXPECT_CALL(*mock_remote_processor(), |
757 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) | 759 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) |
758 .WillOnce(PrepareForRemoteChange_Busy()); | 760 .WillOnce(PrepareForRemoteChange_Busy()); |
759 | 761 |
760 SetUpDriveSyncService(); | 762 SetUpDriveSyncService(); |
761 | 763 |
762 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( | 764 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( |
763 *LoadJSONFile("gdata/file_entry.json"))); | 765 *LoadJSONFile("gdata/file_entry.json"))); |
764 AppendIncrementalRemoteChange(kOrigin, entry.get(), 12345); | 766 AppendIncrementalRemoteChange(kOrigin, *entry, 12345); |
765 | 767 |
766 ProcessRemoteChange(fileapi::SYNC_STATUS_FILE_BUSY, | 768 ProcessRemoteChange(fileapi::SYNC_STATUS_FILE_BUSY, |
767 CreateURL(kOrigin, kFileName), | 769 CreateURL(kOrigin, kFileName), |
768 fileapi::SYNC_OPERATION_NONE); | 770 fileapi::SYNC_OPERATION_NONE); |
769 } | 771 } |
770 | 772 |
771 TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) { | 773 TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) { |
772 const GURL kOrigin("chrome-extension://example"); | 774 const GURL kOrigin("chrome-extension://example"); |
773 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 775 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
774 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 776 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
775 const FilePath::StringType kFileName(FPL("File 1.mp3")); | 777 const FilePath::StringType kFileName(FPL("File 1.mp3")); |
776 const std::string kFileResourceId("file:2_file_resource_id"); | 778 const std::string kFileResourceId("file:2_file_resource_id"); |
777 | 779 |
778 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 780 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
779 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); | 781 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); |
780 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); | 782 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); |
781 | 783 |
782 EXPECT_CALL(*mock_remote_observer(), | 784 EXPECT_CALL(*mock_remote_observer(), |
783 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 785 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
784 .Times(AnyNumber()); | 786 .Times(AnyNumber()); |
785 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(_)) | 787 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
786 .Times(AnyNumber()); | 788 .Times(AnyNumber()); |
787 | 789 |
788 EXPECT_CALL(*mock_remote_processor(), | 790 EXPECT_CALL(*mock_remote_processor(), |
789 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) | 791 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) |
790 .WillOnce(PrepareForRemoteChange_NotFound()); | 792 .WillOnce(PrepareForRemoteChange_NotFound()); |
791 | 793 |
792 scoped_ptr<Value> file_entry(LoadJSONFile("gdata/file_entry.json").Pass()); | 794 scoped_ptr<Value> file_entry(LoadJSONFile("gdata/file_entry.json").Pass()); |
793 EXPECT_CALL(*mock_drive_service(), | 795 EXPECT_CALL(*mock_drive_service(), |
794 GetDocumentEntry(kFileResourceId, _)) | 796 GetDocumentEntry(kFileResourceId, _)) |
795 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, | 797 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, |
796 base::Passed(&file_entry))); | 798 base::Passed(&file_entry))); |
797 | 799 |
798 EXPECT_CALL(*mock_drive_service(), | 800 EXPECT_CALL(*mock_drive_service(), |
799 DownloadFile(_, _, GURL("https://file_content_url"), _, _)) | 801 DownloadFile(_, _, GURL("https://file_content_url"), _, _)) |
800 .WillOnce(InvokeDidDownloadFile()); | 802 .WillOnce(InvokeDidDownloadFile()); |
801 | 803 |
802 EXPECT_CALL(*mock_remote_processor(), | 804 EXPECT_CALL(*mock_remote_processor(), |
803 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _)) | 805 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _)) |
804 .WillOnce(InvokeDidApplyRemoteChange()); | 806 .WillOnce(InvokeDidApplyRemoteChange()); |
805 | 807 |
806 SetUpDriveSyncService(); | 808 SetUpDriveSyncService(); |
807 | 809 |
808 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( | 810 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( |
809 *LoadJSONFile("gdata/file_entry.json"))); | 811 *LoadJSONFile("gdata/file_entry.json"))); |
810 AppendIncrementalRemoteChange(kOrigin, entry.get(), 12345); | 812 AppendIncrementalRemoteChange(kOrigin, *entry, 12345); |
811 | 813 |
812 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, | 814 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, |
813 CreateURL(kOrigin, kFileName), | 815 CreateURL(kOrigin, kFileName), |
814 fileapi::SYNC_OPERATION_ADD); | 816 fileapi::SYNC_OPERATION_ADD); |
815 } | 817 } |
816 | 818 |
817 TEST_F(DriveFileSyncServiceTest, RemoteChange_UpdateFile) { | 819 TEST_F(DriveFileSyncServiceTest, RemoteChange_UpdateFile) { |
818 const GURL kOrigin("chrome-extension://example"); | 820 const GURL kOrigin("chrome-extension://example"); |
819 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 821 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
820 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 822 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
821 const FilePath::StringType kFileName(FPL("File 1.mp3")); | 823 const FilePath::StringType kFileName(FPL("File 1.mp3")); |
822 const std::string kFileResourceId("file:2_file_resource_id"); | 824 const std::string kFileResourceId("file:2_file_resource_id"); |
823 | 825 |
824 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 826 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
825 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); | 827 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); |
826 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); | 828 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin); |
827 | 829 |
828 EXPECT_CALL(*mock_remote_observer(), | 830 EXPECT_CALL(*mock_remote_observer(), |
829 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 831 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
830 .Times(AnyNumber()); | 832 .Times(AnyNumber()); |
831 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(_)) | 833 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
832 .Times(AnyNumber()); | 834 .Times(AnyNumber()); |
833 | 835 |
834 EXPECT_CALL(*mock_remote_processor(), | 836 EXPECT_CALL(*mock_remote_processor(), |
835 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) | 837 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), _)) |
836 .WillOnce(PrepareForRemoteChange_NotModified()); | 838 .WillOnce(PrepareForRemoteChange_NotModified()); |
837 | 839 |
838 scoped_ptr<Value> file_entry(LoadJSONFile("gdata/file_entry.json").Pass()); | 840 scoped_ptr<Value> file_entry(LoadJSONFile("gdata/file_entry.json").Pass()); |
839 EXPECT_CALL(*mock_drive_service(), | 841 EXPECT_CALL(*mock_drive_service(), |
840 GetDocumentEntry(kFileResourceId, _)) | 842 GetDocumentEntry(kFileResourceId, _)) |
841 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, | 843 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, |
842 base::Passed(&file_entry))); | 844 base::Passed(&file_entry))); |
843 | 845 |
844 EXPECT_CALL(*mock_drive_service(), | 846 EXPECT_CALL(*mock_drive_service(), |
845 DownloadFile(_, _, GURL("https://file_content_url"), _, _)) | 847 DownloadFile(_, _, GURL("https://file_content_url"), _, _)) |
846 .WillOnce(InvokeDidDownloadFile()); | 848 .WillOnce(InvokeDidDownloadFile()); |
847 | 849 |
848 EXPECT_CALL(*mock_remote_processor(), | 850 EXPECT_CALL(*mock_remote_processor(), |
849 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _)) | 851 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _)) |
850 .WillOnce(InvokeDidApplyRemoteChange()); | 852 .WillOnce(InvokeDidApplyRemoteChange()); |
851 | 853 |
852 SetUpDriveSyncService(); | 854 SetUpDriveSyncService(); |
853 | 855 |
854 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( | 856 scoped_ptr<DocumentEntry> entry(DocumentEntry::ExtractAndParse( |
855 *LoadJSONFile("gdata/file_entry.json"))); | 857 *LoadJSONFile("gdata/file_entry.json"))); |
856 AppendIncrementalRemoteChange(kOrigin, entry.get(), 12345); | 858 AppendIncrementalRemoteChange(kOrigin, *entry, 12345); |
857 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, | 859 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, |
858 CreateURL(kOrigin, kFileName), | 860 CreateURL(kOrigin, kFileName), |
859 fileapi::SYNC_OPERATION_UPDATE); | 861 fileapi::SYNC_OPERATION_UPDATE); |
860 } | 862 } |
861 | 863 |
862 #endif // !defined(OS_ANDROID) | 864 #endif // !defined(OS_ANDROID) |
863 | 865 |
864 } // namespace sync_file_system | 866 } // namespace sync_file_system |
OLD | NEW |