| 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/sessions/test_util.h" | 16 #include "sync/sessions/test_util.h" |
| 16 #include "sync/test/callback_counter.h" | 17 #include "sync/test/callback_counter.h" |
| 17 #include "sync/test/engine/fake_model_worker.h" | 18 #include "sync/test/engine/fake_model_worker.h" |
| 18 #include "sync/test/engine/mock_connection_manager.h" | 19 #include "sync/test/engine/mock_connection_manager.h" |
| 19 #include "sync/test/engine/test_directory_setter_upper.h" | 20 #include "sync/test/engine/test_directory_setter_upper.h" |
| 20 #include "sync/test/fake_extensions_activity_monitor.h" | 21 #include "sync/test/fake_extensions_activity_monitor.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using base::TimeDelta; | 25 using base::TimeDelta; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 RunLoop(); | 192 RunLoop(); |
| 192 | 193 |
| 193 return scheduler()->IsBackingOff(); | 194 return scheduler()->IsBackingOff(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void UseMockDelayProvider() { | 197 void UseMockDelayProvider() { |
| 197 delay_ = new MockDelayProvider(); | 198 delay_ = new MockDelayProvider(); |
| 198 scheduler_->delay_provider_.reset(delay_); | 199 scheduler_->delay_provider_.reset(delay_); |
| 199 } | 200 } |
| 200 | 201 |
| 201 // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring | 202 // Compare a ModelTypeSet to a ModelTypeStateMap, ignoring |
| 202 // payload values. | 203 // state values. |
| 203 bool CompareModelTypeSetToModelTypePayloadMap( | 204 bool CompareModelTypeSetToModelTypeStateMap( |
| 204 ModelTypeSet lhs, | 205 ModelTypeSet lhs, |
| 205 const ModelTypePayloadMap& rhs) { | 206 const ModelTypeStateMap& rhs) { |
| 206 size_t count = 0; | 207 size_t count = 0; |
| 207 for (ModelTypePayloadMap::const_iterator i = rhs.begin(); | 208 for (ModelTypeStateMap::const_iterator i = rhs.begin(); |
| 208 i != rhs.end(); ++i, ++count) { | 209 i != rhs.end(); ++i, ++count) { |
| 209 if (!lhs.Has(i->first)) | 210 if (!lhs.Has(i->first)) |
| 210 return false; | 211 return false; |
| 211 } | 212 } |
| 212 if (lhs.Size() != count) | 213 if (lhs.Size() != count) |
| 213 return false; | 214 return false; |
| 214 return true; | 215 return true; |
| 215 } | 216 } |
| 216 | 217 |
| 217 SyncSessionContext* context() { return context_.get(); } | 218 SyncSessionContext* context() { return context_.get(); } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 WithArg<0>(RecordSyncShare(&records)))) | 274 WithArg<0>(RecordSyncShare(&records)))) |
| 274 .RetiresOnSaturation(); | 275 .RetiresOnSaturation(); |
| 275 | 276 |
| 276 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 277 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 277 | 278 |
| 278 scheduler()->ScheduleNudgeAsync( | 279 scheduler()->ScheduleNudgeAsync( |
| 279 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 280 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
| 280 RunLoop(); | 281 RunLoop(); |
| 281 | 282 |
| 282 ASSERT_EQ(1U, records.snapshots.size()); | 283 ASSERT_EQ(1U, records.snapshots.size()); |
| 283 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 284 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 284 records.snapshots[0].source().types)); | 285 records.snapshots[0].source().types)); |
| 285 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 286 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 286 records.snapshots[0].source().updates_source); | 287 records.snapshots[0].source().updates_source); |
| 287 | 288 |
| 288 Mock::VerifyAndClearExpectations(syncer()); | 289 Mock::VerifyAndClearExpectations(syncer()); |
| 289 | 290 |
| 290 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 291 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 291 SyncShareRecords records2; | 292 SyncShareRecords records2; |
| 292 model_types.Remove(BOOKMARKS); | 293 model_types.Remove(BOOKMARKS); |
| 293 model_types.Put(AUTOFILL); | 294 model_types.Put(AUTOFILL); |
| 294 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 295 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 295 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 296 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 296 WithArg<0>(RecordSyncShare(&records2)))); | 297 WithArg<0>(RecordSyncShare(&records2)))); |
| 297 scheduler()->ScheduleNudgeAsync( | 298 scheduler()->ScheduleNudgeAsync( |
| 298 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 299 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
| 299 RunLoop(); | 300 RunLoop(); |
| 300 | 301 |
| 301 ASSERT_EQ(1U, records2.snapshots.size()); | 302 ASSERT_EQ(1U, records2.snapshots.size()); |
| 302 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 303 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 303 records2.snapshots[0].source().types)); | 304 records2.snapshots[0].source().types)); |
| 304 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 305 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 305 records2.snapshots[0].source().updates_source); | 306 records2.snapshots[0].source().updates_source); |
| 306 } | 307 } |
| 307 | 308 |
| 308 // Make sure a regular config command is scheduled fine in the absence of any | 309 // Make sure a regular config command is scheduled fine in the absence of any |
| 309 // errors. | 310 // errors. |
| 310 TEST_F(SyncSchedulerTest, Config) { | 311 TEST_F(SyncSchedulerTest, Config) { |
| 311 SyncShareRecords records; | 312 SyncShareRecords records; |
| 312 const ModelTypeSet model_types(BOOKMARKS); | 313 const ModelTypeSet model_types(BOOKMARKS); |
| 313 | 314 |
| 314 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 315 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 315 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 316 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 316 WithArg<0>(RecordSyncShare(&records)))); | 317 WithArg<0>(RecordSyncShare(&records)))); |
| 317 | 318 |
| 318 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 319 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 319 | 320 |
| 320 CallbackCounter counter; | 321 CallbackCounter counter; |
| 321 ConfigurationParams params( | 322 ConfigurationParams params( |
| 322 GetUpdatesCallerInfo::RECONFIGURATION, | 323 GetUpdatesCallerInfo::RECONFIGURATION, |
| 323 model_types, | 324 model_types, |
| 324 TypesToRoutingInfo(model_types), | 325 TypesToRoutingInfo(model_types), |
| 325 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 326 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 326 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 327 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 327 ASSERT_EQ(1, counter.times_called()); | 328 ASSERT_EQ(1, counter.times_called()); |
| 328 | 329 |
| 329 ASSERT_EQ(1U, records.snapshots.size()); | 330 ASSERT_EQ(1U, records.snapshots.size()); |
| 330 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 331 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 331 records.snapshots[0].source().types)); | 332 records.snapshots[0].source().types)); |
| 332 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 333 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 333 records.snapshots[0].source().updates_source); | 334 records.snapshots[0].source().updates_source); |
| 334 } | 335 } |
| 335 | 336 |
| 336 // Simulate a failure and make sure the config request is retried. | 337 // Simulate a failure and make sure the config request is retried. |
| 337 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 338 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 338 UseMockDelayProvider(); | 339 UseMockDelayProvider(); |
| 339 EXPECT_CALL(*delay(), GetDelay(_)) | 340 EXPECT_CALL(*delay(), GetDelay(_)) |
| 340 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 341 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 357 TypesToRoutingInfo(model_types), | 358 TypesToRoutingInfo(model_types), |
| 358 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 359 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 359 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 360 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 360 ASSERT_EQ(0, counter.times_called()); | 361 ASSERT_EQ(0, counter.times_called()); |
| 361 | 362 |
| 362 ASSERT_EQ(1U, records.snapshots.size()); | 363 ASSERT_EQ(1U, records.snapshots.size()); |
| 363 RunLoop(); | 364 RunLoop(); |
| 364 | 365 |
| 365 ASSERT_EQ(2U, records.snapshots.size()); | 366 ASSERT_EQ(2U, records.snapshots.size()); |
| 366 ASSERT_EQ(1, counter.times_called()); | 367 ASSERT_EQ(1, counter.times_called()); |
| 367 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 368 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 368 records.snapshots[1].source().types)); | 369 records.snapshots[1].source().types)); |
| 369 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 370 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 370 records.snapshots[1].source().updates_source); | 371 records.snapshots[1].source().updates_source); |
| 371 } | 372 } |
| 372 | 373 |
| 373 // Issue a nudge when the config has failed. Make sure both the config and | 374 // Issue a nudge when the config has failed. Make sure both the config and |
| 374 // nudge are executed. | 375 // nudge are executed. |
| 375 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 376 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 376 const ModelTypeSet model_types(BOOKMARKS); | 377 const ModelTypeSet model_types(BOOKMARKS); |
| 377 UseMockDelayProvider(); | 378 UseMockDelayProvider(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 411 |
| 411 RunLoop(); | 412 RunLoop(); |
| 412 ASSERT_EQ(3U, records.snapshots.size()); | 413 ASSERT_EQ(3U, records.snapshots.size()); |
| 413 ASSERT_EQ(1, counter.times_called()); | 414 ASSERT_EQ(1, counter.times_called()); |
| 414 | 415 |
| 415 // Now change the mode so nudge can execute. | 416 // Now change the mode so nudge can execute. |
| 416 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 417 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 417 | 418 |
| 418 ASSERT_EQ(4U, records.snapshots.size()); | 419 ASSERT_EQ(4U, records.snapshots.size()); |
| 419 | 420 |
| 420 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 421 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 421 records.snapshots[2].source().types)); | 422 records.snapshots[2].source().types)); |
| 422 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 423 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 423 records.snapshots[2].source().updates_source); | 424 records.snapshots[2].source().updates_source); |
| 424 | 425 |
| 425 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 426 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 426 records.snapshots[3].source().types)); | 427 records.snapshots[3].source().types)); |
| 427 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 428 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 428 records.snapshots[3].source().updates_source); | 429 records.snapshots[3].source().updates_source); |
| 429 | 430 |
| 430 } | 431 } |
| 431 | 432 |
| 432 // Test that nudges are coalesced. | 433 // Test that nudges are coalesced. |
| 433 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 434 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
| 434 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 435 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 435 | 436 |
| 436 SyncShareRecords r; | 437 SyncShareRecords r; |
| 437 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 438 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 438 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 439 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 439 WithArg<0>(RecordSyncShare(&r)))); | 440 WithArg<0>(RecordSyncShare(&r)))); |
| 440 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 441 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); |
| 441 TimeDelta delay = zero(); | 442 TimeDelta delay = zero(); |
| 442 TimeTicks optimal_time = TimeTicks::Now() + delay; | 443 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 443 scheduler()->ScheduleNudgeAsync( | 444 scheduler()->ScheduleNudgeAsync( |
| 444 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 445 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
| 445 scheduler()->ScheduleNudgeAsync( | 446 scheduler()->ScheduleNudgeAsync( |
| 446 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 447 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
| 447 RunLoop(); | 448 RunLoop(); |
| 448 | 449 |
| 449 ASSERT_EQ(1U, r.snapshots.size()); | 450 ASSERT_EQ(1U, r.snapshots.size()); |
| 450 EXPECT_GE(r.times[0], optimal_time); | 451 EXPECT_GE(r.times[0], optimal_time); |
| 451 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( | 452 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( |
| 452 Union(types1, types2), r.snapshots[0].source().types)); | 453 Union(types1, types2), r.snapshots[0].source().types)); |
| 453 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 454 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 454 r.snapshots[0].source().updates_source); | 455 r.snapshots[0].source().updates_source); |
| 455 | 456 |
| 456 Mock::VerifyAndClearExpectations(syncer()); | 457 Mock::VerifyAndClearExpectations(syncer()); |
| 457 | 458 |
| 458 SyncShareRecords r2; | 459 SyncShareRecords r2; |
| 459 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 460 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 460 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 461 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 461 WithArg<0>(RecordSyncShare(&r2)))); | 462 WithArg<0>(RecordSyncShare(&r2)))); |
| 462 scheduler()->ScheduleNudgeAsync( | 463 scheduler()->ScheduleNudgeAsync( |
| 463 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); | 464 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); |
| 464 RunLoop(); | 465 RunLoop(); |
| 465 | 466 |
| 466 ASSERT_EQ(1U, r2.snapshots.size()); | 467 ASSERT_EQ(1U, r2.snapshots.size()); |
| 467 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(types3, | 468 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(types3, |
| 468 r2.snapshots[0].source().types)); | 469 r2.snapshots[0].source().types)); |
| 469 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 470 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 470 r2.snapshots[0].source().updates_source); | 471 r2.snapshots[0].source().updates_source); |
| 471 } | 472 } |
| 472 | 473 |
| 473 // Test that nudges are coalesced. | 474 // Test that nudges are coalesced. |
| 474 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 475 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
| 475 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 476 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 476 | 477 |
| 477 SyncShareRecords r; | 478 SyncShareRecords r; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 489 scheduler()->ScheduleNudgeAsync( | 490 scheduler()->ScheduleNudgeAsync( |
| 490 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); | 491 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); |
| 491 | 492 |
| 492 TimeTicks min_time = TimeTicks::Now(); | 493 TimeTicks min_time = TimeTicks::Now(); |
| 493 TimeTicks max_time = TimeTicks::Now() + delay; | 494 TimeTicks max_time = TimeTicks::Now() + delay; |
| 494 | 495 |
| 495 RunLoop(); | 496 RunLoop(); |
| 496 | 497 |
| 497 // Make sure the sync has happened. | 498 // Make sure the sync has happened. |
| 498 ASSERT_EQ(1U, r.snapshots.size()); | 499 ASSERT_EQ(1U, r.snapshots.size()); |
| 499 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( | 500 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( |
| 500 Union(types1, types2), r.snapshots[0].source().types)); | 501 Union(types1, types2), r.snapshots[0].source().types)); |
| 501 | 502 |
| 502 // Make sure the sync happened at the right time. | 503 // Make sure the sync happened at the right time. |
| 503 EXPECT_GE(r.times[0], min_time); | 504 EXPECT_GE(r.times[0], min_time); |
| 504 EXPECT_LE(r.times[0], max_time); | 505 EXPECT_LE(r.times[0], max_time); |
| 505 } | 506 } |
| 506 | 507 |
| 507 // Test nudge scheduling. | 508 // Test nudge scheduling. |
| 508 TEST_F(SyncSchedulerTest, NudgeWithPayloads) { | 509 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 509 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 510 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 510 | 511 |
| 511 SyncShareRecords records; | 512 SyncShareRecords records; |
| 512 ModelTypePayloadMap model_types_with_payloads; | 513 ModelTypeStateMap type_state_map; |
| 513 model_types_with_payloads[BOOKMARKS] = "test"; | 514 type_state_map[BOOKMARKS].payload = "test"; |
| 514 | 515 |
| 515 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 516 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 516 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 517 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 517 WithArg<0>(RecordSyncShare(&records)))) | 518 WithArg<0>(RecordSyncShare(&records)))) |
| 518 .RetiresOnSaturation(); | 519 .RetiresOnSaturation(); |
| 519 scheduler()->ScheduleNudgeWithPayloadsAsync( | 520 scheduler()->ScheduleNudgeWithStatesAsync( |
| 520 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); | 521 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); |
| 521 RunLoop(); | 522 RunLoop(); |
| 522 | 523 |
| 523 ASSERT_EQ(1U, records.snapshots.size()); | 524 ASSERT_EQ(1U, records.snapshots.size()); |
| 524 EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types); | 525 EXPECT_THAT(type_state_map, Eq(records.snapshots[0].source().types)); |
| 525 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 526 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 526 records.snapshots[0].source().updates_source); | 527 records.snapshots[0].source().updates_source); |
| 527 | 528 |
| 528 Mock::VerifyAndClearExpectations(syncer()); | 529 Mock::VerifyAndClearExpectations(syncer()); |
| 529 | 530 |
| 530 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 531 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 531 SyncShareRecords records2; | 532 SyncShareRecords records2; |
| 532 model_types_with_payloads.erase(BOOKMARKS); | 533 type_state_map.erase(BOOKMARKS); |
| 533 model_types_with_payloads[AUTOFILL] = "test2"; | 534 type_state_map[AUTOFILL].payload = "test2"; |
| 534 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 535 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 535 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 536 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 536 WithArg<0>(RecordSyncShare(&records2)))); | 537 WithArg<0>(RecordSyncShare(&records2)))); |
| 537 scheduler()->ScheduleNudgeWithPayloadsAsync( | 538 scheduler()->ScheduleNudgeWithStatesAsync( |
| 538 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); | 539 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); |
| 539 RunLoop(); | 540 RunLoop(); |
| 540 | 541 |
| 541 ASSERT_EQ(1U, records2.snapshots.size()); | 542 ASSERT_EQ(1U, records2.snapshots.size()); |
| 542 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types); | 543 EXPECT_THAT(type_state_map, Eq(records2.snapshots[0].source().types)); |
| 543 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 544 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 544 records2.snapshots[0].source().updates_source); | 545 records2.snapshots[0].source().updates_source); |
| 545 } | 546 } |
| 546 | 547 |
| 547 // Test that nudges are coalesced. | 548 // Test that nudges are coalesced. |
| 548 TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { | 549 TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) { |
| 549 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 550 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 550 | 551 |
| 551 SyncShareRecords r; | 552 SyncShareRecords r; |
| 552 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 553 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 553 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 554 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 554 WithArg<0>(RecordSyncShare(&r)))); | 555 WithArg<0>(RecordSyncShare(&r)))); |
| 555 ModelTypePayloadMap types1, types2, types3; | 556 ModelTypeStateMap types1, types2, types3; |
| 556 types1[BOOKMARKS] = "test1"; | 557 types1[BOOKMARKS].payload = "test1"; |
| 557 types2[AUTOFILL] = "test2"; | 558 types2[AUTOFILL].payload = "test2"; |
| 558 types3[THEMES] = "test3"; | 559 types3[THEMES].payload = "test3"; |
| 559 TimeDelta delay = zero(); | 560 TimeDelta delay = zero(); |
| 560 TimeTicks optimal_time = TimeTicks::Now() + delay; | 561 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 561 scheduler()->ScheduleNudgeWithPayloadsAsync( | 562 scheduler()->ScheduleNudgeWithStatesAsync( |
| 562 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 563 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
| 563 scheduler()->ScheduleNudgeWithPayloadsAsync( | 564 scheduler()->ScheduleNudgeWithStatesAsync( |
| 564 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 565 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
| 565 RunLoop(); | 566 RunLoop(); |
| 566 | 567 |
| 567 ASSERT_EQ(1U, r.snapshots.size()); | 568 ASSERT_EQ(1U, r.snapshots.size()); |
| 568 EXPECT_GE(r.times[0], optimal_time); | 569 EXPECT_GE(r.times[0], optimal_time); |
| 569 ModelTypePayloadMap coalesced_types; | 570 ModelTypeStateMap coalesced_types; |
| 570 CoalescePayloads(&coalesced_types, types1); | 571 CoalesceStates(&coalesced_types, types1); |
| 571 CoalescePayloads(&coalesced_types, types2); | 572 CoalesceStates(&coalesced_types, types2); |
| 572 EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); | 573 EXPECT_THAT(coalesced_types, Eq(r.snapshots[0].source().types)); |
| 573 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 574 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 574 r.snapshots[0].source().updates_source); | 575 r.snapshots[0].source().updates_source); |
| 575 | 576 |
| 576 Mock::VerifyAndClearExpectations(syncer()); | 577 Mock::VerifyAndClearExpectations(syncer()); |
| 577 | 578 |
| 578 SyncShareRecords r2; | 579 SyncShareRecords r2; |
| 579 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 580 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 580 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 581 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 581 WithArg<0>(RecordSyncShare(&r2)))); | 582 WithArg<0>(RecordSyncShare(&r2)))); |
| 582 scheduler()->ScheduleNudgeWithPayloadsAsync( | 583 scheduler()->ScheduleNudgeWithStatesAsync( |
| 583 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); | 584 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); |
| 584 RunLoop(); | 585 RunLoop(); |
| 585 | 586 |
| 586 ASSERT_EQ(1U, r2.snapshots.size()); | 587 ASSERT_EQ(1U, r2.snapshots.size()); |
| 587 EXPECT_EQ(types3, r2.snapshots[0].source().types); | 588 EXPECT_THAT(types3, Eq(r2.snapshots[0].source().types)); |
| 588 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 589 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 589 r2.snapshots[0].source().updates_source); | 590 r2.snapshots[0].source().updates_source); |
| 590 } | 591 } |
| 591 | 592 |
| 592 // Test that polling works as expected. | 593 // Test that polling works as expected. |
| 593 TEST_F(SyncSchedulerTest, Polling) { | 594 TEST_F(SyncSchedulerTest, Polling) { |
| 594 SyncShareRecords records; | 595 SyncShareRecords records; |
| 595 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 596 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 596 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) | 597 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
| 597 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 598 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 CallbackCounter counter; | 789 CallbackCounter counter; |
| 789 ConfigurationParams params( | 790 ConfigurationParams params( |
| 790 GetUpdatesCallerInfo::RECONFIGURATION, | 791 GetUpdatesCallerInfo::RECONFIGURATION, |
| 791 config_types, | 792 config_types, |
| 792 TypesToRoutingInfo(config_types), | 793 TypesToRoutingInfo(config_types), |
| 793 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 794 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 794 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 795 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 795 ASSERT_EQ(1, counter.times_called()); | 796 ASSERT_EQ(1, counter.times_called()); |
| 796 | 797 |
| 797 ASSERT_EQ(1U, records.snapshots.size()); | 798 ASSERT_EQ(1U, records.snapshots.size()); |
| 798 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, | 799 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(config_types, |
| 799 records.snapshots[0].source().types)); | 800 records.snapshots[0].source().types)); |
| 800 } | 801 } |
| 801 | 802 |
| 802 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 803 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
| 803 void SetUp() { | 804 void SetUp() { |
| 804 SyncSchedulerTest::SetUp(); | 805 SyncSchedulerTest::SetUp(); |
| 805 UseMockDelayProvider(); | 806 UseMockDelayProvider(); |
| 806 EXPECT_CALL(*delay(), GetDelay(_)) | 807 EXPECT_CALL(*delay(), GetDelay(_)) |
| 807 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 808 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 808 } | 809 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 938 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 938 RecordSyncShareMultiple(&r, kMinNumSamples))); | 939 RecordSyncShareMultiple(&r, kMinNumSamples))); |
| 939 | 940 |
| 940 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 941 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 941 const TimeDelta second = TimeDelta::FromMilliseconds(2); | 942 const TimeDelta second = TimeDelta::FromMilliseconds(2); |
| 942 const TimeDelta third = TimeDelta::FromMilliseconds(3); | 943 const TimeDelta third = TimeDelta::FromMilliseconds(3); |
| 943 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); | 944 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); |
| 944 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); | 945 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); |
| 945 const TimeDelta sixth = TimeDelta::FromDays(1); | 946 const TimeDelta sixth = TimeDelta::FromDays(1); |
| 946 | 947 |
| 947 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) | 948 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) |
| 948 .RetiresOnSaturation(); | 949 .RetiresOnSaturation(); |
| 949 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) | 950 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) |
| 950 .RetiresOnSaturation(); | 951 .RetiresOnSaturation(); |
| 951 EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth)) | 952 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) |
| 952 .RetiresOnSaturation(); | 953 .RetiresOnSaturation(); |
| 953 EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth)) | 954 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) |
| 954 .RetiresOnSaturation(); | 955 .RetiresOnSaturation(); |
| 955 EXPECT_CALL(*delay(), GetDelay(Eq(fifth))).WillOnce(Return(sixth)); | 956 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); |
| 956 | 957 |
| 957 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 958 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 958 | 959 |
| 959 // Run again with a nudge. | 960 // Run again with a nudge. |
| 960 scheduler()->ScheduleNudgeAsync( | 961 scheduler()->ScheduleNudgeAsync( |
| 961 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 962 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 962 RunLoop(); | 963 RunLoop(); |
| 963 | 964 |
| 964 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); | 965 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); |
| 965 EXPECT_GE(r.times[1] - r.times[0], second); | 966 EXPECT_GE(r.times[1] - r.times[0], second); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 // Should save the nudge for until after the server is reachable. | 1117 // Should save the nudge for until after the server is reachable. |
| 1117 MessageLoop::current()->RunAllPending(); | 1118 MessageLoop::current()->RunAllPending(); |
| 1118 | 1119 |
| 1119 connection()->SetServerReachable(); | 1120 connection()->SetServerReachable(); |
| 1120 connection()->UpdateConnectionStatus(); | 1121 connection()->UpdateConnectionStatus(); |
| 1121 scheduler()->OnConnectionStatusChange(); | 1122 scheduler()->OnConnectionStatusChange(); |
| 1122 MessageLoop::current()->RunAllPending(); | 1123 MessageLoop::current()->RunAllPending(); |
| 1123 } | 1124 } |
| 1124 | 1125 |
| 1125 } // namespace syncer | 1126 } // namespace syncer |
| OLD | NEW |