| 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" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 RunLoop(); | 182 RunLoop(); |
| 183 | 183 |
| 184 return scheduler()->IsBackingOff(); | 184 return scheduler()->IsBackingOff(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void UseMockDelayProvider() { | 187 void UseMockDelayProvider() { |
| 188 delay_ = new MockDelayProvider(); | 188 delay_ = new MockDelayProvider(); |
| 189 scheduler_->delay_provider_.reset(delay_); | 189 scheduler_->delay_provider_.reset(delay_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring | 192 // Compare a ModelTypeSet to a ModelTypeStateMap, ignoring |
| 193 // payload values. | 193 // state values. |
| 194 bool CompareModelTypeSetToModelTypePayloadMap( | 194 bool CompareModelTypeSetToModelTypeStateMap( |
| 195 ModelTypeSet lhs, | 195 ModelTypeSet lhs, |
| 196 const ModelTypePayloadMap& rhs) { | 196 const ModelTypeStateMap& rhs) { |
| 197 size_t count = 0; | 197 size_t count = 0; |
| 198 for (ModelTypePayloadMap::const_iterator i = rhs.begin(); | 198 for (ModelTypeStateMap::const_iterator i = rhs.begin(); |
| 199 i != rhs.end(); ++i, ++count) { | 199 i != rhs.end(); ++i, ++count) { |
| 200 if (!lhs.Has(i->first)) | 200 if (!lhs.Has(i->first)) |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 if (lhs.Size() != count) | 203 if (lhs.Size() != count) |
| 204 return false; | 204 return false; |
| 205 return true; | 205 return true; |
| 206 } | 206 } |
| 207 | 207 |
| 208 SyncSessionContext* context() { return context_.get(); } | 208 SyncSessionContext* context() { return context_.get(); } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 WithArg<0>(RecordSyncShare(&records)))) | 264 WithArg<0>(RecordSyncShare(&records)))) |
| 265 .RetiresOnSaturation(); | 265 .RetiresOnSaturation(); |
| 266 | 266 |
| 267 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 267 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 268 | 268 |
| 269 scheduler()->ScheduleNudgeAsync( | 269 scheduler()->ScheduleNudgeAsync( |
| 270 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 270 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
| 271 RunLoop(); | 271 RunLoop(); |
| 272 | 272 |
| 273 ASSERT_EQ(1U, records.snapshots.size()); | 273 ASSERT_EQ(1U, records.snapshots.size()); |
| 274 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 274 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 275 records.snapshots[0].source().types)); | 275 records.snapshots[0].source().types)); |
| 276 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 276 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 277 records.snapshots[0].source().updates_source); | 277 records.snapshots[0].source().updates_source); |
| 278 | 278 |
| 279 Mock::VerifyAndClearExpectations(syncer()); | 279 Mock::VerifyAndClearExpectations(syncer()); |
| 280 | 280 |
| 281 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 281 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 282 SyncShareRecords records2; | 282 SyncShareRecords records2; |
| 283 model_types.Remove(BOOKMARKS); | 283 model_types.Remove(BOOKMARKS); |
| 284 model_types.Put(AUTOFILL); | 284 model_types.Put(AUTOFILL); |
| 285 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 285 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 286 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 286 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 287 WithArg<0>(RecordSyncShare(&records2)))); | 287 WithArg<0>(RecordSyncShare(&records2)))); |
| 288 scheduler()->ScheduleNudgeAsync( | 288 scheduler()->ScheduleNudgeAsync( |
| 289 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 289 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
| 290 RunLoop(); | 290 RunLoop(); |
| 291 | 291 |
| 292 ASSERT_EQ(1U, records2.snapshots.size()); | 292 ASSERT_EQ(1U, records2.snapshots.size()); |
| 293 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 293 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 294 records2.snapshots[0].source().types)); | 294 records2.snapshots[0].source().types)); |
| 295 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 295 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 296 records2.snapshots[0].source().updates_source); | 296 records2.snapshots[0].source().updates_source); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Make sure a regular config command is scheduled fine in the absence of any | 299 // Make sure a regular config command is scheduled fine in the absence of any |
| 300 // errors. | 300 // errors. |
| 301 TEST_F(SyncSchedulerTest, Config) { | 301 TEST_F(SyncSchedulerTest, Config) { |
| 302 SyncShareRecords records; | 302 SyncShareRecords records; |
| 303 const ModelTypeSet model_types(BOOKMARKS); | 303 const ModelTypeSet model_types(BOOKMARKS); |
| 304 | 304 |
| 305 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 305 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 307 WithArg<0>(RecordSyncShare(&records)))); | 307 WithArg<0>(RecordSyncShare(&records)))); |
| 308 | 308 |
| 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 310 | 310 |
| 311 CallbackCounter counter; | 311 CallbackCounter counter; |
| 312 ConfigurationParams params( | 312 ConfigurationParams params( |
| 313 GetUpdatesCallerInfo::RECONFIGURATION, | 313 GetUpdatesCallerInfo::RECONFIGURATION, |
| 314 model_types, | 314 model_types, |
| 315 TypesToRoutingInfo(model_types), | 315 TypesToRoutingInfo(model_types), |
| 316 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 316 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 317 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 317 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 318 ASSERT_EQ(1, counter.times_called()); | 318 ASSERT_EQ(1, counter.times_called()); |
| 319 | 319 |
| 320 ASSERT_EQ(1U, records.snapshots.size()); | 320 ASSERT_EQ(1U, records.snapshots.size()); |
| 321 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 321 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 322 records.snapshots[0].source().types)); | 322 records.snapshots[0].source().types)); |
| 323 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 323 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 324 records.snapshots[0].source().updates_source); | 324 records.snapshots[0].source().updates_source); |
| 325 } | 325 } |
| 326 | 326 |
| 327 // Simulate a failure and make sure the config request is retried. | 327 // Simulate a failure and make sure the config request is retried. |
| 328 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 328 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 329 UseMockDelayProvider(); | 329 UseMockDelayProvider(); |
| 330 EXPECT_CALL(*delay(), GetDelay(_)) | 330 EXPECT_CALL(*delay(), GetDelay(_)) |
| 331 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 331 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 348 TypesToRoutingInfo(model_types), | 348 TypesToRoutingInfo(model_types), |
| 349 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 349 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 350 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 350 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 351 ASSERT_EQ(0, counter.times_called()); | 351 ASSERT_EQ(0, counter.times_called()); |
| 352 | 352 |
| 353 ASSERT_EQ(1U, records.snapshots.size()); | 353 ASSERT_EQ(1U, records.snapshots.size()); |
| 354 RunLoop(); | 354 RunLoop(); |
| 355 | 355 |
| 356 ASSERT_EQ(2U, records.snapshots.size()); | 356 ASSERT_EQ(2U, records.snapshots.size()); |
| 357 ASSERT_EQ(1, counter.times_called()); | 357 ASSERT_EQ(1, counter.times_called()); |
| 358 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 358 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 359 records.snapshots[1].source().types)); | 359 records.snapshots[1].source().types)); |
| 360 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 360 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 361 records.snapshots[1].source().updates_source); | 361 records.snapshots[1].source().updates_source); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Issue a nudge when the config has failed. Make sure both the config and | 364 // Issue a nudge when the config has failed. Make sure both the config and |
| 365 // nudge are executed. | 365 // nudge are executed. |
| 366 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 366 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 367 const ModelTypeSet model_types(BOOKMARKS); | 367 const ModelTypeSet model_types(BOOKMARKS); |
| 368 UseMockDelayProvider(); | 368 UseMockDelayProvider(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 401 |
| 402 RunLoop(); | 402 RunLoop(); |
| 403 ASSERT_EQ(3U, records.snapshots.size()); | 403 ASSERT_EQ(3U, records.snapshots.size()); |
| 404 ASSERT_EQ(1, counter.times_called()); | 404 ASSERT_EQ(1, counter.times_called()); |
| 405 | 405 |
| 406 // Now change the mode so nudge can execute. | 406 // Now change the mode so nudge can execute. |
| 407 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 407 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 408 | 408 |
| 409 ASSERT_EQ(4U, records.snapshots.size()); | 409 ASSERT_EQ(4U, records.snapshots.size()); |
| 410 | 410 |
| 411 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 411 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 412 records.snapshots[2].source().types)); | 412 records.snapshots[2].source().types)); |
| 413 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 413 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 414 records.snapshots[2].source().updates_source); | 414 records.snapshots[2].source().updates_source); |
| 415 | 415 |
| 416 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 416 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, |
| 417 records.snapshots[3].source().types)); | 417 records.snapshots[3].source().types)); |
| 418 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 418 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 419 records.snapshots[3].source().updates_source); | 419 records.snapshots[3].source().updates_source); |
| 420 | 420 |
| 421 } | 421 } |
| 422 | 422 |
| 423 // Test that nudges are coalesced. | 423 // Test that nudges are coalesced. |
| 424 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 424 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
| 425 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 425 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 426 | 426 |
| 427 SyncShareRecords r; | 427 SyncShareRecords r; |
| 428 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 428 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 429 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 429 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 430 WithArg<0>(RecordSyncShare(&r)))); | 430 WithArg<0>(RecordSyncShare(&r)))); |
| 431 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 431 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); |
| 432 TimeDelta delay = zero(); | 432 TimeDelta delay = zero(); |
| 433 TimeTicks optimal_time = TimeTicks::Now() + delay; | 433 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 434 scheduler()->ScheduleNudgeAsync( | 434 scheduler()->ScheduleNudgeAsync( |
| 435 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 435 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
| 436 scheduler()->ScheduleNudgeAsync( | 436 scheduler()->ScheduleNudgeAsync( |
| 437 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 437 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
| 438 RunLoop(); | 438 RunLoop(); |
| 439 | 439 |
| 440 ASSERT_EQ(1U, r.snapshots.size()); | 440 ASSERT_EQ(1U, r.snapshots.size()); |
| 441 EXPECT_GE(r.times[0], optimal_time); | 441 EXPECT_GE(r.times[0], optimal_time); |
| 442 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( | 442 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( |
| 443 Union(types1, types2), r.snapshots[0].source().types)); | 443 Union(types1, types2), r.snapshots[0].source().types)); |
| 444 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 444 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 445 r.snapshots[0].source().updates_source); | 445 r.snapshots[0].source().updates_source); |
| 446 | 446 |
| 447 Mock::VerifyAndClearExpectations(syncer()); | 447 Mock::VerifyAndClearExpectations(syncer()); |
| 448 | 448 |
| 449 SyncShareRecords r2; | 449 SyncShareRecords r2; |
| 450 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 450 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 451 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 451 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 452 WithArg<0>(RecordSyncShare(&r2)))); | 452 WithArg<0>(RecordSyncShare(&r2)))); |
| 453 scheduler()->ScheduleNudgeAsync( | 453 scheduler()->ScheduleNudgeAsync( |
| 454 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); | 454 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); |
| 455 RunLoop(); | 455 RunLoop(); |
| 456 | 456 |
| 457 ASSERT_EQ(1U, r2.snapshots.size()); | 457 ASSERT_EQ(1U, r2.snapshots.size()); |
| 458 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(types3, | 458 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(types3, |
| 459 r2.snapshots[0].source().types)); | 459 r2.snapshots[0].source().types)); |
| 460 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 460 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 461 r2.snapshots[0].source().updates_source); | 461 r2.snapshots[0].source().updates_source); |
| 462 } | 462 } |
| 463 | 463 |
| 464 // Test that nudges are coalesced. | 464 // Test that nudges are coalesced. |
| 465 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 465 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
| 466 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 466 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 467 | 467 |
| 468 SyncShareRecords r; | 468 SyncShareRecords r; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 480 scheduler()->ScheduleNudgeAsync( | 480 scheduler()->ScheduleNudgeAsync( |
| 481 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); | 481 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); |
| 482 | 482 |
| 483 TimeTicks min_time = TimeTicks::Now(); | 483 TimeTicks min_time = TimeTicks::Now(); |
| 484 TimeTicks max_time = TimeTicks::Now() + delay; | 484 TimeTicks max_time = TimeTicks::Now() + delay; |
| 485 | 485 |
| 486 RunLoop(); | 486 RunLoop(); |
| 487 | 487 |
| 488 // Make sure the sync has happened. | 488 // Make sure the sync has happened. |
| 489 ASSERT_EQ(1U, r.snapshots.size()); | 489 ASSERT_EQ(1U, r.snapshots.size()); |
| 490 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( | 490 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( |
| 491 Union(types1, types2), r.snapshots[0].source().types)); | 491 Union(types1, types2), r.snapshots[0].source().types)); |
| 492 | 492 |
| 493 // Make sure the sync happened at the right time. | 493 // Make sure the sync happened at the right time. |
| 494 EXPECT_GE(r.times[0], min_time); | 494 EXPECT_GE(r.times[0], min_time); |
| 495 EXPECT_LE(r.times[0], max_time); | 495 EXPECT_LE(r.times[0], max_time); |
| 496 } | 496 } |
| 497 | 497 |
| 498 // Test nudge scheduling. | 498 // Test nudge scheduling. |
| 499 TEST_F(SyncSchedulerTest, NudgeWithPayloads) { | 499 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 500 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 500 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 501 | 501 |
| 502 SyncShareRecords records; | 502 SyncShareRecords records; |
| 503 ModelTypePayloadMap model_types_with_payloads; | 503 ModelTypeStateMap type_state_map; |
| 504 model_types_with_payloads[BOOKMARKS] = "test"; | 504 type_state_map[BOOKMARKS].payload = "test"; |
| 505 | 505 |
| 506 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 506 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 507 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 507 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 508 WithArg<0>(RecordSyncShare(&records)))) | 508 WithArg<0>(RecordSyncShare(&records)))) |
| 509 .RetiresOnSaturation(); | 509 .RetiresOnSaturation(); |
| 510 scheduler()->ScheduleNudgeWithPayloadsAsync( | 510 scheduler()->ScheduleNudgeWithStatesAsync( |
| 511 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); | 511 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); |
| 512 RunLoop(); | 512 RunLoop(); |
| 513 | 513 |
| 514 ASSERT_EQ(1U, records.snapshots.size()); | 514 ASSERT_EQ(1U, records.snapshots.size()); |
| 515 EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types); | 515 EXPECT_EQ(type_state_map, records.snapshots[0].source().types); |
| 516 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 516 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 517 records.snapshots[0].source().updates_source); | 517 records.snapshots[0].source().updates_source); |
| 518 | 518 |
| 519 Mock::VerifyAndClearExpectations(syncer()); | 519 Mock::VerifyAndClearExpectations(syncer()); |
| 520 | 520 |
| 521 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 521 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 522 SyncShareRecords records2; | 522 SyncShareRecords records2; |
| 523 model_types_with_payloads.erase(BOOKMARKS); | 523 type_state_map.erase(BOOKMARKS); |
| 524 model_types_with_payloads[AUTOFILL] = "test2"; | 524 type_state_map[AUTOFILL].payload = "test2"; |
| 525 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 525 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 526 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 526 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 527 WithArg<0>(RecordSyncShare(&records2)))); | 527 WithArg<0>(RecordSyncShare(&records2)))); |
| 528 scheduler()->ScheduleNudgeWithPayloadsAsync( | 528 scheduler()->ScheduleNudgeWithStatesAsync( |
| 529 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); | 529 zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); |
| 530 RunLoop(); | 530 RunLoop(); |
| 531 | 531 |
| 532 ASSERT_EQ(1U, records2.snapshots.size()); | 532 ASSERT_EQ(1U, records2.snapshots.size()); |
| 533 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types); | 533 EXPECT_EQ(type_state_map, records2.snapshots[0].source().types); |
| 534 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 534 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 535 records2.snapshots[0].source().updates_source); | 535 records2.snapshots[0].source().updates_source); |
| 536 } | 536 } |
| 537 | 537 |
| 538 // Test that nudges are coalesced. | 538 // Test that nudges are coalesced. |
| 539 TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { | 539 TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) { |
| 540 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 540 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 541 | 541 |
| 542 SyncShareRecords r; | 542 SyncShareRecords r; |
| 543 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 543 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 544 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 544 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 545 WithArg<0>(RecordSyncShare(&r)))); | 545 WithArg<0>(RecordSyncShare(&r)))); |
| 546 ModelTypePayloadMap types1, types2, types3; | 546 ModelTypeStateMap types1, types2, types3; |
| 547 types1[BOOKMARKS] = "test1"; | 547 types1[BOOKMARKS].payload = "test1"; |
| 548 types2[AUTOFILL] = "test2"; | 548 types2[AUTOFILL].payload = "test2"; |
| 549 types3[THEMES] = "test3"; | 549 types3[THEMES].payload = "test3"; |
| 550 TimeDelta delay = zero(); | 550 TimeDelta delay = zero(); |
| 551 TimeTicks optimal_time = TimeTicks::Now() + delay; | 551 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 552 scheduler()->ScheduleNudgeWithPayloadsAsync( | 552 scheduler()->ScheduleNudgeWithStatesAsync( |
| 553 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); | 553 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); |
| 554 scheduler()->ScheduleNudgeWithPayloadsAsync( | 554 scheduler()->ScheduleNudgeWithStatesAsync( |
| 555 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); | 555 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); |
| 556 RunLoop(); | 556 RunLoop(); |
| 557 | 557 |
| 558 ASSERT_EQ(1U, r.snapshots.size()); | 558 ASSERT_EQ(1U, r.snapshots.size()); |
| 559 EXPECT_GE(r.times[0], optimal_time); | 559 EXPECT_GE(r.times[0], optimal_time); |
| 560 ModelTypePayloadMap coalesced_types; | 560 ModelTypeStateMap coalesced_types; |
| 561 CoalescePayloads(&coalesced_types, types1); | 561 CoalesceStates(&coalesced_types, types1); |
| 562 CoalescePayloads(&coalesced_types, types2); | 562 CoalesceStates(&coalesced_types, types2); |
| 563 EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); | 563 EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); |
| 564 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 564 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 565 r.snapshots[0].source().updates_source); | 565 r.snapshots[0].source().updates_source); |
| 566 | 566 |
| 567 Mock::VerifyAndClearExpectations(syncer()); | 567 Mock::VerifyAndClearExpectations(syncer()); |
| 568 | 568 |
| 569 SyncShareRecords r2; | 569 SyncShareRecords r2; |
| 570 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 570 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 571 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 571 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 572 WithArg<0>(RecordSyncShare(&r2)))); | 572 WithArg<0>(RecordSyncShare(&r2)))); |
| 573 scheduler()->ScheduleNudgeWithPayloadsAsync( | 573 scheduler()->ScheduleNudgeWithStatesAsync( |
| 574 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); | 574 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); |
| 575 RunLoop(); | 575 RunLoop(); |
| 576 | 576 |
| 577 ASSERT_EQ(1U, r2.snapshots.size()); | 577 ASSERT_EQ(1U, r2.snapshots.size()); |
| 578 EXPECT_EQ(types3, r2.snapshots[0].source().types); | 578 EXPECT_EQ(types3, r2.snapshots[0].source().types); |
| 579 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 579 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 580 r2.snapshots[0].source().updates_source); | 580 r2.snapshots[0].source().updates_source); |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Test that polling works as expected. | 583 // Test that polling works as expected. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 CallbackCounter counter; | 779 CallbackCounter counter; |
| 780 ConfigurationParams params( | 780 ConfigurationParams params( |
| 781 GetUpdatesCallerInfo::RECONFIGURATION, | 781 GetUpdatesCallerInfo::RECONFIGURATION, |
| 782 config_types, | 782 config_types, |
| 783 TypesToRoutingInfo(config_types), | 783 TypesToRoutingInfo(config_types), |
| 784 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 784 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 785 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 785 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 786 ASSERT_EQ(1, counter.times_called()); | 786 ASSERT_EQ(1, counter.times_called()); |
| 787 | 787 |
| 788 ASSERT_EQ(1U, records.snapshots.size()); | 788 ASSERT_EQ(1U, records.snapshots.size()); |
| 789 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, | 789 EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(config_types, |
| 790 records.snapshots[0].source().types)); | 790 records.snapshots[0].source().types)); |
| 791 } | 791 } |
| 792 | 792 |
| 793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
| 794 void SetUp() { | 794 void SetUp() { |
| 795 SyncSchedulerTest::SetUp(); | 795 SyncSchedulerTest::SetUp(); |
| 796 UseMockDelayProvider(); | 796 UseMockDelayProvider(); |
| 797 EXPECT_CALL(*delay(), GetDelay(_)) | 797 EXPECT_CALL(*delay(), GetDelay(_)) |
| 798 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 798 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 799 } | 799 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 // Should save the nudge for until after the server is reachable. | 1126 // Should save the nudge for until after the server is reachable. |
| 1127 MessageLoop::current()->RunAllPending(); | 1127 MessageLoop::current()->RunAllPending(); |
| 1128 | 1128 |
| 1129 connection()->SetServerReachable(); | 1129 connection()->SetServerReachable(); |
| 1130 connection()->UpdateConnectionStatus(); | 1130 connection()->UpdateConnectionStatus(); |
| 1131 scheduler()->OnConnectionStatusChange(); | 1131 scheduler()->OnConnectionStatusChange(); |
| 1132 MessageLoop::current()->RunAllPending(); | 1132 MessageLoop::current()->RunAllPending(); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 } // namespace syncer | 1135 } // namespace syncer |
| OLD | NEW |