Chromium Code Reviews| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 ASSERT_TRUE(entry.good()); | 188 ASSERT_TRUE(entry.good()); |
| 189 | 189 |
| 190 EXPECT_FALSE(entry.ShouldMaintainPosition()); | 190 EXPECT_FALSE(entry.ShouldMaintainPosition()); |
| 191 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); | 191 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); |
| 192 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); | 192 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); |
| 193 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); | 193 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Test the receipt of a non-bookmark item. | 196 // Test the receipt of a non-bookmark item. |
| 197 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { | 197 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { |
| 198 DirectoryUpdateHandler handler(dir(), PREFERENCES, ui_worker()); | 198 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker()); |
| 199 sync_pb::GetUpdatesResponse gu_response; | 199 sync_pb::GetUpdatesResponse gu_response; |
| 200 sessions::StatusController status; | 200 sessions::StatusController status; |
| 201 | 201 |
| 202 std::string root = syncable::GetNullId().GetServerId(); | 202 std::string root = syncable::GetNullId().GetServerId(); |
| 203 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); | 203 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); |
| 204 scoped_ptr<sync_pb::SyncEntity> e = | 204 scoped_ptr<sync_pb::SyncEntity> e = |
| 205 CreateUpdate(SyncableIdToProto(server_id), root, PREFERENCES); | 205 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); |
| 206 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); | 206 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); |
| 207 | 207 |
| 208 // Add it to the applicable updates list. | 208 // Add it to the applicable updates list. |
| 209 SyncEntityList autofill_updates; | 209 SyncEntityList autofill_updates; |
| 210 autofill_updates.push_back(e.get()); | 210 autofill_updates.push_back(e.get()); |
| 211 | 211 |
| 212 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); | 212 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); |
| 213 | 213 |
| 214 // Process it. | 214 // Process it. |
| 215 UpdateSyncEntities(&handler, autofill_updates, &status); | 215 UpdateSyncEntities(&handler, autofill_updates, &status); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 SYNCED_NOTIFICATIONS); | 276 SYNCED_NOTIFICATIONS); |
| 277 e2->set_version(kDefaultVersion + 100); | 277 e2->set_version(kDefaultVersion + 100); |
| 278 | 278 |
| 279 // Add to the applicable updates list. | 279 // Add to the applicable updates list. |
| 280 SyncEntityList updates; | 280 SyncEntityList updates; |
| 281 updates.push_back(type_root.get()); | 281 updates.push_back(type_root.get()); |
| 282 updates.push_back(e1.get()); | 282 updates.push_back(e1.get()); |
| 283 updates.push_back(e2.get()); | 283 updates.push_back(e2.get()); |
| 284 | 284 |
| 285 // Process and apply updates. | 285 // Process and apply updates. |
| 286 handler.ProcessGetUpdatesResponse(progress, context, updates, &status); | 286 EXPECT_EQ( |
| 287 SYNCER_OK, | |
| 288 handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); | |
| 287 handler.ApplyUpdates(&status); | 289 handler.ApplyUpdates(&status); |
| 288 | 290 |
| 289 // Verify none is deleted because they are unapplied during GC. | 291 // Verify none is deleted because they are unapplied during GC. |
| 290 EXPECT_TRUE(EntryExists(type_root->id_string())); | 292 EXPECT_TRUE(EntryExists(type_root->id_string())); |
| 291 EXPECT_TRUE(EntryExists(e1->id_string())); | 293 EXPECT_TRUE(EntryExists(e1->id_string())); |
| 292 EXPECT_TRUE(EntryExists(e2->id_string())); | 294 EXPECT_TRUE(EntryExists(e2->id_string())); |
| 293 | 295 |
| 294 // Process and apply again. Old entry is deleted but not root. | 296 // Process and apply again. Old entry is deleted but not root. |
| 295 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); | 297 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); |
| 296 handler.ProcessGetUpdatesResponse( | 298 EXPECT_EQ(SYNCER_OK, |
| 297 progress, context, SyncEntityList(), &status); | 299 handler.ProcessGetUpdatesResponse( |
| 300 progress, context, SyncEntityList(), &status)); | |
| 298 handler.ApplyUpdates(&status); | 301 handler.ApplyUpdates(&status); |
| 299 EXPECT_TRUE(EntryExists(type_root->id_string())); | 302 EXPECT_TRUE(EntryExists(type_root->id_string())); |
| 300 EXPECT_FALSE(EntryExists(e1->id_string())); | 303 EXPECT_FALSE(EntryExists(e1->id_string())); |
| 301 EXPECT_TRUE(EntryExists(e2->id_string())); | 304 EXPECT_TRUE(EntryExists(e2->id_string())); |
| 302 } | 305 } |
| 303 | 306 |
| 307 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { | |
| 308 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); | |
| 309 sessions::StatusController status; | |
| 310 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); | |
| 311 | |
| 312 sync_pb::DataTypeProgressMarker progress; | |
| 313 progress.set_data_type_id( | |
| 314 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); | |
| 315 progress.set_token("token"); | |
| 316 | |
| 317 sync_pb::DataTypeContext old_context; | |
| 318 old_context.set_version(1); | |
| 319 old_context.set_context("data"); | |
| 320 old_context.set_data_type_id(field_number); | |
| 321 | |
| 322 scoped_ptr<sync_pb::SyncEntity> type_root = | |
| 323 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), | |
| 324 syncable::GetNullId().GetServerId(), | |
| 325 SYNCED_NOTIFICATIONS); | |
| 326 type_root->set_server_defined_unique_tag( | |
| 327 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); | |
| 328 type_root->set_folder(true); | |
| 329 scoped_ptr<sync_pb::SyncEntity> e1 = | |
| 330 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), | |
| 331 type_root->id_string(), | |
| 332 SYNCED_NOTIFICATIONS); | |
| 333 | |
| 334 SyncEntityList updates; | |
| 335 updates.push_back(type_root.get()); | |
| 336 updates.push_back(e1.get()); | |
| 337 | |
| 338 // The first response should be processed fine. | |
| 339 EXPECT_EQ(SYNCER_OK, | |
| 340 handler.ProcessGetUpdatesResponse( | |
| 341 progress, old_context, updates, &status)); | |
| 342 handler.ApplyUpdates(&status); | |
| 343 | |
| 344 EXPECT_TRUE(EntryExists(type_root->id_string())); | |
| 345 EXPECT_TRUE(EntryExists(e1->id_string())); | |
| 346 | |
| 347 { | |
| 348 sync_pb::DataTypeContext dir_context; | |
| 349 syncable::ReadTransaction trans(FROM_HERE, dir()); | |
| 350 trans.directory()->GetDataTypeContext( | |
| 351 &trans, SYNCED_NOTIFICATIONS, &dir_context); | |
| 352 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); | |
| 353 } | |
| 354 | |
| 355 sync_pb::DataTypeContext new_context; | |
|
rlarocque
2014/04/10 20:02:36
Could this second half be made into a separate tes
Nicolas Zea
2014/04/10 20:44:21
Not really. The first half is mainly setting up th
| |
| 356 new_context.set_version(0); | |
| 357 new_context.set_context("old"); | |
| 358 new_context.set_data_type_id(field_number); | |
| 359 | |
| 360 scoped_ptr<sync_pb::SyncEntity> e2 = | |
| 361 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), | |
| 362 type_root->id_string(), | |
| 363 SYNCED_NOTIFICATIONS); | |
| 364 updates.clear(); | |
| 365 updates.push_back(e2.get()); | |
| 366 | |
| 367 // The second response, with an old context version, should result in an | |
| 368 // error and the updates should be dropped. | |
| 369 EXPECT_EQ(DATATYPE_TRIGGERED_RETRY, | |
| 370 handler.ProcessGetUpdatesResponse( | |
| 371 progress, new_context, updates, &status)); | |
| 372 handler.ApplyUpdates(&status); | |
| 373 | |
| 374 EXPECT_FALSE(EntryExists(e2->id_string())); | |
| 375 | |
| 376 { | |
| 377 sync_pb::DataTypeContext dir_context; | |
| 378 syncable::ReadTransaction trans(FROM_HERE, dir()); | |
| 379 trans.directory()->GetDataTypeContext( | |
| 380 &trans, SYNCED_NOTIFICATIONS, &dir_context); | |
| 381 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); | |
| 382 } | |
| 383 } | |
| 384 | |
| 304 // A test harness for tests that focus on applying updates. | 385 // A test harness for tests that focus on applying updates. |
| 305 // | 386 // |
| 306 // Update application is performed when we want to take updates that were | 387 // Update application is performed when we want to take updates that were |
| 307 // previously downloaded, processed, and stored in our syncable::Directory | 388 // previously downloaded, processed, and stored in our syncable::Directory |
| 308 // and use them to update our local state (both the Directory's local state | 389 // and use them to update our local state (both the Directory's local state |
| 309 // and the model's local state, though these tests focus only on the Directory's | 390 // and the model's local state, though these tests focus only on the Directory's |
| 310 // local state). | 391 // local state). |
| 311 // | 392 // |
| 312 // This is kept separate from the update processing test in part for historical | 393 // This is kept separate from the update processing test in part for historical |
| 313 // reasons, and in part because these tests may require a bit more infrastrcture | 394 // reasons, and in part because these tests may require a bit more infrastrcture |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); | 969 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); |
| 889 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); | 970 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); |
| 890 ASSERT_TRUE(e1.good()); | 971 ASSERT_TRUE(e1.good()); |
| 891 ASSERT_TRUE(e2.good()); | 972 ASSERT_TRUE(e2.good()); |
| 892 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); | 973 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); |
| 893 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); | 974 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); |
| 894 } | 975 } |
| 895 } | 976 } |
| 896 | 977 |
| 897 } // namespace syncer | 978 } // namespace syncer |
| OLD | NEW |