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

Side by Side Diff: sync/engine/sync_scheduler_unittest.cc

Issue 10541079: [Sync] Remove CleanupDisabledTypes command and move purge logic into SyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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(syncer::BOOKMARKS); 301 const ModelTypeSet model_types(syncer::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
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(syncer::BOOKMARKS); 332 const ModelTypeSet model_types(syncer::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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 } 710 }
715 711
716 // Test that no syncing occurs when throttled (although CleanupDisabledTypes 712 // Test that no syncing occurs when throttled (although CleanupDisabledTypes
717 // is allowed). 713 // is allowed).
718 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 714 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
719 const ModelTypeSet types(syncer::BOOKMARKS); 715 const ModelTypeSet types(syncer::BOOKMARKS);
720 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 716 TimeDelta poll(TimeDelta::FromMilliseconds(5));
721 TimeDelta throttle(TimeDelta::FromMinutes(10)); 717 TimeDelta throttle(TimeDelta::FromMinutes(10));
722 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 718 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
723 719
724 EXPECT_CALL(*syncer(), 720 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
725 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
726 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
727 EXPECT_CALL(*syncer(), SyncShare(_,Not(CLEANUP_DISABLED_TYPES),
728 Not(CLEANUP_DISABLED_TYPES)))
729 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) 721 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)))
730 .WillRepeatedly(AddFailureAndQuitLoopNow()); 722 .WillRepeatedly(AddFailureAndQuitLoopNow());
731 723
732 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 724 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
733 725
734 scheduler()->ScheduleNudgeAsync( 726 scheduler()->ScheduleNudgeAsync(
735 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 727 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
736 PumpLoop(); 728 PumpLoop();
737 729
738 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 730 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 StopSyncScheduler(); 763 StopSyncScheduler();
772 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); 764 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll);
773 } 765 }
774 766
775 // Test nudges / polls don't run in config mode and config tasks do. 767 // Test nudges / polls don't run in config mode and config tasks do.
776 TEST_F(SyncSchedulerTest, ConfigurationMode) { 768 TEST_F(SyncSchedulerTest, ConfigurationMode) {
777 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 769 TimeDelta poll(TimeDelta::FromMilliseconds(15));
778 SyncShareRecords records; 770 SyncShareRecords records;
779 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 771 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
780 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 772 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
781 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
782 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 773 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
783 WithArg<0>(RecordSyncShare(&records)))); 774 WithArg<0>(RecordSyncShare(&records))));
784 775
785 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 776 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
786 777
787 const ModelTypeSet nudge_types(syncer::AUTOFILL); 778 const ModelTypeSet nudge_types(syncer::AUTOFILL);
788 scheduler()->ScheduleNudgeAsync( 779 scheduler()->ScheduleNudgeAsync(
789 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 780 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
790 scheduler()->ScheduleNudgeAsync( 781 scheduler()->ScheduleNudgeAsync(
791 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 782 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 scheduler()->ScheduleNudgeAsync( 887 scheduler()->ScheduleNudgeAsync(
897 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); 888 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE);
898 RunLoop(); 889 RunLoop();
899 890
900 Mock::VerifyAndClearExpectations(syncer()); 891 Mock::VerifyAndClearExpectations(syncer());
901 Mock::VerifyAndClearExpectations(delay()); 892 Mock::VerifyAndClearExpectations(delay());
902 ASSERT_EQ(2U, r.snapshots.size()); 893 ASSERT_EQ(2U, r.snapshots.size());
903 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 894 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
904 r.snapshots[1].source().updates_source); 895 r.snapshots[1].source().updates_source);
905 896
906 // Cleanup is not affected by backoff, but it should not relieve it either.
907 EXPECT_CALL(*syncer(),
908 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
909 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
910 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 897 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
911 898
912 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 899 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
913 900
914 CallbackCounter counter; 901 CallbackCounter counter;
915 ConfigurationParams params( 902 ConfigurationParams params(
916 GetUpdatesCallerInfo::RECONFIGURATION, 903 GetUpdatesCallerInfo::RECONFIGURATION,
917 types, 904 types,
918 TypesToRoutingInfo(types), 905 TypesToRoutingInfo(types),
919 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, 906 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1058
1072 scheduler()->ScheduleNudgeAsync( 1059 scheduler()->ScheduleNudgeAsync(
1073 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 1060 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1074 PumpLoop(); 1061 PumpLoop();
1075 // Pump again to run job. 1062 // Pump again to run job.
1076 PumpLoop(); 1063 PumpLoop();
1077 1064
1078 StopSyncScheduler(); 1065 StopSyncScheduler();
1079 Mock::VerifyAndClearExpectations(syncer()); 1066 Mock::VerifyAndClearExpectations(syncer());
1080 1067
1081 // Configuration (always includes a cleanup disabled types). 1068 // Configuration.
1082 EXPECT_CALL(*syncer(),
1083 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
1084 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1085 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1069 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1086 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1070 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1087 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1071 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1088 1072
1089 syncer::ModelTypeSet model_types(syncer::BOOKMARKS); 1073 syncer::ModelTypeSet model_types(syncer::BOOKMARKS);
1090 CallbackCounter counter; 1074 CallbackCounter counter;
1091 ConfigurationParams params( 1075 ConfigurationParams params(
1092 GetUpdatesCallerInfo::RECONFIGURATION, 1076 GetUpdatesCallerInfo::RECONFIGURATION,
1093 model_types, 1077 model_types,
1094 TypesToRoutingInfo(model_types), 1078 TypesToRoutingInfo(model_types),
1095 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, 1079 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1096 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1080 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1097 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 1081 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
1098 ASSERT_EQ(1, counter.times_called()); 1082 ASSERT_EQ(1, counter.times_called());
1099 // Runs directly so no need to pump the loop. 1083 // Runs directly so no need to pump the loop.
1100 StopSyncScheduler(); 1084 StopSyncScheduler();
1101 Mock::VerifyAndClearExpectations(syncer()); 1085 Mock::VerifyAndClearExpectations(syncer());
1102 1086
1103 // Cleanup disabled types. Because no types are being configured, we just
1104 // perform the cleanup.
1105 EXPECT_CALL(*syncer(),
1106 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)).
1107 WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1108 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1109
1110 CallbackCounter counter2;
1111 ConfigurationParams params2(
1112 GetUpdatesCallerInfo::RECONFIGURATION,
1113 ModelTypeSet(),
1114 ModelSafeRoutingInfo(),
1115 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1116 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter2)));
1117 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params2));
1118 ASSERT_EQ(1, counter2.times_called());
1119 StopSyncScheduler();
1120 Mock::VerifyAndClearExpectations(syncer());
1121
1122 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1123 1088
1124 // Poll. 1089 // Poll.
1125 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 1090 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1126 .Times(AtLeast(1)) 1091 .Times(AtLeast(1))
1127 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1092 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1128 QuitLoopNowAction())); 1093 QuitLoopNowAction()));
1129 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 1094 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1130 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1095 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1131 1096
(...skipping 25 matching lines...) Expand all
1157 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 1122 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1158 // Should save the nudge for until after the server is reachable. 1123 // Should save the nudge for until after the server is reachable.
1159 MessageLoop::current()->RunAllPending(); 1124 MessageLoop::current()->RunAllPending();
1160 1125
1161 connection()->SetServerReachable(); 1126 connection()->SetServerReachable();
1162 connection()->UpdateConnectionStatus(); 1127 connection()->UpdateConnectionStatus();
1163 scheduler()->OnConnectionStatusChange(); 1128 scheduler()->OnConnectionStatusChange();
1164 MessageLoop::current()->RunAllPending(); 1129 MessageLoop::current()->RunAllPending();
1165 } 1130 }
1166 1131
1167 TEST_F(SyncSchedulerTest, SetsPreviousRoutingInfo) { 1132 } // namespace browser_sync
tim (not reviewing) 2012/07/19 22:05:59 huh?
Nicolas Zea 2012/07/20 22:07:01 Done.
1168 ModelSafeRoutingInfo info;
1169 EXPECT_TRUE(info == context()->previous_session_routing_info());
1170 ModelSafeRoutingInfo expected(context()->routing_info());
1171 ASSERT_FALSE(expected.empty());
1172 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1);
1173
1174 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1175
1176 scheduler()->ScheduleNudgeAsync(
1177 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1178 PumpLoop();
1179 // Pump again to run job.
1180 PumpLoop();
1181
1182 StopSyncScheduler();
1183
1184 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1185 }
1186
1187 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698