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