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

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

Issue 8919021: [Sync] Rename ModelEnumSet to ModelTypeSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 14 matching lines...) Expand all
25 using testing::Eq; 25 using testing::Eq;
26 using testing::Invoke; 26 using testing::Invoke;
27 using testing::Mock; 27 using testing::Mock;
28 using testing::Return; 28 using testing::Return;
29 using testing::WithArg; 29 using testing::WithArg;
30 30
31 namespace browser_sync { 31 namespace browser_sync {
32 using sessions::SyncSession; 32 using sessions::SyncSession;
33 using sessions::SyncSessionContext; 33 using sessions::SyncSessionContext;
34 using sessions::SyncSessionSnapshot; 34 using sessions::SyncSessionSnapshot;
35 using syncable::ModelEnumSet; 35 using syncable::ModelTypeSet;
36 using sync_pb::GetUpdatesCallerInfo; 36 using sync_pb::GetUpdatesCallerInfo;
37 37
38 class MockSyncer : public Syncer { 38 class MockSyncer : public Syncer {
39 public: 39 public:
40 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, 40 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep,
41 SyncerStep)); 41 SyncerStep));
42 }; 42 };
43 43
44 // Used when tests want to record syncing activity to examine later. 44 // Used when tests want to record syncing activity to examine later.
45 struct SyncShareRecords { 45 struct SyncShareRecords {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 144
145 // This stops the scheduler synchronously. 145 // This stops the scheduler synchronously.
146 void StopSyncScheduler() { 146 void StopSyncScheduler() {
147 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, 147 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow,
148 weak_ptr_factory_.GetWeakPtr())); 148 weak_ptr_factory_.GetWeakPtr()));
149 RunLoop(); 149 RunLoop();
150 } 150 }
151 151
152 bool GetBackoffAndResetTest() { 152 bool GetBackoffAndResetTest() {
153 ModelEnumSet nudge_types; 153 ModelTypeSet nudge_types;
154 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 154 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
155 RunLoop(); 155 RunLoop();
156 156
157 scheduler()->ScheduleNudge( 157 scheduler()->ScheduleNudge(
158 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 158 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
159 RunLoop(); 159 RunLoop();
160 160
161 bool backing_off = scheduler()->IsBackingOff(); 161 bool backing_off = scheduler()->IsBackingOff();
162 StopSyncScheduler(); 162 StopSyncScheduler();
163 163
164 syncdb_.TearDown(); 164 syncdb_.TearDown();
165 165
166 Mock::VerifyAndClearExpectations(syncer()); 166 Mock::VerifyAndClearExpectations(syncer());
167 167
168 TearDown(); 168 TearDown();
169 SetUp(); 169 SetUp();
170 UseMockDelayProvider(); 170 UseMockDelayProvider();
171 EXPECT_CALL(*delay(), GetDelay(_)) 171 EXPECT_CALL(*delay(), GetDelay(_))
172 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 172 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
173 return backing_off; 173 return backing_off;
174 } 174 }
175 175
176 void UseMockDelayProvider() { 176 void UseMockDelayProvider() {
177 delay_ = new MockDelayProvider(); 177 delay_ = new MockDelayProvider();
178 scheduler_->delay_provider_.reset(delay_); 178 scheduler_->delay_provider_.reset(delay_);
179 } 179 }
180 180
181 // Compare a ModelEnumSet to a ModelTypePayloadMap, ignoring 181 // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring
182 // payload values. 182 // payload values.
183 bool CompareModelEnumSetToModelTypePayloadMap( 183 bool CompareModelTypeSetToModelTypePayloadMap(
184 ModelEnumSet lhs, 184 ModelTypeSet lhs,
185 const syncable::ModelTypePayloadMap& rhs) { 185 const syncable::ModelTypePayloadMap& rhs) {
186 size_t count = 0; 186 size_t count = 0;
187 for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin(); 187 for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin();
188 i != rhs.end(); ++i, ++count) { 188 i != rhs.end(); ++i, ++count) {
189 if (!lhs.Has(i->first)) 189 if (!lhs.Has(i->first))
190 return false; 190 return false;
191 } 191 }
192 if (lhs.Size() != count) 192 if (lhs.Size() != count)
193 return false; 193 return false;
194 return true; 194 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 QuitLoopNow(); 232 QuitLoopNow();
233 } 233 }
234 234
235 ACTION(QuitLoopNowAction) { 235 ACTION(QuitLoopNowAction) {
236 QuitLoopNow(); 236 QuitLoopNow();
237 } 237 }
238 238
239 // Test nudge scheduling. 239 // Test nudge scheduling.
240 TEST_F(SyncSchedulerTest, Nudge) { 240 TEST_F(SyncSchedulerTest, Nudge) {
241 SyncShareRecords records; 241 SyncShareRecords records;
242 ModelEnumSet model_types(syncable::BOOKMARKS); 242 ModelTypeSet model_types(syncable::BOOKMARKS);
243 243
244 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 244 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
245 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 245 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
246 WithArg<0>(RecordSyncShare(&records)))) 246 WithArg<0>(RecordSyncShare(&records))))
247 .RetiresOnSaturation(); 247 .RetiresOnSaturation();
248 248
249 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 249 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
250 RunLoop(); 250 RunLoop();
251 251
252 scheduler()->ScheduleNudge( 252 scheduler()->ScheduleNudge(
253 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 253 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
254 RunLoop(); 254 RunLoop();
255 255
256 ASSERT_EQ(1U, records.snapshots.size()); 256 ASSERT_EQ(1U, records.snapshots.size());
257 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 257 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
258 records.snapshots[0]->source.types)); 258 records.snapshots[0]->source.types));
259 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 259 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
260 records.snapshots[0]->source.updates_source); 260 records.snapshots[0]->source.updates_source);
261 261
262 Mock::VerifyAndClearExpectations(syncer()); 262 Mock::VerifyAndClearExpectations(syncer());
263 263
264 // Make sure a second, later, nudge is unaffected by first (no coalescing). 264 // Make sure a second, later, nudge is unaffected by first (no coalescing).
265 SyncShareRecords records2; 265 SyncShareRecords records2;
266 model_types.Remove(syncable::BOOKMARKS); 266 model_types.Remove(syncable::BOOKMARKS);
267 model_types.Put(syncable::AUTOFILL); 267 model_types.Put(syncable::AUTOFILL);
268 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 268 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
269 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 269 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
270 WithArg<0>(RecordSyncShare(&records2)))); 270 WithArg<0>(RecordSyncShare(&records2))));
271 scheduler()->ScheduleNudge( 271 scheduler()->ScheduleNudge(
272 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 272 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
273 RunLoop(); 273 RunLoop();
274 274
275 ASSERT_EQ(1U, records2.snapshots.size()); 275 ASSERT_EQ(1U, records2.snapshots.size());
276 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 276 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
277 records2.snapshots[0]->source.types)); 277 records2.snapshots[0]->source.types));
278 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 278 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
279 records2.snapshots[0]->source.updates_source); 279 records2.snapshots[0]->source.updates_source);
280 } 280 }
281 281
282 // Make sure a regular config command is scheduled fine in the absence of any 282 // Make sure a regular config command is scheduled fine in the absence of any
283 // errors. 283 // errors.
284 TEST_F(SyncSchedulerTest, Config) { 284 TEST_F(SyncSchedulerTest, Config) {
285 SyncShareRecords records; 285 SyncShareRecords records;
286 const ModelEnumSet model_types(syncable::BOOKMARKS); 286 const ModelTypeSet model_types(syncable::BOOKMARKS);
287 287
288 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 288 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
289 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 289 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
290 WithArg<0>(RecordSyncShare(&records)))); 290 WithArg<0>(RecordSyncShare(&records))));
291 291
292 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 292 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
293 RunLoop(); 293 RunLoop();
294 294
295 scheduler()->ScheduleConfig( 295 scheduler()->ScheduleConfig(
296 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 296 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
297 RunLoop(); 297 RunLoop();
298 298
299 ASSERT_EQ(1U, records.snapshots.size()); 299 ASSERT_EQ(1U, records.snapshots.size());
300 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 300 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
301 records.snapshots[0]->source.types)); 301 records.snapshots[0]->source.types));
302 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 302 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
303 records.snapshots[0]->source.updates_source); 303 records.snapshots[0]->source.updates_source);
304 } 304 }
305 305
306 // Simulate a failure and make sure the config request is retried. 306 // Simulate a failure and make sure the config request is retried.
307 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 307 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
308 UseMockDelayProvider(); 308 UseMockDelayProvider();
309 EXPECT_CALL(*delay(), GetDelay(_)) 309 EXPECT_CALL(*delay(), GetDelay(_))
310 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 310 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
311 SyncShareRecords records; 311 SyncShareRecords records;
312 const ModelEnumSet model_types(syncable::BOOKMARKS); 312 const ModelTypeSet model_types(syncable::BOOKMARKS);
313 313
314 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 314 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
315 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 315 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
316 WithArg<0>(RecordSyncShare(&records)))) 316 WithArg<0>(RecordSyncShare(&records))))
317 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 317 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
318 WithArg<0>(RecordSyncShare(&records)))); 318 WithArg<0>(RecordSyncShare(&records))));
319 319
320 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 320 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
321 RunLoop(); 321 RunLoop();
322 322
323 ASSERT_EQ(0U, records.snapshots.size()); 323 ASSERT_EQ(0U, records.snapshots.size());
324 scheduler()->ScheduleConfig( 324 scheduler()->ScheduleConfig(
325 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 325 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
326 RunLoop(); 326 RunLoop();
327 327
328 ASSERT_EQ(1U, records.snapshots.size()); 328 ASSERT_EQ(1U, records.snapshots.size());
329 RunLoop(); 329 RunLoop();
330 330
331 ASSERT_EQ(2U, records.snapshots.size()); 331 ASSERT_EQ(2U, records.snapshots.size());
332 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 332 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
333 records.snapshots[1]->source.types)); 333 records.snapshots[1]->source.types));
334 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 334 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
335 records.snapshots[1]->source.updates_source); 335 records.snapshots[1]->source.updates_source);
336 } 336 }
337 337
338 // Issue 2 config commands. Second one right after the first has failed 338 // Issue 2 config commands. Second one right after the first has failed
339 // and make sure LATEST is executed. 339 // and make sure LATEST is executed.
340 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) { 340 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) {
341 const ModelEnumSet 341 const ModelTypeSet
342 model_types1(syncable::BOOKMARKS), 342 model_types1(syncable::BOOKMARKS),
343 model_types2(syncable::AUTOFILL); 343 model_types2(syncable::AUTOFILL);
344 UseMockDelayProvider(); 344 UseMockDelayProvider();
345 EXPECT_CALL(*delay(), GetDelay(_)) 345 EXPECT_CALL(*delay(), GetDelay(_))
346 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); 346 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30)));
347 SyncShareRecords records; 347 SyncShareRecords records;
348 348
349 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 349 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
350 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 350 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
351 WithArg<0>(RecordSyncShare(&records)))) 351 WithArg<0>(RecordSyncShare(&records))))
(...skipping 12 matching lines...) Expand all
364 364
365 ASSERT_EQ(1U, records.snapshots.size()); 365 ASSERT_EQ(1U, records.snapshots.size());
366 scheduler()->ScheduleConfig( 366 scheduler()->ScheduleConfig(
367 model_types2, GetUpdatesCallerInfo::RECONFIGURATION); 367 model_types2, GetUpdatesCallerInfo::RECONFIGURATION);
368 RunLoop(); 368 RunLoop();
369 369
370 ASSERT_EQ(2U, records.snapshots.size()); 370 ASSERT_EQ(2U, records.snapshots.size());
371 RunLoop(); 371 RunLoop();
372 372
373 ASSERT_EQ(3U, records.snapshots.size()); 373 ASSERT_EQ(3U, records.snapshots.size());
374 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types2, 374 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2,
375 records.snapshots[2]->source.types)); 375 records.snapshots[2]->source.types));
376 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 376 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
377 records.snapshots[2]->source.updates_source); 377 records.snapshots[2]->source.updates_source);
378 } 378 }
379 379
380 // Issue a nudge when the config has failed. Make sure both the config and 380 // Issue a nudge when the config has failed. Make sure both the config and
381 // nudge are executed. 381 // nudge are executed.
382 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 382 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
383 const ModelEnumSet model_types(syncable::BOOKMARKS); 383 const ModelTypeSet model_types(syncable::BOOKMARKS);
384 UseMockDelayProvider(); 384 UseMockDelayProvider();
385 EXPECT_CALL(*delay(), GetDelay(_)) 385 EXPECT_CALL(*delay(), GetDelay(_))
386 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 386 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
387 SyncShareRecords records; 387 SyncShareRecords records;
388 388
389 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 389 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
390 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 390 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
391 WithArg<0>(RecordSyncShare(&records)))) 391 WithArg<0>(RecordSyncShare(&records))))
392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
393 WithArg<0>(RecordSyncShare(&records)))) 393 WithArg<0>(RecordSyncShare(&records))))
(...skipping 18 matching lines...) Expand all
412 ASSERT_EQ(2U, records.snapshots.size()); 412 ASSERT_EQ(2U, records.snapshots.size());
413 RunLoop(); 413 RunLoop();
414 414
415 // Now change the mode so nudge can execute. 415 // Now change the mode so nudge can execute.
416 ASSERT_EQ(3U, records.snapshots.size()); 416 ASSERT_EQ(3U, records.snapshots.size());
417 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 417 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
418 RunLoop(); 418 RunLoop();
419 419
420 ASSERT_EQ(4U, records.snapshots.size()); 420 ASSERT_EQ(4U, records.snapshots.size());
421 421
422 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 422 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
423 records.snapshots[2]->source.types)); 423 records.snapshots[2]->source.types));
424 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 424 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
425 records.snapshots[2]->source.updates_source); 425 records.snapshots[2]->source.updates_source);
426 426
427 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(model_types, 427 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
428 records.snapshots[3]->source.types)); 428 records.snapshots[3]->source.types));
429 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 429 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
430 records.snapshots[3]->source.updates_source); 430 records.snapshots[3]->source.updates_source);
431 431
432 } 432 }
433 433
434 // Test that nudges are coalesced. 434 // Test that nudges are coalesced.
435 TEST_F(SyncSchedulerTest, NudgeCoalescing) { 435 TEST_F(SyncSchedulerTest, NudgeCoalescing) {
436 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 436 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
437 RunLoop(); 437 RunLoop();
438 438
439 SyncShareRecords r; 439 SyncShareRecords r;
440 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 440 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
441 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 441 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
442 WithArg<0>(RecordSyncShare(&r)))); 442 WithArg<0>(RecordSyncShare(&r))));
443 const ModelEnumSet 443 const ModelTypeSet
444 types1(syncable::BOOKMARKS), 444 types1(syncable::BOOKMARKS),
445 types2(syncable::AUTOFILL), 445 types2(syncable::AUTOFILL),
446 types3(syncable::THEMES); 446 types3(syncable::THEMES);
447 TimeDelta delay = zero(); 447 TimeDelta delay = zero();
448 TimeTicks optimal_time = TimeTicks::Now() + delay; 448 TimeTicks optimal_time = TimeTicks::Now() + delay;
449 scheduler()->ScheduleNudge( 449 scheduler()->ScheduleNudge(
450 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 450 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE);
451 scheduler()->ScheduleNudge( 451 scheduler()->ScheduleNudge(
452 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); 452 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE);
453 RunLoop(); 453 RunLoop();
454 454
455 ASSERT_EQ(1U, r.snapshots.size()); 455 ASSERT_EQ(1U, r.snapshots.size());
456 EXPECT_GE(r.times[0], optimal_time); 456 EXPECT_GE(r.times[0], optimal_time);
457 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap( 457 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(
458 Union(types1, types2), r.snapshots[0]->source.types)); 458 Union(types1, types2), r.snapshots[0]->source.types));
459 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 459 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
460 r.snapshots[0]->source.updates_source); 460 r.snapshots[0]->source.updates_source);
461 461
462 Mock::VerifyAndClearExpectations(syncer()); 462 Mock::VerifyAndClearExpectations(syncer());
463 463
464 SyncShareRecords r2; 464 SyncShareRecords r2;
465 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 465 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
466 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 466 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
467 WithArg<0>(RecordSyncShare(&r2)))); 467 WithArg<0>(RecordSyncShare(&r2))));
468 scheduler()->ScheduleNudge( 468 scheduler()->ScheduleNudge(
469 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); 469 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE);
470 RunLoop(); 470 RunLoop();
471 471
472 ASSERT_EQ(1U, r2.snapshots.size()); 472 ASSERT_EQ(1U, r2.snapshots.size());
473 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(types3, 473 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(types3,
474 r2.snapshots[0]->source.types)); 474 r2.snapshots[0]->source.types));
475 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, 475 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
476 r2.snapshots[0]->source.updates_source); 476 r2.snapshots[0]->source.updates_source);
477 } 477 }
478 478
479 // Test nudge scheduling. 479 // Test nudge scheduling.
480 TEST_F(SyncSchedulerTest, NudgeWithPayloads) { 480 TEST_F(SyncSchedulerTest, NudgeWithPayloads) {
481 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 481 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
482 RunLoop(); 482 RunLoop();
483 483
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 sessions::test_util::SimulateSessionsCommitDelayUpdate( 645 sessions::test_util::SimulateSessionsCommitDelayUpdate(
646 delay2)), 646 delay2)),
647 Invoke(sessions::test_util::SimulateSuccess), 647 Invoke(sessions::test_util::SimulateSuccess),
648 QuitLoopNowAction())); 648 QuitLoopNowAction()));
649 649
650 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay()); 650 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay());
651 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 651 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
652 RunLoop(); 652 RunLoop();
653 653
654 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay()); 654 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay());
655 const ModelEnumSet model_types(syncable::BOOKMARKS); 655 const ModelTypeSet model_types(syncable::BOOKMARKS);
656 scheduler()->ScheduleNudge( 656 scheduler()->ScheduleNudge(
657 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 657 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
658 RunLoop(); 658 RunLoop();
659 659
660 EXPECT_EQ(delay2, scheduler()->sessions_commit_delay()); 660 EXPECT_EQ(delay2, scheduler()->sessions_commit_delay());
661 StopSyncScheduler(); 661 StopSyncScheduler();
662 } 662 }
663 663
664 // Test that a sync session is run through to completion. 664 // Test that a sync session is run through to completion.
665 TEST_F(SyncSchedulerTest, HasMoreToSync) { 665 TEST_F(SyncSchedulerTest, HasMoreToSync) {
666 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 666 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
667 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) 667 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync))
668 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 668 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
669 QuitLoopNowAction())); 669 QuitLoopNowAction()));
670 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 670 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
671 RunLoop(); 671 RunLoop();
672 672
673 scheduler()->ScheduleNudge( 673 scheduler()->ScheduleNudge(
674 zero(), NUDGE_SOURCE_LOCAL, ModelEnumSet(), FROM_HERE); 674 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
675 RunLoop(); 675 RunLoop();
676 // If more nudges are scheduled, they'll be waited on by TearDown, and would 676 // If more nudges are scheduled, they'll be waited on by TearDown, and would
677 // cause our expectation to break. 677 // cause our expectation to break.
678 } 678 }
679 679
680 // Test that no syncing occurs when throttled. 680 // Test that no syncing occurs when throttled.
681 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 681 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
682 const ModelEnumSet types(syncable::BOOKMARKS); 682 const ModelTypeSet types(syncable::BOOKMARKS);
683 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 683 TimeDelta poll(TimeDelta::FromMilliseconds(5));
684 TimeDelta throttle(TimeDelta::FromMinutes(10)); 684 TimeDelta throttle(TimeDelta::FromMinutes(10));
685 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 685 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
686 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 686 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
687 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) 687 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)))
688 .WillRepeatedly(AddFailureAndQuitLoopNow()); 688 .WillRepeatedly(AddFailureAndQuitLoopNow());
689 689
690 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 690 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
691 RunLoop(); 691 RunLoop();
692 692
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 733 TimeDelta poll(TimeDelta::FromMilliseconds(15));
734 SyncShareRecords records; 734 SyncShareRecords records;
735 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 735 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
736 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 736 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
737 .WillOnce((Invoke(sessions::test_util::SimulateSuccess), 737 .WillOnce((Invoke(sessions::test_util::SimulateSuccess),
738 WithArg<0>(RecordSyncShare(&records)))); 738 WithArg<0>(RecordSyncShare(&records))));
739 739
740 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 740 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
741 RunLoop(); 741 RunLoop();
742 742
743 const ModelEnumSet nudge_types(syncable::AUTOFILL); 743 const ModelTypeSet nudge_types(syncable::AUTOFILL);
744 scheduler()->ScheduleNudge( 744 scheduler()->ScheduleNudge(
745 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 745 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
746 scheduler()->ScheduleNudge( 746 scheduler()->ScheduleNudge(
747 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 747 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
748 748
749 const ModelEnumSet config_types(syncable::BOOKMARKS); 749 const ModelTypeSet config_types(syncable::BOOKMARKS);
750 750
751 scheduler()->ScheduleConfig( 751 scheduler()->ScheduleConfig(
752 config_types, GetUpdatesCallerInfo::RECONFIGURATION); 752 config_types, GetUpdatesCallerInfo::RECONFIGURATION);
753 RunLoop(); 753 RunLoop();
754 754
755 ASSERT_EQ(1U, records.snapshots.size()); 755 ASSERT_EQ(1U, records.snapshots.size());
756 EXPECT_TRUE(CompareModelEnumSetToModelTypePayloadMap(config_types, 756 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types,
757 records.snapshots[0]->source.types)); 757 records.snapshots[0]->source.types));
758 } 758 }
759 759
760 // Test that exponential backoff is properly triggered. 760 // Test that exponential backoff is properly triggered.
761 TEST_F(SyncSchedulerTest, BackoffTriggers) { 761 TEST_F(SyncSchedulerTest, BackoffTriggers) {
762 UseMockDelayProvider(); 762 UseMockDelayProvider();
763 763
764 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 764 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
765 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) 765 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed))
766 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 766 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
(...skipping 27 matching lines...) Expand all
794 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 794 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed))
795 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 795 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
796 QuitLoopNowAction())); 796 QuitLoopNowAction()));
797 EXPECT_FALSE(GetBackoffAndResetTest()); 797 EXPECT_FALSE(GetBackoffAndResetTest());
798 } 798 }
799 799
800 // Test that no polls or extraneous nudges occur when in backoff. 800 // Test that no polls or extraneous nudges occur when in backoff.
801 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 801 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
802 SyncShareRecords r; 802 SyncShareRecords r;
803 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 803 TimeDelta poll(TimeDelta::FromMilliseconds(5));
804 const ModelEnumSet types(syncable::BOOKMARKS); 804 const ModelTypeSet types(syncable::BOOKMARKS);
805 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 805 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
806 UseMockDelayProvider(); 806 UseMockDelayProvider();
807 807
808 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2) 808 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2)
809 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 809 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
810 RecordSyncShareMultiple(&r, 2U))); 810 RecordSyncShareMultiple(&r, 2U)));
811 EXPECT_CALL(*delay(), GetDelay(_)). 811 EXPECT_CALL(*delay(), GetDelay(_)).
812 WillRepeatedly(Return(TimeDelta::FromDays(1))); 812 WillRepeatedly(Return(TimeDelta::FromDays(1)));
813 813
814 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 814 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 958
959 // Test that appropriate syncer steps are requested for each job type. 959 // Test that appropriate syncer steps are requested for each job type.
960 TEST_F(SyncSchedulerTest, SyncerSteps) { 960 TEST_F(SyncSchedulerTest, SyncerSteps) {
961 // Nudges. 961 // Nudges.
962 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 962 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
963 .Times(1); 963 .Times(1);
964 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 964 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
965 RunLoop(); 965 RunLoop();
966 966
967 scheduler()->ScheduleNudge( 967 scheduler()->ScheduleNudge(
968 zero(), NUDGE_SOURCE_LOCAL, ModelEnumSet(), FROM_HERE); 968 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
969 PumpLoop(); 969 PumpLoop();
970 // Pump again to run job. 970 // Pump again to run job.
971 PumpLoop(); 971 PumpLoop();
972 972
973 StopSyncScheduler(); 973 StopSyncScheduler();
974 Mock::VerifyAndClearExpectations(syncer()); 974 Mock::VerifyAndClearExpectations(syncer());
975 975
976 // ClearUserData. 976 // ClearUserData.
977 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) 977 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA))
978 .Times(1); 978 .Times(1);
979 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 979 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
980 RunLoop(); 980 RunLoop();
981 981
982 scheduler()->ScheduleClearUserData(); 982 scheduler()->ScheduleClearUserData();
983 PumpLoop(); 983 PumpLoop();
984 PumpLoop(); 984 PumpLoop();
985 985
986 StopSyncScheduler(); 986 StopSyncScheduler();
987 Mock::VerifyAndClearExpectations(syncer()); 987 Mock::VerifyAndClearExpectations(syncer());
988 988
989 // Configuration. 989 // Configuration.
990 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); 990 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES));
991 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 991 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
992 RunLoop(); 992 RunLoop();
993 993
994 scheduler()->ScheduleConfig( 994 scheduler()->ScheduleConfig(
995 ModelEnumSet(), GetUpdatesCallerInfo::RECONFIGURATION); 995 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION);
996 PumpLoop(); 996 PumpLoop();
997 PumpLoop(); 997 PumpLoop();
998 998
999 StopSyncScheduler(); 999 StopSyncScheduler();
1000 Mock::VerifyAndClearExpectations(syncer()); 1000 Mock::VerifyAndClearExpectations(syncer());
1001 1001
1002 // Cleanup disabled types. 1002 // Cleanup disabled types.
1003 EXPECT_CALL(*syncer(), 1003 EXPECT_CALL(*syncer(),
1004 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)); 1004 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES));
1005 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1005 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 1037
1038 // Test that starting the syncer thread without a valid connection doesn't 1038 // Test that starting the syncer thread without a valid connection doesn't
1039 // break things when a connection is detected. 1039 // break things when a connection is detected.
1040 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { 1040 TEST_F(SyncSchedulerTest, StartWhenNotConnected) {
1041 connection()->SetServerNotReachable(); 1041 connection()->SetServerNotReachable();
1042 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(QuitLoopNowAction()); 1042 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(QuitLoopNowAction());
1043 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1043 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1044 RunLoop(); 1044 RunLoop();
1045 1045
1046 scheduler()->ScheduleNudge( 1046 scheduler()->ScheduleNudge(
1047 zero(), NUDGE_SOURCE_LOCAL, ModelEnumSet(), FROM_HERE); 1047 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1048 // Should save the nudge for until after the server is reachable. 1048 // Should save the nudge for until after the server is reachable.
1049 PumpLoop(); 1049 PumpLoop();
1050 1050
1051 connection()->SetServerReachable(); 1051 connection()->SetServerReachable();
1052 PumpLoop(); 1052 PumpLoop();
1053 } 1053 }
1054 1054
1055 TEST_F(SyncSchedulerTest, SetsPreviousRoutingInfo) { 1055 TEST_F(SyncSchedulerTest, SetsPreviousRoutingInfo) {
1056 ModelSafeRoutingInfo info; 1056 ModelSafeRoutingInfo info;
1057 EXPECT_TRUE(info == context()->previous_session_routing_info()); 1057 EXPECT_TRUE(info == context()->previous_session_routing_info());
1058 ModelSafeRoutingInfo expected; 1058 ModelSafeRoutingInfo expected;
1059 context()->registrar()->GetModelSafeRoutingInfo(&expected); 1059 context()->registrar()->GetModelSafeRoutingInfo(&expected);
1060 ASSERT_FALSE(expected.empty()); 1060 ASSERT_FALSE(expected.empty());
1061 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); 1061 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1);
1062 1062
1063 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1063 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1064 RunLoop(); 1064 RunLoop();
1065 1065
1066 scheduler()->ScheduleNudge( 1066 scheduler()->ScheduleNudge(
1067 zero(), NUDGE_SOURCE_LOCAL, ModelEnumSet(), FROM_HERE); 1067 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1068 PumpLoop(); 1068 PumpLoop();
1069 // Pump again to run job. 1069 // Pump again to run job.
1070 PumpLoop(); 1070 PumpLoop();
1071 1071
1072 StopSyncScheduler(); 1072 StopSyncScheduler();
1073 1073
1074 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1074 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1075 } 1075 }
1076 1076
1077 } // namespace browser_sync 1077 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | chrome/browser/sync/engine/syncer_proto_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698