| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/engine/directory_update_handler.h" | 5 #include "sync/engine/directory_update_handler.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "sync/engine/syncer_proto_util.h" | 10 #include "sync/engine/syncer_proto_util.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { | 244 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { |
| 245 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); | 245 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); |
| 246 sessions::StatusController status; | 246 sessions::StatusController status; |
| 247 | 247 |
| 248 sync_pb::DataTypeProgressMarker progress; | 248 sync_pb::DataTypeProgressMarker progress; |
| 249 progress.set_data_type_id( | 249 progress.set_data_type_id( |
| 250 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); | 250 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); |
| 251 progress.set_token("token"); | 251 progress.set_token("token"); |
| 252 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); | 252 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); |
| 253 | 253 |
| 254 sync_pb::DataTypeContext context; |
| 255 context.set_data_type_id( |
| 256 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); |
| 257 context.set_context("context"); |
| 258 context.set_version(1); |
| 259 |
| 254 scoped_ptr<sync_pb::SyncEntity> type_root = | 260 scoped_ptr<sync_pb::SyncEntity> type_root = |
| 255 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), | 261 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), |
| 256 syncable::GetNullId().GetServerId(), | 262 syncable::GetNullId().GetServerId(), |
| 257 SYNCED_NOTIFICATIONS); | 263 SYNCED_NOTIFICATIONS); |
| 258 type_root->set_server_defined_unique_tag( | 264 type_root->set_server_defined_unique_tag( |
| 259 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); | 265 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); |
| 260 type_root->set_folder(true); | 266 type_root->set_folder(true); |
| 261 | 267 |
| 262 scoped_ptr<sync_pb::SyncEntity> e1 = | 268 scoped_ptr<sync_pb::SyncEntity> e1 = |
| 263 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), | 269 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), |
| 264 type_root->id_string(), | 270 type_root->id_string(), |
| 265 SYNCED_NOTIFICATIONS); | 271 SYNCED_NOTIFICATIONS); |
| 266 | 272 |
| 267 scoped_ptr<sync_pb::SyncEntity> e2 = | 273 scoped_ptr<sync_pb::SyncEntity> e2 = |
| 268 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), | 274 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), |
| 269 type_root->id_string(), | 275 type_root->id_string(), |
| 270 SYNCED_NOTIFICATIONS); | 276 SYNCED_NOTIFICATIONS); |
| 271 e2->set_version(kDefaultVersion + 100); | 277 e2->set_version(kDefaultVersion + 100); |
| 272 | 278 |
| 273 // Add to the applicable updates list. | 279 // Add to the applicable updates list. |
| 274 SyncEntityList updates; | 280 SyncEntityList updates; |
| 275 updates.push_back(type_root.get()); | 281 updates.push_back(type_root.get()); |
| 276 updates.push_back(e1.get()); | 282 updates.push_back(e1.get()); |
| 277 updates.push_back(e2.get()); | 283 updates.push_back(e2.get()); |
| 278 | 284 |
| 279 // Process and apply updates. | 285 // Process and apply updates. |
| 280 handler.ProcessGetUpdatesResponse(progress, updates, &status); | 286 handler.ProcessGetUpdatesResponse(progress, context, updates, &status); |
| 281 handler.ApplyUpdates(&status); | 287 handler.ApplyUpdates(&status); |
| 282 | 288 |
| 283 // Verify none is deleted because they are unapplied during GC. | 289 // Verify none is deleted because they are unapplied during GC. |
| 284 EXPECT_TRUE(EntryExists(type_root->id_string())); | 290 EXPECT_TRUE(EntryExists(type_root->id_string())); |
| 285 EXPECT_TRUE(EntryExists(e1->id_string())); | 291 EXPECT_TRUE(EntryExists(e1->id_string())); |
| 286 EXPECT_TRUE(EntryExists(e2->id_string())); | 292 EXPECT_TRUE(EntryExists(e2->id_string())); |
| 287 | 293 |
| 288 // Process and apply again. Old entry is deleted but not root. | 294 // Process and apply again. Old entry is deleted but not root. |
| 289 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); | 295 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); |
| 290 handler.ProcessGetUpdatesResponse(progress, SyncEntityList(), &status); | 296 handler.ProcessGetUpdatesResponse( |
| 297 progress, context, SyncEntityList(), &status); |
| 291 handler.ApplyUpdates(&status); | 298 handler.ApplyUpdates(&status); |
| 292 EXPECT_TRUE(EntryExists(type_root->id_string())); | 299 EXPECT_TRUE(EntryExists(type_root->id_string())); |
| 293 EXPECT_FALSE(EntryExists(e1->id_string())); | 300 EXPECT_FALSE(EntryExists(e1->id_string())); |
| 294 EXPECT_TRUE(EntryExists(e2->id_string())); | 301 EXPECT_TRUE(EntryExists(e2->id_string())); |
| 295 } | 302 } |
| 296 | 303 |
| 297 // A test harness for tests that focus on applying updates. | 304 // A test harness for tests that focus on applying updates. |
| 298 // | 305 // |
| 299 // Update application is performed when we want to take updates that were | 306 // Update application is performed when we want to take updates that were |
| 300 // previously downloaded, processed, and stored in our syncable::Directory | 307 // previously downloaded, processed, and stored in our syncable::Directory |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); | 888 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); |
| 882 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); | 889 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); |
| 883 ASSERT_TRUE(e1.good()); | 890 ASSERT_TRUE(e1.good()); |
| 884 ASSERT_TRUE(e2.good()); | 891 ASSERT_TRUE(e2.good()); |
| 885 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); | 892 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); |
| 886 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); | 893 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); |
| 887 } | 894 } |
| 888 } | 895 } |
| 889 | 896 |
| 890 } // namespace syncer | 897 } // namespace syncer |
| OLD | NEW |