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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 120 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
121 }; | 121 }; |
122 | 122 |
123 virtual void SetUp() { | 123 virtual void SetUp() { |
124 dir_maker_.SetUp(); | 124 dir_maker_.SetUp(); |
125 syncer_ = new testing::StrictMock<MockSyncer>(); | 125 syncer_ = new testing::StrictMock<MockSyncer>(); |
126 delay_ = NULL; | 126 delay_ = NULL; |
127 extensions_activity_ = new ExtensionsActivity(); | 127 extensions_activity_ = new ExtensionsActivity(); |
128 | 128 |
129 routing_info_[BOOKMARKS] = GROUP_UI; | 129 routing_info_[THEMES] = GROUP_UI; |
130 routing_info_[AUTOFILL] = GROUP_DB; | 130 routing_info_[TYPED_URLS] = GROUP_DB; |
131 routing_info_[THEMES] = GROUP_UI; | 131 routing_info_[THEMES] = GROUP_UI; |
132 routing_info_[NIGORI] = GROUP_PASSIVE; | 132 routing_info_[NIGORI] = GROUP_PASSIVE; |
133 | 133 |
134 workers_.clear(); | 134 workers_.clear(); |
135 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 135 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
136 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 136 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
137 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 137 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
138 | 138 |
139 connection_.reset(new MockConnectionManager(directory(), | 139 connection_.reset(new MockConnectionManager(directory(), |
140 &cancelation_signal_)); | 140 &cancelation_signal_)); |
(...skipping 11 matching lines...) Expand all Loading... |
152 false, // force enable pre-commit GU avoidance | 152 false, // force enable pre-commit GU avoidance |
153 "fake_invalidator_client_id")); | 153 "fake_invalidator_client_id")); |
154 context_->SetRoutingInfo(routing_info_); | 154 context_->SetRoutingInfo(routing_info_); |
155 context_->set_notifications_enabled(true); | 155 context_->set_notifications_enabled(true); |
156 context_->set_account_name("Test"); | 156 context_->set_account_name("Test"); |
157 scheduler_.reset( | 157 scheduler_.reset( |
158 new SyncSchedulerImpl("TestSyncScheduler", | 158 new SyncSchedulerImpl("TestSyncScheduler", |
159 BackoffDelayProvider::FromDefaults(), | 159 BackoffDelayProvider::FromDefaults(), |
160 context(), | 160 context(), |
161 syncer_)); | 161 syncer_)); |
| 162 scheduler_->SetDefaultNudgeDelay(default_delay()); |
162 } | 163 } |
163 | 164 |
164 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 165 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
165 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 166 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
166 MockSyncer* syncer() { return syncer_; } | 167 MockSyncer* syncer() { return syncer_; } |
167 MockDelayProvider* delay() { return delay_; } | 168 MockDelayProvider* delay() { return delay_; } |
168 MockConnectionManager* connection() { return connection_.get(); } | 169 MockConnectionManager* connection() { return connection_.get(); } |
169 TimeDelta zero() { return TimeDelta::FromSeconds(0); } | 170 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
170 TimeDelta timeout() { | 171 TimeDelta timeout() { |
171 return TestTimeouts::action_timeout(); | 172 return TestTimeouts::action_timeout(); |
172 } | 173 } |
173 | 174 |
174 virtual void TearDown() { | 175 virtual void TearDown() { |
175 PumpLoop(); | 176 PumpLoop(); |
176 scheduler_.reset(); | 177 scheduler_.reset(); |
177 PumpLoop(); | 178 PumpLoop(); |
178 dir_maker_.TearDown(); | 179 dir_maker_.TearDown(); |
179 } | 180 } |
(...skipping 19 matching lines...) Expand all Loading... |
199 // This stops the scheduler synchronously. | 200 // This stops the scheduler synchronously. |
200 void StopSyncScheduler() { | 201 void StopSyncScheduler() { |
201 base::MessageLoop::current()->PostTask( | 202 base::MessageLoop::current()->PostTask( |
202 FROM_HERE, | 203 FROM_HERE, |
203 base::Bind(&SyncSchedulerTest::DoQuitLoopNow, | 204 base::Bind(&SyncSchedulerTest::DoQuitLoopNow, |
204 weak_ptr_factory_.GetWeakPtr())); | 205 weak_ptr_factory_.GetWeakPtr())); |
205 RunLoop(); | 206 RunLoop(); |
206 } | 207 } |
207 | 208 |
208 bool RunAndGetBackoff() { | 209 bool RunAndGetBackoff() { |
209 ModelTypeSet nudge_types(BOOKMARKS); | 210 ModelTypeSet nudge_types(THEMES); |
210 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 211 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
211 | 212 |
212 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 213 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
213 RunLoop(); | 214 RunLoop(); |
214 | 215 |
215 return scheduler()->IsBackingOff(); | 216 return scheduler()->IsBackingOff(); |
216 } | 217 } |
217 | 218 |
218 void UseMockDelayProvider() { | 219 void UseMockDelayProvider() { |
219 delay_ = new MockDelayProvider(); | 220 delay_ = new MockDelayProvider(); |
220 scheduler_->delay_provider_.reset(delay_); | 221 scheduler_->delay_provider_.reset(delay_); |
221 } | 222 } |
222 | 223 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 292 } |
292 | 293 |
293 ACTION(QuitLoopNowAction) { | 294 ACTION(QuitLoopNowAction) { |
294 QuitLoopNow(); | 295 QuitLoopNow(); |
295 return true; | 296 return true; |
296 } | 297 } |
297 | 298 |
298 // Test nudge scheduling. | 299 // Test nudge scheduling. |
299 TEST_F(SyncSchedulerTest, Nudge) { | 300 TEST_F(SyncSchedulerTest, Nudge) { |
300 SyncShareTimes times; | 301 SyncShareTimes times; |
301 ModelTypeSet model_types(BOOKMARKS); | 302 ModelTypeSet model_types(THEMES); |
302 | 303 |
303 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 304 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
304 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 305 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
305 RecordSyncShare(×))) | 306 RecordSyncShare(×))) |
306 .RetiresOnSaturation(); | 307 .RetiresOnSaturation(); |
307 | 308 |
308 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 309 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
309 | 310 |
310 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 311 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
311 RunLoop(); | 312 RunLoop(); |
312 | 313 |
313 Mock::VerifyAndClearExpectations(syncer()); | 314 Mock::VerifyAndClearExpectations(syncer()); |
314 | 315 |
315 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 316 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
316 SyncShareTimes times2; | 317 SyncShareTimes times2; |
317 model_types.Remove(BOOKMARKS); | 318 model_types.Remove(THEMES); |
318 model_types.Put(AUTOFILL); | 319 model_types.Put(TYPED_URLS); |
319 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 320 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
320 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 321 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
321 RecordSyncShare(×2))); | 322 RecordSyncShare(×2))); |
322 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 323 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
323 RunLoop(); | 324 RunLoop(); |
324 } | 325 } |
325 | 326 |
326 // Make sure a regular config command is scheduled fine in the absence of any | 327 // Make sure a regular config command is scheduled fine in the absence of any |
327 // errors. | 328 // errors. |
328 TEST_F(SyncSchedulerTest, Config) { | 329 TEST_F(SyncSchedulerTest, Config) { |
329 SyncShareTimes times; | 330 SyncShareTimes times; |
330 const ModelTypeSet model_types(BOOKMARKS); | 331 const ModelTypeSet model_types(THEMES); |
331 | 332 |
332 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 333 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
333 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 334 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
334 RecordSyncShare(×))); | 335 RecordSyncShare(×))); |
335 | 336 |
336 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 337 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
337 | 338 |
338 CallbackCounter ready_counter; | 339 CallbackCounter ready_counter; |
339 CallbackCounter retry_counter; | 340 CallbackCounter retry_counter; |
340 ConfigurationParams params( | 341 ConfigurationParams params( |
341 GetUpdatesCallerInfo::RECONFIGURATION, | 342 GetUpdatesCallerInfo::RECONFIGURATION, |
342 model_types, | 343 model_types, |
343 TypesToRoutingInfo(model_types), | 344 TypesToRoutingInfo(model_types), |
344 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 345 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
345 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 346 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
346 scheduler()->ScheduleConfiguration(params); | 347 scheduler()->ScheduleConfiguration(params); |
347 PumpLoop(); | 348 PumpLoop(); |
348 ASSERT_EQ(1, ready_counter.times_called()); | 349 ASSERT_EQ(1, ready_counter.times_called()); |
349 ASSERT_EQ(0, retry_counter.times_called()); | 350 ASSERT_EQ(0, retry_counter.times_called()); |
350 } | 351 } |
351 | 352 |
352 // Simulate a failure and make sure the config request is retried. | 353 // Simulate a failure and make sure the config request is retried. |
353 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 354 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
354 UseMockDelayProvider(); | 355 UseMockDelayProvider(); |
355 EXPECT_CALL(*delay(), GetDelay(_)) | 356 EXPECT_CALL(*delay(), GetDelay(_)) |
356 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 357 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
357 SyncShareTimes times; | 358 SyncShareTimes times; |
358 const ModelTypeSet model_types(BOOKMARKS); | 359 const ModelTypeSet model_types(THEMES); |
359 | 360 |
360 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 361 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
361 | 362 |
362 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 363 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
363 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 364 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
364 RecordSyncShare(×))) | 365 RecordSyncShare(×))) |
365 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 366 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
366 RecordSyncShare(×))); | 367 RecordSyncShare(×))); |
367 | 368 |
368 CallbackCounter ready_counter; | 369 CallbackCounter ready_counter; |
(...skipping 25 matching lines...) Expand all Loading... |
394 ASSERT_EQ(1, ready_counter.times_called()); | 395 ASSERT_EQ(1, ready_counter.times_called()); |
395 } | 396 } |
396 | 397 |
397 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. | 398 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. |
398 // This can happen if server returns NOT_MY_BIRTHDAY. | 399 // This can happen if server returns NOT_MY_BIRTHDAY. |
399 TEST_F(SyncSchedulerTest, ConfigWithStop) { | 400 TEST_F(SyncSchedulerTest, ConfigWithStop) { |
400 UseMockDelayProvider(); | 401 UseMockDelayProvider(); |
401 EXPECT_CALL(*delay(), GetDelay(_)) | 402 EXPECT_CALL(*delay(), GetDelay(_)) |
402 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 403 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
403 SyncShareTimes times; | 404 SyncShareTimes times; |
404 const ModelTypeSet model_types(BOOKMARKS); | 405 const ModelTypeSet model_types(THEMES); |
405 | 406 |
406 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 407 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
407 | 408 |
408 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call | 409 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call |
409 // retry_task or dereference configuration params. | 410 // retry_task or dereference configuration params. |
410 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 411 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
411 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 412 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
412 StopScheduler(scheduler()), | 413 StopScheduler(scheduler()), |
413 RecordSyncShare(×))); | 414 RecordSyncShare(×))); |
414 | 415 |
415 CallbackCounter ready_counter; | 416 CallbackCounter ready_counter; |
416 CallbackCounter retry_counter; | 417 CallbackCounter retry_counter; |
417 ConfigurationParams params( | 418 ConfigurationParams params( |
418 GetUpdatesCallerInfo::RECONFIGURATION, | 419 GetUpdatesCallerInfo::RECONFIGURATION, |
419 model_types, | 420 model_types, |
420 TypesToRoutingInfo(model_types), | 421 TypesToRoutingInfo(model_types), |
421 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 422 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
422 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 423 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
423 scheduler()->ScheduleConfiguration(params); | 424 scheduler()->ScheduleConfiguration(params); |
424 PumpLoop(); | 425 PumpLoop(); |
425 ASSERT_EQ(0, ready_counter.times_called()); | 426 ASSERT_EQ(0, ready_counter.times_called()); |
426 ASSERT_EQ(0, retry_counter.times_called()); | 427 ASSERT_EQ(0, retry_counter.times_called()); |
427 } | 428 } |
428 | 429 |
429 // Issue a nudge when the config has failed. Make sure both the config and | 430 // Issue a nudge when the config has failed. Make sure both the config and |
430 // nudge are executed. | 431 // nudge are executed. |
431 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 432 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
432 const ModelTypeSet model_types(BOOKMARKS); | 433 const ModelTypeSet model_types(THEMES); |
433 UseMockDelayProvider(); | 434 UseMockDelayProvider(); |
434 EXPECT_CALL(*delay(), GetDelay(_)) | 435 EXPECT_CALL(*delay(), GetDelay(_)) |
435 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 436 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
436 SyncShareTimes times; | 437 SyncShareTimes times; |
437 | 438 |
438 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 439 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
439 | 440 |
440 // Request a configure and make sure it fails. | 441 // Request a configure and make sure it fails. |
441 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 442 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
442 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 443 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
443 RecordSyncShare(×))); | 444 RecordSyncShare(×))); |
444 CallbackCounter ready_counter; | 445 CallbackCounter ready_counter; |
445 CallbackCounter retry_counter; | 446 CallbackCounter retry_counter; |
446 ConfigurationParams params( | 447 ConfigurationParams params( |
447 GetUpdatesCallerInfo::RECONFIGURATION, | 448 GetUpdatesCallerInfo::RECONFIGURATION, |
448 model_types, | 449 model_types, |
449 TypesToRoutingInfo(model_types), | 450 TypesToRoutingInfo(model_types), |
450 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 451 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
451 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 452 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
452 scheduler()->ScheduleConfiguration(params); | 453 scheduler()->ScheduleConfiguration(params); |
453 RunLoop(); | 454 RunLoop(); |
454 ASSERT_EQ(0, ready_counter.times_called()); | 455 ASSERT_EQ(0, ready_counter.times_called()); |
455 ASSERT_EQ(1, retry_counter.times_called()); | 456 ASSERT_EQ(1, retry_counter.times_called()); |
456 Mock::VerifyAndClearExpectations(syncer()); | 457 Mock::VerifyAndClearExpectations(syncer()); |
457 | 458 |
458 // Ask for a nudge while dealing with repeated configure failure. | 459 // Ask for a nudge while dealing with repeated configure failure. |
459 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 460 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
460 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 461 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
461 RecordSyncShare(×))); | 462 RecordSyncShare(×))); |
462 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 463 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
463 RunLoop(); | 464 RunLoop(); |
464 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but | 465 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but |
465 // for the first retry attempt from the config job (after | 466 // for the first retry attempt from the config job (after |
466 // waiting ~+/- 50ms). | 467 // waiting ~+/- 50ms). |
467 Mock::VerifyAndClearExpectations(syncer()); | 468 Mock::VerifyAndClearExpectations(syncer()); |
468 ASSERT_EQ(0, ready_counter.times_called()); | 469 ASSERT_EQ(0, ready_counter.times_called()); |
469 | 470 |
470 // Let the next configure retry succeed. | 471 // Let the next configure retry succeed. |
471 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 472 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
472 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 473 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
473 RecordSyncShare(×))); | 474 RecordSyncShare(×))); |
474 RunLoop(); | 475 RunLoop(); |
475 | 476 |
476 // Now change the mode so nudge can execute. | 477 // Now change the mode so nudge can execute. |
477 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 478 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
478 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 479 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
479 RecordSyncShare(×))); | 480 RecordSyncShare(×))); |
480 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 481 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
481 PumpLoop(); | 482 PumpLoop(); |
482 } | 483 } |
483 | 484 |
484 // Test that nudges are coalesced. | 485 // Test that nudges are coalesced. |
485 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 486 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
486 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 487 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
487 | 488 |
488 SyncShareTimes times; | 489 SyncShareTimes times; |
489 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 490 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
490 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 491 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
491 RecordSyncShare(×))); | 492 RecordSyncShare(×))); |
492 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 493 const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); |
493 TimeDelta delay = zero(); | 494 TimeTicks optimal_time = TimeTicks::Now() + default_delay(); |
494 TimeTicks optimal_time = TimeTicks::Now() + delay; | 495 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
495 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 496 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); |
496 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | |
497 RunLoop(); | 497 RunLoop(); |
498 | 498 |
499 ASSERT_EQ(1U, times.size()); | 499 ASSERT_EQ(1U, times.size()); |
500 EXPECT_GE(times[0], optimal_time); | 500 EXPECT_GE(times[0], optimal_time); |
501 | 501 |
502 Mock::VerifyAndClearExpectations(syncer()); | 502 Mock::VerifyAndClearExpectations(syncer()); |
503 | 503 |
504 SyncShareTimes times2; | 504 SyncShareTimes times2; |
505 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 505 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
506 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 506 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
507 RecordSyncShare(×2))); | 507 RecordSyncShare(×2))); |
508 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); | 508 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); |
509 RunLoop(); | 509 RunLoop(); |
510 } | 510 } |
511 | 511 |
512 // Test that nudges are coalesced. | 512 // Test that nudges are coalesced. |
513 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 513 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
514 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 514 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
515 | 515 |
516 SyncShareTimes times; | 516 SyncShareTimes times; |
517 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 517 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
518 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 518 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
519 RecordSyncShare(×))); | 519 RecordSyncShare(×))); |
520 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; | 520 ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; |
521 | 521 |
522 // Create a huge time delay. | 522 // Create a huge time delay. |
523 TimeDelta delay = TimeDelta::FromDays(1); | 523 TimeDelta delay = TimeDelta::FromDays(1); |
524 | 524 |
525 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 525 std::map<ModelType, TimeDelta> delay_map; |
526 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | 526 delay_map[types1.First().Get()] = delay; |
| 527 scheduler()->OnReceivedCustomNudgeDelays(delay_map); |
| 528 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
| 529 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); |
527 | 530 |
528 TimeTicks min_time = TimeTicks::Now(); | 531 TimeTicks min_time = TimeTicks::Now(); |
529 TimeTicks max_time = TimeTicks::Now() + delay; | 532 TimeTicks max_time = TimeTicks::Now() + delay; |
530 | 533 |
531 RunLoop(); | 534 RunLoop(); |
532 Mock::VerifyAndClearExpectations(syncer()); | 535 Mock::VerifyAndClearExpectations(syncer()); |
533 | 536 |
534 // Make sure the sync happened at the right time. | 537 // Make sure the sync happened at the right time. |
535 ASSERT_EQ(1U, times.size()); | 538 ASSERT_EQ(1U, times.size()); |
536 EXPECT_GE(times[0], min_time); | 539 EXPECT_GE(times[0], min_time); |
537 EXPECT_LE(times[0], max_time); | 540 EXPECT_LE(times[0], max_time); |
538 } | 541 } |
539 | 542 |
540 // Test nudge scheduling. | 543 // Test nudge scheduling. |
541 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 544 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
542 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 545 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
543 | 546 |
544 SyncShareTimes times1; | 547 SyncShareTimes times1; |
545 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 548 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
546 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 549 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
547 RecordSyncShare(×1))) | 550 RecordSyncShare(×1))) |
548 .RetiresOnSaturation(); | 551 .RetiresOnSaturation(); |
549 scheduler()->ScheduleInvalidationNudge( | 552 scheduler()->ScheduleInvalidationNudge( |
550 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); | 553 THEMES, BuildInvalidation(10, "test"), FROM_HERE); |
551 RunLoop(); | 554 RunLoop(); |
552 | 555 |
553 Mock::VerifyAndClearExpectations(syncer()); | 556 Mock::VerifyAndClearExpectations(syncer()); |
554 | 557 |
555 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 558 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
556 SyncShareTimes times2; | 559 SyncShareTimes times2; |
557 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 560 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 561 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
559 RecordSyncShare(×2))); | 562 RecordSyncShare(×2))); |
560 scheduler()->ScheduleInvalidationNudge( | 563 scheduler()->ScheduleInvalidationNudge( |
561 zero(), AUTOFILL, BuildInvalidation(10, "test2"), FROM_HERE); | 564 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); |
562 RunLoop(); | 565 RunLoop(); |
563 } | 566 } |
564 | 567 |
565 // Test that polling works as expected. | 568 // Test that polling works as expected. |
566 TEST_F(SyncSchedulerTest, Polling) { | 569 TEST_F(SyncSchedulerTest, Polling) { |
567 SyncShareTimes times; | 570 SyncShareTimes times; |
568 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 571 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
569 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 572 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
570 .WillRepeatedly( | 573 .WillRepeatedly( |
571 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 574 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 627 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
625 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 628 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
626 | 629 |
627 // Run again to wait for polling. | 630 // Run again to wait for polling. |
628 RunLoop(); | 631 RunLoop(); |
629 | 632 |
630 StopSyncScheduler(); | 633 StopSyncScheduler(); |
631 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); | 634 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); |
632 } | 635 } |
633 | 636 |
634 // Test that the sessions commit delay is updated when needed. | |
635 TEST_F(SyncSchedulerTest, SessionsCommitDelay) { | |
636 SyncShareTimes times; | |
637 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); | |
638 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); | |
639 scheduler()->OnReceivedSessionsCommitDelay(delay1); | |
640 | |
641 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | |
642 .WillOnce( | |
643 DoAll( | |
644 WithArgs<0,1,2>( | |
645 sessions::test_util::SimulateSessionsCommitDelayUpdate( | |
646 delay2)), | |
647 Invoke(sessions::test_util::SimulateNormalSuccess), | |
648 QuitLoopNowAction())); | |
649 | |
650 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); | |
651 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
652 | |
653 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); | |
654 const ModelTypeSet model_types(BOOKMARKS); | |
655 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | |
656 RunLoop(); | |
657 | |
658 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); | |
659 StopSyncScheduler(); | |
660 } | |
661 | |
662 // Test that no syncing occurs when throttled. | 637 // Test that no syncing occurs when throttled. |
663 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 638 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
664 const ModelTypeSet types(BOOKMARKS); | 639 const ModelTypeSet types(THEMES); |
665 TimeDelta poll(TimeDelta::FromMilliseconds(20)); | 640 TimeDelta poll(TimeDelta::FromMilliseconds(20)); |
666 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 641 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
667 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 642 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
668 | 643 |
669 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 644 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
670 .WillOnce(DoAll( | 645 .WillOnce(DoAll( |
671 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), | 646 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), |
672 Return(true))) | 647 Return(true))) |
673 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 648 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
674 | 649 |
675 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 650 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
676 | 651 |
677 scheduler()->ScheduleLocalNudge( | 652 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
678 TimeDelta::FromMicroseconds(1), types, FROM_HERE); | |
679 PumpLoop(); | 653 PumpLoop(); |
680 | 654 |
681 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 655 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
682 | 656 |
683 CallbackCounter ready_counter; | 657 CallbackCounter ready_counter; |
684 CallbackCounter retry_counter; | 658 CallbackCounter retry_counter; |
685 ConfigurationParams params( | 659 ConfigurationParams params( |
686 GetUpdatesCallerInfo::RECONFIGURATION, | 660 GetUpdatesCallerInfo::RECONFIGURATION, |
687 types, | 661 types, |
688 TypesToRoutingInfo(types), | 662 TypesToRoutingInfo(types), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 ::testing::InSequence seq; | 705 ::testing::InSequence seq; |
732 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 706 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
733 .WillOnce(DoAll( | 707 .WillOnce(DoAll( |
734 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 708 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), |
735 Return(true))) | 709 Return(true))) |
736 .RetiresOnSaturation(); | 710 .RetiresOnSaturation(); |
737 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 711 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
738 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 712 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
739 QuitLoopNowAction())); | 713 QuitLoopNowAction())); |
740 | 714 |
741 const ModelTypeSet types(BOOKMARKS); | 715 const ModelTypeSet types(THEMES); |
742 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 716 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
743 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 717 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
744 | 718 |
745 PumpLoop(); // To get PerformDelayedNudge called. | 719 PumpLoop(); // To get PerformDelayedNudge called. |
746 PumpLoop(); // To get TrySyncSessionJob called | 720 PumpLoop(); // To get TrySyncSessionJob called |
747 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 721 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
748 RunLoop(); | 722 RunLoop(); |
749 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 723 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
750 | 724 |
751 StopSyncScheduler(); | 725 StopSyncScheduler(); |
752 } | 726 } |
753 | 727 |
754 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { | 728 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { |
755 SyncShareTimes times; | 729 SyncShareTimes times; |
756 TimeDelta poll(TimeDelta::FromDays(1)); | 730 TimeDelta poll(TimeDelta::FromDays(1)); |
757 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 731 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
758 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 732 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
759 | 733 |
760 ::testing::InSequence seq; | 734 ::testing::InSequence seq; |
761 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 735 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
762 .WillOnce(DoAll( | 736 .WillOnce(DoAll( |
763 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 737 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), |
764 Return(true))) | 738 Return(true))) |
765 .RetiresOnSaturation(); | 739 .RetiresOnSaturation(); |
766 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 740 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
767 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 741 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
768 QuitLoopNowAction())); | 742 QuitLoopNowAction())); |
769 | 743 |
770 const ModelTypeSet types(BOOKMARKS); | 744 const ModelTypeSet types(THEMES); |
771 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 745 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
772 | 746 |
773 CallbackCounter ready_counter; | 747 CallbackCounter ready_counter; |
774 CallbackCounter retry_counter; | 748 CallbackCounter retry_counter; |
775 ConfigurationParams params( | 749 ConfigurationParams params( |
776 GetUpdatesCallerInfo::RECONFIGURATION, | 750 GetUpdatesCallerInfo::RECONFIGURATION, |
777 types, | 751 types, |
778 TypesToRoutingInfo(types), | 752 TypesToRoutingInfo(types), |
779 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 753 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
780 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 754 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
781 scheduler()->ScheduleConfiguration(params); | 755 scheduler()->ScheduleConfiguration(params); |
782 PumpLoop(); | 756 PumpLoop(); |
783 EXPECT_EQ(0, ready_counter.times_called()); | 757 EXPECT_EQ(0, ready_counter.times_called()); |
784 EXPECT_EQ(1, retry_counter.times_called()); | 758 EXPECT_EQ(1, retry_counter.times_called()); |
785 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 759 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
786 | 760 |
787 RunLoop(); | 761 RunLoop(); |
788 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 762 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
789 | 763 |
790 StopSyncScheduler(); | 764 StopSyncScheduler(); |
791 } | 765 } |
792 | 766 |
793 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { | 767 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { |
794 UseMockDelayProvider(); | 768 UseMockDelayProvider(); |
795 EXPECT_CALL(*delay(), GetDelay(_)) | 769 EXPECT_CALL(*delay(), GetDelay(_)) |
796 .WillRepeatedly(Return(zero())); | 770 .WillRepeatedly(Return(default_delay())); |
797 | 771 |
798 TimeDelta poll(TimeDelta::FromDays(1)); | 772 TimeDelta poll(TimeDelta::FromDays(1)); |
799 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 773 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
800 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 774 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
801 | 775 |
802 const ModelTypeSet types(BOOKMARKS); | 776 const ModelTypeSet types(THEMES); |
803 | 777 |
804 ::testing::InSequence seq; | 778 ::testing::InSequence seq; |
805 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 779 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
806 .WillOnce(DoAll( | 780 .WillOnce(DoAll( |
807 WithArg<2>( | 781 WithArg<2>( |
808 sessions::test_util::SimulateTypesThrottled(types, throttle1)), | 782 sessions::test_util::SimulateTypesThrottled(types, throttle1)), |
809 Return(true))) | 783 Return(true))) |
810 .RetiresOnSaturation(); | 784 .RetiresOnSaturation(); |
811 | 785 |
812 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 786 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
813 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 787 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
814 PumpLoop(); // To get PerformDelayedNudge called. | 788 PumpLoop(); // To get PerformDelayedNudge called. |
815 PumpLoop(); // To get TrySyncSessionJob called | 789 PumpLoop(); // To get TrySyncSessionJob called |
816 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 790 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
817 | 791 |
818 // This won't cause a sync cycle because the types are throttled. | 792 // This won't cause a sync cycle because the types are throttled. |
819 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 793 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
820 PumpLoop(); | 794 PumpLoop(); |
821 | 795 |
822 StopSyncScheduler(); | 796 StopSyncScheduler(); |
823 } | 797 } |
824 | 798 |
825 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 799 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { |
826 UseMockDelayProvider(); | 800 UseMockDelayProvider(); |
827 EXPECT_CALL(*delay(), GetDelay(_)) | 801 EXPECT_CALL(*delay(), GetDelay(_)) |
828 .WillRepeatedly(Return(zero())); | 802 .WillRepeatedly(Return(default_delay())); |
829 | 803 |
830 SyncShareTimes times; | 804 SyncShareTimes times; |
831 TimeDelta poll(TimeDelta::FromDays(1)); | 805 TimeDelta poll(TimeDelta::FromDays(1)); |
832 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 806 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
833 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 807 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
834 | 808 |
835 const ModelTypeSet throttled_types(BOOKMARKS); | 809 const ModelTypeSet throttled_types(THEMES); |
836 const ModelTypeSet unthrottled_types(PREFERENCES); | 810 const ModelTypeSet unthrottled_types(PREFERENCES); |
837 | 811 |
838 ::testing::InSequence seq; | 812 ::testing::InSequence seq; |
839 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 813 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
840 .WillOnce(DoAll( | 814 .WillOnce(DoAll( |
841 WithArg<2>( | 815 WithArg<2>( |
842 sessions::test_util::SimulateTypesThrottled( | 816 sessions::test_util::SimulateTypesThrottled( |
843 throttled_types, throttle1)), | 817 throttled_types, throttle1)), |
844 Return(true))) | 818 Return(true))) |
845 .RetiresOnSaturation(); | 819 .RetiresOnSaturation(); |
846 | 820 |
847 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 821 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
848 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); | 822 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
849 PumpLoop(); // To get PerformDelayedNudge called. | 823 PumpLoop(); // To get PerformDelayedNudge called. |
850 PumpLoop(); // To get TrySyncSessionJob called | 824 PumpLoop(); // To get TrySyncSessionJob called |
851 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 825 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
852 | 826 |
853 // Ignore invalidations for throttled types. | 827 // Ignore invalidations for throttled types. |
854 scheduler()->ScheduleInvalidationNudge( | 828 scheduler()->ScheduleInvalidationNudge( |
855 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); | 829 THEMES, BuildInvalidation(10, "test"), FROM_HERE); |
856 PumpLoop(); | 830 PumpLoop(); |
857 | 831 |
858 // Ignore refresh requests for throttled types. | 832 // Ignore refresh requests for throttled types. |
859 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); | 833 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
860 PumpLoop(); | 834 PumpLoop(); |
861 | 835 |
862 Mock::VerifyAndClearExpectations(syncer()); | 836 Mock::VerifyAndClearExpectations(syncer()); |
863 | 837 |
864 // Local nudges for non-throttled types will trigger a sync. | 838 // Local nudges for non-throttled types will trigger a sync. |
865 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 839 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
866 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 840 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
867 RecordSyncShare(×))); | 841 RecordSyncShare(×))); |
868 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE); | 842 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
869 RunLoop(); | 843 RunLoop(); |
870 Mock::VerifyAndClearExpectations(syncer()); | 844 Mock::VerifyAndClearExpectations(syncer()); |
871 | 845 |
872 StopSyncScheduler(); | 846 StopSyncScheduler(); |
873 } | 847 } |
874 | 848 |
875 // Test nudges / polls don't run in config mode and config tasks do. | 849 // Test nudges / polls don't run in config mode and config tasks do. |
876 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 850 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
877 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 851 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
878 SyncShareTimes times; | 852 SyncShareTimes times; |
879 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 853 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
880 | 854 |
881 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 855 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
882 | 856 |
883 const ModelTypeSet nudge_types(AUTOFILL); | 857 const ModelTypeSet nudge_types(TYPED_URLS); |
884 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 858 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
885 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 859 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
886 | 860 |
887 const ModelTypeSet config_types(BOOKMARKS); | 861 const ModelTypeSet config_types(THEMES); |
888 | 862 |
889 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 863 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
890 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 864 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
891 RecordSyncShare(×))) | 865 RecordSyncShare(×))) |
892 .RetiresOnSaturation(); | 866 .RetiresOnSaturation(); |
893 CallbackCounter ready_counter; | 867 CallbackCounter ready_counter; |
894 CallbackCounter retry_counter; | 868 CallbackCounter retry_counter; |
895 ConfigurationParams params( | 869 ConfigurationParams params( |
896 GetUpdatesCallerInfo::RECONFIGURATION, | 870 GetUpdatesCallerInfo::RECONFIGURATION, |
897 config_types, | 871 config_types, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 960 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { |
987 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 961 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
988 .WillOnce(DoAll( | 962 .WillOnce(DoAll( |
989 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 963 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
990 Return(true))) | 964 Return(true))) |
991 .WillRepeatedly(DoAll( | 965 .WillRepeatedly(DoAll( |
992 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 966 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
993 QuitLoopNowAction())); | 967 QuitLoopNowAction())); |
994 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 968 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
995 | 969 |
996 ModelTypeSet types(BOOKMARKS); | 970 ModelTypeSet types(THEMES); |
997 CallbackCounter ready_counter; | 971 CallbackCounter ready_counter; |
998 CallbackCounter retry_counter; | 972 CallbackCounter retry_counter; |
999 ConfigurationParams params( | 973 ConfigurationParams params( |
1000 GetUpdatesCallerInfo::RECONFIGURATION, | 974 GetUpdatesCallerInfo::RECONFIGURATION, |
1001 types, | 975 types, |
1002 TypesToRoutingInfo(types), | 976 TypesToRoutingInfo(types), |
1003 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 977 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
1004 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 978 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
1005 scheduler()->ScheduleConfiguration(params); | 979 scheduler()->ScheduleConfiguration(params); |
1006 RunLoop(); | 980 RunLoop(); |
1007 | 981 |
1008 EXPECT_TRUE(scheduler()->IsBackingOff()); | 982 EXPECT_TRUE(scheduler()->IsBackingOff()); |
1009 } | 983 } |
1010 | 984 |
1011 // Test that no polls or extraneous nudges occur when in backoff. | 985 // Test that no polls or extraneous nudges occur when in backoff. |
1012 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 986 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
1013 SyncShareTimes times; | 987 SyncShareTimes times; |
1014 TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 988 TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1015 const ModelTypeSet types(BOOKMARKS); | 989 const ModelTypeSet types(THEMES); |
1016 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 990 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1017 UseMockDelayProvider(); | 991 UseMockDelayProvider(); |
1018 | 992 |
1019 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 993 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1020 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 994 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1021 RecordSyncShareMultiple(×, 1U))); | 995 RecordSyncShareMultiple(×, 1U))); |
1022 EXPECT_CALL(*delay(), GetDelay(_)). | 996 EXPECT_CALL(*delay(), GetDelay(_)). |
1023 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 997 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
1024 | 998 |
1025 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 999 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1026 | 1000 |
1027 // This nudge should fail and put us into backoff. Thanks to our mock | 1001 // This nudge should fail and put us into backoff. Thanks to our mock |
1028 // GetDelay() setup above, this will be a long backoff. | 1002 // GetDelay() setup above, this will be a long backoff. |
1029 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 1003 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
1030 RunLoop(); | 1004 RunLoop(); |
1031 | 1005 |
1032 // From this point forward, no SyncShare functions should be invoked. | 1006 // From this point forward, no SyncShare functions should be invoked. |
1033 Mock::VerifyAndClearExpectations(syncer()); | 1007 Mock::VerifyAndClearExpectations(syncer()); |
1034 | 1008 |
1035 // Wait a while (10x poll interval) so a few poll jobs will be attempted. | 1009 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
1036 PumpLoopFor(poll * 10); | 1010 PumpLoopFor(poll * 10); |
1037 | 1011 |
1038 // Try (and fail) to schedule a nudge. | 1012 // Try (and fail) to schedule a nudge. |
1039 scheduler()->ScheduleLocalNudge( | 1013 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
1040 base::TimeDelta::FromMilliseconds(10), | |
1041 types, | |
1042 FROM_HERE); | |
1043 | 1014 |
1044 Mock::VerifyAndClearExpectations(syncer()); | 1015 Mock::VerifyAndClearExpectations(syncer()); |
1045 Mock::VerifyAndClearExpectations(delay()); | 1016 Mock::VerifyAndClearExpectations(delay()); |
1046 | 1017 |
1047 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1018 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
1048 | 1019 |
1049 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1020 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1050 | 1021 |
1051 CallbackCounter ready_counter; | 1022 CallbackCounter ready_counter; |
1052 CallbackCounter retry_counter; | 1023 CallbackCounter retry_counter; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 .RetiresOnSaturation(); | 1056 .RetiresOnSaturation(); |
1086 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) | 1057 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) |
1087 .RetiresOnSaturation(); | 1058 .RetiresOnSaturation(); |
1088 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) | 1059 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) |
1089 .RetiresOnSaturation(); | 1060 .RetiresOnSaturation(); |
1090 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); | 1061 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); |
1091 | 1062 |
1092 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1063 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1093 | 1064 |
1094 // Run again with a nudge. | 1065 // Run again with a nudge. |
1095 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1066 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1096 RunLoop(); | 1067 RunLoop(); |
1097 | 1068 |
1098 ASSERT_EQ(kMinNumSamples, times.size()); | 1069 ASSERT_EQ(kMinNumSamples, times.size()); |
1099 EXPECT_GE(times[1] - times[0], second); | 1070 EXPECT_GE(times[1] - times[0], second); |
1100 EXPECT_GE(times[2] - times[1], third); | 1071 EXPECT_GE(times[2] - times[1], third); |
1101 EXPECT_GE(times[3] - times[2], fourth); | 1072 EXPECT_GE(times[3] - times[2], fourth); |
1102 EXPECT_GE(times[4] - times[3], fifth); | 1073 EXPECT_GE(times[4] - times[3], fifth); |
1103 } | 1074 } |
1104 | 1075 |
1105 // Test that things go back to normal once a retry makes forward progress. | 1076 // Test that things go back to normal once a retry makes forward progress. |
1106 TEST_F(SyncSchedulerTest, BackoffRelief) { | 1077 TEST_F(SyncSchedulerTest, BackoffRelief) { |
1107 SyncShareTimes times; | 1078 SyncShareTimes times; |
1108 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1079 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1109 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1080 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1110 UseMockDelayProvider(); | 1081 UseMockDelayProvider(); |
1111 | 1082 |
1112 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); | 1083 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); |
1113 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 1084 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
1114 | 1085 |
1115 // Optimal start for the post-backoff poll party. | 1086 // Optimal start for the post-backoff poll party. |
1116 TimeTicks optimal_start = TimeTicks::Now(); | 1087 TimeTicks optimal_start = TimeTicks::Now(); |
1117 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1088 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1118 | 1089 |
1119 // Kick off the test with a failed nudge. | 1090 // Kick off the test with a failed nudge. |
1120 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1091 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1121 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1092 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1122 RecordSyncShare(×))); | 1093 RecordSyncShare(×))); |
1123 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1094 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1124 RunLoop(); | 1095 RunLoop(); |
1125 Mock::VerifyAndClearExpectations(syncer()); | 1096 Mock::VerifyAndClearExpectations(syncer()); |
1126 TimeTicks optimal_job_time = optimal_start; | 1097 TimeTicks optimal_job_time = optimal_start; |
1127 ASSERT_EQ(1U, times.size()); | 1098 ASSERT_EQ(1U, times.size()); |
1128 EXPECT_GE(times[0], optimal_job_time); | 1099 EXPECT_GE(times[0], optimal_job_time); |
1129 | 1100 |
1130 // The retry succeeds. | 1101 // The retry succeeds. |
1131 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1102 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1132 .WillOnce(DoAll( | 1103 .WillOnce(DoAll( |
1133 Invoke(sessions::test_util::SimulateNormalSuccess), | 1104 Invoke(sessions::test_util::SimulateNormalSuccess), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1156 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
1186 connection()->SetServerNotReachable(); | 1157 connection()->SetServerNotReachable(); |
1187 connection()->UpdateConnectionStatus(); | 1158 connection()->UpdateConnectionStatus(); |
1188 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1159 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1189 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1160 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1190 Return(true))) | 1161 Return(true))) |
1191 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1162 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1192 Return(true))); | 1163 Return(true))); |
1193 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1164 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1194 | 1165 |
1195 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1166 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1196 // Should save the nudge for until after the server is reachable. | 1167 // Should save the nudge for until after the server is reachable. |
1197 base::MessageLoop::current()->RunUntilIdle(); | 1168 base::MessageLoop::current()->RunUntilIdle(); |
1198 | 1169 |
1199 scheduler()->OnConnectionStatusChange(); | 1170 scheduler()->OnConnectionStatusChange(); |
1200 connection()->SetServerReachable(); | 1171 connection()->SetServerReachable(); |
1201 connection()->UpdateConnectionStatus(); | 1172 connection()->UpdateConnectionStatus(); |
1202 base::MessageLoop::current()->RunUntilIdle(); | 1173 base::MessageLoop::current()->RunUntilIdle(); |
1203 } | 1174 } |
1204 | 1175 |
1205 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { | 1176 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { |
1206 UseMockDelayProvider(); | 1177 UseMockDelayProvider(); |
1207 EXPECT_CALL(*delay(), GetDelay(_)) | 1178 EXPECT_CALL(*delay(), GetDelay(_)) |
1208 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1179 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
1209 | 1180 |
1210 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1181 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1211 connection()->SetServerNotReachable(); | 1182 connection()->SetServerNotReachable(); |
1212 connection()->UpdateConnectionStatus(); | 1183 connection()->UpdateConnectionStatus(); |
1213 | 1184 |
1214 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1185 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1215 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1186 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1216 Return(true))) | 1187 Return(true))) |
1217 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1188 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1218 Return(true))); | 1189 Return(true))); |
1219 | 1190 |
1220 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1191 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1221 PumpLoop(); // To get PerformDelayedNudge called. | 1192 PumpLoop(); // To get PerformDelayedNudge called. |
1222 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1193 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1223 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1194 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1224 | 1195 |
1225 // Before we run the scheduled canary, trigger a server connection change. | 1196 // Before we run the scheduled canary, trigger a server connection change. |
1226 scheduler()->OnConnectionStatusChange(); | 1197 scheduler()->OnConnectionStatusChange(); |
1227 connection()->SetServerReachable(); | 1198 connection()->SetServerReachable(); |
1228 connection()->UpdateConnectionStatus(); | 1199 connection()->UpdateConnectionStatus(); |
1229 base::MessageLoop::current()->RunUntilIdle(); | 1200 base::MessageLoop::current()->RunUntilIdle(); |
1230 } | 1201 } |
(...skipping 11 matching lines...) Expand all Loading... |
1242 connection()->UpdateConnectionStatus(); | 1213 connection()->UpdateConnectionStatus(); |
1243 | 1214 |
1244 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1215 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1245 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1216 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1246 Return(true))) | 1217 Return(true))) |
1247 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1218 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1248 Return(true))) | 1219 Return(true))) |
1249 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1220 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1250 QuitLoopNowAction())); | 1221 QuitLoopNowAction())); |
1251 | 1222 |
1252 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1223 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1253 | 1224 |
1254 PumpLoop(); // To get PerformDelayedNudge called. | 1225 PumpLoop(); // To get PerformDelayedNudge called. |
1255 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1226 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1256 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1227 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1257 | 1228 |
1258 // Before we run the scheduled canary, trigger a server connection change. | 1229 // Before we run the scheduled canary, trigger a server connection change. |
1259 scheduler()->OnConnectionStatusChange(); | 1230 scheduler()->OnConnectionStatusChange(); |
1260 PumpLoop(); | 1231 PumpLoop(); |
1261 connection()->SetServerReachable(); | 1232 connection()->SetServerReachable(); |
1262 connection()->UpdateConnectionStatus(); | 1233 connection()->UpdateConnectionStatus(); |
1263 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1234 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1264 base::MessageLoop::current()->RunUntilIdle(); | 1235 base::MessageLoop::current()->RunUntilIdle(); |
1265 } | 1236 } |
1266 | 1237 |
1267 // Tests that we don't crash trying to run two canaries at once if we receive | 1238 // Tests that we don't crash trying to run two canaries at once if we receive |
1268 // extra connection status change notifications. See crbug.com/190085. | 1239 // extra connection status change notifications. See crbug.com/190085. |
1269 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1240 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { |
1270 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 1241 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
1271 .WillRepeatedly(DoAll( | 1242 .WillRepeatedly(DoAll( |
1272 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1243 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), |
1273 Return(true))); | 1244 Return(true))); |
1274 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1245 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1275 connection()->SetServerNotReachable(); | 1246 connection()->SetServerNotReachable(); |
1276 connection()->UpdateConnectionStatus(); | 1247 connection()->UpdateConnectionStatus(); |
1277 | 1248 |
1278 ModelTypeSet model_types(BOOKMARKS); | 1249 ModelTypeSet model_types(THEMES); |
1279 CallbackCounter ready_counter; | 1250 CallbackCounter ready_counter; |
1280 CallbackCounter retry_counter; | 1251 CallbackCounter retry_counter; |
1281 ConfigurationParams params( | 1252 ConfigurationParams params( |
1282 GetUpdatesCallerInfo::RECONFIGURATION, | 1253 GetUpdatesCallerInfo::RECONFIGURATION, |
1283 model_types, | 1254 model_types, |
1284 TypesToRoutingInfo(model_types), | 1255 TypesToRoutingInfo(model_types), |
1285 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1256 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
1286 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1257 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
1287 scheduler()->ScheduleConfiguration(params); | 1258 scheduler()->ScheduleConfiguration(params); |
1288 | 1259 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1345 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
1375 } | 1346 } |
1376 | 1347 |
1377 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { | 1348 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { |
1378 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1349 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1379 | 1350 |
1380 SyncShareTimes times; | 1351 SyncShareTimes times; |
1381 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1352 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); |
1382 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1353 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); |
1383 | 1354 |
1384 scheduler()->ScheduleLocalRefreshRequest(zero(), ModelTypeSet(BOOKMARKS), | 1355 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1385 FROM_HERE); | |
1386 scheduler()->OnReceivedGuRetryDelay(delay1); | 1356 scheduler()->OnReceivedGuRetryDelay(delay1); |
1387 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1357 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
1388 | 1358 |
1389 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1359 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1390 .WillOnce(DoAll( | 1360 .WillOnce(DoAll( |
1391 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), | 1361 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), |
1392 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), | 1362 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), |
1393 RecordSyncShare(×))); | 1363 RecordSyncShare(×))); |
1394 | 1364 |
1395 // Run nudge GU. | 1365 // Run nudge GU. |
1396 RunLoop(); | 1366 RunLoop(); |
1397 EXPECT_EQ(delay2, GetRetryTimerDelay()); | 1367 EXPECT_EQ(delay2, GetRetryTimerDelay()); |
1398 | 1368 |
1399 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1369 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1400 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1370 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1401 RecordSyncShare(×))); | 1371 RecordSyncShare(×))); |
1402 | 1372 |
1403 // Run to wait for retrying. | 1373 // Run to wait for retrying. |
1404 RunLoop(); | 1374 RunLoop(); |
1405 | 1375 |
1406 StopSyncScheduler(); | 1376 StopSyncScheduler(); |
1407 } | 1377 } |
1408 | 1378 |
1409 } // namespace syncer | 1379 } // namespace syncer |
OLD | NEW |