Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / sync_driver / device_info_sync_service_unittest.cc
blob1eb5116790c1a750159ba22ceffa1a7e135eae72
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
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "components/sync_driver/device_info_sync_service.h"
7 #include "components/sync_driver/local_device_info_provider_mock.h"
8 #include "sync/api/sync_change.h"
9 #include "sync/api/sync_change_processor.h"
10 #include "sync/api/sync_change_processor_wrapper_for_test.h"
11 #include "sync/api/sync_error_factory_mock.h"
12 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
13 #include "sync/util/time.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using syncer::AttachmentIdList;
17 using syncer::AttachmentServiceProxyForTest;
18 using syncer::ModelType;
19 using syncer::SyncChange;
20 using syncer::SyncChangeList;
21 using syncer::SyncChangeProcessor;
22 using syncer::SyncChangeProcessorWrapperForTest;
23 using syncer::SyncData;
24 using syncer::SyncDataList;
25 using syncer::SyncError;
26 using syncer::SyncErrorFactory;
27 using syncer::SyncErrorFactoryMock;
28 using syncer::SyncMergeResult;
30 namespace sync_driver {
32 namespace {
34 class TestChangeProcessor : public SyncChangeProcessor {
35 public:
36 TestChangeProcessor() {}
37 ~TestChangeProcessor() override {}
39 // SyncChangeProcessor implementation.
40 // Store a copy of all the changes passed in so we can examine them later.
41 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here,
42 const SyncChangeList& change_list) override {
43 change_list_ = change_list;
44 return SyncError();
47 // This method isn't used in these tests.
48 SyncDataList GetAllSyncData(ModelType type) const override {
49 return SyncDataList();
52 size_t change_list_size() const { return change_list_.size(); }
54 SyncChange::SyncChangeType change_type_at(size_t index) const {
55 CHECK_LT(index, change_list_size());
56 return change_list_[index].change_type();
59 const sync_pb::DeviceInfoSpecifics& device_info_at(size_t index) const {
60 CHECK_LT(index, change_list_size());
61 return change_list_[index].sync_data().GetSpecifics().device_info();
64 const std::string& cache_guid_at(size_t index) const {
65 return device_info_at(index).cache_guid();
68 const std::string& client_name_at(size_t index) const {
69 return device_info_at(index).client_name();
72 private:
73 SyncChangeList change_list_;
76 class DeviceInfoSyncServiceTest : public testing::Test,
77 public DeviceInfoTracker::Observer {
78 public:
79 DeviceInfoSyncServiceTest() : num_device_info_changed_callbacks_(0) {}
80 ~DeviceInfoSyncServiceTest() override {}
82 void SetUp() override {
83 local_device_.reset(new LocalDeviceInfoProviderMock(
84 "guid_1",
85 "client_1",
86 "Chromium 10k",
87 "Chrome 10k",
88 sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
89 "device_id"));
90 sync_service_.reset(new DeviceInfoSyncService(local_device_.get()));
91 sync_processor_.reset(new TestChangeProcessor());
92 // Register observer
93 sync_service_->AddObserver(this);
96 void TearDown() override { sync_service_->RemoveObserver(this); }
98 void OnDeviceInfoChange() override { num_device_info_changed_callbacks_++; }
100 scoped_ptr<SyncChangeProcessor> PassProcessor() {
101 return scoped_ptr<SyncChangeProcessor>(
102 new SyncChangeProcessorWrapperForTest(sync_processor_.get()));
105 scoped_ptr<SyncErrorFactory> CreateAndPassSyncErrorFactory() {
106 return scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock());
109 SyncData CreateRemoteData(const std::string& client_id,
110 const std::string& client_name,
111 int64 backup_timestamp = 0) {
112 sync_pb::EntitySpecifics entity;
113 sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info();
115 specifics.set_cache_guid(client_id);
116 specifics.set_client_name(client_name);
117 specifics.set_chrome_version("Chromium 10k");
118 specifics.set_sync_user_agent("Chrome 10k");
119 specifics.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_LINUX);
120 specifics.set_signin_scoped_device_id("device_id");
122 if (backup_timestamp != 0) {
123 specifics.set_backup_timestamp(backup_timestamp);
126 return SyncData::CreateRemoteData(1,
127 entity,
128 base::Time(),
129 AttachmentIdList(),
130 AttachmentServiceProxyForTest::Create());
133 void AddInitialData(SyncDataList& sync_data_list,
134 const std::string& client_id,
135 const std::string& client_name) {
136 SyncData sync_data = CreateRemoteData(client_id, client_name);
137 sync_data_list.push_back(sync_data);
140 void AddChange(SyncChangeList& change_list,
141 SyncChange::SyncChangeType change_type,
142 const std::string& client_id,
143 const std::string& client_name) {
144 SyncData sync_data = CreateRemoteData(client_id, client_name);
145 SyncChange sync_change(FROM_HERE, change_type, sync_data);
146 change_list.push_back(sync_change);
149 protected:
150 int num_device_info_changed_callbacks_;
151 base::MessageLoopForUI message_loop_;
152 scoped_ptr<LocalDeviceInfoProviderMock> local_device_;
153 scoped_ptr<DeviceInfoSyncService> sync_service_;
154 scoped_ptr<TestChangeProcessor> sync_processor_;
157 // Sync with empty initial data.
158 TEST_F(DeviceInfoSyncServiceTest, StartSyncEmptyInitialData) {
159 EXPECT_FALSE(sync_service_->IsSyncing());
161 SyncMergeResult merge_result =
162 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
163 SyncDataList(),
164 PassProcessor(),
165 CreateAndPassSyncErrorFactory());
167 EXPECT_TRUE(sync_service_->IsSyncing());
168 EXPECT_EQ(0, merge_result.num_items_added());
169 EXPECT_EQ(0, merge_result.num_items_modified());
170 EXPECT_EQ(0, merge_result.num_items_deleted());
171 EXPECT_EQ(1, merge_result.num_items_before_association());
172 EXPECT_EQ(1, merge_result.num_items_after_association());
173 EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0));
175 EXPECT_EQ(1U, sync_processor_->change_list_size());
176 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
178 // Should have one device info corresponding to local device info.
179 EXPECT_EQ(1U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size());
180 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size());
181 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1"));
182 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0"));
185 TEST_F(DeviceInfoSyncServiceTest, StopSyncing) {
186 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing(
187 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(),
188 CreateAndPassSyncErrorFactory());
189 EXPECT_TRUE(sync_service_->IsSyncing());
190 EXPECT_EQ(1, num_device_info_changed_callbacks_);
191 sync_service_->StopSyncing(syncer::DEVICE_INFO);
192 EXPECT_FALSE(sync_service_->IsSyncing());
193 EXPECT_EQ(2, num_device_info_changed_callbacks_);
196 // Sync with initial data matching the local device data.
197 TEST_F(DeviceInfoSyncServiceTest, StartSyncMatchingInitialData) {
198 SyncDataList sync_data;
199 AddInitialData(sync_data, "guid_1", "client_1");
201 SyncMergeResult merge_result =
202 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
203 sync_data,
204 PassProcessor(),
205 CreateAndPassSyncErrorFactory());
206 EXPECT_EQ(0, merge_result.num_items_added());
207 EXPECT_EQ(0, merge_result.num_items_modified());
208 EXPECT_EQ(0, merge_result.num_items_deleted());
209 EXPECT_EQ(1, merge_result.num_items_before_association());
210 EXPECT_EQ(1, merge_result.num_items_after_association());
212 // No changes expected because the device info matches.
213 EXPECT_EQ(0U, sync_processor_->change_list_size());
215 EXPECT_EQ(1U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size());
216 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size());
217 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1"));
218 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0"));
221 // Sync with misc initial data.
222 TEST_F(DeviceInfoSyncServiceTest, StartSync) {
223 SyncDataList sync_data;
224 AddInitialData(sync_data, "guid_2", "foo");
225 AddInitialData(sync_data, "guid_3", "bar");
226 // This guid matches the local device but the client name is different.
227 AddInitialData(sync_data, "guid_1", "baz");
229 SyncMergeResult merge_result =
230 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
231 sync_data,
232 PassProcessor(),
233 CreateAndPassSyncErrorFactory());
235 EXPECT_EQ(2, merge_result.num_items_added());
236 EXPECT_EQ(1, merge_result.num_items_modified());
237 EXPECT_EQ(0, merge_result.num_items_deleted());
238 EXPECT_EQ(1, merge_result.num_items_before_association());
239 EXPECT_EQ(3, merge_result.num_items_after_association());
241 EXPECT_EQ(1U, sync_processor_->change_list_size());
242 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0));
243 EXPECT_EQ("client_1", sync_processor_->client_name_at(0));
245 EXPECT_EQ(3U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size());
246 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size());
247 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1"));
248 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2"));
249 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_3"));
250 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0"));
253 // Process sync change with ACTION_ADD.
254 // Verify callback.
255 TEST_F(DeviceInfoSyncServiceTest, ProcessAddChange) {
256 EXPECT_EQ(0, num_device_info_changed_callbacks_);
258 // Start with an empty initial data.
259 SyncMergeResult merge_result =
260 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
261 SyncDataList(),
262 PassProcessor(),
263 CreateAndPassSyncErrorFactory());
264 // There should be only one item corresponding to the local device
265 EXPECT_EQ(1, merge_result.num_items_after_association());
266 EXPECT_EQ(1, num_device_info_changed_callbacks_);
268 // Add a new device info with a non-matching guid.
269 SyncChangeList change_list;
270 AddChange(change_list, SyncChange::ACTION_ADD, "guid_2", "foo");
272 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
273 EXPECT_FALSE(error.IsSet());
274 EXPECT_EQ(2, num_device_info_changed_callbacks_);
276 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size());
278 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1"));
279 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2"));
280 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0"));
283 // Process multiple sync change with ACTION_UPDATE and ACTION_ADD.
284 // Verify that callback is called multiple times.
285 TEST_F(DeviceInfoSyncServiceTest, ProcessMultipleChanges) {
286 SyncDataList sync_data;
287 AddInitialData(sync_data, "guid_2", "foo");
288 AddInitialData(sync_data, "guid_3", "bar");
290 SyncMergeResult merge_result =
291 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
292 sync_data,
293 PassProcessor(),
294 CreateAndPassSyncErrorFactory());
295 EXPECT_EQ(3, merge_result.num_items_after_association());
296 // reset callbacks counter
297 num_device_info_changed_callbacks_ = 0;
299 SyncChangeList change_list;
300 AddChange(change_list, SyncChange::ACTION_UPDATE, "guid_2", "foo_2");
302 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
303 EXPECT_FALSE(error.IsSet());
305 EXPECT_EQ(1, num_device_info_changed_callbacks_);
306 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size());
307 EXPECT_EQ("foo_2", sync_service_->GetDeviceInfo("guid_2")->client_name());
309 change_list.clear();
310 AddChange(change_list, SyncChange::ACTION_UPDATE, "guid_3", "bar_3");
311 AddChange(change_list, SyncChange::ACTION_ADD, "guid_4", "baz_4");
313 error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
314 EXPECT_FALSE(error.IsSet());
316 EXPECT_EQ(2, num_device_info_changed_callbacks_);
317 EXPECT_EQ(4U, sync_service_->GetAllDeviceInfo().size());
318 EXPECT_EQ("bar_3", sync_service_->GetDeviceInfo("guid_3")->client_name());
319 EXPECT_EQ("baz_4", sync_service_->GetDeviceInfo("guid_4")->client_name());
322 // Process update to the local device info and verify that it is ignored.
323 TEST_F(DeviceInfoSyncServiceTest, ProcessUpdateChangeMatchingLocalDevice) {
324 SyncMergeResult merge_result =
325 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
326 SyncDataList(),
327 PassProcessor(),
328 CreateAndPassSyncErrorFactory());
329 EXPECT_EQ(1, merge_result.num_items_after_association());
330 // reset callbacks counter
331 num_device_info_changed_callbacks_ = 0;
333 SyncChangeList change_list;
334 AddChange(change_list, SyncChange::ACTION_UPDATE, "guid_1", "foo_1");
336 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
337 EXPECT_FALSE(error.IsSet());
338 // Callback shouldn't be sent in this case.
339 EXPECT_EQ(0, num_device_info_changed_callbacks_);
340 // Should still have the old local device Info.
341 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size());
342 EXPECT_EQ("client_1", sync_service_->GetDeviceInfo("guid_1")->client_name());
345 // Process sync change with ACTION_DELETE.
346 TEST_F(DeviceInfoSyncServiceTest, ProcessDeleteChange) {
347 SyncDataList sync_data;
348 AddInitialData(sync_data, "guid_2", "foo");
349 AddInitialData(sync_data, "guid_3", "bar");
351 SyncMergeResult merge_result =
352 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
353 sync_data,
354 PassProcessor(),
355 CreateAndPassSyncErrorFactory());
356 EXPECT_EQ(3, merge_result.num_items_after_association());
357 // reset callbacks counter
358 num_device_info_changed_callbacks_ = 0;
360 SyncChangeList change_list;
361 AddChange(change_list, SyncChange::ACTION_DELETE, "guid_2", "foo_2");
363 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
364 EXPECT_FALSE(error.IsSet());
366 EXPECT_EQ(1, num_device_info_changed_callbacks_);
367 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size());
368 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_2"));
371 // Process sync change with unexpected action.
372 TEST_F(DeviceInfoSyncServiceTest, ProcessInvalidChange) {
373 SyncMergeResult merge_result =
374 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
375 SyncDataList(),
376 PassProcessor(),
377 CreateAndPassSyncErrorFactory());
378 EXPECT_EQ(1, merge_result.num_items_after_association());
379 // reset callbacks counter
380 num_device_info_changed_callbacks_ = 0;
382 SyncChangeList change_list;
383 AddChange(change_list, (SyncChange::SyncChangeType)100, "guid_2", "foo_2");
385 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
386 EXPECT_TRUE(error.IsSet());
388 // The number of callback should still be zero.
389 EXPECT_EQ(0, num_device_info_changed_callbacks_);
390 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size());
393 // Process sync change after unsubscribing from notifications.
394 TEST_F(DeviceInfoSyncServiceTest, ProcessChangesAfterUnsubscribing) {
395 SyncMergeResult merge_result =
396 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
397 SyncDataList(),
398 PassProcessor(),
399 CreateAndPassSyncErrorFactory());
400 EXPECT_EQ(1, merge_result.num_items_after_association());
401 // reset callbacks counter
402 num_device_info_changed_callbacks_ = 0;
404 SyncChangeList change_list;
405 AddChange(change_list, SyncChange::ACTION_ADD, "guid_2", "foo_2");
407 // Unsubscribe observer before processing changes.
408 sync_service_->RemoveObserver(this);
410 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
411 EXPECT_FALSE(error.IsSet());
413 // The number of callback should still be zero.
414 EXPECT_EQ(0, num_device_info_changed_callbacks_);
417 // Verifies setting backup timestamp after the initial sync.
418 TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTime) {
419 // Shouldn't have backuptime initially.
420 base::Time backup_time = sync_service_->GetLocalDeviceBackupTime();
421 EXPECT_TRUE(backup_time.is_null());
423 // Perform the initial sync with empty data.
424 SyncMergeResult merge_result =
425 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
426 SyncDataList(),
427 PassProcessor(),
428 CreateAndPassSyncErrorFactory());
430 // Should have local device after the initial sync.
431 EXPECT_EQ(1U, sync_processor_->change_list_size());
432 EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0));
434 // Shouldn't have backup time initially.
435 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
436 EXPECT_FALSE(sync_processor_->device_info_at(0).has_backup_timestamp());
438 sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(1000));
440 // Should have local device info updated with the specified backup timestamp.
441 EXPECT_EQ(1U, sync_processor_->change_list_size());
442 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0));
443 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
444 EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp());
446 backup_time = syncer::ProtoTimeToTime(
447 sync_processor_->device_info_at(0).backup_timestamp());
448 EXPECT_EQ(1000, backup_time.ToTimeT());
450 // Also verify that we get the same backup time directly from the service.
451 backup_time = sync_service_->GetLocalDeviceBackupTime();
452 EXPECT_EQ(1000, backup_time.ToTimeT());
455 // Verifies setting backup timestamp prior to the initial sync.
456 TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTimeBeforeSync) {
457 // Set the backup timestamp.
458 sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(2000));
459 // Verify that we get it back.
460 base::Time backup_time = sync_service_->GetLocalDeviceBackupTime();
461 EXPECT_EQ(2000, backup_time.ToTimeT());
463 // Now perform the initial sync with empty data.
464 SyncMergeResult merge_result =
465 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
466 SyncDataList(),
467 PassProcessor(),
468 CreateAndPassSyncErrorFactory());
470 // Should have local device after the initial sync.
471 // Should have the backup timestamp set.
472 EXPECT_EQ(1U, sync_processor_->change_list_size());
473 EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0));
474 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
475 EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp());
477 backup_time = syncer::ProtoTimeToTime(
478 sync_processor_->device_info_at(0).backup_timestamp());
479 EXPECT_EQ(2000, backup_time.ToTimeT());
482 // Verifies that the backup timestamp that comes in the intial sync data
483 // gets preserved when there are no changes to the local device.
484 TEST_F(DeviceInfoSyncServiceTest, PreserveBackupTimeWithMatchingLocalDevice) {
485 base::Time backup_time = base::Time::FromTimeT(3000);
486 SyncDataList sync_data;
487 sync_data.push_back(CreateRemoteData(
488 "guid_1", "client_1", syncer::TimeToProtoTime(backup_time)));
490 SyncMergeResult merge_result =
491 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
492 sync_data,
493 PassProcessor(),
494 CreateAndPassSyncErrorFactory());
496 // Everything is matching so there should be no updates.
497 EXPECT_EQ(0U, sync_processor_->change_list_size());
499 // Verify that we get back the same time.
500 backup_time = sync_service_->GetLocalDeviceBackupTime();
501 EXPECT_EQ(3000, backup_time.ToTimeT());
504 // Verifies that the backup timestamp that comes in the intial sync data
505 // gets merged with the local device data.
506 TEST_F(DeviceInfoSyncServiceTest, MergeBackupTimeWithMatchingLocalDevice) {
507 base::Time backup_time = base::Time::FromTimeT(4000);
508 SyncDataList sync_data;
509 sync_data.push_back(CreateRemoteData(
510 "guid_1", "foo_1", syncer::TimeToProtoTime(backup_time)));
512 SyncMergeResult merge_result =
513 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
514 sync_data,
515 PassProcessor(),
516 CreateAndPassSyncErrorFactory());
518 // Should be one change because of the client name mismatch.
519 // However the backup time passed in the initial data should be merged into
520 // the change.
521 EXPECT_EQ(1U, sync_processor_->change_list_size());
523 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0));
524 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
525 EXPECT_EQ("client_1", sync_processor_->client_name_at(0));
527 backup_time = syncer::ProtoTimeToTime(
528 sync_processor_->device_info_at(0).backup_timestamp());
529 EXPECT_EQ(4000, backup_time.ToTimeT());
532 // Verifies that mismatching backup timestamp generates an update even
533 // when the rest of local device data is matching.
534 TEST_F(DeviceInfoSyncServiceTest,
535 MergeMismatchingBackupTimeWithMatchingLocalDevice) {
536 base::Time backup_time = base::Time::FromTimeT(5000);
537 SyncDataList sync_data;
538 sync_data.push_back(CreateRemoteData(
539 "guid_1", "client_1", syncer::TimeToProtoTime(backup_time)));
541 // Set the backup timestamp different than the one in the sync data.
542 sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(6000));
544 SyncMergeResult merge_result =
545 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO,
546 sync_data,
547 PassProcessor(),
548 CreateAndPassSyncErrorFactory());
550 // Should generate and update due to timestamp mismatch.
551 // The locally set timestamp wins.
552 EXPECT_EQ(1U, sync_processor_->change_list_size());
554 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0));
555 EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0));
556 EXPECT_EQ("client_1", sync_processor_->client_name_at(0));
558 backup_time = syncer::ProtoTimeToTime(
559 sync_processor_->device_info_at(0).backup_timestamp());
560 EXPECT_EQ(6000, backup_time.ToTimeT());
563 } // namespace
565 } // namespace sync_driver