| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 293 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 294 records2.snapshots[0].source().updates_source); | 294 records2.snapshots[0].source().updates_source); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Make sure a regular config command is scheduled fine in the absence of any | 297 // Make sure a regular config command is scheduled fine in the absence of any |
| 298 // errors. | 298 // errors. |
| 299 TEST_F(SyncSchedulerTest, Config) { | 299 TEST_F(SyncSchedulerTest, Config) { |
| 300 SyncShareRecords records; | 300 SyncShareRecords records; |
| 301 const ModelTypeSet model_types(BOOKMARKS); | 301 const ModelTypeSet model_types(BOOKMARKS); |
| 302 | 302 |
| 303 EXPECT_CALL(*syncer(), | 303 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 304 SyncShare(_,_,_)) | |
| 305 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 304 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 307 WithArg<0>(RecordSyncShare(&records)))); | 305 WithArg<0>(RecordSyncShare(&records)))); |
| 308 | 306 |
| 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 307 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 310 | 308 |
| 311 CallbackCounter counter; | 309 CallbackCounter counter; |
| 312 ConfigurationParams params( | 310 ConfigurationParams params( |
| 313 GetUpdatesCallerInfo::RECONFIGURATION, | 311 GetUpdatesCallerInfo::RECONFIGURATION, |
| 314 model_types, | 312 model_types, |
| 315 TypesToRoutingInfo(model_types), | 313 TypesToRoutingInfo(model_types), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 326 } | 324 } |
| 327 | 325 |
| 328 // Simulate a failure and make sure the config request is retried. | 326 // Simulate a failure and make sure the config request is retried. |
| 329 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 327 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 330 UseMockDelayProvider(); | 328 UseMockDelayProvider(); |
| 331 EXPECT_CALL(*delay(), GetDelay(_)) | 329 EXPECT_CALL(*delay(), GetDelay(_)) |
| 332 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 330 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 333 SyncShareRecords records; | 331 SyncShareRecords records; |
| 334 const ModelTypeSet model_types(BOOKMARKS); | 332 const ModelTypeSet model_types(BOOKMARKS); |
| 335 | 333 |
| 336 EXPECT_CALL(*syncer(), | 334 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 337 SyncShare(_,_,_)) | |
| 338 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 339 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 335 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 340 WithArg<0>(RecordSyncShare(&records)))) | 336 WithArg<0>(RecordSyncShare(&records)))) |
| 341 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 337 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 342 WithArg<0>(RecordSyncShare(&records)))); | 338 WithArg<0>(RecordSyncShare(&records)))); |
| 343 | 339 |
| 344 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 340 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 345 | 341 |
| 346 ASSERT_EQ(0U, records.snapshots.size()); | 342 ASSERT_EQ(0U, records.snapshots.size()); |
| 347 CallbackCounter counter; | 343 CallbackCounter counter; |
| 348 ConfigurationParams params( | 344 ConfigurationParams params( |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 } | 706 } |
| 711 | 707 |
| 712 // Test that no syncing occurs when throttled (although CleanupDisabledTypes | 708 // Test that no syncing occurs when throttled (although CleanupDisabledTypes |
| 713 // is allowed). | 709 // is allowed). |
| 714 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 710 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
| 715 const ModelTypeSet types(BOOKMARKS); | 711 const ModelTypeSet types(BOOKMARKS); |
| 716 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 712 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 717 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 713 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 718 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 714 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 719 | 715 |
| 720 EXPECT_CALL(*syncer(), | 716 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 721 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | |
| 722 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 723 EXPECT_CALL(*syncer(), SyncShare(_,Not(CLEANUP_DISABLED_TYPES), | |
| 724 Not(CLEANUP_DISABLED_TYPES))) | |
| 725 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 717 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) |
| 726 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 718 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 727 | 719 |
| 728 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 720 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 729 | 721 |
| 730 scheduler()->ScheduleNudgeAsync( | 722 scheduler()->ScheduleNudgeAsync( |
| 731 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 723 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 732 PumpLoop(); | 724 PumpLoop(); |
| 733 | 725 |
| 734 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 726 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 StopSyncScheduler(); | 759 StopSyncScheduler(); |
| 768 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); | 760 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); |
| 769 } | 761 } |
| 770 | 762 |
| 771 // Test nudges / polls don't run in config mode and config tasks do. | 763 // Test nudges / polls don't run in config mode and config tasks do. |
| 772 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 764 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
| 773 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 765 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 774 SyncShareRecords records; | 766 SyncShareRecords records; |
| 775 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 767 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 776 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 768 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 777 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 778 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 769 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 779 WithArg<0>(RecordSyncShare(&records)))); | 770 WithArg<0>(RecordSyncShare(&records)))); |
| 780 | 771 |
| 781 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 772 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 782 | 773 |
| 783 const ModelTypeSet nudge_types(AUTOFILL); | 774 const ModelTypeSet nudge_types(AUTOFILL); |
| 784 scheduler()->ScheduleNudgeAsync( | 775 scheduler()->ScheduleNudgeAsync( |
| 785 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 776 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
| 786 scheduler()->ScheduleNudgeAsync( | 777 scheduler()->ScheduleNudgeAsync( |
| 787 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 778 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 scheduler()->ScheduleNudgeAsync( | 883 scheduler()->ScheduleNudgeAsync( |
| 893 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 884 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 894 RunLoop(); | 885 RunLoop(); |
| 895 | 886 |
| 896 Mock::VerifyAndClearExpectations(syncer()); | 887 Mock::VerifyAndClearExpectations(syncer()); |
| 897 Mock::VerifyAndClearExpectations(delay()); | 888 Mock::VerifyAndClearExpectations(delay()); |
| 898 ASSERT_EQ(2U, r.snapshots.size()); | 889 ASSERT_EQ(2U, r.snapshots.size()); |
| 899 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 890 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 900 r.snapshots[1].source().updates_source); | 891 r.snapshots[1].source().updates_source); |
| 901 | 892 |
| 902 // Cleanup is not affected by backoff, but it should not relieve it either. | |
| 903 EXPECT_CALL(*syncer(), | |
| 904 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | |
| 905 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 906 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 893 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 907 | 894 |
| 908 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 895 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 909 | 896 |
| 910 CallbackCounter counter; | 897 CallbackCounter counter; |
| 911 ConfigurationParams params( | 898 ConfigurationParams params( |
| 912 GetUpdatesCallerInfo::RECONFIGURATION, | 899 GetUpdatesCallerInfo::RECONFIGURATION, |
| 913 types, | 900 types, |
| 914 TypesToRoutingInfo(types), | 901 TypesToRoutingInfo(types), |
| 915 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | 902 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1056 |
| 1070 scheduler()->ScheduleNudgeAsync( | 1057 scheduler()->ScheduleNudgeAsync( |
| 1071 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 1058 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 1072 PumpLoop(); | 1059 PumpLoop(); |
| 1073 // Pump again to run job. | 1060 // Pump again to run job. |
| 1074 PumpLoop(); | 1061 PumpLoop(); |
| 1075 | 1062 |
| 1076 StopSyncScheduler(); | 1063 StopSyncScheduler(); |
| 1077 Mock::VerifyAndClearExpectations(syncer()); | 1064 Mock::VerifyAndClearExpectations(syncer()); |
| 1078 | 1065 |
| 1079 // Configuration (always includes a cleanup disabled types). | 1066 // Configuration. |
| 1080 EXPECT_CALL(*syncer(), | |
| 1081 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | |
| 1082 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 1083 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) | 1067 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
| 1084 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1068 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
| 1085 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1069 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 1086 | 1070 |
| 1087 ModelTypeSet model_types(BOOKMARKS); | 1071 ModelTypeSet model_types(BOOKMARKS); |
| 1088 CallbackCounter counter; | 1072 CallbackCounter counter; |
| 1089 ConfigurationParams params( | 1073 ConfigurationParams params( |
| 1090 GetUpdatesCallerInfo::RECONFIGURATION, | 1074 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1091 model_types, | 1075 model_types, |
| 1092 TypesToRoutingInfo(model_types), | 1076 TypesToRoutingInfo(model_types), |
| 1093 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | 1077 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 1094 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 1078 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1095 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 1079 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 1096 ASSERT_EQ(1, counter.times_called()); | 1080 ASSERT_EQ(1, counter.times_called()); |
| 1097 // Runs directly so no need to pump the loop. | 1081 // Runs directly so no need to pump the loop. |
| 1098 StopSyncScheduler(); | 1082 StopSyncScheduler(); |
| 1099 Mock::VerifyAndClearExpectations(syncer()); | 1083 Mock::VerifyAndClearExpectations(syncer()); |
| 1100 | 1084 |
| 1101 // Cleanup disabled types. Because no types are being configured, we just | |
| 1102 // perform the cleanup. | |
| 1103 EXPECT_CALL(*syncer(), | |
| 1104 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)). | |
| 1105 WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 1106 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | |
| 1107 | |
| 1108 CallbackCounter counter2; | |
| 1109 ConfigurationParams params2( | |
| 1110 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 1111 ModelTypeSet(), | |
| 1112 ModelSafeRoutingInfo(), | |
| 1113 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 1114 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter2))); | |
| 1115 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params2)); | |
| 1116 ASSERT_EQ(1, counter2.times_called()); | |
| 1117 StopSyncScheduler(); | |
| 1118 Mock::VerifyAndClearExpectations(syncer()); | |
| 1119 | |
| 1120 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1085 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1121 | 1086 |
| 1122 // Poll. | 1087 // Poll. |
| 1123 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1088 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
| 1124 .Times(AtLeast(1)) | 1089 .Times(AtLeast(1)) |
| 1125 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 1090 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1126 QuitLoopNowAction())); | 1091 QuitLoopNowAction())); |
| 1127 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1092 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1128 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1093 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1129 | 1094 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1155 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 1120 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 1156 // Should save the nudge for until after the server is reachable. | 1121 // Should save the nudge for until after the server is reachable. |
| 1157 MessageLoop::current()->RunAllPending(); | 1122 MessageLoop::current()->RunAllPending(); |
| 1158 | 1123 |
| 1159 connection()->SetServerReachable(); | 1124 connection()->SetServerReachable(); |
| 1160 connection()->UpdateConnectionStatus(); | 1125 connection()->UpdateConnectionStatus(); |
| 1161 scheduler()->OnConnectionStatusChange(); | 1126 scheduler()->OnConnectionStatusChange(); |
| 1162 MessageLoop::current()->RunAllPending(); | 1127 MessageLoop::current()->RunAllPending(); |
| 1163 } | 1128 } |
| 1164 | 1129 |
| 1165 TEST_F(SyncSchedulerTest, SetsPreviousRoutingInfo) { | |
| 1166 ModelSafeRoutingInfo info; | |
| 1167 EXPECT_TRUE(info == context()->previous_session_routing_info()); | |
| 1168 ModelSafeRoutingInfo expected(context()->routing_info()); | |
| 1169 ASSERT_FALSE(expected.empty()); | |
| 1170 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); | |
| 1171 | |
| 1172 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
| 1173 | |
| 1174 scheduler()->ScheduleNudgeAsync( | |
| 1175 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | |
| 1176 PumpLoop(); | |
| 1177 // Pump again to run job. | |
| 1178 PumpLoop(); | |
| 1179 | |
| 1180 StopSyncScheduler(); | |
| 1181 | |
| 1182 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | |
| 1183 } | |
| 1184 | |
| 1185 } // namespace syncer | 1130 } // namespace syncer |
| OLD | NEW |