| 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" |
| 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/internal_api/public/base/model_type_test_util.h" |
| 15 #include "sync/notifier/invalidation_util.h" |
| 16 #include "sync/notifier/object_id_invalidation_map.h" |
| 14 #include "sync/sessions/test_util.h" | 17 #include "sync/sessions/test_util.h" |
| 15 #include "sync/test/callback_counter.h" | 18 #include "sync/test/callback_counter.h" |
| 16 #include "sync/test/engine/fake_model_worker.h" | 19 #include "sync/test/engine/fake_model_worker.h" |
| 17 #include "sync/test/engine/mock_connection_manager.h" | 20 #include "sync/test/engine/mock_connection_manager.h" |
| 18 #include "sync/test/engine/test_directory_setter_upper.h" | 21 #include "sync/test/engine/test_directory_setter_upper.h" |
| 19 #include "sync/util/extensions_activity.h" | 22 #include "sync/util/extensions_activity.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 25 |
| 23 using base::TimeDelta; | 26 using base::TimeDelta; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 // Make sure the sync happened at the right time. | 446 // Make sure the sync happened at the right time. |
| 444 ASSERT_EQ(1U, times.size()); | 447 ASSERT_EQ(1U, times.size()); |
| 445 EXPECT_GE(times[0], min_time); | 448 EXPECT_GE(times[0], min_time); |
| 446 EXPECT_LE(times[0], max_time); | 449 EXPECT_LE(times[0], max_time); |
| 447 } | 450 } |
| 448 | 451 |
| 449 // Test nudge scheduling. | 452 // Test nudge scheduling. |
| 450 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 453 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 451 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 454 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 452 | 455 |
| 453 SyncShareTimes times; | 456 SyncShareTimes times1; |
| 454 const ModelTypeSet types(BOOKMARKS); | 457 ObjectIdInvalidationMap invalidations1 = |
| 455 ModelTypeInvalidationMap invalidation_map = | 458 BuildInvalidationMap(BOOKMARKS, 10, "test"); |
| 456 ModelTypeSetToInvalidationMap(types, "test"); | |
| 457 | |
| 458 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 459 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 459 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 460 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 460 RecordSyncShare(×))) | 461 RecordSyncShare(×1))) |
| 461 .RetiresOnSaturation(); | 462 .RetiresOnSaturation(); |
| 462 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 463 scheduler()->ScheduleInvalidationNudge(zero(), invalidations1, FROM_HERE); |
| 463 RunLoop(); | 464 RunLoop(); |
| 464 | 465 |
| 465 Mock::VerifyAndClearExpectations(syncer()); | 466 Mock::VerifyAndClearExpectations(syncer()); |
| 466 | 467 |
| 467 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 468 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 468 SyncShareTimes times2; | 469 SyncShareTimes times2; |
| 469 invalidation_map.erase(BOOKMARKS); | 470 ObjectIdInvalidationMap invalidations2 = |
| 470 invalidation_map[AUTOFILL].payload = "test2"; | 471 BuildInvalidationMap(AUTOFILL, 10, "test2"); |
| 471 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 472 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 472 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 473 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 473 RecordSyncShare(×2))); | 474 RecordSyncShare(×2))); |
| 474 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 475 scheduler()->ScheduleInvalidationNudge(zero(), invalidations2, FROM_HERE); |
| 475 RunLoop(); | 476 RunLoop(); |
| 476 } | 477 } |
| 477 | 478 |
| 478 // Test that polling works as expected. | 479 // Test that polling works as expected. |
| 479 TEST_F(SyncSchedulerTest, Polling) { | 480 TEST_F(SyncSchedulerTest, Polling) { |
| 480 SyncShareTimes times; | 481 SyncShareTimes times; |
| 481 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 482 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 482 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 483 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
| 483 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 484 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 484 RecordSyncShareMultiple(×, kMinNumSamples))); | 485 RecordSyncShareMultiple(×, kMinNumSamples))); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 throttled_types, throttle1)), | 743 throttled_types, throttle1)), |
| 743 Return(true))) | 744 Return(true))) |
| 744 .RetiresOnSaturation(); | 745 .RetiresOnSaturation(); |
| 745 | 746 |
| 746 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 747 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 747 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); | 748 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); |
| 748 PumpLoop(); | 749 PumpLoop(); |
| 749 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 750 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 750 | 751 |
| 751 // Ignore invalidations for throttled types. | 752 // Ignore invalidations for throttled types. |
| 752 ModelTypeInvalidationMap invalidation_map = | 753 ObjectIdInvalidationMap invalidations = |
| 753 ModelTypeSetToInvalidationMap(throttled_types, "test"); | 754 BuildInvalidationMap(BOOKMARKS, 10, "test"); |
| 754 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 755 scheduler()->ScheduleInvalidationNudge(zero(), invalidations, FROM_HERE); |
| 755 PumpLoop(); | 756 PumpLoop(); |
| 756 | 757 |
| 757 // Ignore refresh requests for throttled types. | 758 // Ignore refresh requests for throttled types. |
| 758 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); | 759 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); |
| 759 PumpLoop(); | 760 PumpLoop(); |
| 760 | 761 |
| 761 Mock::VerifyAndClearExpectations(syncer()); | 762 Mock::VerifyAndClearExpectations(syncer()); |
| 762 | 763 |
| 763 // Local nudges for non-throttled types will trigger a sync. | 764 // Local nudges for non-throttled types will trigger a sync. |
| 764 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 765 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 // poll once more | 1196 // poll once more |
| 1196 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1197 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 1197 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1198 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 1198 RecordSyncShare(×))); | 1199 RecordSyncShare(×))); |
| 1199 scheduler()->OnCredentialsUpdated(); | 1200 scheduler()->OnCredentialsUpdated(); |
| 1200 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1201 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
| 1201 StopSyncScheduler(); | 1202 StopSyncScheduler(); |
| 1202 } | 1203 } |
| 1203 | 1204 |
| 1204 } // namespace syncer | 1205 } // namespace syncer |
| OLD | NEW |