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 12 matching lines...) Expand all Loading... |
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 Loading... |
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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; | 590 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; |
594 | 591 |
595 scoped_ptr<drive::APIUtil> api_util_; | 592 scoped_ptr<drive::APIUtil> api_util_; |
596 scoped_ptr<DriveMetadataStore> metadata_store_; | 593 scoped_ptr<DriveMetadataStore> metadata_store_; |
597 | 594 |
598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); | 595 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); |
599 }; | 596 }; |
600 | 597 |
601 #if !defined(OS_ANDROID) | 598 #if !defined(OS_ANDROID) |
602 | 599 |
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) { | 600 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) { |
645 const GURL kOrigin("chrome-extension://example"); | 601 const GURL kOrigin("chrome-extension://example"); |
646 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 602 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
647 // The root id is in the "sync_root_entry.json" file. | 603 // The root id is in the "sync_root_entry.json" file. |
648 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 604 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
649 | 605 |
650 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 606 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
651 | 607 |
652 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) | 608 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
653 .Times(AnyNumber()); | 609 .Times(AnyNumber()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 699 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
744 | 700 |
745 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 701 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
746 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | 702 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); |
747 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | 703 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); |
748 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | 704 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); |
749 | 705 |
750 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 706 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
751 .Times(AnyNumber()); | 707 .Times(AnyNumber()); |
752 | 708 |
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); | 709 SetUpDriveSyncService(true); |
763 message_loop()->RunUntilIdle(); | 710 message_loop()->RunUntilIdle(); |
764 | 711 |
765 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 712 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
766 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); | 713 EXPECT_EQ(0u, remote_change_handler().ChangesSize()); |
767 | 714 |
768 bool done = false; | 715 bool done = false; |
769 sync_service()->UnregisterOriginForTrackingChanges( | 716 sync_service()->UnregisterOriginForTrackingChanges( |
770 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 717 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
771 message_loop()->RunUntilIdle(); | 718 message_loop()->RunUntilIdle(); |
772 EXPECT_TRUE(done); | 719 EXPECT_TRUE(done); |
773 | 720 |
774 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); | 721 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); |
775 EXPECT_TRUE(!remote_change_handler().HasChanges()); | 722 EXPECT_TRUE(!remote_change_handler().HasChanges()); |
776 } | 723 } |
(...skipping 12 matching lines...) Expand all Loading... |
789 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); | 736 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); |
790 | 737 |
791 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 738 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
792 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | 739 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); |
793 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | 740 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); |
794 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | 741 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); |
795 | 742 |
796 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 743 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
797 .Times(AnyNumber()); | 744 .Times(AnyNumber()); |
798 | 745 |
799 InSequence sequence; | 746 // InSequence sequence; |
800 | 747 // |
801 SetUpDriveServiceExpectCallsForGetAboutResource(); | 748 // SetUpDriveServiceExpectCallsForGetAboutResource(); |
802 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | 749 // SetUpDriveServiceExpectCallsForGetResourceListInDirectory( |
803 "chromeos/sync_file_system/listing_files_in_directory.json", | 750 // "chromeos/sync_file_system/listing_files_in_directory.json", |
804 kDirectoryResourceId1); | 751 // kDirectoryResourceId1); |
805 | 752 // |
806 SetUpDriveServiceExpectCallsForIncrementalSync(); | 753 // SetUpDriveServiceExpectCallsForIncrementalSync(); |
807 | 754 |
808 SetUpDriveSyncService(true); | 755 SetUpDriveSyncService(true); |
809 message_loop()->RunUntilIdle(); | 756 message_loop()->RunUntilIdle(); |
810 | 757 |
811 // [1] Both extensions and origins are enabled. Nothing to do. | 758 // [1] Both extensions and origins are enabled. Nothing to do. |
812 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 759 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
813 UpdateRegisteredOrigins(); | 760 UpdateRegisteredOrigins(); |
814 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 761 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
815 | 762 |
816 DisableExtension(extension_id1); | 763 DisableExtension(extension_id1); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); | 1063 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); |
1117 | 1064 |
1118 // Expect to drop this change for file. | 1065 // Expect to drop this change for file. |
1119 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( | 1066 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( |
1120 kOrigin, *entry, 1)); | 1067 kOrigin, *entry, 1)); |
1121 } | 1068 } |
1122 | 1069 |
1123 #endif // !defined(OS_ANDROID) | 1070 #endif // !defined(OS_ANDROID) |
1124 | 1071 |
1125 } // namespace sync_file_system | 1072 } // namespace sync_file_system |
OLD | NEW |