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" |
11 #include "sync/engine/backoff_delay_provider.h" | 11 #include "sync/engine/backoff_delay_provider.h" |
12 #include "sync/engine/sync_scheduler_impl.h" | 12 #include "sync/engine/sync_scheduler_impl.h" |
13 #include "sync/engine/syncer.h" | 13 #include "sync/engine/syncer.h" |
14 #include "sync/engine/throttled_data_type_tracker.h" | 14 #include "sync/engine/throttled_data_type_tracker.h" |
15 #include "sync/internal_api/public/base/model_type_state_map_test_util.h" | 15 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" |
16 #include "sync/sessions/test_util.h" | 16 #include "sync/sessions/test_util.h" |
17 #include "sync/test/callback_counter.h" | 17 #include "sync/test/callback_counter.h" |
18 #include "sync/test/engine/fake_model_worker.h" | 18 #include "sync/test/engine/fake_model_worker.h" |
19 #include "sync/test/engine/mock_connection_manager.h" | 19 #include "sync/test/engine/mock_connection_manager.h" |
20 #include "sync/test/engine/test_directory_setter_upper.h" | 20 #include "sync/test/engine/test_directory_setter_upper.h" |
21 #include "sync/test/fake_extensions_activity_monitor.h" | 21 #include "sync/test/fake_extensions_activity_monitor.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using base::TimeDelta; | 25 using base::TimeDelta; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 RunLoop(); | 192 RunLoop(); |
193 | 193 |
194 return scheduler()->IsBackingOff(); | 194 return scheduler()->IsBackingOff(); |
195 } | 195 } |
196 | 196 |
197 void UseMockDelayProvider() { | 197 void UseMockDelayProvider() { |
198 delay_ = new MockDelayProvider(); | 198 delay_ = new MockDelayProvider(); |
199 scheduler_->delay_provider_.reset(delay_); | 199 scheduler_->delay_provider_.reset(delay_); |
200 } | 200 } |
201 | 201 |
202 // Compare a ModelTypeSet to a ModelTypeStateMap, ignoring | 202 // Compare a ModelTypeSet to a ModelTypeInvalidationMap, ignoring |
203 // state values. | 203 // state values. |
204 bool CompareModelTypeSetToModelTypeStateMap( | 204 bool CompareModelTypeSetToModelTypeInvalidationMap( |
205 ModelTypeSet lhs, | 205 ModelTypeSet lhs, |
206 const ModelTypeStateMap& rhs) { | 206 const ModelTypeInvalidationMap& rhs) { |
207 size_t count = 0; | 207 size_t count = 0; |
208 for (ModelTypeStateMap::const_iterator i = rhs.begin(); | 208 for (ModelTypeInvalidationMap::const_iterator i = rhs.begin(); |
209 i != rhs.end(); ++i, ++count) { | 209 i != rhs.end(); ++i, ++count) { |
210 if (!lhs.Has(i->first)) | 210 if (!lhs.Has(i->first)) |
211 return false; | 211 return false; |
212 } | 212 } |
213 if (lhs.Size() != count) | 213 if (lhs.Size() != count) |
214 return false; | 214 return false; |
215 return true; | 215 return true; |
216 } | 216 } |
217 | 217 |
218 SyncSessionContext* context() { return context_.get(); } | 218 SyncSessionContext* context() { return context_.get(); } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 WithArg<0>(RecordSyncShare(&records)))) | 275 WithArg<0>(RecordSyncShare(&records)))) |
276 .RetiresOnSaturation(); | 276 .RetiresOnSaturation(); |
277 | 277 |
278 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 278 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
279 | 279 |
280 scheduler()->ScheduleNudgeAsync( | 280 scheduler()->ScheduleNudgeAsync( |
281 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 281 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
282 RunLoop(); | 282 RunLoop(); |
283 | 283 |
284 ASSERT_EQ(1U, records.snapshots.size()); | 284 ASSERT_EQ(1U, records.snapshots.size()); |
285 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 285 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
286 records.snapshots[0].source().types)); | 286 records.snapshots[0].source().types)); |
287 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 287 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
288 records.snapshots[0].source().updates_source); | 288 records.snapshots[0].source().updates_source); |
289 | 289 |
290 Mock::VerifyAndClearExpectations(syncer()); | 290 Mock::VerifyAndClearExpectations(syncer()); |
291 | 291 |
292 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 292 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
293 SyncShareRecords records2; | 293 SyncShareRecords records2; |
294 model_types.Remove(BOOKMARKS); | 294 model_types.Remove(BOOKMARKS); |
295 model_types.Put(AUTOFILL); | 295 model_types.Put(AUTOFILL); |
296 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 296 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
297 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 297 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
298 WithArg<0>(RecordSyncShare(&records2)))); | 298 WithArg<0>(RecordSyncShare(&records2)))); |
299 scheduler()->ScheduleNudgeAsync( | 299 scheduler()->ScheduleNudgeAsync( |
300 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 300 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
301 RunLoop(); | 301 RunLoop(); |
302 | 302 |
303 ASSERT_EQ(1U, records2.snapshots.size()); | 303 ASSERT_EQ(1U, records2.snapshots.size()); |
304 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 304 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
305 records2.snapshots[0].source().types)); | 305 records2.snapshots[0].source().types)); |
306 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 306 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
307 records2.snapshots[0].source().updates_source); | 307 records2.snapshots[0].source().updates_source); |
308 } | 308 } |
309 | 309 |
310 // Make sure a regular config command is scheduled fine in the absence of any | 310 // Make sure a regular config command is scheduled fine in the absence of any |
311 // errors. | 311 // errors. |
312 TEST_F(SyncSchedulerTest, Config) { | 312 TEST_F(SyncSchedulerTest, Config) { |
313 SyncShareRecords records; | 313 SyncShareRecords records; |
314 const ModelTypeSet model_types(BOOKMARKS); | 314 const ModelTypeSet model_types(BOOKMARKS); |
315 | 315 |
316 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 316 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
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 | 321 |
322 CallbackCounter counter; | 322 CallbackCounter counter; |
323 ConfigurationParams params( | 323 ConfigurationParams params( |
324 GetUpdatesCallerInfo::RECONFIGURATION, | 324 GetUpdatesCallerInfo::RECONFIGURATION, |
325 model_types, | 325 model_types, |
326 TypesToRoutingInfo(model_types), | 326 TypesToRoutingInfo(model_types), |
327 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 327 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
328 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 328 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
329 ASSERT_EQ(1, counter.times_called()); | 329 ASSERT_EQ(1, counter.times_called()); |
330 | 330 |
331 ASSERT_EQ(1U, records.snapshots.size()); | 331 ASSERT_EQ(1U, records.snapshots.size()); |
332 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 332 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
333 records.snapshots[0].source().types)); | 333 records.snapshots[0].source().types)); |
334 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 334 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
335 records.snapshots[0].source().updates_source); | 335 records.snapshots[0].source().updates_source); |
336 } | 336 } |
337 | 337 |
338 // Simulate a failure and make sure the config request is retried. | 338 // Simulate a failure and make sure the config request is retried. |
339 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 339 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
340 UseMockDelayProvider(); | 340 UseMockDelayProvider(); |
341 EXPECT_CALL(*delay(), GetDelay(_)) | 341 EXPECT_CALL(*delay(), GetDelay(_)) |
342 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 342 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
(...skipping 16 matching lines...) Expand all Loading... |
359 TypesToRoutingInfo(model_types), | 359 TypesToRoutingInfo(model_types), |
360 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 360 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
361 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 361 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
362 ASSERT_EQ(0, counter.times_called()); | 362 ASSERT_EQ(0, counter.times_called()); |
363 | 363 |
364 ASSERT_EQ(1U, records.snapshots.size()); | 364 ASSERT_EQ(1U, records.snapshots.size()); |
365 RunLoop(); | 365 RunLoop(); |
366 | 366 |
367 ASSERT_EQ(2U, records.snapshots.size()); | 367 ASSERT_EQ(2U, records.snapshots.size()); |
368 ASSERT_EQ(1, counter.times_called()); | 368 ASSERT_EQ(1, counter.times_called()); |
369 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 369 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
370 records.snapshots[1].source().types)); | 370 records.snapshots[1].source().types)); |
371 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 371 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
372 records.snapshots[1].source().updates_source); | 372 records.snapshots[1].source().updates_source); |
373 } | 373 } |
374 | 374 |
375 // Issue a nudge when the config has failed. Make sure both the config and | 375 // Issue a nudge when the config has failed. Make sure both the config and |
376 // nudge are executed. | 376 // nudge are executed. |
377 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 377 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
378 const ModelTypeSet model_types(BOOKMARKS); | 378 const ModelTypeSet model_types(BOOKMARKS); |
379 UseMockDelayProvider(); | 379 UseMockDelayProvider(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 RunLoop(); | 418 RunLoop(); |
419 // This is the 3rd attempt, which we've set up to SimulateSuccess. | 419 // This is the 3rd attempt, which we've set up to SimulateSuccess. |
420 ASSERT_EQ(3U, records.snapshots.size()); | 420 ASSERT_EQ(3U, records.snapshots.size()); |
421 ASSERT_EQ(1, counter.times_called()); | 421 ASSERT_EQ(1, counter.times_called()); |
422 | 422 |
423 // Now change the mode so nudge can execute. | 423 // Now change the mode so nudge can execute. |
424 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 424 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
425 | 425 |
426 ASSERT_EQ(4U, records.snapshots.size()); | 426 ASSERT_EQ(4U, records.snapshots.size()); |
427 | 427 |
428 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 428 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
429 records.snapshots[2].source().types)); | 429 records.snapshots[2].source().types)); |
430 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 430 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
431 records.snapshots[2].source().updates_source); | 431 records.snapshots[2].source().updates_source); |
432 | 432 |
433 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, | 433 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, |
434 records.snapshots[3].source().types)); | 434 records.snapshots[3].source().types)); |
435 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 435 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
436 records.snapshots[3].source().updates_source); | 436 records.snapshots[3].source().updates_source); |
437 | 437 |
438 } | 438 } |
439 | 439 |
440 // Test that nudges are coalesced. | 440 // Test that nudges are coalesced. |
441 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 441 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
442 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 442 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
443 | 443 |
444 SyncShareRecords r; | 444 SyncShareRecords r; |
445 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 445 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
446 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 446 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
447 WithArg<0>(RecordSyncShare(&r)))); | 447 WithArg<0>(RecordSyncShare(&r)))); |
448 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 448 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); |
449 TimeDelta delay = zero(); | 449 TimeDelta delay = zero(); |
450 TimeTicks optimal_time = TimeTicks::Now() + delay; | 450 TimeTicks optimal_time = TimeTicks::Now() + delay; |
451 scheduler()->ScheduleNudgeAsync( | 451 scheduler()->ScheduleNudgeAsync( |
452 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 452 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
453 scheduler()->ScheduleNudgeAsync( | 453 scheduler()->ScheduleNudgeAsync( |
454 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 454 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
455 RunLoop(); | 455 RunLoop(); |
456 | 456 |
457 ASSERT_EQ(1U, r.snapshots.size()); | 457 ASSERT_EQ(1U, r.snapshots.size()); |
458 EXPECT_GE(r.times[0], optimal_time); | 458 EXPECT_GE(r.times[0], optimal_time); |
459 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( | 459 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap( |
460 Union(types1, types2), r.snapshots[0].source().types)); | 460 Union(types1, types2), r.snapshots[0].source().types)); |
461 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 461 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
462 r.snapshots[0].source().updates_source); | 462 r.snapshots[0].source().updates_source); |
463 | 463 |
464 Mock::VerifyAndClearExpectations(syncer()); | 464 Mock::VerifyAndClearExpectations(syncer()); |
465 | 465 |
466 SyncShareRecords r2; | 466 SyncShareRecords r2; |
467 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 467 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
468 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 468 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
469 WithArg<0>(RecordSyncShare(&r2)))); | 469 WithArg<0>(RecordSyncShare(&r2)))); |
470 scheduler()->ScheduleNudgeAsync( | 470 scheduler()->ScheduleNudgeAsync( |
471 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); | 471 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); |
472 RunLoop(); | 472 RunLoop(); |
473 | 473 |
474 ASSERT_EQ(1U, r2.snapshots.size()); | 474 ASSERT_EQ(1U, r2.snapshots.size()); |
475 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(types3, | 475 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(types3, |
476 r2.snapshots[0].source().types)); | 476 r2.snapshots[0].source().types)); |
477 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 477 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
478 r2.snapshots[0].source().updates_source); | 478 r2.snapshots[0].source().updates_source); |
479 } | 479 } |
480 | 480 |
481 // Test that nudges are coalesced. | 481 // Test that nudges are coalesced. |
482 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 482 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
483 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 483 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
484 | 484 |
485 SyncShareRecords r; | 485 SyncShareRecords r; |
(...skipping 11 matching lines...) Expand all Loading... |
497 scheduler()->ScheduleNudgeAsync( | 497 scheduler()->ScheduleNudgeAsync( |
498 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); | 498 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); |
499 | 499 |
500 TimeTicks min_time = TimeTicks::Now(); | 500 TimeTicks min_time = TimeTicks::Now(); |
501 TimeTicks max_time = TimeTicks::Now() + delay; | 501 TimeTicks max_time = TimeTicks::Now() + delay; |
502 | 502 |
503 RunLoop(); | 503 RunLoop(); |
504 | 504 |
505 // Make sure the sync has happened. | 505 // Make sure the sync has happened. |
506 ASSERT_EQ(1U, r.snapshots.size()); | 506 ASSERT_EQ(1U, r.snapshots.size()); |
507 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( | 507 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap( |
508 Union(types1, types2), r.snapshots[0].source().types)); | 508 Union(types1, types2), r.snapshots[0].source().types)); |
509 | 509 |
510 // Make sure the sync happened at the right time. | 510 // Make sure the sync happened at the right time. |
511 EXPECT_GE(r.times[0], min_time); | 511 EXPECT_GE(r.times[0], min_time); |
512 EXPECT_LE(r.times[0], max_time); | 512 EXPECT_LE(r.times[0], max_time); |
513 } | 513 } |
514 | 514 |
515 // Test nudge scheduling. | 515 // Test nudge scheduling. |
516 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 516 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
517 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 517 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
518 | 518 |
519 SyncShareRecords records; | 519 SyncShareRecords records; |
520 ModelTypeStateMap type_state_map; | 520 const ModelTypeSet types(BOOKMARKS); |
521 type_state_map[BOOKMARKS].payload = "test"; | 521 ModelTypeInvalidationMap invalidation_map = |
| 522 ModelTypeSetToInvalidationMap(types, "test"); |
522 | 523 |
523 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 524 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
524 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 525 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
525 WithArg<0>(RecordSyncShare(&records)))) | 526 WithArg<0>(RecordSyncShare(&records)))) |
526 .RetiresOnSaturation(); | 527 .RetiresOnSaturation(); |
527 scheduler()->ScheduleNudgeWithStatesAsync( | 528 scheduler()->ScheduleNudgeWithStatesAsync( |
528 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); | 529 zero(), NUDGE_SOURCE_LOCAL, invalidation_map, FROM_HERE); |
529 RunLoop(); | 530 RunLoop(); |
530 | 531 |
531 ASSERT_EQ(1U, records.snapshots.size()); | 532 ASSERT_EQ(1U, records.snapshots.size()); |
532 EXPECT_THAT(type_state_map, Eq(records.snapshots[0].source().types)); | 533 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types)); |
533 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 534 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
534 records.snapshots[0].source().updates_source); | 535 records.snapshots[0].source().updates_source); |
535 | 536 |
536 Mock::VerifyAndClearExpectations(syncer()); | 537 Mock::VerifyAndClearExpectations(syncer()); |
537 | 538 |
538 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 539 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
539 SyncShareRecords records2; | 540 SyncShareRecords records2; |
540 type_state_map.erase(BOOKMARKS); | 541 invalidation_map.erase(BOOKMARKS); |
541 type_state_map[AUTOFILL].payload = "test2"; | 542 invalidation_map[AUTOFILL].payload = "test2"; |
542 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 543 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
543 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 544 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
544 WithArg<0>(RecordSyncShare(&records2)))); | 545 WithArg<0>(RecordSyncShare(&records2)))); |
545 scheduler()->ScheduleNudgeWithStatesAsync( | 546 scheduler()->ScheduleNudgeWithStatesAsync( |
546 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); | 547 zero(), NUDGE_SOURCE_LOCAL, invalidation_map, FROM_HERE); |
547 RunLoop(); | 548 RunLoop(); |
548 | 549 |
549 ASSERT_EQ(1U, records2.snapshots.size()); | 550 ASSERT_EQ(1U, records2.snapshots.size()); |
550 EXPECT_THAT(type_state_map, Eq(records2.snapshots[0].source().types)); | 551 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types)); |
551 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 552 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
552 records2.snapshots[0].source().updates_source); | 553 records2.snapshots[0].source().updates_source); |
553 } | 554 } |
554 | 555 |
555 // Test that nudges are coalesced. | 556 // Test that nudges are coalesced. |
556 TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) { | 557 TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) { |
557 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 558 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
558 | 559 |
559 SyncShareRecords r; | 560 SyncShareRecords r; |
560 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 561 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
561 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 562 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
562 WithArg<0>(RecordSyncShare(&r)))); | 563 WithArg<0>(RecordSyncShare(&r)))); |
563 ModelTypeStateMap types1, types2, types3; | 564 ModelTypeInvalidationMap types1, types2, types3; |
564 types1[BOOKMARKS].payload = "test1"; | 565 types1[BOOKMARKS].payload = "test1"; |
565 types2[AUTOFILL].payload = "test2"; | 566 types2[AUTOFILL].payload = "test2"; |
566 types3[THEMES].payload = "test3"; | 567 types3[THEMES].payload = "test3"; |
567 TimeDelta delay = zero(); | 568 TimeDelta delay = zero(); |
568 TimeTicks optimal_time = TimeTicks::Now() + delay; | 569 TimeTicks optimal_time = TimeTicks::Now() + delay; |
569 scheduler()->ScheduleNudgeWithStatesAsync( | 570 scheduler()->ScheduleNudgeWithStatesAsync( |
570 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 571 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
571 scheduler()->ScheduleNudgeWithStatesAsync( | 572 scheduler()->ScheduleNudgeWithStatesAsync( |
572 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 573 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
573 RunLoop(); | 574 RunLoop(); |
574 | 575 |
575 ASSERT_EQ(1U, r.snapshots.size()); | 576 ASSERT_EQ(1U, r.snapshots.size()); |
576 EXPECT_GE(r.times[0], optimal_time); | 577 EXPECT_GE(r.times[0], optimal_time); |
577 ModelTypeStateMap coalesced_types; | 578 ModelTypeInvalidationMap coalesced_types; |
578 CoalesceStates(&coalesced_types, types1); | 579 CoalesceStates(&coalesced_types, types1); |
579 CoalesceStates(&coalesced_types, types2); | 580 CoalesceStates(&coalesced_types, types2); |
580 EXPECT_THAT(coalesced_types, Eq(r.snapshots[0].source().types)); | 581 EXPECT_THAT(coalesced_types, Eq(r.snapshots[0].source().types)); |
581 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 582 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
582 r.snapshots[0].source().updates_source); | 583 r.snapshots[0].source().updates_source); |
583 | 584 |
584 Mock::VerifyAndClearExpectations(syncer()); | 585 Mock::VerifyAndClearExpectations(syncer()); |
585 | 586 |
586 SyncShareRecords r2; | 587 SyncShareRecords r2; |
587 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 588 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 CallbackCounter counter; | 798 CallbackCounter counter; |
798 ConfigurationParams params( | 799 ConfigurationParams params( |
799 GetUpdatesCallerInfo::RECONFIGURATION, | 800 GetUpdatesCallerInfo::RECONFIGURATION, |
800 config_types, | 801 config_types, |
801 TypesToRoutingInfo(config_types), | 802 TypesToRoutingInfo(config_types), |
802 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 803 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
803 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 804 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
804 ASSERT_EQ(1, counter.times_called()); | 805 ASSERT_EQ(1, counter.times_called()); |
805 | 806 |
806 ASSERT_EQ(1U, records.snapshots.size()); | 807 ASSERT_EQ(1U, records.snapshots.size()); |
807 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(config_types, | 808 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(config_types, |
808 records.snapshots[0].source().types)); | 809 records.snapshots[0].source().types)); |
809 | 810 |
810 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. | 811 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. |
811 // SyncSchedulerWhiteboxTest also provides coverage for this, but much | 812 // SyncSchedulerWhiteboxTest also provides coverage for this, but much |
812 // more targeted ('whitebox' style). | 813 // more targeted ('whitebox' style). |
813 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); | 814 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); |
814 SyncShareRecords records2; | 815 SyncShareRecords records2; |
815 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 816 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
816 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 817 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
817 WithArg<0>(RecordSyncShare(&records2)))); | 818 WithArg<0>(RecordSyncShare(&records2)))); |
818 | 819 |
819 // TODO(tim): Figure out how to remove this dangerous need to reset | 820 // TODO(tim): Figure out how to remove this dangerous need to reset |
820 // routing info between mode switches. | 821 // routing info between mode switches. |
821 context()->set_routing_info(routing_info()); | 822 context()->set_routing_info(routing_info()); |
822 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 823 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
823 | 824 |
824 ASSERT_EQ(1U, records2.snapshots.size()); | 825 ASSERT_EQ(1U, records2.snapshots.size()); |
825 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 826 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
826 records2.snapshots[0].source().updates_source); | 827 records2.snapshots[0].source().updates_source); |
827 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(nudge_types, | 828 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(nudge_types, |
828 records2.snapshots[0].source().types)); | 829 records2.snapshots[0].source().types)); |
829 PumpLoop(); | 830 PumpLoop(); |
830 } | 831 } |
831 | 832 |
832 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 833 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
833 void SetUp() { | 834 void SetUp() { |
834 SyncSchedulerTest::SetUp(); | 835 SyncSchedulerTest::SetUp(); |
835 UseMockDelayProvider(); | 836 UseMockDelayProvider(); |
836 EXPECT_CALL(*delay(), GetDelay(_)) | 837 EXPECT_CALL(*delay(), GetDelay(_)) |
837 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 838 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 // Should save the nudge for until after the server is reachable. | 1134 // Should save the nudge for until after the server is reachable. |
1134 MessageLoop::current()->RunAllPending(); | 1135 MessageLoop::current()->RunAllPending(); |
1135 | 1136 |
1136 connection()->SetServerReachable(); | 1137 connection()->SetServerReachable(); |
1137 connection()->UpdateConnectionStatus(); | 1138 connection()->UpdateConnectionStatus(); |
1138 scheduler()->OnConnectionStatusChange(); | 1139 scheduler()->OnConnectionStatusChange(); |
1139 MessageLoop::current()->RunAllPending(); | 1140 MessageLoop::current()->RunAllPending(); |
1140 } | 1141 } |
1141 | 1142 |
1142 } // namespace syncer | 1143 } // namespace syncer |
OLD | NEW |