Commit d2ffd480 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Sync::USS] Set the model type state upon handling remote updates

Bug: 516866
Change-Id: I2a460de83529e88058054d2407da6a6d8f6e9357
Reviewed-on: https://chromium-review.googlesource.com/1169053
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581943}
parent 36164bd9
...@@ -153,13 +153,13 @@ void BookmarkModelTypeProcessor::OnUpdateReceived( ...@@ -153,13 +153,13 @@ void BookmarkModelTypeProcessor::OnUpdateReceived(
NudgeForCommitIfNeeded(); NudgeForCommitIfNeeded();
return; return;
} }
// TODO(crbug.com/516866): Set the model type state.
ScopedRemoteUpdateBookmarks update_bookmarks( ScopedRemoteUpdateBookmarks update_bookmarks(
bookmark_model_, bookmark_undo_service_, bookmark_model_observer_.get()); bookmark_model_, bookmark_undo_service_, bookmark_model_observer_.get());
BookmarkRemoteUpdatesHandler updates_handler(bookmark_model_, BookmarkRemoteUpdatesHandler updates_handler(bookmark_model_,
bookmark_tracker_.get()); bookmark_tracker_.get());
updates_handler.Process(updates); updates_handler.Process(updates);
bookmark_tracker_->set_model_type_state(
std::make_unique<sync_pb::ModelTypeState>(model_type_state));
// Schedule save just in case one is needed. // Schedule save just in case one is needed.
schedule_save_closure_.Run(); schedule_save_closure_.Run();
} }
......
...@@ -339,6 +339,34 @@ TEST_F(BookmarkModelTypeProcessorTest, ShouldDecodeEncodedSyncMetadata) { ...@@ -339,6 +339,34 @@ TEST_F(BookmarkModelTypeProcessorTest, ShouldDecodeEncodedSyncMetadata) {
AssertState(&new_processor, bookmarks); AssertState(&new_processor, bookmarks);
} }
// Verifies that the model type state stored in the tracker gets
// updated upon handling remote updates by assigning a new encryption
// key name.
TEST_F(BookmarkModelTypeProcessorTest,
ShouldUpdateModelTypeStateUponHandlingRemoteUpdates) {
// Initialize the process to make sure the tracker has been created.
InitWithSyncedBookmarks({}, processor());
const SyncedBookmarkTracker* tracker = processor()->GetTrackerForTest();
// The encryption key name should be empty.
ASSERT_TRUE(tracker->model_type_state().encryption_key_name().empty());
// Build a model type state with an encryption key name.
const std::string kEncryptionKeyName = "new_encryption_key_name";
sync_pb::ModelTypeState model_type_state(CreateDummyModelTypeState());
model_type_state.set_encryption_key_name(kEncryptionKeyName);
EXPECT_CALL(*schedule_save_closure(), Run());
// Push empty updates list to the processor together with the updated model
// type state.
processor()->OnUpdateReceived(model_type_state,
syncer::UpdateResponseDataList());
// The model type state inside the tracker should have been updated, and
// carries the new encryption key name.
EXPECT_THAT(tracker->model_type_state().encryption_key_name(),
Eq(kEncryptionKeyName));
}
} // namespace } // namespace
} // namespace sync_bookmarks } // namespace sync_bookmarks
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment