| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using sessions::SyncSession; | 34 using sessions::SyncSession; |
| 35 using sessions::SyncSessionContext; | 35 using sessions::SyncSessionContext; |
| 36 using sessions::SyncSessionSnapshot; | 36 using sessions::SyncSessionSnapshot; |
| 37 using syncable::ModelTypeBitSet; | 37 using syncable::ModelTypeBitSet; |
| 38 using sync_pb::GetUpdatesCallerInfo; | 38 using sync_pb::GetUpdatesCallerInfo; |
| 39 | 39 |
| 40 class MockSyncer : public Syncer { | 40 class MockSyncer : public Syncer { |
| 41 public: | 41 public: |
| 42 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, | 42 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, |
| 43 SyncerStep)); | 43 SyncerStep)); |
| 44 MOCK_METHOD1(CleanupDisabledTypes, void(sessions::SyncSession*)); |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 // Used when tests want to record syncing activity to examine later. | 47 // Used when tests want to record syncing activity to examine later. |
| 47 struct SyncShareRecords { | 48 struct SyncShareRecords { |
| 48 std::vector<TimeTicks> times; | 49 std::vector<TimeTicks> times; |
| 49 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; | 50 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 void QuitLoopNow() { | 53 void QuitLoopNow() { |
| 53 // We use QuitNow() instead of Quit() as the latter may get stalled | 54 // We use QuitNow() instead of Quit() as the latter may get stalled |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 scheduler()->ScheduleNudge( | 940 scheduler()->ScheduleNudge( |
| 940 zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), FROM_HERE); | 941 zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), FROM_HERE); |
| 941 PumpLoop(); | 942 PumpLoop(); |
| 942 // Pump again to run job. | 943 // Pump again to run job. |
| 943 PumpLoop(); | 944 PumpLoop(); |
| 944 | 945 |
| 945 scheduler()->Stop(); | 946 scheduler()->Stop(); |
| 946 Mock::VerifyAndClearExpectations(syncer()); | 947 Mock::VerifyAndClearExpectations(syncer()); |
| 947 | 948 |
| 948 // ClearUserData. | 949 // ClearUserData. |
| 949 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, SYNCER_END)) | 950 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) |
| 950 .Times(1); | 951 .Times(1); |
| 951 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 952 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 952 RunLoop(); | 953 RunLoop(); |
| 953 | 954 |
| 954 scheduler()->ScheduleClearUserData(); | 955 scheduler()->ScheduleClearUserData(); |
| 955 PumpLoop(); | 956 PumpLoop(); |
| 956 PumpLoop(); | 957 PumpLoop(); |
| 957 | 958 |
| 958 scheduler()->Stop(); | 959 scheduler()->Stop(); |
| 960 Mock::VerifyAndClearExpectations(syncer()); |
| 959 | 961 |
| 960 Mock::VerifyAndClearExpectations(syncer()); | |
| 961 // Configuration. | 962 // Configuration. |
| 962 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); | 963 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); |
| 963 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 964 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 964 RunLoop(); | 965 RunLoop(); |
| 965 | 966 |
| 966 scheduler()->ScheduleConfig( | 967 scheduler()->ScheduleConfig( |
| 967 ModelTypeBitSet(), sync_api::CONFIGURE_REASON_RECONFIGURATION); | 968 ModelTypeBitSet(), sync_api::CONFIGURE_REASON_RECONFIGURATION); |
| 968 PumpLoop(); | 969 PumpLoop(); |
| 969 PumpLoop(); | 970 PumpLoop(); |
| 970 | 971 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 981 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 982 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 982 RunLoop(); | 983 RunLoop(); |
| 983 | 984 |
| 984 // Run again to wait for polling. | 985 // Run again to wait for polling. |
| 985 RunLoop(); | 986 RunLoop(); |
| 986 | 987 |
| 987 scheduler()->Stop(); | 988 scheduler()->Stop(); |
| 988 Mock::VerifyAndClearExpectations(syncer()); | 989 Mock::VerifyAndClearExpectations(syncer()); |
| 989 } | 990 } |
| 990 | 991 |
| 992 TEST_F(SyncSchedulerTest, CleanupDisabledTypes) { |
| 993 EXPECT_CALL(*syncer(), CleanupDisabledTypes(_)); |
| 994 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 995 RunLoop(); |
| 996 |
| 997 scheduler()->ScheduleCleanupDisabledTypes(); |
| 998 PumpLoop(); |
| 999 PumpLoop(); |
| 1000 |
| 1001 scheduler()->Stop(); |
| 1002 Mock::VerifyAndClearExpectations(syncer()); |
| 1003 } |
| 1004 |
| 991 // Test config tasks don't run during normal mode. | 1005 // Test config tasks don't run during normal mode. |
| 992 // TODO(tim): Implement this test and then the functionality! | 1006 // TODO(tim): Implement this test and then the functionality! |
| 993 TEST_F(SyncSchedulerTest, DISABLED_NoConfigDuringNormal) { | 1007 TEST_F(SyncSchedulerTest, DISABLED_NoConfigDuringNormal) { |
| 994 } | 1008 } |
| 995 | 1009 |
| 996 // Test that starting the syncer thread without a valid connection doesn't | 1010 // Test that starting the syncer thread without a valid connection doesn't |
| 997 // break things when a connection is detected. | 1011 // break things when a connection is detected. |
| 998 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1012 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
| 999 connection()->SetServerNotReachable(); | 1013 connection()->SetServerNotReachable(); |
| 1000 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(QuitLoopNowAction()); | 1014 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(QuitLoopNowAction()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1026 PumpLoop(); | 1040 PumpLoop(); |
| 1027 // Pump again to run job. | 1041 // Pump again to run job. |
| 1028 PumpLoop(); | 1042 PumpLoop(); |
| 1029 | 1043 |
| 1030 scheduler()->Stop(); | 1044 scheduler()->Stop(); |
| 1031 | 1045 |
| 1032 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 1046 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
| 1033 } | 1047 } |
| 1034 | 1048 |
| 1035 } // namespace browser_sync | 1049 } // namespace browser_sync |
| OLD | NEW |