OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_backend/metadata_database.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace drive_backend { | 21 namespace drive_backend { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 typedef MetadataDatabase::FileIDList FileIDList; | 25 typedef MetadataDatabase::FileIDList FileIDList; |
26 | 26 |
27 const int64 kInitialChangeID = 1234; | 27 const int64 kInitialChangeID = 1234; |
28 const int64 kSyncRootTrackerID = 100; | 28 const int64 kSyncRootTrackerID = 100; |
29 const char kSyncRootFolderID[] = "sync_root_folder_id"; | 29 const char kSyncRootFolderID[] = "sync_root_folder_id"; |
30 | 30 |
| 31 // This struct is used to setup initial state of the database in the test and |
| 32 // also used to match to the modified content of the database as the |
| 33 // expectation. |
31 struct TrackedFile { | 34 struct TrackedFile { |
| 35 // Holds the latest remote metadata which may be not-yet-synced to |tracker|. |
32 FileMetadata metadata; | 36 FileMetadata metadata; |
33 FileTracker tracker; | 37 FileTracker tracker; |
34 | 38 |
35 // Implies the file should not in the database. | 39 // Implies the file should not in the database. |
36 bool should_be_absent; | 40 bool should_be_absent; |
37 | 41 |
38 // Implies the file should have a tracker in the database but should have no | 42 // Implies the file should have a tracker in the database but should have no |
39 // metadata. | 43 // metadata. |
40 bool tracker_only; | 44 bool tracker_only; |
41 | 45 |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 582 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
579 metadata_database_->UpdateByChangeList( | 583 metadata_database_->UpdateByChangeList( |
580 changes.Pass(), base::Bind(&SyncStatusResultCallback, &status)); | 584 changes.Pass(), base::Bind(&SyncStatusResultCallback, &status)); |
581 message_loop_.RunUntilIdle(); | 585 message_loop_.RunUntilIdle(); |
582 return status; | 586 return status; |
583 } | 587 } |
584 | 588 |
585 SyncStatusCode PopulateFolder(const std::string& folder_id, | 589 SyncStatusCode PopulateFolder(const std::string& folder_id, |
586 const FileIDList& listed_children) { | 590 const FileIDList& listed_children) { |
587 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 591 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
588 metadata_database_->PopulateFolder( | 592 metadata_database_->PopulateFolderByChildList( |
589 folder_id, listed_children, | 593 folder_id, listed_children, |
590 base::Bind(&SyncStatusResultCallback, &status)); | 594 base::Bind(&SyncStatusResultCallback, &status)); |
591 message_loop_.RunUntilIdle(); | 595 message_loop_.RunUntilIdle(); |
592 return status; | 596 return status; |
593 } | 597 } |
594 | 598 |
| 599 SyncStatusCode UpdateTracker(const FileTracker& tracker) { |
| 600 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 601 metadata_database_->UpdateTracker( |
| 602 tracker.tracker_id(), tracker.synced_details(), |
| 603 base::Bind(&SyncStatusResultCallback, &status)); |
| 604 message_loop_.RunUntilIdle(); |
| 605 return status; |
| 606 } |
| 607 |
595 private: | 608 private: |
596 base::ScopedTempDir database_dir_; | 609 base::ScopedTempDir database_dir_; |
597 base::MessageLoop message_loop_; | 610 base::MessageLoop message_loop_; |
598 | 611 |
599 scoped_ptr<MetadataDatabase> metadata_database_; | 612 scoped_ptr<MetadataDatabase> metadata_database_; |
600 | 613 |
601 int64 next_change_id_; | 614 int64 next_change_id_; |
602 int64 next_tracker_id_; | 615 int64 next_tracker_id_; |
603 int64 next_file_id_number_; | 616 int64 next_file_id_number_; |
604 int64 next_md5_sequence_number_; | 617 int64 next_md5_sequence_number_; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 file.tracker.set_active(false); | 914 file.tracker.set_active(false); |
902 file.should_be_absent = false; | 915 file.should_be_absent = false; |
903 file.tracker_only = true; | 916 file.tracker_only = true; |
904 | 917 |
905 disabled_app_root.tracker.set_dirty(false); | 918 disabled_app_root.tracker.set_dirty(false); |
906 disabled_app_root.tracker.set_needs_folder_listing(false); | 919 disabled_app_root.tracker.set_needs_folder_listing(false); |
907 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | 920 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
908 VerifyReloadConsistency(); | 921 VerifyReloadConsistency(); |
909 } | 922 } |
910 | 923 |
| 924 TEST_F(MetadataDatabaseTest, UpdateTrackerTest) { |
| 925 TrackedFile sync_root(CreateTrackedSyncRoot()); |
| 926 TrackedFile app_root(CreateTrackedAppRoot(sync_root, "app_root")); |
| 927 TrackedFile file(CreateTrackedFile(app_root, "file")); |
| 928 file.tracker.set_dirty(true); |
| 929 file.metadata.mutable_details()->set_title("renamed file");; |
| 930 |
| 931 TrackedFile inactive_file(CreateTrackedFile(app_root, "inactive_file")); |
| 932 inactive_file.tracker.set_active(false); |
| 933 inactive_file.tracker.set_dirty(true); |
| 934 inactive_file.metadata.mutable_details()->set_title("renamed inactive file"); |
| 935 inactive_file.metadata.mutable_details()->set_md5("modified_md5"); |
| 936 |
| 937 TrackedFile new_conflict(CreateTrackedFile(app_root, "new conflict file")); |
| 938 new_conflict.tracker.set_dirty(true); |
| 939 new_conflict.metadata.mutable_details()->set_title("renamed file"); |
| 940 |
| 941 const TrackedFile* tracked_files[] = { |
| 942 &sync_root, &app_root, &file, &inactive_file, &new_conflict |
| 943 }; |
| 944 |
| 945 SetUpDatabaseByTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 946 EXPECT_EQ(SYNC_STATUS_OK, InitializeMetadataDatabase()); |
| 947 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 948 VerifyReloadConsistency(); |
| 949 |
| 950 *file.tracker.mutable_synced_details() = file.metadata.details(); |
| 951 file.tracker.set_dirty(false); |
| 952 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(file.tracker)); |
| 953 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 954 VerifyReloadConsistency(); |
| 955 |
| 956 *inactive_file.tracker.mutable_synced_details() = |
| 957 inactive_file.metadata.details(); |
| 958 inactive_file.tracker.set_dirty(false); |
| 959 inactive_file.tracker.set_active(true); |
| 960 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(inactive_file.tracker)); |
| 961 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 962 VerifyReloadConsistency(); |
| 963 |
| 964 *new_conflict.tracker.mutable_synced_details() = |
| 965 new_conflict.metadata.details(); |
| 966 new_conflict.tracker.set_dirty(false); |
| 967 new_conflict.tracker.set_active(true); |
| 968 file.tracker.set_dirty(true); |
| 969 file.tracker.set_active(false); |
| 970 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(new_conflict.tracker)); |
| 971 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 972 VerifyReloadConsistency(); |
| 973 } |
| 974 |
911 } // namespace drive_backend | 975 } // namespace drive_backend |
912 } // namespace sync_file_system | 976 } // namespace sync_file_system |
OLD | NEW |