| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 using testing::WithArg; | 35 using testing::WithArg; |
| 36 | 36 |
| 37 namespace syncer { | 37 namespace syncer { |
| 38 using sessions::SyncSession; | 38 using sessions::SyncSession; |
| 39 using sessions::SyncSessionContext; | 39 using sessions::SyncSessionContext; |
| 40 using sessions::SyncSessionSnapshot; | 40 using sessions::SyncSessionSnapshot; |
| 41 using sync_pb::GetUpdatesCallerInfo; | 41 using sync_pb::GetUpdatesCallerInfo; |
| 42 | 42 |
| 43 class MockSyncer : public Syncer { | 43 class MockSyncer : public Syncer { |
| 44 public: | 44 public: |
| 45 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, | 45 MOCK_METHOD3(SyncShare, bool(sessions::SyncSession*, SyncerStep, |
| 46 SyncerStep)); | 46 SyncerStep)); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // Used when tests want to record syncing activity to examine later. | 49 // Used when tests want to record syncing activity to examine later. |
| 50 struct SyncShareRecords { | 50 struct SyncShareRecords { |
| 51 std::vector<TimeTicks> times; | 51 std::vector<TimeTicks> times; |
| 52 std::vector<SyncSessionSnapshot> snapshots; | 52 std::vector<SyncSessionSnapshot> snapshots; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 void QuitLoopNow() { | 55 void QuitLoopNow() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 virtual void SetUp() { | 103 virtual void SetUp() { |
| 104 dir_maker_.SetUp(); | 104 dir_maker_.SetUp(); |
| 105 syncer_ = new MockSyncer(); | 105 syncer_ = new MockSyncer(); |
| 106 delay_ = NULL; | 106 delay_ = NULL; |
| 107 | 107 |
| 108 routing_info_[BOOKMARKS] = GROUP_UI; | 108 routing_info_[BOOKMARKS] = GROUP_UI; |
| 109 routing_info_[AUTOFILL] = GROUP_DB; | 109 routing_info_[AUTOFILL] = GROUP_DB; |
| 110 routing_info_[THEMES] = GROUP_UI; | 110 routing_info_[THEMES] = GROUP_UI; |
| 111 routing_info_[NIGORI] = GROUP_PASSIVE; | 111 routing_info_[NIGORI] = GROUP_PASSIVE; |
| 112 | 112 |
| 113 workers_.clear(); |
| 113 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 114 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 114 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 115 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 115 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 116 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 116 | 117 |
| 117 std::vector<ModelSafeWorker*> workers; | 118 std::vector<ModelSafeWorker*> workers; |
| 118 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = | 119 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = |
| 119 workers_.begin(); it != workers_.end(); ++it) { | 120 workers_.begin(); it != workers_.end(); ++it) { |
| 120 workers.push_back(it->get()); | 121 workers.push_back(it->get()); |
| 121 } | 122 } |
| 122 | 123 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 239 |
| 239 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { | 240 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { |
| 240 record->times.push_back(TimeTicks::Now()); | 241 record->times.push_back(TimeTicks::Now()); |
| 241 record->snapshots.push_back(s->TakeSnapshot()); | 242 record->snapshots.push_back(s->TakeSnapshot()); |
| 242 } | 243 } |
| 243 | 244 |
| 244 ACTION_P(RecordSyncShare, record) { | 245 ACTION_P(RecordSyncShare, record) { |
| 245 RecordSyncShareImpl(arg0, record); | 246 RecordSyncShareImpl(arg0, record); |
| 246 if (MessageLoop::current()->is_running()) | 247 if (MessageLoop::current()->is_running()) |
| 247 QuitLoopNow(); | 248 QuitLoopNow(); |
| 249 return true; |
| 248 } | 250 } |
| 249 | 251 |
| 250 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { | 252 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { |
| 251 RecordSyncShareImpl(arg0, record); | 253 RecordSyncShareImpl(arg0, record); |
| 252 EXPECT_LE(record->times.size(), quit_after); | 254 EXPECT_LE(record->times.size(), quit_after); |
| 253 if (record->times.size() >= quit_after && | 255 if (record->times.size() >= quit_after && |
| 254 MessageLoop::current()->is_running()) { | 256 MessageLoop::current()->is_running()) { |
| 255 QuitLoopNow(); | 257 QuitLoopNow(); |
| 256 } | 258 } |
| 259 return true; |
| 257 } | 260 } |
| 258 | 261 |
| 259 ACTION(AddFailureAndQuitLoopNow) { | 262 ACTION(AddFailureAndQuitLoopNow) { |
| 260 ADD_FAILURE(); | 263 ADD_FAILURE(); |
| 261 QuitLoopNow(); | 264 QuitLoopNow(); |
| 265 return true; |
| 262 } | 266 } |
| 263 | 267 |
| 264 ACTION(QuitLoopNowAction) { | 268 ACTION(QuitLoopNowAction) { |
| 265 QuitLoopNow(); | 269 QuitLoopNow(); |
| 270 return true; |
| 266 } | 271 } |
| 267 | 272 |
| 268 // Test nudge scheduling. | 273 // Test nudge scheduling. |
| 269 TEST_F(SyncSchedulerTest, Nudge) { | 274 TEST_F(SyncSchedulerTest, Nudge) { |
| 270 SyncShareRecords records; | 275 SyncShareRecords records; |
| 271 ModelTypeSet model_types(BOOKMARKS); | 276 ModelTypeSet model_types(BOOKMARKS); |
| 272 | 277 |
| 273 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 278 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 274 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 279 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 275 WithArg<0>(RecordSyncShare(&records)))) | 280 WithArg<0>(RecordSyncShare(&records)))) |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 644 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); |
| 640 } | 645 } |
| 641 | 646 |
| 642 // Test that polling intervals are updated when needed. | 647 // Test that polling intervals are updated when needed. |
| 643 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 648 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { |
| 644 SyncShareRecords records; | 649 SyncShareRecords records; |
| 645 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 650 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
| 646 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 651 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
| 647 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 652 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
| 648 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) | 653 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
| 649 .WillOnce(WithArg<0>( | 654 .WillOnce(DoAll( |
| 650 sessions::test_util::SimulatePollIntervalUpdate(poll2))) | 655 WithArg<0>( |
| 656 sessions::test_util::SimulatePollIntervalUpdate(poll2)), |
| 657 Return(true))) |
| 651 .WillRepeatedly( | 658 .WillRepeatedly( |
| 652 DoAll(Invoke(sessions::test_util::SimulateSuccess), | 659 DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 653 WithArg<0>( | 660 WithArg<0>( |
| 654 RecordSyncShareMultiple(&records, kMinNumSamples)))); | 661 RecordSyncShareMultiple(&records, kMinNumSamples)))); |
| 655 | 662 |
| 656 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 663 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
| 657 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 664 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 658 | 665 |
| 659 // Run again to wait for polling. | 666 // Run again to wait for polling. |
| 660 RunLoop(); | 667 RunLoop(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 700 } |
| 694 | 701 |
| 695 // Test that no syncing occurs when throttled. | 702 // Test that no syncing occurs when throttled. |
| 696 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 703 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
| 697 const ModelTypeSet types(BOOKMARKS); | 704 const ModelTypeSet types(BOOKMARKS); |
| 698 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 705 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 699 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 706 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 700 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 707 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 701 | 708 |
| 702 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 709 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 703 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 710 .WillOnce(DoAll( |
| 711 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)), |
| 712 Return(true))) |
| 704 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 713 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 705 | 714 |
| 706 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 715 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 707 | 716 |
| 708 scheduler()->ScheduleNudgeAsync( | 717 scheduler()->ScheduleNudgeAsync( |
| 709 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 718 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 710 PumpLoop(); | 719 PumpLoop(); |
| 711 | 720 |
| 712 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 721 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 713 | 722 |
| 714 CallbackCounter counter; | 723 CallbackCounter counter; |
| 715 ConfigurationParams params( | 724 ConfigurationParams params( |
| 716 GetUpdatesCallerInfo::RECONFIGURATION, | 725 GetUpdatesCallerInfo::RECONFIGURATION, |
| 717 types, | 726 types, |
| 718 TypesToRoutingInfo(types), | 727 TypesToRoutingInfo(types), |
| 719 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 728 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 720 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 729 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 721 ASSERT_EQ(0, counter.times_called()); | 730 ASSERT_EQ(0, counter.times_called()); |
| 722 } | 731 } |
| 723 | 732 |
| 724 TEST_F(SyncSchedulerTest, ThrottlingExpires) { | 733 TEST_F(SyncSchedulerTest, ThrottlingExpires) { |
| 725 SyncShareRecords records; | 734 SyncShareRecords records; |
| 726 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 735 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 727 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 736 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 728 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 737 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 729 | 738 |
| 730 ::testing::InSequence seq; | 739 ::testing::InSequence seq; |
| 731 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 740 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 732 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) | 741 .WillOnce(DoAll( |
| 742 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), |
| 743 Return(true))) |
| 733 .RetiresOnSaturation(); | 744 .RetiresOnSaturation(); |
| 734 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 745 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 735 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 746 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 736 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 747 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); |
| 737 | 748 |
| 738 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 749 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
| 739 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 750 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 740 | 751 |
| 741 // Run again to wait for polling. | 752 // Run again to wait for polling. |
| 742 RunLoop(); | 753 RunLoop(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 831 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 821 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 832 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 822 QuitLoopNowAction())); | 833 QuitLoopNowAction())); |
| 823 EXPECT_TRUE(RunAndGetBackoff()); | 834 EXPECT_TRUE(RunAndGetBackoff()); |
| 824 } | 835 } |
| 825 | 836 |
| 826 // Have the syncer fail during download updates and succeed on the first | 837 // Have the syncer fail during download updates and succeed on the first |
| 827 // retry. Expect that this clears the backoff state. | 838 // retry. Expect that this clears the backoff state. |
| 828 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { | 839 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { |
| 829 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 840 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 830 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 841 .WillOnce(DoAll( |
| 842 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 843 Return(true))) |
| 831 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 844 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 832 QuitLoopNowAction())); | 845 QuitLoopNowAction())); |
| 833 EXPECT_FALSE(RunAndGetBackoff()); | 846 EXPECT_FALSE(RunAndGetBackoff()); |
| 834 } | 847 } |
| 835 | 848 |
| 836 // Have the syncer fail during commit and succeed on the first retry. Expect | 849 // Have the syncer fail during commit and succeed on the first retry. Expect |
| 837 // that this clears the backoff state. | 850 // that this clears the backoff state. |
| 838 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { | 851 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { |
| 839 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 852 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 840 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 853 .WillOnce(DoAll( |
| 854 Invoke(sessions::test_util::SimulateCommitFailed), |
| 855 Return(true))) |
| 841 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 856 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 842 QuitLoopNowAction())); | 857 QuitLoopNowAction())); |
| 843 EXPECT_FALSE(RunAndGetBackoff()); | 858 EXPECT_FALSE(RunAndGetBackoff()); |
| 844 } | 859 } |
| 845 | 860 |
| 846 // Have the syncer fail to download updates and fail again on the retry. | 861 // Have the syncer fail to download updates and fail again on the retry. |
| 847 // Expect this will leave the scheduler in backoff. | 862 // Expect this will leave the scheduler in backoff. |
| 848 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { | 863 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { |
| 849 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 864 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 850 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 865 .WillOnce(DoAll( |
| 866 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 867 Return(true))) |
| 851 .WillRepeatedly(DoAll( | 868 .WillRepeatedly(DoAll( |
| 852 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 869 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 853 QuitLoopNowAction())); | 870 QuitLoopNowAction())); |
| 854 EXPECT_TRUE(RunAndGetBackoff()); | 871 EXPECT_TRUE(RunAndGetBackoff()); |
| 855 } | 872 } |
| 856 | 873 |
| 857 // Have the syncer fail to get the encryption key yet succeed in downloading | 874 // Have the syncer fail to get the encryption key yet succeed in downloading |
| 858 // updates. Expect this will leave the scheduler in backoff. | 875 // updates. Expect this will leave the scheduler in backoff. |
| 859 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 876 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { |
| 860 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 877 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 861 .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed)) | 878 .WillOnce(DoAll( |
| 879 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 880 Return(true))) |
| 862 .WillRepeatedly(DoAll( | 881 .WillRepeatedly(DoAll( |
| 863 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 882 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 864 QuitLoopNowAction())); | 883 QuitLoopNowAction())); |
| 865 EXPECT_TRUE(RunAndGetBackoff()); | 884 EXPECT_TRUE(RunAndGetBackoff()); |
| 866 } | 885 } |
| 867 | 886 |
| 868 // Test that no polls or extraneous nudges occur when in backoff. | 887 // Test that no polls or extraneous nudges occur when in backoff. |
| 869 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 888 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
| 870 SyncShareRecords r; | 889 SyncShareRecords r; |
| 871 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 890 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 | 1052 |
| 1034 // Run the successful poll. | 1053 // Run the successful poll. |
| 1035 RunLoop(); | 1054 RunLoop(); |
| 1036 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1055 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1037 } | 1056 } |
| 1038 | 1057 |
| 1039 // Test that appropriate syncer steps are requested for each job type. | 1058 // Test that appropriate syncer steps are requested for each job type. |
| 1040 TEST_F(SyncSchedulerTest, SyncerSteps) { | 1059 TEST_F(SyncSchedulerTest, SyncerSteps) { |
| 1041 // Nudges. | 1060 // Nudges. |
| 1042 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1061 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
| 1043 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1062 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1063 Return(true))); |
| 1044 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1064 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1045 | 1065 |
| 1046 scheduler()->ScheduleNudgeAsync( | 1066 scheduler()->ScheduleNudgeAsync( |
| 1047 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 1067 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
| 1048 PumpLoop(); | 1068 PumpLoop(); |
| 1049 // Pump again to run job. | 1069 // Pump again to run job. |
| 1050 PumpLoop(); | 1070 PumpLoop(); |
| 1051 | 1071 |
| 1052 StopSyncScheduler(); | 1072 StopSyncScheduler(); |
| 1053 Mock::VerifyAndClearExpectations(syncer()); | 1073 Mock::VerifyAndClearExpectations(syncer()); |
| 1054 | 1074 |
| 1055 // Configuration. | 1075 // Configuration. |
| 1056 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) | 1076 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
| 1057 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1077 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1078 Return(true))); |
| 1058 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1079 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 1059 | 1080 |
| 1060 ModelTypeSet model_types(BOOKMARKS); | 1081 ModelTypeSet model_types(BOOKMARKS); |
| 1061 CallbackCounter counter; | 1082 CallbackCounter counter; |
| 1062 ConfigurationParams params( | 1083 ConfigurationParams params( |
| 1063 GetUpdatesCallerInfo::RECONFIGURATION, | 1084 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1064 model_types, | 1085 model_types, |
| 1065 TypesToRoutingInfo(model_types), | 1086 TypesToRoutingInfo(model_types), |
| 1066 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 1087 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1067 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 1088 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1088 StopSyncScheduler(); | 1109 StopSyncScheduler(); |
| 1089 Mock::VerifyAndClearExpectations(syncer()); | 1110 Mock::VerifyAndClearExpectations(syncer()); |
| 1090 } | 1111 } |
| 1091 | 1112 |
| 1092 // Test that starting the syncer thread without a valid connection doesn't | 1113 // Test that starting the syncer thread without a valid connection doesn't |
| 1093 // break things when a connection is detected. | 1114 // break things when a connection is detected. |
| 1094 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1115 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
| 1095 connection()->SetServerNotReachable(); | 1116 connection()->SetServerNotReachable(); |
| 1096 connection()->UpdateConnectionStatus(); | 1117 connection()->UpdateConnectionStatus(); |
| 1097 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 1118 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 1098 .WillOnce(Invoke(sessions::test_util::SimulateConnectionFailure)) | 1119 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
| 1099 .WillOnce(QuitLoopNowAction()); | 1120 Return(true))) |
| 1121 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1122 QuitLoopNowAction())); |
| 1100 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1123 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1101 | 1124 |
| 1102 scheduler()->ScheduleNudgeAsync( | 1125 scheduler()->ScheduleNudgeAsync( |
| 1103 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 1126 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
| 1104 // Should save the nudge for until after the server is reachable. | 1127 // Should save the nudge for until after the server is reachable. |
| 1105 MessageLoop::current()->RunAllPending(); | 1128 MessageLoop::current()->RunAllPending(); |
| 1106 | 1129 |
| 1107 connection()->SetServerReachable(); | 1130 connection()->SetServerReachable(); |
| 1108 connection()->UpdateConnectionStatus(); | 1131 connection()->UpdateConnectionStatus(); |
| 1109 scheduler()->OnConnectionStatusChange(); | 1132 scheduler()->OnConnectionStatusChange(); |
| 1110 MessageLoop::current()->RunAllPending(); | 1133 MessageLoop::current()->RunAllPending(); |
| 1111 } | 1134 } |
| 1112 | 1135 |
| 1113 } // namespace syncer | 1136 } // namespace syncer |
| OLD | NEW |