| 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 11 matching lines...) Expand all Loading... |
| 22 #include "sync/syncable/syncable_read_transaction.h" | 22 #include "sync/syncable/syncable_read_transaction.h" |
| 23 #include "sync/syncable/syncable_write_transaction.h" | 23 #include "sync/syncable/syncable_write_transaction.h" |
| 24 #include "sync/test/engine/fake_model_worker.h" | 24 #include "sync/test/engine/fake_model_worker.h" |
| 25 #include "sync/test/engine/test_directory_setter_upper.h" | 25 #include "sync/test/engine/test_directory_setter_upper.h" |
| 26 #include "sync/test/engine/test_id_factory.h" | 26 #include "sync/test/engine/test_id_factory.h" |
| 27 #include "sync/test/engine/test_syncable_utils.h" | 27 #include "sync/test/engine/test_syncable_utils.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 namespace syncer { | 30 namespace syncer { |
| 31 | 31 |
| 32 using syncable::Id; |
| 32 using syncable::UNITTEST; | 33 using syncable::UNITTEST; |
| 33 | 34 |
| 34 static const int64 kDefaultVersion = 1000; | 35 static const int64 kDefaultVersion = 1000; |
| 35 | 36 |
| 36 // A test harness for tests that focus on processing updates. | 37 // A test harness for tests that focus on processing updates. |
| 37 // | 38 // |
| 38 // Update processing is what occurs when we first download updates. It converts | 39 // Update processing is what occurs when we first download updates. It converts |
| 39 // the received protobuf message into information in the syncable::Directory. | 40 // the received protobuf message into information in the syncable::Directory. |
| 40 // Any invalid or redundant updates will be dropped at this point. | 41 // Any invalid or redundant updates will be dropped at this point. |
| 41 class DirectoryUpdateHandlerProcessUpdateTest : public ::testing::Test { | 42 class DirectoryUpdateHandlerProcessUpdateTest : public ::testing::Test { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 DirectoryUpdateHandler* handler, | 77 DirectoryUpdateHandler* handler, |
| 77 const sync_pb::DataTypeProgressMarker& progress); | 78 const sync_pb::DataTypeProgressMarker& progress); |
| 78 | 79 |
| 79 scoped_refptr<FakeModelWorker> ui_worker() { | 80 scoped_refptr<FakeModelWorker> ui_worker() { |
| 80 return ui_worker_; | 81 return ui_worker_; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool EntryExists(const std::string& id) { | 84 bool EntryExists(const std::string& id) { |
| 84 syncable::ReadTransaction trans(FROM_HERE, dir()); | 85 syncable::ReadTransaction trans(FROM_HERE, dir()); |
| 85 syncable::Entry e(&trans, syncable::GET_BY_ID, | 86 syncable::Entry e(&trans, syncable::GET_BY_ID, |
| 86 syncable::Id::CreateFromServerId(id)); | 87 Id::CreateFromServerId(id)); |
| 87 return e.good() && !e.GetIsDel(); | 88 return e.good() && !e.GetIsDel(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 protected: | 91 protected: |
| 91 // Used in the construction of DirectoryTypeDebugInfoEmitters. | 92 // Used in the construction of DirectoryTypeDebugInfoEmitters. |
| 92 ObserverList<TypeDebugInfoObserver> type_observers_; | 93 ObserverList<TypeDebugInfoObserver> type_observers_; |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 base::MessageLoop loop_; // Needed to initialize the directory. | 96 base::MessageLoop loop_; // Needed to initialize the directory. |
| 96 TestDirectorySetterUpper dir_maker_; | 97 TestDirectorySetterUpper dir_maker_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; | 130 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; |
| 130 | 131 |
| 131 // Test that the bookmark tag is set on newly downloaded items. | 132 // Test that the bookmark tag is set on newly downloaded items. |
| 132 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { | 133 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { |
| 133 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); | 134 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); |
| 134 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); | 135 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); |
| 135 sync_pb::GetUpdatesResponse gu_response; | 136 sync_pb::GetUpdatesResponse gu_response; |
| 136 sessions::StatusController status; | 137 sessions::StatusController status; |
| 137 | 138 |
| 138 // Add a bookmark item to the update message. | 139 // Add a bookmark item to the update message. |
| 139 std::string root = syncable::GetNullId().GetServerId(); | 140 std::string root = Id::GetRoot().GetServerId(); |
| 140 syncable::Id server_id = syncable::Id::CreateFromServerId("b1"); | 141 Id server_id = Id::CreateFromServerId("b1"); |
| 141 scoped_ptr<sync_pb::SyncEntity> e = | 142 scoped_ptr<sync_pb::SyncEntity> e = |
| 142 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); | 143 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); |
| 143 e->set_originator_cache_guid( | 144 e->set_originator_cache_guid( |
| 144 std::string(kCacheGuid, arraysize(kCacheGuid)-1)); | 145 std::string(kCacheGuid, arraysize(kCacheGuid)-1)); |
| 145 syncable::Id client_id = syncable::Id::CreateFromClientString("-2"); | 146 Id client_id = Id::CreateFromClientString("-2"); |
| 146 e->set_originator_client_item_id(client_id.GetServerId()); | 147 e->set_originator_client_item_id(client_id.GetServerId()); |
| 147 e->set_position_in_parent(0); | 148 e->set_position_in_parent(0); |
| 148 | 149 |
| 149 // Add it to the applicable updates list. | 150 // Add it to the applicable updates list. |
| 150 SyncEntityList bookmark_updates; | 151 SyncEntityList bookmark_updates; |
| 151 bookmark_updates.push_back(e.get()); | 152 bookmark_updates.push_back(e.get()); |
| 152 | 153 |
| 153 // Process the update. | 154 // Process the update. |
| 154 UpdateSyncEntities(&handler, bookmark_updates, &status); | 155 UpdateSyncEntities(&handler, bookmark_updates, &status); |
| 155 | 156 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 168 | 169 |
| 169 // Test the receipt of a type root node. | 170 // Test the receipt of a type root node. |
| 170 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, | 171 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, |
| 171 ReceiveServerCreatedBookmarkFolders) { | 172 ReceiveServerCreatedBookmarkFolders) { |
| 172 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); | 173 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); |
| 173 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); | 174 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); |
| 174 sync_pb::GetUpdatesResponse gu_response; | 175 sync_pb::GetUpdatesResponse gu_response; |
| 175 sessions::StatusController status; | 176 sessions::StatusController status; |
| 176 | 177 |
| 177 // Create an update that mimics the bookmark root. | 178 // Create an update that mimics the bookmark root. |
| 178 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); | 179 Id server_id = Id::CreateFromServerId("xyz"); |
| 179 std::string root = syncable::GetNullId().GetServerId(); | 180 std::string root = Id::GetRoot().GetServerId(); |
| 180 scoped_ptr<sync_pb::SyncEntity> e = | 181 scoped_ptr<sync_pb::SyncEntity> e = |
| 181 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); | 182 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); |
| 182 e->set_server_defined_unique_tag("google_chrome_bookmarks"); | 183 e->set_server_defined_unique_tag("google_chrome_bookmarks"); |
| 183 e->set_folder(true); | 184 e->set_folder(true); |
| 184 | 185 |
| 185 // Add it to the applicable updates list. | 186 // Add it to the applicable updates list. |
| 186 SyncEntityList bookmark_updates; | 187 SyncEntityList bookmark_updates; |
| 187 bookmark_updates.push_back(e.get()); | 188 bookmark_updates.push_back(e.get()); |
| 188 | 189 |
| 189 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); | 190 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 202 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); | 203 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); |
| 203 } | 204 } |
| 204 | 205 |
| 205 // Test the receipt of a non-bookmark item. | 206 // Test the receipt of a non-bookmark item. |
| 206 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { | 207 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { |
| 207 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_); | 208 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_); |
| 208 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter); | 209 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter); |
| 209 sync_pb::GetUpdatesResponse gu_response; | 210 sync_pb::GetUpdatesResponse gu_response; |
| 210 sessions::StatusController status; | 211 sessions::StatusController status; |
| 211 | 212 |
| 212 std::string root = syncable::GetNullId().GetServerId(); | 213 std::string root = Id::GetRoot().GetServerId(); |
| 213 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); | 214 Id server_id = Id::CreateFromServerId("xyz"); |
| 214 scoped_ptr<sync_pb::SyncEntity> e = | 215 scoped_ptr<sync_pb::SyncEntity> e = |
| 215 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); | 216 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); |
| 216 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); | 217 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); |
| 217 | 218 |
| 218 // Add it to the applicable updates list. | 219 // Add it to the applicable updates list. |
| 219 SyncEntityList autofill_updates; | 220 SyncEntityList autofill_updates; |
| 220 autofill_updates.push_back(e.get()); | 221 autofill_updates.push_back(e.get()); |
| 221 | 222 |
| 222 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); | 223 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); |
| 223 | 224 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 progress.set_token("token"); | 265 progress.set_token("token"); |
| 265 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); | 266 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); |
| 266 | 267 |
| 267 sync_pb::DataTypeContext context; | 268 sync_pb::DataTypeContext context; |
| 268 context.set_data_type_id( | 269 context.set_data_type_id( |
| 269 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); | 270 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); |
| 270 context.set_context("context"); | 271 context.set_context("context"); |
| 271 context.set_version(1); | 272 context.set_version(1); |
| 272 | 273 |
| 273 scoped_ptr<sync_pb::SyncEntity> type_root = | 274 scoped_ptr<sync_pb::SyncEntity> type_root = |
| 274 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), | 275 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("root")), |
| 275 syncable::GetNullId().GetServerId(), | 276 Id::GetRoot().GetServerId(), SYNCED_NOTIFICATIONS); |
| 276 SYNCED_NOTIFICATIONS); | |
| 277 type_root->set_server_defined_unique_tag( | 277 type_root->set_server_defined_unique_tag( |
| 278 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); | 278 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); |
| 279 type_root->set_folder(true); | 279 type_root->set_folder(true); |
| 280 | 280 |
| 281 scoped_ptr<sync_pb::SyncEntity> e1 = | 281 scoped_ptr<sync_pb::SyncEntity> e1 = |
| 282 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), | 282 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("e1")), |
| 283 type_root->id_string(), | 283 type_root->id_string(), |
| 284 SYNCED_NOTIFICATIONS); | 284 SYNCED_NOTIFICATIONS); |
| 285 | 285 |
| 286 scoped_ptr<sync_pb::SyncEntity> e2 = | 286 scoped_ptr<sync_pb::SyncEntity> e2 = |
| 287 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), | 287 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("e2")), |
| 288 type_root->id_string(), | 288 type_root->id_string(), |
| 289 SYNCED_NOTIFICATIONS); | 289 SYNCED_NOTIFICATIONS); |
| 290 e2->set_version(kDefaultVersion + 100); | 290 e2->set_version(kDefaultVersion + 100); |
| 291 | 291 |
| 292 // Add to the applicable updates list. | 292 // Add to the applicable updates list. |
| 293 SyncEntityList updates; | 293 SyncEntityList updates; |
| 294 updates.push_back(type_root.get()); | 294 updates.push_back(type_root.get()); |
| 295 updates.push_back(e1.get()); | 295 updates.push_back(e1.get()); |
| 296 updates.push_back(e2.get()); | 296 updates.push_back(e2.get()); |
| 297 | 297 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 328 progress.set_data_type_id( | 328 progress.set_data_type_id( |
| 329 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); | 329 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); |
| 330 progress.set_token("token"); | 330 progress.set_token("token"); |
| 331 | 331 |
| 332 sync_pb::DataTypeContext old_context; | 332 sync_pb::DataTypeContext old_context; |
| 333 old_context.set_version(1); | 333 old_context.set_version(1); |
| 334 old_context.set_context("data"); | 334 old_context.set_context("data"); |
| 335 old_context.set_data_type_id(field_number); | 335 old_context.set_data_type_id(field_number); |
| 336 | 336 |
| 337 scoped_ptr<sync_pb::SyncEntity> type_root = | 337 scoped_ptr<sync_pb::SyncEntity> type_root = |
| 338 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), | 338 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("root")), |
| 339 syncable::GetNullId().GetServerId(), | 339 Id::GetRoot().GetServerId(), SYNCED_NOTIFICATIONS); |
| 340 SYNCED_NOTIFICATIONS); | |
| 341 type_root->set_server_defined_unique_tag( | 340 type_root->set_server_defined_unique_tag( |
| 342 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); | 341 ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); |
| 343 type_root->set_folder(true); | 342 type_root->set_folder(true); |
| 344 scoped_ptr<sync_pb::SyncEntity> e1 = | 343 scoped_ptr<sync_pb::SyncEntity> e1 = |
| 345 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), | 344 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("e1")), |
| 346 type_root->id_string(), | 345 type_root->id_string(), |
| 347 SYNCED_NOTIFICATIONS); | 346 SYNCED_NOTIFICATIONS); |
| 348 | 347 |
| 349 SyncEntityList updates; | 348 SyncEntityList updates; |
| 350 updates.push_back(type_root.get()); | 349 updates.push_back(type_root.get()); |
| 351 updates.push_back(e1.get()); | 350 updates.push_back(e1.get()); |
| 352 | 351 |
| 353 // The first response should be processed fine. | 352 // The first response should be processed fine. |
| 354 EXPECT_EQ(SYNCER_OK, | 353 EXPECT_EQ(SYNCER_OK, |
| 355 handler.ProcessGetUpdatesResponse( | 354 handler.ProcessGetUpdatesResponse( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 366 &trans, SYNCED_NOTIFICATIONS, &dir_context); | 365 &trans, SYNCED_NOTIFICATIONS, &dir_context); |
| 367 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); | 366 EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); |
| 368 } | 367 } |
| 369 | 368 |
| 370 sync_pb::DataTypeContext new_context; | 369 sync_pb::DataTypeContext new_context; |
| 371 new_context.set_version(0); | 370 new_context.set_version(0); |
| 372 new_context.set_context("old"); | 371 new_context.set_context("old"); |
| 373 new_context.set_data_type_id(field_number); | 372 new_context.set_data_type_id(field_number); |
| 374 | 373 |
| 375 scoped_ptr<sync_pb::SyncEntity> e2 = | 374 scoped_ptr<sync_pb::SyncEntity> e2 = |
| 376 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), | 375 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("e2")), |
| 377 type_root->id_string(), | 376 type_root->id_string(), |
| 378 SYNCED_NOTIFICATIONS); | 377 SYNCED_NOTIFICATIONS); |
| 379 updates.clear(); | 378 updates.clear(); |
| 380 updates.push_back(e2.get()); | 379 updates.push_back(e2.get()); |
| 381 | 380 |
| 382 // The second response, with an old context version, should result in an | 381 // The second response, with an old context version, should result in an |
| 383 // error and the updates should be dropped. | 382 // error and the updates should be dropped. |
| 384 EXPECT_EQ(DATATYPE_TRIGGERED_RETRY, | 383 EXPECT_EQ(DATATYPE_TRIGGERED_RETRY, |
| 385 handler.ProcessGetUpdatesResponse( | 384 handler.ProcessGetUpdatesResponse( |
| 386 progress, new_context, updates, &status)); | 385 progress, new_context, updates, &status)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 409 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); | 408 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); |
| 410 progress.set_token("token"); | 409 progress.set_token("token"); |
| 411 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); | 410 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); |
| 412 | 411 |
| 413 sync_pb::DataTypeContext context; | 412 sync_pb::DataTypeContext context; |
| 414 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); | 413 context.set_data_type_id(GetSpecificsFieldNumberFromModelType(ARTICLES)); |
| 415 context.set_context("context"); | 414 context.set_context("context"); |
| 416 context.set_version(1); | 415 context.set_version(1); |
| 417 | 416 |
| 418 scoped_ptr<sync_pb::SyncEntity> type_root = | 417 scoped_ptr<sync_pb::SyncEntity> type_root = |
| 419 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), | 418 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("root")), |
| 420 syncable::GetNullId().GetServerId(), | 419 Id::GetRoot().GetServerId(), ARTICLES); |
| 421 ARTICLES); | |
| 422 type_root->set_server_defined_unique_tag(ModelTypeToRootTag(ARTICLES)); | 420 type_root->set_server_defined_unique_tag(ModelTypeToRootTag(ARTICLES)); |
| 423 type_root->set_folder(true); | 421 type_root->set_folder(true); |
| 424 | 422 |
| 425 scoped_ptr<sync_pb::SyncEntity> e1 = | 423 scoped_ptr<sync_pb::SyncEntity> e1 = |
| 426 CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), | 424 CreateUpdate(SyncableIdToProto(Id::CreateFromServerId("e1")), |
| 427 type_root->id_string(), | 425 type_root->id_string(), |
| 428 ARTICLES); | 426 ARTICLES); |
| 429 sync_pb::AttachmentIdProto* attachment_id = e1->add_attachment_id(); | 427 sync_pb::AttachmentIdProto* attachment_id = e1->add_attachment_id(); |
| 430 *attachment_id = CreateAttachmentIdProto(); | 428 *attachment_id = CreateAttachmentIdProto(); |
| 431 | 429 |
| 432 SyncEntityList updates; | 430 SyncEntityList updates; |
| 433 updates.push_back(type_root.get()); | 431 updates.push_back(type_root.get()); |
| 434 updates.push_back(e1.get()); | 432 updates.push_back(e1.get()); |
| 435 | 433 |
| 436 // Process and apply updates. | 434 // Process and apply updates. |
| 437 EXPECT_EQ( | 435 EXPECT_EQ( |
| 438 SYNCER_OK, | 436 SYNCER_OK, |
| 439 handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); | 437 handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); |
| 440 handler.ApplyUpdates(&status); | 438 handler.ApplyUpdates(&status); |
| 441 | 439 |
| 442 ASSERT_TRUE(EntryExists(type_root->id_string())); | 440 ASSERT_TRUE(EntryExists(type_root->id_string())); |
| 443 ASSERT_TRUE(EntryExists(e1->id_string())); | 441 ASSERT_TRUE(EntryExists(e1->id_string())); |
| 444 { | 442 { |
| 445 syncable::ReadTransaction trans(FROM_HERE, dir()); | 443 syncable::ReadTransaction trans(FROM_HERE, dir()); |
| 446 syncable::Entry e(&trans, | 444 syncable::Entry e(&trans, |
| 447 syncable::GET_BY_ID, | 445 syncable::GET_BY_ID, |
| 448 syncable::Id::CreateFromServerId(e1->id_string())); | 446 Id::CreateFromServerId(e1->id_string())); |
| 449 | 447 |
| 450 // See that the attachment_metadata is correct. | 448 // See that the attachment_metadata is correct. |
| 451 sync_pb::AttachmentMetadata attachment_metadata = e.GetAttachmentMetadata(); | 449 sync_pb::AttachmentMetadata attachment_metadata = e.GetAttachmentMetadata(); |
| 452 ASSERT_EQ(1, attachment_metadata.record_size()); | 450 ASSERT_EQ(1, attachment_metadata.record_size()); |
| 453 ASSERT_EQ(attachment_id->SerializeAsString(), | 451 ASSERT_EQ(attachment_id->SerializeAsString(), |
| 454 attachment_metadata.record(0).id().SerializeAsString()); | 452 attachment_metadata.record(0).id().SerializeAsString()); |
| 455 ASSERT_TRUE(attachment_metadata.record(0).is_on_server()); | 453 ASSERT_TRUE(attachment_metadata.record(0).is_on_server()); |
| 456 | 454 |
| 457 // See that attachment_metadata and server_attachment_metadata are equal. | 455 // See that attachment_metadata and server_attachment_metadata are equal. |
| 458 ASSERT_EQ(attachment_metadata.SerializeAsString(), | 456 ASSERT_EQ(attachment_metadata.SerializeAsString(), |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 sync_pb::EntitySpecifics result; | 566 sync_pb::EntitySpecifics result; |
| 569 AddDefaultFieldValue(BOOKMARKS, &result); | 567 AddDefaultFieldValue(BOOKMARKS, &result); |
| 570 return result; | 568 return result; |
| 571 } | 569 } |
| 572 } // namespace | 570 } // namespace |
| 573 | 571 |
| 574 // Test update application for a few bookmark items. | 572 // Test update application for a few bookmark items. |
| 575 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { | 573 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { |
| 576 sessions::StatusController status; | 574 sessions::StatusController status; |
| 577 | 575 |
| 578 std::string root_server_id = syncable::GetNullId().GetServerId(); | 576 std::string root_server_id = Id::GetRoot().GetServerId(); |
| 579 int64 parent_handle = | 577 int64 parent_handle = |
| 580 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 578 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 581 "parent", DefaultBookmarkSpecifics(), root_server_id); | 579 "parent", DefaultBookmarkSpecifics(), root_server_id); |
| 582 int64 child_handle = | 580 int64 child_handle = |
| 583 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 581 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 584 "child", DefaultBookmarkSpecifics(), "parent"); | 582 "child", DefaultBookmarkSpecifics(), "parent"); |
| 585 | 583 |
| 586 ApplyBookmarkUpdates(&status); | 584 ApplyBookmarkUpdates(&status); |
| 587 | 585 |
| 588 const UpdateCounters& counter = GetBookmarksUpdateCounters(); | 586 const UpdateCounters& counter = GetBookmarksUpdateCounters(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 606 EXPECT_FALSE(parent.GetIsUnappliedUpdate()); | 604 EXPECT_FALSE(parent.GetIsUnappliedUpdate()); |
| 607 EXPECT_FALSE(child.GetIsUnsynced()); | 605 EXPECT_FALSE(child.GetIsUnsynced()); |
| 608 EXPECT_FALSE(child.GetIsUnappliedUpdate()); | 606 EXPECT_FALSE(child.GetIsUnappliedUpdate()); |
| 609 } | 607 } |
| 610 } | 608 } |
| 611 | 609 |
| 612 // Test that the applicator can handle updates delivered out of order. | 610 // Test that the applicator can handle updates delivered out of order. |
| 613 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, | 611 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 614 BookmarkChildrenBeforeParent) { | 612 BookmarkChildrenBeforeParent) { |
| 615 // Start with some bookmarks whose parents are unknown. | 613 // Start with some bookmarks whose parents are unknown. |
| 616 std::string root_server_id = syncable::GetNullId().GetServerId(); | 614 std::string root_server_id = Id::GetRoot().GetServerId(); |
| 617 int64 a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 615 int64 a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 618 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 616 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 619 int64 x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 617 int64 x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 620 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 618 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 621 | 619 |
| 622 // Update application will fail. | 620 // Update application will fail. |
| 623 sessions::StatusController status1; | 621 sessions::StatusController status1; |
| 624 ApplyBookmarkUpdates(&status1); | 622 ApplyBookmarkUpdates(&status1); |
| 625 EXPECT_EQ(0, status1.num_updates_applied()); | 623 EXPECT_EQ(0, status1.num_updates_applied()); |
| 626 EXPECT_EQ(2, status1.num_hierarchy_conflicts()); | 624 EXPECT_EQ(2, status1.num_hierarchy_conflicts()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 } | 781 } |
| 784 } | 782 } |
| 785 | 783 |
| 786 // Test update application where the update has been orphaned by a local folder | 784 // Test update application where the update has been orphaned by a local folder |
| 787 // deletion. The update application attempt should fail. | 785 // deletion. The update application attempt should fail. |
| 788 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, | 786 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 789 HierarchyConflictDeletedParent) { | 787 HierarchyConflictDeletedParent) { |
| 790 // Create a locally deleted parent item. | 788 // Create a locally deleted parent item. |
| 791 int64 parent_handle; | 789 int64 parent_handle; |
| 792 entry_factory()->CreateUnsyncedItem( | 790 entry_factory()->CreateUnsyncedItem( |
| 793 syncable::Id::CreateFromServerId("parent"), TestIdFactory::root(), | 791 Id::CreateFromServerId("parent"), TestIdFactory::root(), |
| 794 "parent", true, BOOKMARKS, &parent_handle); | 792 "parent", true, BOOKMARKS, &parent_handle); |
| 795 { | 793 { |
| 796 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 794 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 797 syncable::MutableEntry entry(&trans, | 795 syncable::MutableEntry entry(&trans, |
| 798 syncable::GET_BY_HANDLE, | 796 syncable::GET_BY_HANDLE, |
| 799 parent_handle); | 797 parent_handle); |
| 800 entry.PutIsDel(true); | 798 entry.PutIsDel(true); |
| 801 } | 799 } |
| 802 | 800 |
| 803 // Create an incoming child from the server. | 801 // Create an incoming child from the server. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 EXPECT_TRUE(y.GetIsUnappliedUpdate()); | 894 EXPECT_TRUE(y.GetIsUnappliedUpdate()); |
| 897 EXPECT_FALSE(x.GetIsUnsynced()); | 895 EXPECT_FALSE(x.GetIsUnsynced()); |
| 898 EXPECT_FALSE(y.GetIsUnsynced()); | 896 EXPECT_FALSE(y.GetIsUnsynced()); |
| 899 } | 897 } |
| 900 } | 898 } |
| 901 | 899 |
| 902 // Attempt application of a mix of items. Some update application attempts will | 900 // Attempt application of a mix of items. Some update application attempts will |
| 903 // fail due to hierarchy conflicts. Others should succeed. | 901 // fail due to hierarchy conflicts. Others should succeed. |
| 904 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, ItemsBothKnownAndUnknown) { | 902 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, ItemsBothKnownAndUnknown) { |
| 905 // See what happens when there's a mixture of good and bad updates. | 903 // See what happens when there's a mixture of good and bad updates. |
| 906 std::string root_server_id = syncable::GetNullId().GetServerId(); | 904 std::string root_server_id = Id::GetRoot().GetServerId(); |
| 907 int64 u1_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 905 int64 u1_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 908 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); | 906 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); |
| 909 int64 k1_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 907 int64 k1_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 910 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); | 908 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); |
| 911 int64 u2_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 909 int64 u2_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 912 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); | 910 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); |
| 913 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 911 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 914 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); | 912 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); |
| 915 int64 k3_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 913 int64 k3_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 916 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item"); | 914 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item"); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 EXPECT_FALSE(e.GetIsUnsynced()); | 985 EXPECT_FALSE(e.GetIsUnsynced()); |
| 988 } | 986 } |
| 989 } | 987 } |
| 990 | 988 |
| 991 // Attempt application of encrypted items when the passphrase is not known. | 989 // Attempt application of encrypted items when the passphrase is not known. |
| 992 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, UndecryptableData) { | 990 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, UndecryptableData) { |
| 993 // Undecryptable updates should not be applied. | 991 // Undecryptable updates should not be applied. |
| 994 sync_pb::EntitySpecifics encrypted_bookmark; | 992 sync_pb::EntitySpecifics encrypted_bookmark; |
| 995 encrypted_bookmark.mutable_encrypted(); | 993 encrypted_bookmark.mutable_encrypted(); |
| 996 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); | 994 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
| 997 std::string root_server_id = syncable::GetNullId().GetServerId(); | 995 std::string root_server_id = Id::GetRoot().GetServerId(); |
| 998 int64 folder_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 996 int64 folder_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 999 "folder", | 997 "folder", |
| 1000 encrypted_bookmark, | 998 encrypted_bookmark, |
| 1001 root_server_id); | 999 root_server_id); |
| 1002 int64 bookmark_handle = entry_factory()->CreateUnappliedNewItem( | 1000 int64 bookmark_handle = entry_factory()->CreateUnappliedNewItem( |
| 1003 "item2", | 1001 "item2", |
| 1004 encrypted_bookmark, | 1002 encrypted_bookmark, |
| 1005 false); | 1003 false); |
| 1006 sync_pb::EntitySpecifics encrypted_password; | 1004 sync_pb::EntitySpecifics encrypted_password; |
| 1007 encrypted_password.mutable_password(); | 1005 encrypted_password.mutable_password(); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 const UpdateCounters& counters = GetArticlesUpdateCounters(); | 1181 const UpdateCounters& counters = GetArticlesUpdateCounters(); |
| 1184 EXPECT_EQ(1, counters.num_updates_applied); | 1182 EXPECT_EQ(1, counters.num_updates_applied); |
| 1185 EXPECT_EQ(1, counters.num_local_overwrites); | 1183 EXPECT_EQ(1, counters.num_local_overwrites); |
| 1186 EXPECT_EQ(0, counters.num_server_overwrites); | 1184 EXPECT_EQ(0, counters.num_server_overwrites); |
| 1187 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); | 1185 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); |
| 1188 EXPECT_EQ(server_metadata.SerializeAsString(), | 1186 EXPECT_EQ(server_metadata.SerializeAsString(), |
| 1189 local_metadata.SerializeAsString()); | 1187 local_metadata.SerializeAsString()); |
| 1190 } | 1188 } |
| 1191 | 1189 |
| 1192 } // namespace syncer | 1190 } // namespace syncer |
| OLD | NEW |