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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); | 685 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); |
686 const ModelTypeSet model_types(BOOKMARKS); | 686 const ModelTypeSet model_types(BOOKMARKS); |
687 scheduler()->ScheduleNudgeAsync( | 687 scheduler()->ScheduleNudgeAsync( |
688 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 688 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
689 RunLoop(); | 689 RunLoop(); |
690 | 690 |
691 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); | 691 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); |
692 StopSyncScheduler(); | 692 StopSyncScheduler(); |
693 } | 693 } |
694 | 694 |
695 // Test that a sync session is run through to completion. | |
696 TEST_F(SyncSchedulerTest, HasMoreToSync) { | |
697 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
698 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) | |
699 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
700 QuitLoopNowAction())); | |
701 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
702 | |
703 scheduler()->ScheduleNudgeAsync( | |
704 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | |
705 RunLoop(); | |
706 // If more nudges are scheduled, they'll be waited on by TearDown, and would | |
707 // cause our expectation to break. | |
708 } | |
709 | |
710 // Test that continuations can go into backoff. | |
711 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) { | |
712 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
713 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) | |
714 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
715 QuitLoopNowAction())); | |
716 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
717 | |
718 scheduler()->ScheduleNudgeAsync( | |
719 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | |
720 | |
721 // We should detect the failure on the second sync share, and go into backoff. | |
722 EXPECT_TRUE(RunAndGetBackoff()); | |
723 } | |
724 | |
725 // Test that no syncing occurs when throttled. | 695 // Test that no syncing occurs when throttled. |
726 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 696 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
727 const ModelTypeSet types(BOOKMARKS); | 697 const ModelTypeSet types(BOOKMARKS); |
728 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 698 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
729 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 699 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
730 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 700 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
731 | 701 |
732 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 702 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
733 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 703 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) |
734 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 704 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 // Should save the nudge for until after the server is reachable. | 1104 // Should save the nudge for until after the server is reachable. |
1135 MessageLoop::current()->RunAllPending(); | 1105 MessageLoop::current()->RunAllPending(); |
1136 | 1106 |
1137 connection()->SetServerReachable(); | 1107 connection()->SetServerReachable(); |
1138 connection()->UpdateConnectionStatus(); | 1108 connection()->UpdateConnectionStatus(); |
1139 scheduler()->OnConnectionStatusChange(); | 1109 scheduler()->OnConnectionStatusChange(); |
1140 MessageLoop::current()->RunAllPending(); | 1110 MessageLoop::current()->RunAllPending(); |
1141 } | 1111 } |
1142 | 1112 |
1143 } // namespace syncer | 1113 } // namespace syncer |
OLD | NEW |