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/cancelation_signal.h" |
14 #include "sync/internal_api/public/base/model_type_test_util.h" | 15 #include "sync/internal_api/public/base/model_type_test_util.h" |
15 #include "sync/notifier/invalidation_util.h" | 16 #include "sync/notifier/invalidation_util.h" |
16 #include "sync/notifier/object_id_invalidation_map.h" | 17 #include "sync/notifier/object_id_invalidation_map.h" |
17 #include "sync/sessions/test_util.h" | 18 #include "sync/sessions/test_util.h" |
18 #include "sync/test/callback_counter.h" | 19 #include "sync/test/callback_counter.h" |
19 #include "sync/test/engine/fake_model_worker.h" | 20 #include "sync/test/engine/fake_model_worker.h" |
20 #include "sync/test/engine/mock_connection_manager.h" | 21 #include "sync/test/engine/mock_connection_manager.h" |
21 #include "sync/test/engine/test_directory_setter_upper.h" | 22 #include "sync/test/engine/test_directory_setter_upper.h" |
22 #include "sync/util/extensions_activity.h" | 23 #include "sync/util/extensions_activity.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 10 matching lines...) Expand all Loading... |
34 using testing::WithArg; | 35 using testing::WithArg; |
35 using testing::WithArgs; | 36 using testing::WithArgs; |
36 | 37 |
37 namespace syncer { | 38 namespace syncer { |
38 using sessions::SyncSession; | 39 using sessions::SyncSession; |
39 using sessions::SyncSessionContext; | 40 using sessions::SyncSessionContext; |
40 using sync_pb::GetUpdatesCallerInfo; | 41 using sync_pb::GetUpdatesCallerInfo; |
41 | 42 |
42 class MockSyncer : public Syncer { | 43 class MockSyncer : public Syncer { |
43 public: | 44 public: |
| 45 MockSyncer(); |
44 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, | 46 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, |
45 const sessions::NudgeTracker&, | 47 const sessions::NudgeTracker&, |
46 sessions::SyncSession*)); | 48 sessions::SyncSession*)); |
47 MOCK_METHOD3(ConfigureSyncShare, | 49 MOCK_METHOD3(ConfigureSyncShare, |
48 bool(ModelTypeSet, | 50 bool(ModelTypeSet, |
49 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | 51 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
50 SyncSession*)); | 52 SyncSession*)); |
51 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 53 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); |
52 }; | 54 }; |
53 | 55 |
| 56 MockSyncer::MockSyncer() |
| 57 : Syncer(NULL) {} |
| 58 |
54 typedef std::vector<TimeTicks> SyncShareTimes; | 59 typedef std::vector<TimeTicks> SyncShareTimes; |
55 | 60 |
56 void QuitLoopNow() { | 61 void QuitLoopNow() { |
57 // We use QuitNow() instead of Quit() as the latter may get stalled | 62 // We use QuitNow() instead of Quit() as the latter may get stalled |
58 // indefinitely in the presence of repeated timers with low delays | 63 // indefinitely in the presence of repeated timers with low delays |
59 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll | 64 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll |
60 // delay of 5ms] run under TSAN on the trybots). | 65 // delay of 5ms] run under TSAN on the trybots). |
61 base::MessageLoop::current()->QuitNow(); | 66 base::MessageLoop::current()->QuitNow(); |
62 } | 67 } |
63 | 68 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 124 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
120 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 125 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
121 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 126 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
122 | 127 |
123 std::vector<ModelSafeWorker*> workers; | 128 std::vector<ModelSafeWorker*> workers; |
124 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = | 129 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = |
125 workers_.begin(); it != workers_.end(); ++it) { | 130 workers_.begin(); it != workers_.end(); ++it) { |
126 workers.push_back(it->get()); | 131 workers.push_back(it->get()); |
127 } | 132 } |
128 | 133 |
129 connection_.reset(new MockConnectionManager(directory())); | 134 connection_.reset(new MockConnectionManager(directory(), |
| 135 &cancelation_signal_)); |
130 connection_->SetServerReachable(); | 136 connection_->SetServerReachable(); |
131 context_.reset(new SyncSessionContext( | 137 context_.reset(new SyncSessionContext( |
132 connection_.get(), directory(), workers, | 138 connection_.get(), directory(), workers, |
133 extensions_activity_.get(), | 139 extensions_activity_.get(), |
134 std::vector<SyncEngineEventListener*>(), NULL, NULL, | 140 std::vector<SyncEngineEventListener*>(), NULL, NULL, |
135 true, // enable keystore encryption | 141 true, // enable keystore encryption |
136 false, // force enable pre-commit GU avoidance | 142 false, // force enable pre-commit GU avoidance |
137 "fake_invalidator_client_id")); | 143 "fake_invalidator_client_id")); |
138 context_->set_routing_info(routing_info_); | 144 context_->set_routing_info(routing_info_); |
139 context_->set_notifications_enabled(true); | 145 context_->set_notifications_enabled(true); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 217 } |
212 | 218 |
213 private: | 219 private: |
214 syncable::Directory* directory() { | 220 syncable::Directory* directory() { |
215 return dir_maker_.directory(); | 221 return dir_maker_.directory(); |
216 } | 222 } |
217 | 223 |
218 base::MessageLoop loop_; | 224 base::MessageLoop loop_; |
219 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | 225 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; |
220 TestDirectorySetterUpper dir_maker_; | 226 TestDirectorySetterUpper dir_maker_; |
| 227 CancelationSignal cancelation_signal_; |
221 scoped_ptr<MockConnectionManager> connection_; | 228 scoped_ptr<MockConnectionManager> connection_; |
222 scoped_ptr<SyncSessionContext> context_; | 229 scoped_ptr<SyncSessionContext> context_; |
223 scoped_ptr<SyncSchedulerImpl> scheduler_; | 230 scoped_ptr<SyncSchedulerImpl> scheduler_; |
224 MockSyncer* syncer_; | 231 MockSyncer* syncer_; |
225 MockDelayProvider* delay_; | 232 MockDelayProvider* delay_; |
226 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 233 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
227 scoped_refptr<ExtensionsActivity> extensions_activity_; | 234 scoped_refptr<ExtensionsActivity> extensions_activity_; |
228 ModelSafeRoutingInfo routing_info_; | 235 ModelSafeRoutingInfo routing_info_; |
229 }; | 236 }; |
230 | 237 |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 // poll once more | 1203 // poll once more |
1197 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1204 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1198 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1205 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1199 RecordSyncShare(×))); | 1206 RecordSyncShare(×))); |
1200 scheduler()->OnCredentialsUpdated(); | 1207 scheduler()->OnCredentialsUpdated(); |
1201 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1208 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
1202 StopSyncScheduler(); | 1209 StopSyncScheduler(); |
1203 } | 1210 } |
1204 | 1211 |
1205 } // namespace syncer | 1212 } // namespace syncer |
OLD | NEW |