diff options
Diffstat (limited to 'sync/engine/directory_update_handler_unittest.cc')
-rw-r--r-- | sync/engine/directory_update_handler_unittest.cc | 91 |
1 files changed, 86 insertions, 5 deletions
diff --git a/sync/engine/directory_update_handler_unittest.cc b/sync/engine/directory_update_handler_unittest.cc index 6d1b35a..ec8cc35 100644 --- a/sync/engine/directory_update_handler_unittest.cc +++ b/sync/engine/directory_update_handler_unittest.cc @@ -195,14 +195,14 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, // Test the receipt of a non-bookmark item. TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { - DirectoryUpdateHandler handler(dir(), PREFERENCES, ui_worker()); + DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker()); sync_pb::GetUpdatesResponse gu_response; sessions::StatusController status; std::string root = syncable::GetNullId().GetServerId(); syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); scoped_ptr<sync_pb::SyncEntity> e = - CreateUpdate(SyncableIdToProto(server_id), root, PREFERENCES); + CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); // Add it to the applicable updates list. @@ -283,7 +283,9 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { updates.push_back(e2.get()); // Process and apply updates. - handler.ProcessGetUpdatesResponse(progress, context, updates, &status); + EXPECT_EQ( + SYNCER_OK, + handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); handler.ApplyUpdates(&status); // Verify none is deleted because they are unapplied during GC. @@ -293,14 +295,93 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { // Process and apply again. Old entry is deleted but not root. progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); - handler.ProcessGetUpdatesResponse( - progress, context, SyncEntityList(), &status); + EXPECT_EQ(SYNCER_OK, + handler.ProcessGetUpdatesResponse( + progress, context, SyncEntityList(), &status)); handler.ApplyUpdates(&status); EXPECT_TRUE(EntryExists(type_root->id_string())); EXPECT_FALSE(EntryExists(e1->id_string())); EXPECT_TRUE(EntryExists(e2->id_string())); } +TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { + DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); + sessions::StatusController status; + int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); + + sync_pb::DataTypeProgressMarker progress; + progress.set_data_type_id( + GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); + progress.set_token("token"); + + sync_pb::DataTypeContext old_context; + old_context.set_version(1); + old_context.set_context("data"); + old_context.set_data_type_id(field_number); + + scoped_ptr<sync_pb::SyncEntity> type_root = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), + syncable::GetNullId().GetServerId(), + SYNCED_NOTIFICATIONS); + type_root->set_server_defined_unique_tag( + ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); + type_root->set_folder(true); + scoped_ptr<sync_pb::SyncEntity> e1 = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), + type_root->id_string(), + SYNCED_NOTIFICATIONS); + + SyncEntityList updates; + updates.push_back(type_root.get()); + updates.push_back(e1.get()); + + // The first response should be processed fine. + EXPECT_EQ(SYNCER_OK, + handler.ProcessGetUpdatesResponse( + progress, old_context, updates, &status)); + handler.ApplyUpdates(&status); + + EXPECT_TRUE(EntryExists(type_root->id_string())); + EXPECT_TRUE(EntryExists(e1->id_string())); + + { + sync_pb::DataTypeContext dir_context; + syncable::ReadTransaction trans(FROM_HERE, dir()); + trans.directory()->GetDataTypeContext( + &trans, SYNCED_NOTIFICATIONS, &dir_context); + EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); + } + + sync_pb::DataTypeContext new_context; + new_context.set_version(0); + new_context.set_context("old"); + new_context.set_data_type_id(field_number); + + scoped_ptr<sync_pb::SyncEntity> e2 = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), + type_root->id_string(), + SYNCED_NOTIFICATIONS); + updates.clear(); + updates.push_back(e2.get()); + + // The second response, with an old context version, should result in an + // error and the updates should be dropped. + EXPECT_EQ(DATATYPE_TRIGGERED_RETRY, + handler.ProcessGetUpdatesResponse( + progress, new_context, updates, &status)); + handler.ApplyUpdates(&status); + + EXPECT_FALSE(EntryExists(e2->id_string())); + + { + sync_pb::DataTypeContext dir_context; + syncable::ReadTransaction trans(FROM_HERE, dir()); + trans.directory()->GetDataTypeContext( + &trans, SYNCED_NOTIFICATIONS, &dir_context); + EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); + } +} + // A test harness for tests that focus on applying updates. // // Update application is performed when we want to take updates that were |