OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <map> | 10 #include <map> |
(...skipping 2890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2901 ModelTypeSet protocol_types = ProtocolTypes(); | 2901 ModelTypeSet protocol_types = ProtocolTypes(); |
2902 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2902 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
2903 iter.Inc()) { | 2903 iter.Inc()) { |
2904 SetProgressMarkerForType(iter.Get(), true); | 2904 SetProgressMarkerForType(iter.Get(), true); |
2905 } | 2905 } |
2906 | 2906 |
2907 CallbackCounter ready_task_counter, retry_task_counter; | 2907 CallbackCounter ready_task_counter, retry_task_counter; |
2908 sync_manager_.ConfigureSyncer( | 2908 sync_manager_.ConfigureSyncer( |
2909 reason, | 2909 reason, |
2910 types_to_download, | 2910 types_to_download, |
2911 ModelTypeSet(), | 2911 disabled_types, |
2912 ModelTypeSet(), | 2912 ModelTypeSet(), |
2913 ModelTypeSet(), | 2913 ModelTypeSet(), |
2914 new_routing_info, | 2914 new_routing_info, |
2915 base::Bind(&CallbackCounter::Callback, | 2915 base::Bind(&CallbackCounter::Callback, |
2916 base::Unretained(&ready_task_counter)), | 2916 base::Unretained(&ready_task_counter)), |
2917 base::Bind(&CallbackCounter::Callback, | 2917 base::Bind(&CallbackCounter::Callback, |
2918 base::Unretained(&retry_task_counter))); | 2918 base::Unretained(&retry_task_counter))); |
2919 EXPECT_EQ(0, ready_task_counter.times_called()); | 2919 EXPECT_EQ(0, ready_task_counter.times_called()); |
2920 EXPECT_EQ(0, retry_task_counter.times_called()); | 2920 EXPECT_EQ(0, retry_task_counter.times_called()); |
2921 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 2921 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 | 3106 |
3107 // Set progress markers for all types. | 3107 // Set progress markers for all types. |
3108 ModelTypeSet protocol_types = ProtocolTypes(); | 3108 ModelTypeSet protocol_types = ProtocolTypes(); |
3109 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 3109 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
3110 iter.Inc()) { | 3110 iter.Inc()) { |
3111 SetProgressMarkerForType(iter.Get(), true); | 3111 SetProgressMarkerForType(iter.Get(), true); |
3112 } | 3112 } |
3113 | 3113 |
3114 // Verify all the enabled types remain after cleanup, and all the disabled | 3114 // Verify all the enabled types remain after cleanup, and all the disabled |
3115 // types were purged. | 3115 // types were purged. |
3116 sync_manager_.PurgeDisabledTypes(ModelTypeSet::All(), | 3116 sync_manager_.PurgeDisabledTypes(disabled_types, |
3117 enabled_types, | |
3118 ModelTypeSet(), | 3117 ModelTypeSet(), |
3119 ModelTypeSet()); | 3118 ModelTypeSet()); |
3120 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); | 3119 EXPECT_TRUE(enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); |
3121 EXPECT_TRUE(disabled_types.Equals( | 3120 EXPECT_TRUE(disabled_types.Equals( |
3122 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 3121 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
3123 | 3122 |
3124 // Disable some more types. | 3123 // Disable some more types. |
3125 disabled_types.Put(BOOKMARKS); | 3124 disabled_types.Put(BOOKMARKS); |
3126 disabled_types.Put(PREFERENCES); | 3125 disabled_types.Put(PREFERENCES); |
3127 ModelTypeSet new_enabled_types = | 3126 ModelTypeSet new_enabled_types = |
3128 Difference(ModelTypeSet::All(), disabled_types); | 3127 Difference(ModelTypeSet::All(), disabled_types); |
3129 | 3128 |
3130 // Verify only the non-disabled types remain after cleanup. | 3129 // Verify only the non-disabled types remain after cleanup. |
3131 sync_manager_.PurgeDisabledTypes(enabled_types, | 3130 sync_manager_.PurgeDisabledTypes(disabled_types, |
3132 new_enabled_types, | |
3133 ModelTypeSet(), | 3131 ModelTypeSet(), |
3134 ModelTypeSet()); | 3132 ModelTypeSet()); |
3135 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); | 3133 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); |
3136 EXPECT_TRUE(disabled_types.Equals( | 3134 EXPECT_TRUE(disabled_types.Equals( |
3137 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 3135 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
3138 } | 3136 } |
3139 | 3137 |
3140 // Test PurgeDisabledTypes properly unapplies types by deleting their local data | 3138 // Test PurgeDisabledTypes properly unapplies types by deleting their local data |
3141 // and preserving their server data and progress marker. | 3139 // and preserving their server data and progress marker. |
3142 TEST_F(SyncManagerTest, PurgeUnappliedTypes) { | 3140 TEST_F(SyncManagerTest, PurgeUnappliedTypes) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3200 pref5.Put(syncable::IS_DEL, true); | 3198 pref5.Put(syncable::IS_DEL, true); |
3201 pref5.Put(syncable::BASE_VERSION, -1); | 3199 pref5.Put(syncable::BASE_VERSION, -1); |
3202 // Bookmark is already set up properly | 3200 // Bookmark is already set up properly |
3203 } | 3201 } |
3204 | 3202 |
3205 // Take a snapshot to clear all the dirty bits. | 3203 // Take a snapshot to clear all the dirty bits. |
3206 share->directory.get()->SaveChanges(); | 3204 share->directory.get()->SaveChanges(); |
3207 | 3205 |
3208 // Now request a purge for the unapplied types. | 3206 // Now request a purge for the unapplied types. |
3209 disabled_types.PutAll(unapplied_types); | 3207 disabled_types.PutAll(unapplied_types); |
3210 ModelTypeSet new_enabled_types = | 3208 sync_manager_.PurgeDisabledTypes(disabled_types, |
3211 Difference(ModelTypeSet::All(), disabled_types); | |
3212 sync_manager_.PurgeDisabledTypes(enabled_types, | |
3213 new_enabled_types, | |
3214 ModelTypeSet(), | 3209 ModelTypeSet(), |
3215 unapplied_types); | 3210 unapplied_types); |
3216 | 3211 |
3217 // Verify the unapplied types still have progress markers and initial sync | 3212 // Verify the unapplied types still have progress markers and initial sync |
3218 // ended after cleanup. | 3213 // ended after cleanup. |
3219 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().HasAll(unapplied_types)); | 3214 EXPECT_TRUE(sync_manager_.InitialSyncEndedTypes().HasAll(unapplied_types)); |
3220 EXPECT_TRUE( | 3215 EXPECT_TRUE( |
3221 sync_manager_.GetTypesWithEmptyProgressMarkerToken(unapplied_types). | 3216 sync_manager_.GetTypesWithEmptyProgressMarkerToken(unapplied_types). |
3222 Empty()); | 3217 Empty()); |
3223 | 3218 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3575 size_t folder_b_pos = | 3570 size_t folder_b_pos = |
3576 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3571 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
3577 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3572 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
3578 | 3573 |
3579 // Deletes should appear before updates. | 3574 // Deletes should appear before updates. |
3580 EXPECT_LT(child_pos, folder_a_pos); | 3575 EXPECT_LT(child_pos, folder_a_pos); |
3581 EXPECT_LT(folder_b_pos, folder_a_pos); | 3576 EXPECT_LT(folder_b_pos, folder_a_pos); |
3582 } | 3577 } |
3583 | 3578 |
3584 } // namespace | 3579 } // namespace |
OLD | NEW |