Commit 248a0ed1 authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Sync] Allow bridge to restore specifics different from the one passed to MakeLocalChange

The issue is that ProcessorEntityTracker hits DCHECK when loading entity data
for commit if its specifics doesn't match the one passed to
ProcessorEntityTracker::MakeLocalChange. This can happen if model type code
assembles specifics differently after restart.

I'm removing the DCHECK and adding unittest for this scenario.

BUG=787741
R=pnoland@chromium.org

Change-Id: I1abe5c9e3d89c9f312c8faa0cae889805e2dc4cb
Reviewed-on: https://chromium-review.googlesource.com/792536Reviewed-by: default avatarPatrick Noland <pnoland@google.com>
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519839}
parent 3bb300a8
......@@ -76,7 +76,6 @@ void ProcessorEntityTracker::SetCommitData(EntityData* data) {
data->id = metadata_.server_id();
data->creation_time = ProtoTimeToTime(metadata_.creation_time());
data->modification_time = ProtoTimeToTime(metadata_.modification_time());
DCHECK(MatchesSpecificsHash(data->specifics));
commit_data_.reset();
CacheCommitData(data->PassToPtr());
......
......@@ -106,6 +106,7 @@ class ProcessorEntityTrackerTest : public ::testing::Test {
std::unique_ptr<ProcessorEntityTracker> CreateNew() {
return ProcessorEntityTracker::CreateNew(kKey, kHash, "", ctime_);
}
std::unique_ptr<ProcessorEntityTracker> CreateNewWithEmptyStorageKey() {
return ProcessorEntityTracker::CreateNew("", kHash, "", ctime_);
}
......@@ -118,6 +119,11 @@ class ProcessorEntityTrackerTest : public ::testing::Test {
return entity;
}
std::unique_ptr<ProcessorEntityTracker> RestoreFromMetadata(
sync_pb::EntityMetadata* entity_metadata) {
return ProcessorEntityTracker::CreateFromMetadata(kKey, entity_metadata);
}
const base::Time ctime_;
};
......@@ -520,4 +526,21 @@ TEST_F(ProcessorEntityTrackerTest, NewLocalChangeUpdatedId) {
EXPECT_EQ(1, request.base_version);
}
// Tests that entity restored after restart accepts specifics that don't match
// the ones passed originally to MakeLocalChange.
TEST_F(ProcessorEntityTrackerTest, RestoredLocalChangeWithUpdatedSpecifics) {
// Create new entity and preserver its metadata.
std::unique_ptr<ProcessorEntityTracker> entity = CreateNew();
entity->MakeLocalChange(GenerateEntityData(kHash, kName, kValue1));
sync_pb::EntityMetadata entity_metadata = entity->metadata();
// Restore entity from metadata and emulate bridge passing different specifics
// to SetCommitData.
entity = RestoreFromMetadata(&entity_metadata);
auto entity_data = GenerateEntityData(kHash, kName, kValue2);
entity->SetCommitData(entity_data.get());
// No verification is necessary. SetCommitData shouldn't DCHECK.
}
} // namespace syncer
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