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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "sync/engine/backoff_delay_provider.h" | 7 #include "sync/engine/backoff_delay_provider.h" |
8 #include "sync/engine/sync_scheduler_impl.h" | 8 #include "sync/engine/sync_scheduler_impl.h" |
9 #include "sync/engine/throttled_data_type_tracker.h" | 9 #include "sync/engine/throttled_data_type_tracker.h" |
10 #include "sync/internal_api/public/engine/polling_constants.h" | 10 #include "sync/internal_api/public/engine/polling_constants.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 104 } |
105 | 105 |
106 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( | 106 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( |
107 SyncSessionJob::Purpose purpose) { | 107 SyncSessionJob::Purpose purpose) { |
108 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo())); | 108 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo())); |
109 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(), | 109 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(), |
110 ConfigurationParams()); | 110 ConfigurationParams()); |
111 return DecideOnJob(job, SyncSchedulerImpl::NORMAL_PRIORITY); | 111 return DecideOnJob(job, SyncSchedulerImpl::NORMAL_PRIORITY); |
112 } | 112 } |
113 | 113 |
| 114 bool ShouldPoll() { |
| 115 return scheduler_->ShouldPoll(); |
| 116 } |
| 117 |
114 SyncSessionContext* context() { return context_.get(); } | 118 SyncSessionContext* context() { return context_.get(); } |
115 | 119 |
116 private: | 120 private: |
117 MessageLoop message_loop_; | 121 MessageLoop message_loop_; |
118 scoped_ptr<MockConnectionManager> connection_; | 122 scoped_ptr<MockConnectionManager> connection_; |
119 scoped_ptr<SyncSessionContext> context_; | 123 scoped_ptr<SyncSessionContext> context_; |
120 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 124 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
121 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 125 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
122 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; | 126 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; |
123 TestDirectorySetterUpper dir_maker_; | 127 TestDirectorySetterUpper dir_maker_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 171 |
168 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { | 172 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { |
169 InitializeSyncerOnNormalMode(); | 173 InitializeSyncerOnNormalMode(); |
170 | 174 |
171 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 175 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
172 SyncSessionJob::NUDGE); | 176 SyncSessionJob::NUDGE); |
173 | 177 |
174 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 178 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
175 } | 179 } |
176 | 180 |
177 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) { | |
178 InitializeSyncerOnNormalMode(); | |
179 SetMode(SyncScheduler::CONFIGURATION_MODE); | |
180 | |
181 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | |
182 SyncSessionJob::POLL); | |
183 | |
184 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); | |
185 } | |
186 | |
187 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { | 181 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { |
188 InitializeSyncerOnNormalMode(); | 182 InitializeSyncerOnNormalMode(); |
| 183 EXPECT_TRUE(ShouldPoll()); |
| 184 } |
189 | 185 |
190 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 186 TEST_F(SyncSchedulerWhiteboxTest, DropPollInConfigureMode) { |
191 SyncSessionJob::POLL); | 187 InitializeSyncerOnNormalMode(); |
| 188 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 189 EXPECT_FALSE(ShouldPoll()); |
| 190 } |
192 | 191 |
193 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 192 TEST_F(SyncSchedulerWhiteboxTest, DropPollWhenThrottled) { |
| 193 InitializeSyncerOnNormalMode(); |
| 194 SetWaitIntervalToThrottled(); |
| 195 EXPECT_FALSE(ShouldPoll()); |
| 196 } |
| 197 |
| 198 TEST_F(SyncSchedulerWhiteboxTest, DropPollInBackoff) { |
| 199 InitializeSyncerOnNormalMode(); |
| 200 SetWaitIntervalToExponentialBackoff(); |
| 201 EXPECT_FALSE(ShouldPoll()); |
194 } | 202 } |
195 | 203 |
196 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { | 204 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { |
197 InitializeSyncerOnNormalMode(); | 205 InitializeSyncerOnNormalMode(); |
198 SetMode(SyncScheduler::CONFIGURATION_MODE); | 206 SetMode(SyncScheduler::CONFIGURATION_MODE); |
199 | 207 |
200 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 208 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
201 SyncSessionJob::CONFIGURATION); | 209 SyncSessionJob::CONFIGURATION); |
202 | 210 |
203 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 211 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 TimeTicks::Now(), scoped_ptr<SyncSession>(), | 267 TimeTicks::Now(), scoped_ptr<SyncSession>(), |
260 ConfigurationParams()); | 268 ConfigurationParams()); |
261 | 269 |
262 SyncSchedulerImpl::JobProcessDecision decision = | 270 SyncSchedulerImpl::JobProcessDecision decision = |
263 DecideOnJob(job, SyncSchedulerImpl::CANARY_PRIORITY); | 271 DecideOnJob(job, SyncSchedulerImpl::CANARY_PRIORITY); |
264 | 272 |
265 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 273 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
266 } | 274 } |
267 | 275 |
268 } // namespace syncer | 276 } // namespace syncer |
OLD | NEW |