Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: components/sync/core/processor_entity_tracker_unittest.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/sync/core/processor_entity_tracker.h" 5 #include "components/sync/core/processor_entity_tracker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/sync/base/model_type.h" 14 #include "components/sync/base/model_type.h"
15 #include "components/sync/base/time.h" 15 #include "components/sync/base/time.h"
16 #include "components/sync/core/non_blocking_sync_common.h" 16 #include "components/sync/core/non_blocking_sync_common.h"
17 #include "components/sync/protocol/sync.pb.h" 17 #include "components/sync/protocol/sync.pb.h"
18 #include "components/sync/syncable/syncable_util.h" 18 #include "components/sync/syncable/syncable_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace syncer_v2 { 21 namespace syncer {
22 22
23 namespace { 23 namespace {
24 24
25 const char kKey[] = "key"; 25 const char kKey[] = "key";
26 const char kHash[] = "hash"; 26 const char kHash[] = "hash";
27 const char kId[] = "id"; 27 const char kId[] = "id";
28 const char kName[] = "name"; 28 const char kName[] = "name";
29 const char kValue1[] = "value1"; 29 const char kValue1[] = "value1";
30 const char kValue2[] = "value2"; 30 const char kValue2[] = "value2";
31 const char kValue3[] = "value3"; 31 const char kValue3[] = "value3";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 TEST_F(ProcessorEntityTrackerTest, DefaultTracker) { 128 TEST_F(ProcessorEntityTrackerTest, DefaultTracker) {
129 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew(); 129 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew();
130 130
131 EXPECT_EQ(kKey, entity->storage_key()); 131 EXPECT_EQ(kKey, entity->storage_key());
132 EXPECT_EQ(kHash, entity->metadata().client_tag_hash()); 132 EXPECT_EQ(kHash, entity->metadata().client_tag_hash());
133 EXPECT_EQ("", entity->metadata().server_id()); 133 EXPECT_EQ("", entity->metadata().server_id());
134 EXPECT_FALSE(entity->metadata().is_deleted()); 134 EXPECT_FALSE(entity->metadata().is_deleted());
135 EXPECT_EQ(0, entity->metadata().sequence_number()); 135 EXPECT_EQ(0, entity->metadata().sequence_number());
136 EXPECT_EQ(0, entity->metadata().acked_sequence_number()); 136 EXPECT_EQ(0, entity->metadata().acked_sequence_number());
137 EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version()); 137 EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version());
138 EXPECT_EQ(syncer::TimeToProtoTime(ctime_), 138 EXPECT_EQ(TimeToProtoTime(ctime_), entity->metadata().creation_time());
139 entity->metadata().creation_time());
140 EXPECT_EQ(0, entity->metadata().modification_time()); 139 EXPECT_EQ(0, entity->metadata().modification_time());
141 EXPECT_TRUE(entity->metadata().specifics_hash().empty()); 140 EXPECT_TRUE(entity->metadata().specifics_hash().empty());
142 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty()); 141 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
143 142
144 EXPECT_FALSE(entity->IsUnsynced()); 143 EXPECT_FALSE(entity->IsUnsynced());
145 EXPECT_FALSE(entity->RequiresCommitRequest()); 144 EXPECT_FALSE(entity->RequiresCommitRequest());
146 EXPECT_FALSE(entity->RequiresCommitData()); 145 EXPECT_FALSE(entity->RequiresCommitData());
147 EXPECT_FALSE(entity->CanClearMetadata()); 146 EXPECT_FALSE(entity->CanClearMetadata());
148 EXPECT_FALSE(entity->UpdateIsReflection(1)); 147 EXPECT_FALSE(entity->UpdateIsReflection(1));
149 EXPECT_FALSE(entity->HasCommitData()); 148 EXPECT_FALSE(entity->HasCommitData());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 EXPECT_FALSE(entity->RequiresCommitData()); 183 EXPECT_FALSE(entity->RequiresCommitData());
185 EXPECT_FALSE(entity->CanClearMetadata()); 184 EXPECT_FALSE(entity->CanClearMetadata());
186 EXPECT_FALSE(entity->UpdateIsReflection(1)); 185 EXPECT_FALSE(entity->UpdateIsReflection(1));
187 EXPECT_TRUE(entity->HasCommitData()); 186 EXPECT_TRUE(entity->HasCommitData());
188 187
189 const EntityData& data = request.entity.value(); 188 const EntityData& data = request.entity.value();
190 EXPECT_EQ("", data.id); 189 EXPECT_EQ("", data.id);
191 EXPECT_EQ(kHash, data.client_tag_hash); 190 EXPECT_EQ(kHash, data.client_tag_hash);
192 EXPECT_EQ(kName, data.non_unique_name); 191 EXPECT_EQ(kName, data.non_unique_name);
193 EXPECT_EQ(kValue1, data.specifics.preference().value()); 192 EXPECT_EQ(kValue1, data.specifics.preference().value());
194 EXPECT_EQ(syncer::TimeToProtoTime(ctime_), 193 EXPECT_EQ(TimeToProtoTime(ctime_), TimeToProtoTime(data.creation_time));
195 syncer::TimeToProtoTime(data.creation_time));
196 EXPECT_EQ(entity->metadata().modification_time(), 194 EXPECT_EQ(entity->metadata().modification_time(),
197 syncer::TimeToProtoTime(data.modification_time)); 195 TimeToProtoTime(data.modification_time));
198 EXPECT_FALSE(data.is_deleted()); 196 EXPECT_FALSE(data.is_deleted());
199 EXPECT_EQ(1, request.sequence_number); 197 EXPECT_EQ(1, request.sequence_number);
200 EXPECT_EQ(kUncommittedVersion, request.base_version); 198 EXPECT_EQ(kUncommittedVersion, request.base_version);
201 EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash); 199 EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash);
202 200
203 // Ack the commit. 201 // Ack the commit.
204 entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1)); 202 entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1));
205 203
206 EXPECT_EQ(kId, entity->metadata().server_id()); 204 EXPECT_EQ(kId, entity->metadata().server_id());
207 EXPECT_FALSE(entity->metadata().is_deleted()); 205 EXPECT_FALSE(entity->metadata().is_deleted());
(...skipping 20 matching lines...) Expand all
228 226
229 const base::Time mtime = base::Time::Now(); 227 const base::Time mtime = base::Time::Now();
230 entity->RecordAcceptedUpdate( 228 entity->RecordAcceptedUpdate(
231 GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10)); 229 GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10));
232 230
233 EXPECT_EQ(kId, entity->metadata().server_id()); 231 EXPECT_EQ(kId, entity->metadata().server_id());
234 EXPECT_FALSE(entity->metadata().is_deleted()); 232 EXPECT_FALSE(entity->metadata().is_deleted());
235 EXPECT_EQ(0, entity->metadata().sequence_number()); 233 EXPECT_EQ(0, entity->metadata().sequence_number());
236 EXPECT_EQ(0, entity->metadata().acked_sequence_number()); 234 EXPECT_EQ(0, entity->metadata().acked_sequence_number());
237 EXPECT_EQ(10, entity->metadata().server_version()); 235 EXPECT_EQ(10, entity->metadata().server_version());
238 EXPECT_EQ(syncer::TimeToProtoTime(mtime), 236 EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
239 entity->metadata().modification_time());
240 EXPECT_FALSE(entity->metadata().specifics_hash().empty()); 237 EXPECT_FALSE(entity->metadata().specifics_hash().empty());
241 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty()); 238 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
242 239
243 EXPECT_FALSE(entity->IsUnsynced()); 240 EXPECT_FALSE(entity->IsUnsynced());
244 EXPECT_FALSE(entity->RequiresCommitRequest()); 241 EXPECT_FALSE(entity->RequiresCommitRequest());
245 EXPECT_FALSE(entity->RequiresCommitData()); 242 EXPECT_FALSE(entity->RequiresCommitData());
246 EXPECT_FALSE(entity->CanClearMetadata()); 243 EXPECT_FALSE(entity->CanClearMetadata());
247 EXPECT_TRUE(entity->UpdateIsReflection(9)); 244 EXPECT_TRUE(entity->UpdateIsReflection(9));
248 EXPECT_TRUE(entity->UpdateIsReflection(10)); 245 EXPECT_TRUE(entity->UpdateIsReflection(10));
249 EXPECT_FALSE(entity->UpdateIsReflection(11)); 246 EXPECT_FALSE(entity->UpdateIsReflection(11));
250 EXPECT_FALSE(entity->HasCommitData()); 247 EXPECT_FALSE(entity->HasCommitData());
251 } 248 }
252 249
253 // Test state for a tombstone received for a previously unknown item. 250 // Test state for a tombstone received for a previously unknown item.
254 TEST_F(ProcessorEntityTrackerTest, NewServerTombstone) { 251 TEST_F(ProcessorEntityTrackerTest, NewServerTombstone) {
255 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew(); 252 std::unique_ptr<ProcessorEntityTracker> entity = CreateNew();
256 253
257 const base::Time mtime = base::Time::Now(); 254 const base::Time mtime = base::Time::Now();
258 entity->RecordAcceptedUpdate( 255 entity->RecordAcceptedUpdate(
259 GenerateTombstone(*entity, kHash, kId, kName, mtime, 1)); 256 GenerateTombstone(*entity, kHash, kId, kName, mtime, 1));
260 257
261 EXPECT_EQ(kId, entity->metadata().server_id()); 258 EXPECT_EQ(kId, entity->metadata().server_id());
262 EXPECT_TRUE(entity->metadata().is_deleted()); 259 EXPECT_TRUE(entity->metadata().is_deleted());
263 EXPECT_EQ(0, entity->metadata().sequence_number()); 260 EXPECT_EQ(0, entity->metadata().sequence_number());
264 EXPECT_EQ(0, entity->metadata().acked_sequence_number()); 261 EXPECT_EQ(0, entity->metadata().acked_sequence_number());
265 EXPECT_EQ(1, entity->metadata().server_version()); 262 EXPECT_EQ(1, entity->metadata().server_version());
266 EXPECT_EQ(syncer::TimeToProtoTime(mtime), 263 EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
267 entity->metadata().modification_time());
268 EXPECT_TRUE(entity->metadata().specifics_hash().empty()); 264 EXPECT_TRUE(entity->metadata().specifics_hash().empty());
269 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty()); 265 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
270 266
271 EXPECT_FALSE(entity->IsUnsynced()); 267 EXPECT_FALSE(entity->IsUnsynced());
272 EXPECT_FALSE(entity->RequiresCommitRequest()); 268 EXPECT_FALSE(entity->RequiresCommitRequest());
273 EXPECT_FALSE(entity->RequiresCommitData()); 269 EXPECT_FALSE(entity->RequiresCommitData());
274 EXPECT_TRUE(entity->CanClearMetadata()); 270 EXPECT_TRUE(entity->CanClearMetadata());
275 EXPECT_TRUE(entity->UpdateIsReflection(1)); 271 EXPECT_TRUE(entity->UpdateIsReflection(1));
276 EXPECT_FALSE(entity->UpdateIsReflection(2)); 272 EXPECT_FALSE(entity->UpdateIsReflection(2));
277 EXPECT_FALSE(entity->HasCommitData()); 273 EXPECT_FALSE(entity->HasCommitData());
278 } 274 }
279 275
280 // Apply a deletion update to a synced item. 276 // Apply a deletion update to a synced item.
281 TEST_F(ProcessorEntityTrackerTest, ServerTombstone) { 277 TEST_F(ProcessorEntityTrackerTest, ServerTombstone) {
282 // Start with a non-deleted state with version 1. 278 // Start with a non-deleted state with version 1.
283 std::unique_ptr<ProcessorEntityTracker> entity = CreateSynced(); 279 std::unique_ptr<ProcessorEntityTracker> entity = CreateSynced();
284 // A deletion update one version later. 280 // A deletion update one version later.
285 const base::Time mtime = base::Time::Now(); 281 const base::Time mtime = base::Time::Now();
286 entity->RecordAcceptedUpdate( 282 entity->RecordAcceptedUpdate(
287 GenerateTombstone(*entity, kHash, kId, kName, mtime, 2)); 283 GenerateTombstone(*entity, kHash, kId, kName, mtime, 2));
288 284
289 EXPECT_TRUE(entity->metadata().is_deleted()); 285 EXPECT_TRUE(entity->metadata().is_deleted());
290 EXPECT_EQ(0, entity->metadata().sequence_number()); 286 EXPECT_EQ(0, entity->metadata().sequence_number());
291 EXPECT_EQ(0, entity->metadata().acked_sequence_number()); 287 EXPECT_EQ(0, entity->metadata().acked_sequence_number());
292 EXPECT_EQ(2, entity->metadata().server_version()); 288 EXPECT_EQ(2, entity->metadata().server_version());
293 EXPECT_EQ(syncer::TimeToProtoTime(mtime), 289 EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
294 entity->metadata().modification_time());
295 EXPECT_TRUE(entity->metadata().specifics_hash().empty()); 290 EXPECT_TRUE(entity->metadata().specifics_hash().empty());
296 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty()); 291 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
297 292
298 EXPECT_FALSE(entity->IsUnsynced()); 293 EXPECT_FALSE(entity->IsUnsynced());
299 EXPECT_FALSE(entity->RequiresCommitRequest()); 294 EXPECT_FALSE(entity->RequiresCommitRequest());
300 EXPECT_FALSE(entity->RequiresCommitData()); 295 EXPECT_FALSE(entity->RequiresCommitData());
301 EXPECT_TRUE(entity->CanClearMetadata()); 296 EXPECT_TRUE(entity->CanClearMetadata());
302 EXPECT_TRUE(entity->UpdateIsReflection(2)); 297 EXPECT_TRUE(entity->UpdateIsReflection(2));
303 EXPECT_FALSE(entity->UpdateIsReflection(3)); 298 EXPECT_FALSE(entity->UpdateIsReflection(3));
304 EXPECT_FALSE(entity->HasCommitData()); 299 EXPECT_FALSE(entity->HasCommitData());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 EXPECT_TRUE(entity->IsUnsynced()); 382 EXPECT_TRUE(entity->IsUnsynced());
388 EXPECT_FALSE(entity->RequiresCommitRequest()); 383 EXPECT_FALSE(entity->RequiresCommitRequest());
389 EXPECT_FALSE(entity->RequiresCommitData()); 384 EXPECT_FALSE(entity->RequiresCommitData());
390 EXPECT_FALSE(entity->CanClearMetadata()); 385 EXPECT_FALSE(entity->CanClearMetadata());
391 EXPECT_FALSE(entity->HasCommitData()); 386 EXPECT_FALSE(entity->HasCommitData());
392 387
393 const EntityData& data = request.entity.value(); 388 const EntityData& data = request.entity.value();
394 EXPECT_EQ(kId, data.id); 389 EXPECT_EQ(kId, data.id);
395 EXPECT_EQ(kHash, data.client_tag_hash); 390 EXPECT_EQ(kHash, data.client_tag_hash);
396 EXPECT_EQ("", data.non_unique_name); 391 EXPECT_EQ("", data.non_unique_name);
397 EXPECT_EQ(syncer::TimeToProtoTime(ctime_), 392 EXPECT_EQ(TimeToProtoTime(ctime_), TimeToProtoTime(data.creation_time));
398 syncer::TimeToProtoTime(data.creation_time));
399 EXPECT_EQ(entity->metadata().modification_time(), 393 EXPECT_EQ(entity->metadata().modification_time(),
400 syncer::TimeToProtoTime(data.modification_time)); 394 TimeToProtoTime(data.modification_time));
401 EXPECT_TRUE(data.is_deleted()); 395 EXPECT_TRUE(data.is_deleted());
402 EXPECT_EQ(1, request.sequence_number); 396 EXPECT_EQ(1, request.sequence_number);
403 EXPECT_EQ(1, request.base_version); 397 EXPECT_EQ(1, request.base_version);
404 EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash); 398 EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash);
405 399
406 // Ack the deletion. 400 // Ack the deletion.
407 entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2)); 401 entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2));
408 402
409 EXPECT_TRUE(entity->metadata().is_deleted()); 403 EXPECT_TRUE(entity->metadata().is_deleted());
410 EXPECT_EQ(1, entity->metadata().sequence_number()); 404 EXPECT_EQ(1, entity->metadata().sequence_number());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_EQ(specifics_hash_v2, entity->metadata().specifics_hash()); 478 EXPECT_EQ(specifics_hash_v2, entity->metadata().specifics_hash());
485 EXPECT_EQ("", entity->metadata().base_specifics_hash()); 479 EXPECT_EQ("", entity->metadata().base_specifics_hash());
486 480
487 EXPECT_FALSE(entity->IsUnsynced()); 481 EXPECT_FALSE(entity->IsUnsynced());
488 EXPECT_FALSE(entity->RequiresCommitRequest()); 482 EXPECT_FALSE(entity->RequiresCommitRequest());
489 EXPECT_FALSE(entity->RequiresCommitData()); 483 EXPECT_FALSE(entity->RequiresCommitData());
490 EXPECT_FALSE(entity->CanClearMetadata()); 484 EXPECT_FALSE(entity->CanClearMetadata());
491 EXPECT_FALSE(entity->HasCommitData()); 485 EXPECT_FALSE(entity->HasCommitData());
492 } 486 }
493 487
494 } // namespace syncer_v2 488 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core/processor_entity_tracker.cc ('k') | components/sync/core/shared_model_type_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698