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" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 90 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
91 routes[iter.Get()] = GROUP_PASSIVE; | 91 routes[iter.Get()] = GROUP_PASSIVE; |
92 } | 92 } |
93 return routes; | 93 return routes; |
94 } | 94 } |
95 | 95 |
96 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 96 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
97 static const size_t kMinNumSamples = 5; | 97 static const size_t kMinNumSamples = 5; |
98 class SyncSchedulerTest : public testing::Test { | 98 class SyncSchedulerTest : public testing::Test { |
99 public: | 99 public: |
100 SyncSchedulerTest() : weak_ptr_factory_(this), syncer_(NULL), delay_(NULL) {} | 100 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} |
101 | 101 |
102 class MockDelayProvider : public BackoffDelayProvider { | 102 class MockDelayProvider : public BackoffDelayProvider { |
103 public: | 103 public: |
104 MockDelayProvider() : BackoffDelayProvider( | 104 MockDelayProvider() : BackoffDelayProvider( |
105 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 105 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
106 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { | 106 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { |
107 } | 107 } |
108 | 108 |
109 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 109 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
110 }; | 110 }; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ModelTypeSet GetThrottledTypes() { | 215 ModelTypeSet GetThrottledTypes() { |
216 return scheduler_->nudge_tracker_.GetThrottledTypes(); | 216 return scheduler_->nudge_tracker_.GetThrottledTypes(); |
217 } | 217 } |
218 | 218 |
219 private: | 219 private: |
220 syncable::Directory* directory() { | 220 syncable::Directory* directory() { |
221 return dir_maker_.directory(); | 221 return dir_maker_.directory(); |
222 } | 222 } |
223 | 223 |
224 base::MessageLoop loop_; | 224 base::MessageLoop loop_; |
225 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | |
226 TestDirectorySetterUpper dir_maker_; | 225 TestDirectorySetterUpper dir_maker_; |
227 CancelationSignal cancelation_signal_; | 226 CancelationSignal cancelation_signal_; |
228 scoped_ptr<MockConnectionManager> connection_; | 227 scoped_ptr<MockConnectionManager> connection_; |
229 scoped_ptr<SyncSessionContext> context_; | 228 scoped_ptr<SyncSessionContext> context_; |
230 scoped_ptr<SyncSchedulerImpl> scheduler_; | 229 scoped_ptr<SyncSchedulerImpl> scheduler_; |
231 MockSyncer* syncer_; | 230 MockSyncer* syncer_; |
232 MockDelayProvider* delay_; | 231 MockDelayProvider* delay_; |
233 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 232 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
234 scoped_refptr<ExtensionsActivity> extensions_activity_; | 233 scoped_refptr<ExtensionsActivity> extensions_activity_; |
235 ModelSafeRoutingInfo routing_info_; | 234 ModelSafeRoutingInfo routing_info_; |
| 235 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; |
236 }; | 236 }; |
237 | 237 |
238 void RecordSyncShareImpl(SyncShareTimes* times) { | 238 void RecordSyncShareImpl(SyncShareTimes* times) { |
239 times->push_back(TimeTicks::Now()); | 239 times->push_back(TimeTicks::Now()); |
240 } | 240 } |
241 | 241 |
242 ACTION_P(RecordSyncShare, times) { | 242 ACTION_P(RecordSyncShare, times) { |
243 RecordSyncShareImpl(times); | 243 RecordSyncShareImpl(times); |
244 if (base::MessageLoop::current()->is_running()) | 244 if (base::MessageLoop::current()->is_running()) |
245 QuitLoopNow(); | 245 QuitLoopNow(); |
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 // poll once more | 1203 // poll once more |
1204 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1204 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1205 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1205 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1206 RecordSyncShare(×))); | 1206 RecordSyncShare(×))); |
1207 scheduler()->OnCredentialsUpdated(); | 1207 scheduler()->OnCredentialsUpdated(); |
1208 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1208 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
1209 StopSyncScheduler(); | 1209 StopSyncScheduler(); |
1210 } | 1210 } |
1211 | 1211 |
1212 } // namespace syncer | 1212 } // namespace syncer |
OLD | NEW |