Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: sync/engine/sync_scheduler_whitebox_unittest.cc

Issue 10701046: sync: Remove SyncManager::TestingMode in favour of InternalComponentsFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now with more scope Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/sync_scheduler.h" 7 #include "sync/engine/sync_scheduler_impl.h"
8 #include "sync/engine/throttled_data_type_tracker.h" 8 #include "sync/engine/throttled_data_type_tracker.h"
9 #include "sync/sessions/sync_session_context.h" 9 #include "sync/sessions/sync_session_context.h"
10 #include "sync/sessions/test_util.h" 10 #include "sync/sessions/test_util.h"
11 #include "sync/test/engine/fake_model_worker.h" 11 #include "sync/test/engine/fake_model_worker.h"
12 #include "sync/test/engine/mock_connection_manager.h" 12 #include "sync/test/engine/mock_connection_manager.h"
13 #include "sync/test/engine/test_directory_setter_upper.h" 13 #include "sync/test/engine/test_directory_setter_upper.h"
14 #include "sync/test/fake_extensions_activity_monitor.h" 14 #include "sync/test/fake_extensions_activity_monitor.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
(...skipping 30 matching lines...) Expand all
48 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); 48 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL));
49 context_.reset( 49 context_.reset(
50 new SyncSessionContext( 50 new SyncSessionContext(
51 connection_.get(), dir_maker_.directory(), 51 connection_.get(), dir_maker_.directory(),
52 routes, workers, &extensions_activity_monitor_, 52 routes, workers, &extensions_activity_monitor_,
53 throttled_data_type_tracker_.get(), 53 throttled_data_type_tracker_.get(),
54 std::vector<SyncEngineEventListener*>(), NULL, NULL)); 54 std::vector<SyncEngineEventListener*>(), NULL, NULL));
55 context_->set_notifications_enabled(true); 55 context_->set_notifications_enabled(true);
56 context_->set_account_name("Test"); 56 context_->set_account_name("Test");
57 scheduler_.reset( 57 scheduler_.reset(
58 new SyncScheduler("TestSyncSchedulerWhitebox", context(), syncer)); 58 new SyncSchedulerImpl("TestSyncSchedulerWhitebox", context(), syncer));
59 } 59 }
60 60
61 virtual void TearDown() { 61 virtual void TearDown() {
62 scheduler_.reset(); 62 scheduler_.reset();
63 } 63 }
64 64
65 void SetMode(SyncScheduler::Mode mode) { 65 void SetMode(SyncScheduler::Mode mode) {
66 scheduler_->mode_ = mode; 66 scheduler_->mode_ = mode;
67 } 67 }
68 68
69 void SetLastSyncedTime(base::TimeTicks ticks) { 69 void SetLastSyncedTime(base::TimeTicks ticks) {
70 scheduler_->last_sync_session_end_time_ = ticks; 70 scheduler_->last_sync_session_end_time_ = ticks;
71 } 71 }
72 72
73 void ResetWaitInterval() { 73 void ResetWaitInterval() {
74 scheduler_->wait_interval_.reset(); 74 scheduler_->wait_interval_.reset();
75 } 75 }
76 76
77 void SetWaitIntervalToThrottled() { 77 void SetWaitIntervalToThrottled() {
78 scheduler_->wait_interval_.reset(new SyncScheduler::WaitInterval( 78 scheduler_->wait_interval_.reset(new SyncSchedulerImpl::WaitInterval(
79 SyncScheduler::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); 79 SyncSchedulerImpl::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1)));
80 } 80 }
81 81
82 void SetWaitIntervalToExponentialBackoff() { 82 void SetWaitIntervalToExponentialBackoff() {
83 scheduler_->wait_interval_.reset( 83 scheduler_->wait_interval_.reset(
84 new SyncScheduler::WaitInterval( 84 new SyncSchedulerImpl::WaitInterval(
85 SyncScheduler::WaitInterval::EXPONENTIAL_BACKOFF, 85 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF,
86 TimeDelta::FromSeconds(1))); 86 TimeDelta::FromSeconds(1)));
87 } 87 }
88 88
89 void SetWaitIntervalHadNudge(bool had_nudge) { 89 void SetWaitIntervalHadNudge(bool had_nudge) {
90 scheduler_->wait_interval_->had_nudge = had_nudge; 90 scheduler_->wait_interval_->had_nudge = had_nudge;
91 } 91 }
92 92
93 SyncScheduler::JobProcessDecision DecideOnJob( 93 SyncSchedulerImpl::JobProcessDecision DecideOnJob(
94 const SyncScheduler::SyncSessionJob& job) { 94 const SyncSchedulerImpl::SyncSessionJob& job) {
95 return scheduler_->DecideOnJob(job); 95 return scheduler_->DecideOnJob(job);
96 } 96 }
97 97
98 void InitializeSyncerOnNormalMode() { 98 void InitializeSyncerOnNormalMode() {
99 SetMode(SyncScheduler::NORMAL_MODE); 99 SetMode(SyncScheduler::NORMAL_MODE);
100 ResetWaitInterval(); 100 ResetWaitInterval();
101 SetLastSyncedTime(base::TimeTicks::Now()); 101 SetLastSyncedTime(base::TimeTicks::Now());
102 } 102 }
103 103
104 SyncScheduler::JobProcessDecision CreateAndDecideJob( 104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob(
105 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { 105 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) {
106 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo()); 106 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo());
107 SyncScheduler::SyncSessionJob job(purpose, TimeTicks::Now(), 107 SyncSchedulerImpl::SyncSessionJob job(purpose, TimeTicks::Now(),
108 make_linked_ptr(s), 108 make_linked_ptr(s),
109 false, 109 false,
110 ConfigurationParams(), 110 ConfigurationParams(),
111 FROM_HERE); 111 FROM_HERE);
112 return DecideOnJob(job); 112 return DecideOnJob(job);
113 } 113 }
114 114
115 SyncSessionContext* context() { return context_.get(); } 115 SyncSessionContext* context() { return context_.get(); }
116 116
117 private: 117 private:
118 MessageLoop message_loop_; 118 MessageLoop message_loop_;
119 scoped_ptr<MockConnectionManager> connection_; 119 scoped_ptr<MockConnectionManager> connection_;
120 scoped_ptr<SyncSessionContext> context_; 120 scoped_ptr<SyncSessionContext> context_;
121 std::vector<scoped_refptr<FakeModelWorker> > workers_; 121 std::vector<scoped_refptr<FakeModelWorker> > workers_;
122 FakeExtensionsActivityMonitor extensions_activity_monitor_; 122 FakeExtensionsActivityMonitor extensions_activity_monitor_;
123 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; 123 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_;
124 TestDirectorySetterUpper dir_maker_; 124 TestDirectorySetterUpper dir_maker_;
125 125
126 protected: 126 protected:
127 // Declared here to ensure it is destructed before the objects it references. 127 // Declared here to ensure it is destructed before the objects it references.
128 scoped_ptr<SyncScheduler> scheduler_; 128 scoped_ptr<SyncSchedulerImpl> scheduler_;
129 }; 129 };
130 130
131 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { 131 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) {
132 InitializeSyncerOnNormalMode(); 132 InitializeSyncerOnNormalMode();
133 133
134 // Now set the mode to configure. 134 // Now set the mode to configure.
135 SetMode(SyncScheduler::CONFIGURATION_MODE); 135 SetMode(SyncScheduler::CONFIGURATION_MODE);
136 136
137 SyncScheduler::JobProcessDecision decision = 137 SyncSchedulerImpl::JobProcessDecision decision =
138 CreateAndDecideJob(SyncScheduler::SyncSessionJob::NUDGE); 138 CreateAndDecideJob(SyncSchedulerImpl::SyncSessionJob::NUDGE);
139 139
140 EXPECT_EQ(decision, SyncScheduler::SAVE); 140 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
141 } 141 }
142 142
143 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { 143 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) {
144 InitializeSyncerOnNormalMode(); 144 InitializeSyncerOnNormalMode();
145 145
146 syncer::ModelTypeSet types; 146 syncer::ModelTypeSet types;
147 types.Put(syncer::BOOKMARKS); 147 types.Put(syncer::BOOKMARKS);
148 148
149 // Mark bookmarks as throttled. 149 // Mark bookmarks as throttled.
150 context()->throttled_data_type_tracker()->SetUnthrottleTime( 150 context()->throttled_data_type_tracker()->SetUnthrottleTime(
151 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); 151 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2));
152 152
153 syncer::ModelTypePayloadMap types_with_payload; 153 syncer::ModelTypePayloadMap types_with_payload;
154 types_with_payload[syncer::BOOKMARKS] = ""; 154 types_with_payload[syncer::BOOKMARKS] = "";
155 155
156 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); 156 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload);
157 SyncSession* s = scheduler_->CreateSyncSession(info); 157 SyncSession* s = scheduler_->CreateSyncSession(info);
158 158
159 // Now schedule a nudge with just bookmarks and the change is local. 159 // Now schedule a nudge with just bookmarks and the change is local.
160 SyncScheduler::SyncSessionJob job(SyncScheduler::SyncSessionJob::NUDGE, 160 SyncSchedulerImpl::SyncSessionJob job(
161 TimeTicks::Now(), 161 SyncSchedulerImpl::SyncSessionJob::NUDGE,
162 make_linked_ptr(s), 162 TimeTicks::Now(),
163 false, 163 make_linked_ptr(s),
164 ConfigurationParams(), 164 false,
165 FROM_HERE); 165 ConfigurationParams(),
166 FROM_HERE);
166 167
167 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); 168 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job);
168 EXPECT_EQ(decision, SyncScheduler::SAVE); 169 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
169 } 170 }
170 171
171 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { 172 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) {
172 InitializeSyncerOnNormalMode(); 173 InitializeSyncerOnNormalMode();
173 174
174 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 175 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
175 SyncScheduler::SyncSessionJob::NUDGE); 176 SyncSchedulerImpl::SyncSessionJob::NUDGE);
176 177
177 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 178 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
178 } 179 }
179 180
180 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) { 181 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) {
181 InitializeSyncerOnNormalMode(); 182 InitializeSyncerOnNormalMode();
182 SetMode(SyncScheduler::CONFIGURATION_MODE); 183 SetMode(SyncScheduler::CONFIGURATION_MODE);
183 184
184 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 185 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
185 SyncScheduler::SyncSessionJob::POLL); 186 SyncSchedulerImpl::SyncSessionJob::POLL);
186 187
187 EXPECT_EQ(decision, SyncScheduler::DROP); 188 EXPECT_EQ(decision, SyncSchedulerImpl::DROP);
188 } 189 }
189 190
190 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { 191 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) {
191 InitializeSyncerOnNormalMode(); 192 InitializeSyncerOnNormalMode();
192 193
193 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 194 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
194 SyncScheduler::SyncSessionJob::POLL); 195 SyncSchedulerImpl::SyncSessionJob::POLL);
195 196
196 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 197 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
197 } 198 }
198 199
199 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { 200 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) {
200 InitializeSyncerOnNormalMode(); 201 InitializeSyncerOnNormalMode();
201 SetMode(SyncScheduler::CONFIGURATION_MODE); 202 SetMode(SyncScheduler::CONFIGURATION_MODE);
202 203
203 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 204 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
204 SyncScheduler::SyncSessionJob::CONFIGURATION); 205 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION);
205 206
206 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 207 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
207 } 208 }
208 209
209 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) { 210 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) {
210 InitializeSyncerOnNormalMode(); 211 InitializeSyncerOnNormalMode();
211 SetMode(SyncScheduler::CONFIGURATION_MODE); 212 SetMode(SyncScheduler::CONFIGURATION_MODE);
212 213
213 SetWaitIntervalToThrottled(); 214 SetWaitIntervalToThrottled();
214 215
215 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 216 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
216 SyncScheduler::SyncSessionJob::CONFIGURATION); 217 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION);
217 218
218 EXPECT_EQ(decision, SyncScheduler::SAVE); 219 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
219 } 220 }
220 221
221 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) { 222 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) {
222 InitializeSyncerOnNormalMode(); 223 InitializeSyncerOnNormalMode();
223 SetMode(SyncScheduler::CONFIGURATION_MODE); 224 SetMode(SyncScheduler::CONFIGURATION_MODE);
224 225
225 SetWaitIntervalToThrottled(); 226 SetWaitIntervalToThrottled();
226 227
227 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 228 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
228 SyncScheduler::SyncSessionJob::NUDGE); 229 SyncSchedulerImpl::SyncSessionJob::NUDGE);
229 230
230 EXPECT_EQ(decision, SyncScheduler::SAVE); 231 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
231 } 232 }
232 233
233 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) { 234 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) {
234 InitializeSyncerOnNormalMode(); 235 InitializeSyncerOnNormalMode();
235 SetMode(SyncScheduler::NORMAL_MODE); 236 SetMode(SyncScheduler::NORMAL_MODE);
236 SetWaitIntervalToExponentialBackoff(); 237 SetWaitIntervalToExponentialBackoff();
237 238
238 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 239 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
239 SyncScheduler::SyncSessionJob::NUDGE); 240 SyncSchedulerImpl::SyncSessionJob::NUDGE);
240 241
241 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 242 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
242 } 243 }
243 244
244 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { 245 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) {
245 InitializeSyncerOnNormalMode(); 246 InitializeSyncerOnNormalMode();
246 SetMode(SyncScheduler::NORMAL_MODE); 247 SetMode(SyncScheduler::NORMAL_MODE);
247 SetWaitIntervalToExponentialBackoff(); 248 SetWaitIntervalToExponentialBackoff();
248 SetWaitIntervalHadNudge(true); 249 SetWaitIntervalHadNudge(true);
249 250
250 SyncScheduler::JobProcessDecision decision = CreateAndDecideJob( 251 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
251 SyncScheduler::SyncSessionJob::NUDGE); 252 SyncSchedulerImpl::SyncSessionJob::NUDGE);
252 253
253 EXPECT_EQ(decision, SyncScheduler::DROP); 254 EXPECT_EQ(decision, SyncSchedulerImpl::DROP);
254 } 255 }
255 256
256 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { 257 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) {
257 InitializeSyncerOnNormalMode(); 258 InitializeSyncerOnNormalMode();
258 SetMode(SyncScheduler::CONFIGURATION_MODE); 259 SetMode(SyncScheduler::CONFIGURATION_MODE);
259 SetWaitIntervalToExponentialBackoff(); 260 SetWaitIntervalToExponentialBackoff();
260 261
261 struct SyncScheduler::SyncSessionJob job; 262 struct SyncSchedulerImpl::SyncSessionJob job;
262 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; 263 job.purpose = SyncSchedulerImpl::SyncSessionJob::CONFIGURATION;
263 job.scheduled_start = TimeTicks::Now(); 264 job.scheduled_start = TimeTicks::Now();
264 job.is_canary_job = true; 265 job.is_canary_job = true;
265 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); 266 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job);
266 267
267 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 268 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
268 } 269 }
269 270
270 } // namespace syncer 271 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698