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

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

Issue 15023022: Add to be fetched files instead of DriveMetadataStore.batch_sync_origins_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tzik review #2 Created 7 years, 7 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 | 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_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 12 matching lines...) Expand all
23 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h" 23 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h"
24 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" 24 #include "chrome/browser/sync_file_system/sync_file_system.pb.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "chrome/common/extensions/extension_builder.h" 26 #include "chrome/common/extensions/extension_builder.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
29 #include "extensions/common/id_util.h" 29 #include "extensions/common/id_util.h"
30 #include "net/base/escape.h" 30 #include "net/base/escape.h"
31 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "webkit/fileapi/file_system_util.h"
33 #include "webkit/fileapi/syncable/sync_direction.h" 34 #include "webkit/fileapi/syncable/sync_direction.h"
34 #include "webkit/fileapi/syncable/sync_file_metadata.h" 35 #include "webkit/fileapi/syncable/sync_file_metadata.h"
35 #include "webkit/fileapi/syncable/syncable_file_system_util.h" 36 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
36 37
37 #if defined(OS_CHROMEOS) 38 #if defined(OS_CHROMEOS)
38 #include "chrome/browser/chromeos/login/user_manager.h" 39 #include "chrome/browser/chromeos/login/user_manager.h"
39 #include "chrome/browser/chromeos/settings/cros_settings.h" 40 #include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/chromeos/settings/device_settings_service.h" 41 #include "chrome/browser/chromeos/settings/device_settings_service.h"
41 #endif 42 #endif
42 43
(...skipping 29 matching lines...) Expand all
72 return base::FilePath().AppendASCII(path).value(); 73 return base::FilePath().AppendASCII(path).value();
73 } 74 }
74 75
75 void DidInitialize(bool* done, SyncStatusCode status, bool created) { 76 void DidInitialize(bool* done, SyncStatusCode status, bool created) {
76 EXPECT_FALSE(*done); 77 EXPECT_FALSE(*done);
77 *done = true; 78 *done = true;
78 EXPECT_EQ(SYNC_STATUS_OK, status); 79 EXPECT_EQ(SYNC_STATUS_OK, status);
79 EXPECT_TRUE(created); 80 EXPECT_TRUE(created);
80 } 81 }
81 82
82 void DidUpdateEntry(SyncStatusCode status) {
83 EXPECT_EQ(SYNC_STATUS_OK, status);
84 }
85
86 void DidGetSyncRoot(bool* done, 83 void DidGetSyncRoot(bool* done,
87 SyncStatusCode status, 84 SyncStatusCode status,
88 const std::string& resource_id) { 85 const std::string& resource_id) {
89 EXPECT_FALSE(*done); 86 EXPECT_FALSE(*done);
90 *done = true; 87 *done = true;
91 } 88 }
92 89
93 void ExpectEqStatus(bool* done, 90 void ExpectEqStatus(bool* done,
94 SyncStatusCode expected, 91 SyncStatusCode expected,
95 SyncStatusCode actual) { 92 SyncStatusCode actual) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 StrictMock<MockFileStatusObserver>* mock_file_status_observer() { 378 StrictMock<MockFileStatusObserver>* mock_file_status_observer() {
382 return &mock_file_status_observer_; 379 return &mock_file_status_observer_;
383 } 380 }
384 381
385 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { 382 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() {
386 return &mock_remote_processor_; 383 return &mock_remote_processor_;
387 } 384 }
388 385
389 MessageLoop* message_loop() { return &message_loop_; } 386 MessageLoop* message_loop() { return &message_loop_; }
390 DriveFileSyncService* sync_service() { return sync_service_.get(); } 387 DriveFileSyncService* sync_service() { return sync_service_.get(); }
388 std::map<GURL, std::string> pending_batch_sync_origins() {
389 return sync_service_->pending_batch_sync_origins_;
390 }
391 391
392 const RemoteChangeHandler& remote_change_handler() const { 392 const RemoteChangeHandler& remote_change_handler() const {
393 return sync_service_->remote_change_handler_; 393 return sync_service_->remote_change_handler_;
394 } 394 }
395 395
396 fileapi::FileSystemURL CreateURL(const GURL& origin, 396 fileapi::FileSystemURL CreateURL(const GURL& origin,
397 const base::FilePath::StringType& path) { 397 const base::FilePath::StringType& path) {
398 return CreateSyncableFileSystemURL( 398 return CreateSyncableFileSystemURL(
399 origin, kServiceName, base::FilePath(path)); 399 origin, kServiceName, base::FilePath(path));
400 } 400 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; 593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_;
594 594
595 scoped_ptr<drive::APIUtil> api_util_; 595 scoped_ptr<drive::APIUtil> api_util_;
596 scoped_ptr<DriveMetadataStore> metadata_store_; 596 scoped_ptr<DriveMetadataStore> metadata_store_;
597 597
598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); 598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest);
599 }; 599 };
600 600
601 #if !defined(OS_ANDROID) 601 #if !defined(OS_ANDROID)
602 602
603 TEST_F(DriveFileSyncServiceMockTest, BatchSyncOnInitialization) {
604 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1"));
605 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2"));
606 const std::string kDirectoryResourceId1(
607 "folder:origin_directory_resource_id");
608 const std::string kDirectoryResourceId2(
609 "folder:origin_directory_resource_id2");
610 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
611
612 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
613 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1);
614 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2);
615 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
616
617 Sequence change_queue_seq;
618 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0))
619 .InSequence(change_queue_seq);
620 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(1))
621 .Times(AnyNumber())
622 .InSequence(change_queue_seq);
623
624 SetUpDriveServiceExpectCallsForGetAboutResource();
625 SetUpDriveServiceExpectCallsForGetResourceListInDirectory(
626 "chromeos/sync_file_system/listing_files_in_directory.json",
627 kDirectoryResourceId1);
628
629 // The service will get called for incremental sync at the end after
630 // batch sync's done.
631 SetUpDriveServiceExpectCallsForIncrementalSync();
632
633 SetUpDriveSyncService(true);
634 message_loop()->RunUntilIdle();
635
636 // kOrigin1 should be a batch sync origin and kOrigin2 should be an
637 // incremental sync origin.
638 // 4 pending remote changes are from listing_files_in_directory as batch sync
639 // changes.
640 VerifySizeOfRegisteredOrigins(1u, 1u, 0u);
641 EXPECT_EQ(1u, remote_change_handler().ChangesSize());
642 }
643
644 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) { 603 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) {
645 const GURL kOrigin("chrome-extension://example"); 604 const GURL kOrigin("chrome-extension://example");
646 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 605 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
647 // The root id is in the "sync_root_entry.json" file. 606 // The root id is in the "sync_root_entry.json" file.
648 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 607 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
649 608
650 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 609 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
651 610
652 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) 611 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0))
653 .Times(AnyNumber()); 612 .Times(AnyNumber());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 "chromeos/sync_file_system/listing_files_in_directory.json", 678 "chromeos/sync_file_system/listing_files_in_directory.json",
720 kDirectoryResourceId); 679 kDirectoryResourceId);
721 680
722 SetUpDriveSyncService(true); 681 SetUpDriveSyncService(true);
723 bool done = false; 682 bool done = false;
724 sync_service()->RegisterOriginForTrackingChanges( 683 sync_service()->RegisterOriginForTrackingChanges(
725 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 684 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
726 message_loop()->RunUntilIdle(); 685 message_loop()->RunUntilIdle();
727 EXPECT_TRUE(done); 686 EXPECT_TRUE(done);
728 687
729 // The origin should be registered as a batch sync origin. 688 // The origin should be registered as an incremental sync origin.
730 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 689 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
731 690
732 // |listing_files_in_directory| contains 4 items to sync. 691 // |listing_files_in_directory| contains 4 items to sync.
733 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); 692 EXPECT_EQ(1u, remote_change_handler().ChangesSize());
734 } 693 }
735 694
736 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) { 695 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) {
737 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); 696 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1"));
738 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); 697 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2"));
739 const std::string kDirectoryResourceId1( 698 const std::string kDirectoryResourceId1(
740 "folder:origin_directory_resource_id"); 699 "folder:origin_directory_resource_id");
741 const std::string kDirectoryResourceId2( 700 const std::string kDirectoryResourceId2(
742 "folder:origin_directory_resource_id2"); 701 "folder:origin_directory_resource_id2");
743 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 702 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
744 703
745 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 704 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
746 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); 705 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1);
747 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); 706 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2);
748 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); 707 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
749 708
750 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 709 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
751 .Times(AnyNumber()); 710 .Times(AnyNumber());
752 711
753 InSequence sequence;
754
755 SetUpDriveServiceExpectCallsForGetAboutResource();
756 SetUpDriveServiceExpectCallsForGetResourceListInDirectory(
757 "chromeos/sync_file_system/listing_files_in_directory.json",
758 kDirectoryResourceId1);
759
760 SetUpDriveServiceExpectCallsForIncrementalSync();
761
762 SetUpDriveSyncService(true); 712 SetUpDriveSyncService(true);
763 message_loop()->RunUntilIdle(); 713 message_loop()->RunUntilIdle();
764 714
765 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); 715 VerifySizeOfRegisteredOrigins(1u, 1u, 0u);
766 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); 716 EXPECT_EQ(0u, remote_change_handler().ChangesSize());
767 717
768 bool done = false; 718 bool done = false;
769 sync_service()->UnregisterOriginForTrackingChanges( 719 sync_service()->UnregisterOriginForTrackingChanges(
770 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 720 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
771 message_loop()->RunUntilIdle(); 721 message_loop()->RunUntilIdle();
772 EXPECT_TRUE(done); 722 EXPECT_TRUE(done);
773 723
774 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); 724 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
775 EXPECT_TRUE(!remote_change_handler().HasChanges()); 725 EXPECT_TRUE(!remote_change_handler().HasChanges());
776 } 726 }
(...skipping 12 matching lines...) Expand all
789 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); 739 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2")));
790 740
791 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 741 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
792 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); 742 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1);
793 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); 743 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2);
794 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); 744 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
795 745
796 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 746 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
797 .Times(AnyNumber()); 747 .Times(AnyNumber());
798 748
799 InSequence sequence;
800
801 SetUpDriveServiceExpectCallsForGetAboutResource();
802 SetUpDriveServiceExpectCallsForGetResourceListInDirectory(
803 "chromeos/sync_file_system/listing_files_in_directory.json",
804 kDirectoryResourceId1);
805
806 SetUpDriveServiceExpectCallsForIncrementalSync();
807
808 SetUpDriveSyncService(true); 749 SetUpDriveSyncService(true);
809 message_loop()->RunUntilIdle(); 750 message_loop()->RunUntilIdle();
810 751
811 // [1] Both extensions and origins are enabled. Nothing to do. 752 // [1] Both extensions and origins are enabled. Nothing to do.
812 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); 753 VerifySizeOfRegisteredOrigins(1u, 1u, 0u);
813 UpdateRegisteredOrigins(); 754 UpdateRegisteredOrigins();
814 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); 755 VerifySizeOfRegisteredOrigins(1u, 1u, 0u);
815 756
816 DisableExtension(extension_id1); 757 DisableExtension(extension_id1);
817 DisableExtension(extension_id2); 758 DisableExtension(extension_id2);
(...skipping 23 matching lines...) Expand all
841 DeleteResource(kDirectoryResourceId2, _, _)) 782 DeleteResource(kDirectoryResourceId2, _, _))
842 .WillOnce(InvokeEntryActionCallback(google_apis::HTTP_SUCCESS)); 783 .WillOnce(InvokeEntryActionCallback(google_apis::HTTP_SUCCESS));
843 SetUpDriveServiceExpectCallsForGetAboutResource(); 784 SetUpDriveServiceExpectCallsForGetAboutResource();
844 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( 785 SetUpDriveServiceExpectCallsForGetResourceListInDirectory(
845 "chromeos/sync_file_system/listing_files_in_directory.json", 786 "chromeos/sync_file_system/listing_files_in_directory.json",
846 kDirectoryResourceId1); 787 kDirectoryResourceId1);
847 788
848 // [5] |kOrigin2| should be unregistered since its extension was uninstalled. 789 // [5] |kOrigin2| should be unregistered since its extension was uninstalled.
849 VerifySizeOfRegisteredOrigins(2u, 0u, 0u); 790 VerifySizeOfRegisteredOrigins(2u, 0u, 0u);
850 UpdateRegisteredOrigins(); 791 UpdateRegisteredOrigins();
851 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 792 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
852 } 793 }
853 794
854 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) { 795 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) {
855 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 796 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
856 797
857 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 798 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
858 799
859 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 800 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
860 .Times(AnyNumber()); 801 .Times(AnyNumber());
861 802
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 962
1022 SetUpDriveSyncService(false); 963 SetUpDriveSyncService(false);
1023 bool done = false; 964 bool done = false;
1024 sync_service()->RegisterOriginForTrackingChanges( 965 sync_service()->RegisterOriginForTrackingChanges(
1025 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 966 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
1026 message_loop()->RunUntilIdle(); 967 message_loop()->RunUntilIdle();
1027 EXPECT_TRUE(done); 968 EXPECT_TRUE(done);
1028 969
1029 // We must not have started batch sync for the newly registered origin, 970 // We must not have started batch sync for the newly registered origin,
1030 // so it should still be in the batch_sync_origins. 971 // so it should still be in the batch_sync_origins.
1031 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 972 EXPECT_EQ(1u, pending_batch_sync_origins().size());
1032 EXPECT_TRUE(!remote_change_handler().HasChanges()); 973 EXPECT_TRUE(!remote_change_handler().HasChanges());
1033 } 974 }
1034 975
1035 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) { 976 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) {
1036 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 977 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
1037 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 978 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
1038 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 979 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
1039 const base::FilePath kFilePath(FPL("File 1.mp3")); 980 const base::FilePath kFilePath(FPL("File 1.mp3"));
1040 const std::string kFileResourceId("file:2_file_resource_id"); 981 const std::string kFileResourceId("file:2_file_resource_id");
1041 const std::string kFileResourceId2("file:2_file_resource_id_2"); 982 const std::string kFileResourceId2("file:2_file_resource_id_2");
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); 1057 entry->set_kind(google_apis::ENTRY_KIND_FOLDER);
1117 1058
1118 // Expect to drop this change for file. 1059 // Expect to drop this change for file.
1119 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( 1060 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry(
1120 kOrigin, *entry, 1)); 1061 kOrigin, *entry, 1));
1121 } 1062 }
1122 1063
1123 #endif // !defined(OS_ANDROID) 1064 #endif // !defined(OS_ANDROID)
1124 1065
1125 } // namespace sync_file_system 1066 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698