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

Side by Side Diff: components/sync/device_info/device_info_sync_bridge_unittest.cc

Issue 2856933005: [Sync] Create UserEventSyncBridge. (Closed)
Patch Set: Removing autocomplete_sync_bridge_unittest.cc from cl. Created 3 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/device_info/device_info_sync_bridge.h" 5 #include "components/sync/device_info/device_info_sync_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Some tests may never initialize the bridge. 186 // Some tests may never initialize the bridge.
187 if (bridge_) 187 if (bridge_)
188 bridge_->RemoveObserver(this); 188 bridge_->RemoveObserver(this);
189 189
190 // Force all remaining (store) tasks to execute so we don't leak memory. 190 // Force all remaining (store) tasks to execute so we don't leak memory.
191 base::RunLoop().RunUntilIdle(); 191 base::RunLoop().RunUntilIdle();
192 } 192 }
193 193
194 void OnDeviceInfoChange() override { change_count_++; } 194 void OnDeviceInfoChange() override { change_count_++; }
195 195
196 std::unique_ptr<ModelTypeChangeProcessor> CreateModelTypeChangeProcessor(
197 ModelType type,
198 ModelTypeSyncBridge* bridge) {
199 auto processor = base::MakeUnique<RecordingModelTypeChangeProcessor>();
200 processor_ = processor.get();
201 return std::move(processor);
202 }
203
204 // Initialized the bridge based on the current local device and store. Can 196 // Initialized the bridge based on the current local device and store. Can
205 // only be called once per run, as it passes |store_|. 197 // only be called once per run, as it passes |store_|.
206 void InitializeBridge() { 198 void InitializeBridge() {
207 ASSERT_TRUE(store_); 199 ASSERT_TRUE(store_);
208 bridge_ = base::MakeUnique<DeviceInfoSyncBridge>( 200 bridge_ = base::MakeUnique<DeviceInfoSyncBridge>(
209 provider_.get(), 201 provider_.get(),
210 base::Bind(&ModelTypeStoreTestUtil::MoveStoreToCallback, 202 base::Bind(&ModelTypeStoreTestUtil::MoveStoreToCallback,
211 base::Passed(&store_)), 203 base::Passed(&store_)),
212 base::Bind(&DeviceInfoSyncBridgeTest::CreateModelTypeChangeProcessor, 204 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_));
213 base::Unretained(this)));
214 bridge_->AddObserver(this); 205 bridge_->AddObserver(this);
215 } 206 }
216 207
217 // Creates the bridge and runs any outstanding tasks. This will typically 208 // Creates the bridge and runs any outstanding tasks. This will typically
218 // cause all initialization callbacks between the sevice and store to fire. 209 // cause all initialization callbacks between the sevice and store to fire.
219 void InitializeAndPump() { 210 void InitializeAndPump() {
220 InitializeBridge(); 211 InitializeBridge();
221 base::RunLoop().RunUntilIdle(); 212 base::RunLoop().RunUntilIdle();
222 } 213 }
223 214
(...skipping 13 matching lines...) Expand all
237 std::swap(provider_, provider); 228 std::swap(provider_, provider);
238 } 229 }
239 LocalDeviceInfoProviderMock* local_device() { return provider_.get(); } 230 LocalDeviceInfoProviderMock* local_device() { return provider_.get(); }
240 231
241 // Allows access to the bridge after InitializeBridge() is called. 232 // Allows access to the bridge after InitializeBridge() is called.
242 DeviceInfoSyncBridge* bridge() { 233 DeviceInfoSyncBridge* bridge() {
243 EXPECT_TRUE(bridge_); 234 EXPECT_TRUE(bridge_);
244 return bridge_.get(); 235 return bridge_.get();
245 } 236 }
246 237
247 RecordingModelTypeChangeProcessor* processor() { 238 const RecordingModelTypeChangeProcessor& processor() { return *processor_; }
248 EXPECT_TRUE(processor_);
249 return processor_;
250 }
251 239
252 const OneShotTimer& pulse_timer() { return bridge()->pulse_timer_; } 240 const OneShotTimer& pulse_timer() { return bridge()->pulse_timer_; }
253 241
254 // Should only be called after the bridge has been initialized. Will first 242 // Should only be called after the bridge has been initialized. Will first
255 // recover the bridge's store, so another can be initialized later, and then 243 // recover the bridge's store, so another can be initialized later, and then
256 // deletes the bridge. 244 // deletes the bridge.
257 void PumpAndShutdown() { 245 void PumpAndShutdown() {
258 ASSERT_TRUE(bridge_); 246 ASSERT_TRUE(bridge_);
259 base::RunLoop().RunUntilIdle(); 247 base::RunLoop().RunUntilIdle();
260 std::swap(store_, bridge_->store_); 248 std::swap(store_, bridge_->store_);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 330
343 const DeviceInfoList devices = bridge()->GetAllDeviceInfo(); 331 const DeviceInfoList devices = bridge()->GetAllDeviceInfo();
344 ASSERT_EQ(1u, devices.size()); 332 ASSERT_EQ(1u, devices.size());
345 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0])); 333 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0]));
346 } 334 }
347 335
348 // Metadata shouldn't be loaded before the provider is initialized. 336 // Metadata shouldn't be loaded before the provider is initialized.
349 TEST_F(DeviceInfoSyncBridgeTest, LocalProviderInitRace) { 337 TEST_F(DeviceInfoSyncBridgeTest, LocalProviderInitRace) {
350 set_provider(base::MakeUnique<LocalDeviceInfoProviderMock>()); 338 set_provider(base::MakeUnique<LocalDeviceInfoProviderMock>());
351 InitializeAndPump(); 339 InitializeAndPump();
352 EXPECT_FALSE(processor()->metadata()); 340 EXPECT_FALSE(processor().metadata());
353 341
354 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size()); 342 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size());
355 local_device()->Initialize(CreateModel(1)); 343 local_device()->Initialize(CreateModel(1));
356 base::RunLoop().RunUntilIdle(); 344 base::RunLoop().RunUntilIdle();
357 345
358 DeviceInfoList devices = bridge()->GetAllDeviceInfo(); 346 DeviceInfoList devices = bridge()->GetAllDeviceInfo();
359 ASSERT_EQ(1u, devices.size()); 347 ASSERT_EQ(1u, devices.size());
360 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0])); 348 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0]));
361 349
362 EXPECT_TRUE(processor()->metadata()); 350 EXPECT_TRUE(processor().metadata());
363 } 351 }
364 352
365 // Simulate shutting down sync during the ModelTypeStore callbacks. The pulse 353 // Simulate shutting down sync during the ModelTypeStore callbacks. The pulse
366 // timer should still be initialized, even though reconcile never occurs. 354 // timer should still be initialized, even though reconcile never occurs.
367 TEST_F(DeviceInfoSyncBridgeTest, ClearProviderDuringInit) { 355 TEST_F(DeviceInfoSyncBridgeTest, ClearProviderDuringInit) {
368 InitializeBridge(); 356 InitializeBridge();
369 local_device()->Clear(); 357 local_device()->Clear();
370 base::RunLoop().RunUntilIdle(); 358 base::RunLoop().RunUntilIdle();
371 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size()); 359 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size());
372 EXPECT_TRUE(pulse_timer().IsRunning()); 360 EXPECT_TRUE(pulse_timer().IsRunning());
(...skipping 28 matching lines...) Expand all
401 *bridge()->GetDeviceInfo(specifics.cache_guid()).get()); 389 *bridge()->GetDeviceInfo(specifics.cache_guid()).get());
402 } 390 }
403 391
404 TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalMetadata) { 392 TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalMetadata) {
405 WriteToStore(std::vector<DeviceInfoSpecifics>(), StateWithEncryption("ekn")); 393 WriteToStore(std::vector<DeviceInfoSpecifics>(), StateWithEncryption("ekn"));
406 InitializeAndPump(); 394 InitializeAndPump();
407 395
408 const DeviceInfoList devices = bridge()->GetAllDeviceInfo(); 396 const DeviceInfoList devices = bridge()->GetAllDeviceInfo();
409 ASSERT_EQ(1u, devices.size()); 397 ASSERT_EQ(1u, devices.size());
410 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0])); 398 EXPECT_TRUE(local_device()->GetLocalDeviceInfo()->Equals(*devices[0]));
411 EXPECT_EQ(1u, processor()->put_multimap().size()); 399 EXPECT_EQ(1u, processor().put_multimap().size());
412 } 400 }
413 401
414 TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) { 402 TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) {
415 const DeviceInfoSpecifics specifics = CreateSpecifics(1); 403 const DeviceInfoSpecifics specifics = CreateSpecifics(1);
416 ModelTypeState state = StateWithEncryption("ekn"); 404 ModelTypeState state = StateWithEncryption("ekn");
417 WriteToStore({specifics}, state); 405 WriteToStore({specifics}, state);
418 InitializeAndPump(); 406 InitializeAndPump();
419 407
420 ASSERT_EQ(2u, bridge()->GetAllDeviceInfo().size()); 408 ASSERT_EQ(2u, bridge()->GetAllDeviceInfo().size());
421 VerifyEqual(specifics, 409 VerifyEqual(specifics,
422 *bridge()->GetDeviceInfo(specifics.cache_guid()).get()); 410 *bridge()->GetDeviceInfo(specifics.cache_guid()).get());
423 EXPECT_TRUE(processor()->metadata()); 411 EXPECT_TRUE(processor().metadata());
424 EXPECT_EQ(state.encryption_key_name(), 412 EXPECT_EQ(state.encryption_key_name(),
425 processor()->metadata()->GetModelTypeState().encryption_key_name()); 413 processor().metadata()->GetModelTypeState().encryption_key_name());
426 } 414 }
427 415
428 TEST_F(DeviceInfoSyncBridgeTest, GetData) { 416 TEST_F(DeviceInfoSyncBridgeTest, GetData) {
429 const DeviceInfoSpecifics specifics1 = CreateSpecifics(1); 417 const DeviceInfoSpecifics specifics1 = CreateSpecifics(1);
430 const DeviceInfoSpecifics specifics2 = CreateSpecifics(2); 418 const DeviceInfoSpecifics specifics2 = CreateSpecifics(2);
431 const DeviceInfoSpecifics specifics3 = CreateSpecifics(3); 419 const DeviceInfoSpecifics specifics3 = CreateSpecifics(3);
432 WriteToStore({specifics1, specifics2, specifics3}); 420 WriteToStore({specifics1, specifics2, specifics3});
433 InitializeAndPump(); 421 InitializeAndPump();
434 422
435 const std::map<std::string, DeviceInfoSpecifics> expected{ 423 const std::map<std::string, DeviceInfoSpecifics> expected{
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 EXPECT_FALSE(error); 495 EXPECT_FALSE(error);
508 EXPECT_EQ(2, change_count()); 496 EXPECT_EQ(2, change_count());
509 497
510 RestartBridge(); 498 RestartBridge();
511 499
512 std::unique_ptr<DeviceInfo> info = 500 std::unique_ptr<DeviceInfo> info =
513 bridge()->GetDeviceInfo(specifics.cache_guid()); 501 bridge()->GetDeviceInfo(specifics.cache_guid());
514 ASSERT_TRUE(info); 502 ASSERT_TRUE(info);
515 VerifyEqual(specifics, *info.get()); 503 VerifyEqual(specifics, *info.get());
516 504
517 EXPECT_TRUE(processor()->metadata()); 505 EXPECT_TRUE(processor().metadata());
518 EXPECT_EQ(state.encryption_key_name(), 506 EXPECT_EQ(state.encryption_key_name(),
519 processor()->metadata()->GetModelTypeState().encryption_key_name()); 507 processor().metadata()->GetModelTypeState().encryption_key_name());
520 } 508 }
521 509
522 TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) { 510 TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) {
523 InitializeAndPump(); 511 InitializeAndPump();
524 512
525 // The bridge should ignore these changes using this specifics because its 513 // The bridge should ignore these changes using this specifics because its
526 // guid will match the local device. 514 // guid will match the local device.
527 const DeviceInfoSpecifics specifics = CreateSpecifics(kDefaultLocalSuffix); 515 const DeviceInfoSpecifics specifics = CreateSpecifics(kDefaultLocalSuffix);
528 516
529 // Should have a single change from reconciliation. 517 // Should have a single change from reconciliation.
530 EXPECT_TRUE( 518 EXPECT_TRUE(
531 bridge()->GetDeviceInfo(local_device()->GetLocalDeviceInfo()->guid())); 519 bridge()->GetDeviceInfo(local_device()->GetLocalDeviceInfo()->guid()));
532 EXPECT_EQ(1, change_count()); 520 EXPECT_EQ(1, change_count());
533 // Ensure |last_updated| is about now, plus or minus a little bit. 521 // Ensure |last_updated| is about now, plus or minus a little bit.
534 const Time last_updated(ProtoTimeToTime(processor() 522 const Time last_updated(ProtoTimeToTime(processor()
535 ->put_multimap() 523 .put_multimap()
536 .begin() 524 .begin()
537 ->second->specifics.device_info() 525 ->second->specifics.device_info()
538 .last_updated_timestamp())); 526 .last_updated_timestamp()));
539 EXPECT_LT(Time::Now() - TimeDelta::FromMinutes(1), last_updated); 527 EXPECT_LT(Time::Now() - TimeDelta::FromMinutes(1), last_updated);
540 EXPECT_GT(Time::Now() + TimeDelta::FromMinutes(1), last_updated); 528 EXPECT_GT(Time::Now() + TimeDelta::FromMinutes(1), last_updated);
541 529
542 auto error_on_add = bridge()->ApplySyncChanges( 530 auto error_on_add = bridge()->ApplySyncChanges(
543 bridge()->CreateMetadataChangeList(), EntityAddList({specifics})); 531 bridge()->CreateMetadataChangeList(), EntityAddList({specifics}));
544 EXPECT_FALSE(error_on_add); 532 EXPECT_FALSE(error_on_add);
545 EXPECT_EQ(1, change_count()); 533 EXPECT_EQ(1, change_count());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) { 571 TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) {
584 InitializeAndPump(); 572 InitializeAndPump();
585 EXPECT_EQ(1, change_count()); 573 EXPECT_EQ(1, change_count());
586 auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), 574 auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
587 EntityDataMap()); 575 EntityDataMap());
588 EXPECT_FALSE(error); 576 EXPECT_FALSE(error);
589 EXPECT_EQ(1, change_count()); 577 EXPECT_EQ(1, change_count());
590 // TODO(skym): Stop sending local twice. The first of the two puts will 578 // TODO(skym): Stop sending local twice. The first of the two puts will
591 // probably happen before the processor is tracking metadata yet, and so there 579 // probably happen before the processor is tracking metadata yet, and so there
592 // should not be much overhead. 580 // should not be much overhead.
593 EXPECT_EQ(2u, processor()->put_multimap().size()); 581 EXPECT_EQ(2u, processor().put_multimap().size());
594 EXPECT_EQ(2u, processor()->put_multimap().count( 582 EXPECT_EQ(2u, processor().put_multimap().count(
595 local_device()->GetLocalDeviceInfo()->guid())); 583 local_device()->GetLocalDeviceInfo()->guid()));
596 EXPECT_EQ(0u, processor()->delete_set().size()); 584 EXPECT_EQ(0u, processor().delete_set().size());
597 } 585 }
598 586
599 TEST_F(DeviceInfoSyncBridgeTest, MergeWithData) { 587 TEST_F(DeviceInfoSyncBridgeTest, MergeWithData) {
600 const DeviceInfoSpecifics unique_local = CreateSpecifics(1); 588 const DeviceInfoSpecifics unique_local = CreateSpecifics(1);
601 DeviceInfoSpecifics conflict_local = CreateSpecifics(2); 589 DeviceInfoSpecifics conflict_local = CreateSpecifics(2);
602 DeviceInfoSpecifics conflict_remote = CreateSpecifics(3); 590 DeviceInfoSpecifics conflict_remote = CreateSpecifics(3);
603 const DeviceInfoSpecifics unique_remote = CreateSpecifics(4); 591 const DeviceInfoSpecifics unique_remote = CreateSpecifics(4);
604 592
605 const std::string conflict_guid = "conflict_guid"; 593 const std::string conflict_guid = "conflict_guid";
606 conflict_local.set_cache_guid(conflict_guid); 594 conflict_local.set_cache_guid(conflict_guid);
(...skipping 16 matching lines...) Expand all
623 611
624 // The remote should beat the local in conflict. 612 // The remote should beat the local in conflict.
625 EXPECT_EQ(4u, bridge()->GetAllDeviceInfo().size()); 613 EXPECT_EQ(4u, bridge()->GetAllDeviceInfo().size());
626 VerifyEqual(unique_local, 614 VerifyEqual(unique_local,
627 *bridge()->GetDeviceInfo(unique_local.cache_guid()).get()); 615 *bridge()->GetDeviceInfo(unique_local.cache_guid()).get());
628 VerifyEqual(unique_remote, 616 VerifyEqual(unique_remote,
629 *bridge()->GetDeviceInfo(unique_remote.cache_guid()).get()); 617 *bridge()->GetDeviceInfo(unique_remote.cache_guid()).get());
630 VerifyEqual(conflict_remote, *bridge()->GetDeviceInfo(conflict_guid).get()); 618 VerifyEqual(conflict_remote, *bridge()->GetDeviceInfo(conflict_guid).get());
631 619
632 // bridge should have told the processor about the existance of unique_local. 620 // bridge should have told the processor about the existance of unique_local.
633 EXPECT_TRUE(processor()->delete_set().empty()); 621 EXPECT_TRUE(processor().delete_set().empty());
634 EXPECT_EQ(3u, processor()->put_multimap().size()); 622 EXPECT_EQ(3u, processor().put_multimap().size());
635 EXPECT_EQ(1u, processor()->put_multimap().count(unique_local.cache_guid())); 623 EXPECT_EQ(1u, processor().put_multimap().count(unique_local.cache_guid()));
636 const auto& it = processor()->put_multimap().find(unique_local.cache_guid()); 624 const auto& it = processor().put_multimap().find(unique_local.cache_guid());
637 ASSERT_NE(processor()->put_multimap().end(), it); 625 ASSERT_NE(processor().put_multimap().end(), it);
638 VerifyEqual(unique_local, it->second->specifics.device_info()); 626 VerifyEqual(unique_local, it->second->specifics.device_info());
639 627
640 RestartBridge(); 628 RestartBridge();
641 EXPECT_EQ(state.encryption_key_name(), 629 EXPECT_EQ(state.encryption_key_name(),
642 processor()->metadata()->GetModelTypeState().encryption_key_name()); 630 processor().metadata()->GetModelTypeState().encryption_key_name());
643 } 631 }
644 632
645 TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) { 633 TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) {
646 // If not recent, then reconcile is going to try to send an updated version to 634 // If not recent, then reconcile is going to try to send an updated version to
647 // Sync, which makes interpreting change_count() more difficult. 635 // Sync, which makes interpreting change_count() more difficult.
648 const DeviceInfoSpecifics specifics = 636 const DeviceInfoSpecifics specifics =
649 CreateSpecifics(kDefaultLocalSuffix, Time::Now()); 637 CreateSpecifics(kDefaultLocalSuffix, Time::Now());
650 WriteToStore({specifics}); 638 WriteToStore({specifics});
651 InitializeAndPump(); 639 InitializeAndPump();
652 640
653 auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), 641 auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
654 InlineEntityDataMap({specifics})); 642 InlineEntityDataMap({specifics}));
655 EXPECT_FALSE(error); 643 EXPECT_FALSE(error);
656 EXPECT_EQ(0, change_count()); 644 EXPECT_EQ(0, change_count());
657 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size()); 645 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
658 EXPECT_TRUE(processor()->delete_set().empty()); 646 EXPECT_TRUE(processor().delete_set().empty());
659 EXPECT_TRUE(processor()->put_multimap().empty()); 647 EXPECT_TRUE(processor().put_multimap().empty());
660 } 648 }
661 649
662 TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuidBeforeReconcile) { 650 TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuidBeforeReconcile) {
663 InitializeBridge(); 651 InitializeBridge();
664 652
665 // The message loop is never pumped, which means local data/metadata is never 653 // The message loop is never pumped, which means local data/metadata is never
666 // loaded, and thus reconcile is never called. The bridge should ignore this 654 // loaded, and thus reconcile is never called. The bridge should ignore this
667 // EntityData because its cache guid is the same the local device's. 655 // EntityData because its cache guid is the same the local device's.
668 auto error = bridge()->MergeSyncData( 656 auto error = bridge()->MergeSyncData(
669 bridge()->CreateMetadataChangeList(), 657 bridge()->CreateMetadataChangeList(),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 704
717 // Now set time to long ago in the past, it should not be active anymore. 705 // Now set time to long ago in the past, it should not be active anymore.
718 bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(), 706 bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
719 EntityAddList({CreateSpecifics(1)})); 707 EntityAddList({CreateSpecifics(1)}));
720 EXPECT_EQ(1, bridge()->CountActiveDevices()); 708 EXPECT_EQ(1, bridge()->CountActiveDevices());
721 } 709 }
722 710
723 TEST_F(DeviceInfoSyncBridgeTest, MultipleOnProviderInitialized) { 711 TEST_F(DeviceInfoSyncBridgeTest, MultipleOnProviderInitialized) {
724 set_provider(base::MakeUnique<LocalDeviceInfoProviderMock>()); 712 set_provider(base::MakeUnique<LocalDeviceInfoProviderMock>());
725 InitializeAndPump(); 713 InitializeAndPump();
726 EXPECT_EQ(nullptr, processor()->metadata()); 714 EXPECT_EQ(nullptr, processor().metadata());
727 715
728 // Verify the processor was given metadata. 716 // Verify the processor was given metadata.
729 local_device()->Initialize(CreateModel(0)); 717 local_device()->Initialize(CreateModel(0));
730 base::RunLoop().RunUntilIdle(); 718 base::RunLoop().RunUntilIdle();
731 const MetadataBatch* metadata = processor()->metadata(); 719 const MetadataBatch* metadata = processor().metadata();
732 EXPECT_NE(nullptr, metadata); 720 EXPECT_NE(nullptr, metadata);
733 721
734 // Pointer address of metadata should remain constant because the processor 722 // Pointer address of metadata should remain constant because the processor
735 // should not have been given new metadata. 723 // should not have been given new metadata.
736 local_device()->Initialize(CreateModel(0)); 724 local_device()->Initialize(CreateModel(0));
737 base::RunLoop().RunUntilIdle(); 725 base::RunLoop().RunUntilIdle();
738 EXPECT_EQ(metadata, processor()->metadata()); 726 EXPECT_EQ(metadata, processor().metadata());
739 } 727 }
740 728
741 TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) { 729 TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) {
742 InitializeAndPump(); 730 InitializeAndPump();
743 EXPECT_EQ(1, change_count()); 731 EXPECT_EQ(1, change_count());
744 EXPECT_EQ(1u, processor()->put_multimap().size()); 732 EXPECT_EQ(1u, processor().put_multimap().size());
745 733
746 ForcePulse(); 734 ForcePulse();
747 EXPECT_EQ(2, change_count()); 735 EXPECT_EQ(2, change_count());
748 EXPECT_EQ(2u, processor()->put_multimap().size()); 736 EXPECT_EQ(2u, processor().put_multimap().size());
749 737
750 // After clearing, pulsing should no-op and not result in a processor put or 738 // After clearing, pulsing should no-op and not result in a processor put or
751 // a notification to observers. 739 // a notification to observers.
752 local_device()->Clear(); 740 local_device()->Clear();
753 ForcePulse(); 741 ForcePulse();
754 EXPECT_EQ(2, change_count()); 742 EXPECT_EQ(2, change_count());
755 EXPECT_EQ(2u, processor()->put_multimap().size()); 743 EXPECT_EQ(2u, processor().put_multimap().size());
756 } 744 }
757 745
758 TEST_F(DeviceInfoSyncBridgeTest, DisableSync) { 746 TEST_F(DeviceInfoSyncBridgeTest, DisableSync) {
759 InitializeAndPump(); 747 InitializeAndPump();
760 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size()); 748 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
761 EXPECT_EQ(1, change_count()); 749 EXPECT_EQ(1, change_count());
762 750
763 const DeviceInfoSpecifics specifics = CreateSpecifics(1); 751 const DeviceInfoSpecifics specifics = CreateSpecifics(1);
764 auto error = bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(), 752 auto error = bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
765 EntityAddList({specifics})); 753 EntityAddList({specifics}));
766 754
767 EXPECT_FALSE(error); 755 EXPECT_FALSE(error);
768 EXPECT_EQ(2u, bridge()->GetAllDeviceInfo().size()); 756 EXPECT_EQ(2u, bridge()->GetAllDeviceInfo().size());
769 EXPECT_EQ(2, change_count()); 757 EXPECT_EQ(2, change_count());
770 758
771 // Should clear out all local data and notify observers. 759 // Should clear out all local data and notify observers.
772 bridge()->DisableSync(); 760 bridge()->DisableSync();
773 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size()); 761 EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size());
774 EXPECT_EQ(3, change_count()); 762 EXPECT_EQ(3, change_count());
775 763
776 // Reloading from storage shouldn't contain remote data. 764 // Reloading from storage shouldn't contain remote data.
777 RestartBridge(); 765 RestartBridge();
778 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size()); 766 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
779 EXPECT_EQ(4, change_count()); 767 EXPECT_EQ(4, change_count());
780 } 768 }
781 769
782 } // namespace 770 } // namespace
783 771
784 } // namespace syncer 772 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/device_info/device_info_sync_bridge.h ('k') | components/sync/model/model_type_store_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698