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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread2_unittest.cc

Issue 6690020: sync: hook up ServerConnectionManager <> SyncerThread2 and tie up more loose ends (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/debug
Patch Set: fix Created 9 years, 9 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) 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/synchronization/waitable_event.h" 5 #include "base/synchronization/waitable_event.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" 7 #include "chrome/browser/sync/engine/mock_model_safe_workers.h"
8 #include "chrome/browser/sync/engine/syncer.h" 8 #include "chrome/browser/sync/engine/syncer.h"
9 #include "chrome/browser/sync/engine/syncer_thread2.h" 9 #include "chrome/browser/sync/engine/syncer_thread2.h"
10 #include "chrome/browser/sync/sessions/test_util.h" 10 #include "chrome/browser/sync/sessions/test_util.h"
11 #include "chrome/test/sync/engine/mock_connection_manager.h"
11 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 12 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 15
15 using base::TimeDelta; 16 using base::TimeDelta;
16 using base::TimeTicks; 17 using base::TimeTicks;
17 using testing::_; 18 using testing::_;
18 using testing::AtLeast; 19 using testing::AtLeast;
19 using testing::DoAll; 20 using testing::DoAll;
20 using testing::Eq; 21 using testing::Eq;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class MockDelayProvider : public SyncerThread::DelayProvider { 53 class MockDelayProvider : public SyncerThread::DelayProvider {
53 public: 54 public:
54 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); 55 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&));
55 }; 56 };
56 57
57 virtual void SetUp() { 58 virtual void SetUp() {
58 syncdb_.SetUp(); 59 syncdb_.SetUp();
59 syncer_ = new MockSyncer(); 60 syncer_ = new MockSyncer();
60 delay_ = NULL; 61 delay_ = NULL;
61 registrar_.reset(MockModelSafeWorkerRegistrar::PassiveBookmarks()); 62 registrar_.reset(MockModelSafeWorkerRegistrar::PassiveBookmarks());
62 context_ = new SyncSessionContext(NULL, syncdb_.manager(), 63 connection_.reset(new MockConnectionManager(syncdb_.manager(), "Test"));
64 connection_->SetServerReachable();
65 context_ = new SyncSessionContext(connection_.get(), syncdb_.manager(),
63 registrar_.get(), std::vector<SyncEngineEventListener*>()); 66 registrar_.get(), std::vector<SyncEngineEventListener*>());
64 context_->set_notifications_enabled(true); 67 context_->set_notifications_enabled(true);
65 context_->set_account_name("Test"); 68 context_->set_account_name("Test");
66 syncer_thread_.reset(new SyncerThread(context_, syncer_)); 69 syncer_thread_.reset(new SyncerThread(context_, syncer_));
67 // TODO(tim): Once the SCM is hooked up, remove this.
68 syncer_thread_->server_connection_ok_ = true;
69 } 70 }
70 71
71 SyncerThread* syncer_thread() { return syncer_thread_.get(); } 72 SyncerThread* syncer_thread() { return syncer_thread_.get(); }
72 MockSyncer* syncer() { return syncer_; } 73 MockSyncer* syncer() { return syncer_; }
73 MockDelayProvider* delay() { return delay_; } 74 MockDelayProvider* delay() { return delay_; }
75 MockConnectionManager* connection() { return connection_.get(); }
74 TimeDelta zero() { return TimeDelta::FromSeconds(0); } 76 TimeDelta zero() { return TimeDelta::FromSeconds(0); }
75 TimeDelta timeout() { 77 TimeDelta timeout() {
76 return TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()); 78 return TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms());
77 } 79 }
78 80
79 virtual void TearDown() { 81 virtual void TearDown() {
80 syncer_thread()->Stop(); 82 syncer_thread()->Stop();
81 syncdb_.TearDown(); 83 syncdb_.TearDown();
82 } 84 }
83 85
84 void AnalyzePollRun(const SyncShareRecords& records, size_t min_num_samples, 86 void AnalyzePollRun(const SyncShareRecords& records, size_t min_num_samples,
85 const TimeTicks& optimal_start, const TimeDelta& poll_interval) { 87 const TimeTicks& optimal_start, const TimeDelta& poll_interval) {
86 const std::vector<TimeTicks>& data(records.times); 88 const std::vector<TimeTicks>& data(records.times);
87 EXPECT_GE(data.size(), min_num_samples); 89 EXPECT_GE(data.size(), min_num_samples);
88 for (size_t i = 0; i < data.size(); i++) { 90 for (size_t i = 0; i < data.size(); i++) {
89 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); 91 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
90 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; 92 TimeTicks optimal_next_sync = optimal_start + poll_interval * i;
91 EXPECT_GE(data[i], optimal_next_sync); 93 EXPECT_GE(data[i], optimal_next_sync);
92 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 94 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
93 records.snapshots[i]->source.updates_source); 95 records.snapshots[i]->source.updates_source);
94 } 96 }
95 } 97 }
96 98
97 bool GetBackoffAndResetTest(base::WaitableEvent* done) { 99 bool GetBackoffAndResetTest(base::WaitableEvent* done) {
98 syncable::ModelTypeBitSet nudge_types; 100 syncable::ModelTypeBitSet nudge_types;
99 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 101 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
100 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); 102 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types);
101 done->TimedWait(timeout()); 103 done->TimedWait(timeout());
102 TearDown(); 104 TearDown();
103 done->Reset(); 105 done->Reset();
104 Mock::VerifyAndClearExpectations(syncer()); 106 Mock::VerifyAndClearExpectations(syncer());
105 bool backing_off = syncer_thread()->IsBackingOff(); 107 bool backing_off = syncer_thread()->IsBackingOff();
106 SetUp(); 108 SetUp();
107 UseMockDelayProvider(); 109 UseMockDelayProvider();
108 EXPECT_CALL(*delay(), GetDelay(_)) 110 EXPECT_CALL(*delay(), GetDelay(_))
109 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 111 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
(...skipping 13 matching lines...) Expand all
123 void FlushLastTask(base::WaitableEvent* done) { 125 void FlushLastTask(base::WaitableEvent* done) {
124 PostSignalTask(done); 126 PostSignalTask(done);
125 done->TimedWait(timeout()); 127 done->TimedWait(timeout());
126 done->Reset(); 128 done->Reset();
127 } 129 }
128 130
129 static void SignalWaitableEvent(base::WaitableEvent* event) { 131 static void SignalWaitableEvent(base::WaitableEvent* event) {
130 event->Signal(); 132 event->Signal();
131 } 133 }
132 134
135 static void QuitMessageLoop() {
136 MessageLoop::current()->Quit();
137 }
138
133 // Compare a ModelTypeBitSet to a ModelTypePayloadMap, ignoring 139 // Compare a ModelTypeBitSet to a ModelTypePayloadMap, ignoring
134 // payload values. 140 // payload values.
135 bool CompareModelTypeBitSetToModelTypePayloadMap( 141 bool CompareModelTypeBitSetToModelTypePayloadMap(
136 const syncable::ModelTypeBitSet& lhs, 142 const syncable::ModelTypeBitSet& lhs,
137 const syncable::ModelTypePayloadMap& rhs) { 143 const syncable::ModelTypePayloadMap& rhs) {
138 size_t count = 0; 144 size_t count = 0;
139 for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin(); 145 for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin();
140 i != rhs.end(); ++i, ++count) { 146 i != rhs.end(); ++i, ++count) {
141 if (!lhs.test(i->first)) 147 if (!lhs.test(i->first))
142 return false; 148 return false;
143 } 149 }
144 if (lhs.count() != count) 150 if (lhs.count() != count)
145 return false; 151 return false;
146 return true; 152 return true;
147 } 153 }
148 154
155 SyncSessionContext* context() { return context_; }
156
149 private: 157 private:
150 scoped_ptr<SyncerThread> syncer_thread_; 158 scoped_ptr<SyncerThread> syncer_thread_;
159 scoped_ptr<MockConnectionManager> connection_;
151 SyncSessionContext* context_; 160 SyncSessionContext* context_;
152 MockSyncer* syncer_; 161 MockSyncer* syncer_;
153 MockDelayProvider* delay_; 162 MockDelayProvider* delay_;
154 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_; 163 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_;
155 MockDirectorySetterUpper syncdb_; 164 MockDirectorySetterUpper syncdb_;
156 }; 165 };
157 166
158 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record, 167 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record,
159 size_t signal_after) { 168 size_t signal_after) {
160 record->times.push_back(TimeTicks::Now()); 169 record->times.push_back(TimeTicks::Now());
(...skipping 11 matching lines...) Expand all
172 if (RecordSyncShareImpl(arg0, record, signal_after) && event) 181 if (RecordSyncShareImpl(arg0, record, signal_after) && event)
173 event->Signal(); 182 event->Signal();
174 } 183 }
175 184
176 ACTION_P(SignalEvent, event) { 185 ACTION_P(SignalEvent, event) {
177 SyncerThread2Test::SignalWaitableEvent(event); 186 SyncerThread2Test::SignalWaitableEvent(event);
178 } 187 }
179 188
180 // Test nudge scheduling. 189 // Test nudge scheduling.
181 TEST_F(SyncerThread2Test, Nudge) { 190 TEST_F(SyncerThread2Test, Nudge) {
182 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 191 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
183 base::WaitableEvent done(false, false); 192 base::WaitableEvent done(false, false);
184 SyncShareRecords records; 193 SyncShareRecords records;
185 syncable::ModelTypeBitSet model_types; 194 syncable::ModelTypeBitSet model_types;
186 model_types[syncable::BOOKMARKS] = true; 195 model_types[syncable::BOOKMARKS] = true;
187 196
188 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 197 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
189 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 198 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
190 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) 199 WithArg<0>(RecordSyncShare(&records, 1U, &done))))
191 .RetiresOnSaturation(); 200 .RetiresOnSaturation();
192 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); 201 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types);
(...skipping 17 matching lines...) Expand all
210 219
211 EXPECT_EQ(1U, records2.snapshots.size()); 220 EXPECT_EQ(1U, records2.snapshots.size());
212 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, 221 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types,
213 records2.snapshots[0]->source.types)); 222 records2.snapshots[0]->source.types));
214 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 223 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
215 records2.snapshots[0]->source.updates_source); 224 records2.snapshots[0]->source.updates_source);
216 } 225 }
217 226
218 // Test that nudges are coalesced. 227 // Test that nudges are coalesced.
219 TEST_F(SyncerThread2Test, NudgeCoalescing) { 228 TEST_F(SyncerThread2Test, NudgeCoalescing) {
220 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 229 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
221 base::WaitableEvent done(false, false); 230 base::WaitableEvent done(false, false);
222 SyncShareRecords r; 231 SyncShareRecords r;
223 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 232 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
224 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 233 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
225 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); 234 WithArg<0>(RecordSyncShare(&r, 1U, &done))));
226 syncable::ModelTypeBitSet types1, types2, types3; 235 syncable::ModelTypeBitSet types1, types2, types3;
227 types1[syncable::BOOKMARKS] = true; 236 types1[syncable::BOOKMARKS] = true;
228 types2[syncable::AUTOFILL] = true; 237 types2[syncable::AUTOFILL] = true;
229 types3[syncable::THEMES] = true; 238 types3[syncable::THEMES] = true;
230 TimeDelta delay = TimeDelta::FromMilliseconds(20); 239 TimeDelta delay = TimeDelta::FromMilliseconds(20);
(...skipping 19 matching lines...) Expand all
250 done.TimedWait(timeout()); 259 done.TimedWait(timeout());
251 EXPECT_EQ(1U, r2.snapshots.size()); 260 EXPECT_EQ(1U, r2.snapshots.size());
252 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(types3, 261 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(types3,
253 r2.snapshots[0]->source.types)); 262 r2.snapshots[0]->source.types));
254 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, 263 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
255 r2.snapshots[0]->source.updates_source); 264 r2.snapshots[0]->source.updates_source);
256 } 265 }
257 266
258 // Test nudge scheduling. 267 // Test nudge scheduling.
259 TEST_F(SyncerThread2Test, NudgeWithPayloads) { 268 TEST_F(SyncerThread2Test, NudgeWithPayloads) {
260 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 269 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
261 base::WaitableEvent done(false, false); 270 base::WaitableEvent done(false, false);
262 SyncShareRecords records; 271 SyncShareRecords records;
263 syncable::ModelTypePayloadMap model_types_with_payloads; 272 syncable::ModelTypePayloadMap model_types_with_payloads;
264 model_types_with_payloads[syncable::BOOKMARKS] = "test"; 273 model_types_with_payloads[syncable::BOOKMARKS] = "test";
265 274
266 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 275 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
267 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 276 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
268 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) 277 WithArg<0>(RecordSyncShare(&records, 1U, &done))))
269 .RetiresOnSaturation(); 278 .RetiresOnSaturation();
270 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, 279 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL,
(...skipping 17 matching lines...) Expand all
288 done.TimedWait(timeout()); 297 done.TimedWait(timeout());
289 298
290 EXPECT_EQ(1U, records2.snapshots.size()); 299 EXPECT_EQ(1U, records2.snapshots.size());
291 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0]->source.types); 300 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0]->source.types);
292 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 301 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
293 records2.snapshots[0]->source.updates_source); 302 records2.snapshots[0]->source.updates_source);
294 } 303 }
295 304
296 // Test that nudges are coalesced. 305 // Test that nudges are coalesced.
297 TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) { 306 TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) {
298 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 307 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
299 base::WaitableEvent done(false, false); 308 base::WaitableEvent done(false, false);
300 SyncShareRecords r; 309 SyncShareRecords r;
301 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 310 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
302 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
303 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); 312 WithArg<0>(RecordSyncShare(&r, 1U, &done))));
304 syncable::ModelTypePayloadMap types1, types2, types3; 313 syncable::ModelTypePayloadMap types1, types2, types3;
305 types1[syncable::BOOKMARKS] = "test1"; 314 types1[syncable::BOOKMARKS] = "test1";
306 types2[syncable::AUTOFILL] = "test2"; 315 types2[syncable::AUTOFILL] = "test2";
307 types3[syncable::THEMES] = "test3"; 316 types3[syncable::THEMES] = "test3";
308 TimeDelta delay = TimeDelta::FromMilliseconds(20); 317 TimeDelta delay = TimeDelta::FromMilliseconds(20);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 TEST_F(SyncerThread2Test, Polling) { 351 TEST_F(SyncerThread2Test, Polling) {
343 SyncShareRecords records; 352 SyncShareRecords records;
344 base::WaitableEvent done(false, false); 353 base::WaitableEvent done(false, false);
345 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 354 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
346 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll_interval); 355 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll_interval);
347 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 356 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
348 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 357 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
349 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); 358 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done))));
350 359
351 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 360 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
352 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 361 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
353 done.TimedWait(timeout()); 362 done.TimedWait(timeout());
354 syncer_thread()->Stop(); 363 syncer_thread()->Stop();
355 364
356 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 365 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
357 } 366 }
358 367
359 // Test that the short poll interval is used. 368 // Test that the short poll interval is used.
360 TEST_F(SyncerThread2Test, PollNotificationsDisabled) { 369 TEST_F(SyncerThread2Test, PollNotificationsDisabled) {
361 SyncShareRecords records; 370 SyncShareRecords records;
362 base::WaitableEvent done(false, false); 371 base::WaitableEvent done(false, false);
363 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 372 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
364 syncer_thread()->OnReceivedShortPollIntervalUpdate(poll_interval); 373 syncer_thread()->OnReceivedShortPollIntervalUpdate(poll_interval);
365 syncer_thread()->set_notifications_enabled(false); 374 syncer_thread()->set_notifications_enabled(false);
366 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 375 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
367 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 376 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
368 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); 377 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done))));
369 378
370 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 379 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
371 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 380 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
372 done.TimedWait(timeout()); 381 done.TimedWait(timeout());
373 syncer_thread()->Stop(); 382 syncer_thread()->Stop();
374 383
375 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 384 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
376 } 385 }
377 386
378 // Test that polling intervals are updated when needed. 387 // Test that polling intervals are updated when needed.
379 TEST_F(SyncerThread2Test, PollIntervalUpdate) { 388 TEST_F(SyncerThread2Test, PollIntervalUpdate) {
380 SyncShareRecords records; 389 SyncShareRecords records;
381 base::WaitableEvent done(false, false); 390 base::WaitableEvent done(false, false);
382 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); 391 TimeDelta poll1(TimeDelta::FromMilliseconds(120));
383 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); 392 TimeDelta poll2(TimeDelta::FromMilliseconds(30));
384 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll1); 393 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll1);
385 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 394 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
386 .WillOnce(WithArg<0>( 395 .WillOnce(WithArg<0>(
387 sessions::test_util::SimulatePollIntervalUpdate(poll2))) 396 sessions::test_util::SimulatePollIntervalUpdate(poll2)))
388 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 397 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
389 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); 398 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done))));
390 399
391 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; 400 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2;
392 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 401 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
393 done.TimedWait(timeout()); 402 done.TimedWait(timeout());
394 syncer_thread()->Stop(); 403 syncer_thread()->Stop();
395 404
396 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); 405 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2);
397 } 406 }
398 407
399 // Test that a sync session is run through to completion. 408 // Test that a sync session is run through to completion.
400 TEST_F(SyncerThread2Test, HasMoreToSync) { 409 TEST_F(SyncerThread2Test, HasMoreToSync) {
401 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 410 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
402 base::WaitableEvent done(false, false); 411 base::WaitableEvent done(false, false);
403 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 412 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
404 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) 413 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync))
405 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 414 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
406 SignalEvent(&done))); 415 SignalEvent(&done)));
407 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); 416 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet());
408 done.TimedWait(timeout()); 417 done.TimedWait(timeout());
409 // If more nudges are scheduled, they'll be waited on by TearDown, and would 418 // If more nudges are scheduled, they'll be waited on by TearDown, and would
410 // cause our expectation to break. 419 // cause our expectation to break.
411 } 420 }
412 421
413 // Test that no syncing occurs when throttled. 422 // Test that no syncing occurs when throttled.
414 TEST_F(SyncerThread2Test, ThrottlingDoesThrottle) { 423 TEST_F(SyncerThread2Test, ThrottlingDoesThrottle) {
415 syncable::ModelTypeBitSet types; 424 syncable::ModelTypeBitSet types;
416 types[syncable::BOOKMARKS] = true; 425 types[syncable::BOOKMARKS] = true;
417 base::WaitableEvent done(false, false); 426 base::WaitableEvent done(false, false);
418 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 427 TimeDelta poll(TimeDelta::FromMilliseconds(5));
419 TimeDelta throttle(TimeDelta::FromMinutes(10)); 428 TimeDelta throttle(TimeDelta::FromMinutes(10));
420 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 429 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
421 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 430 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
422 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))); 431 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)));
423 432
424 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 433 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
425 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); 434 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types);
426 FlushLastTask(&done); 435 FlushLastTask(&done);
427 436
428 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); 437 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL);
429 syncer_thread()->ScheduleConfig(types); 438 syncer_thread()->ScheduleConfig(types);
430 FlushLastTask(&done); 439 FlushLastTask(&done);
431 } 440 }
432 441
433 TEST_F(SyncerThread2Test, ThrottlingExpires) { 442 TEST_F(SyncerThread2Test, ThrottlingExpires) {
434 SyncShareRecords records; 443 SyncShareRecords records;
435 base::WaitableEvent done(false, false); 444 base::WaitableEvent done(false, false);
436 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 445 TimeDelta poll(TimeDelta::FromMilliseconds(15));
437 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 446 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
438 TimeDelta throttle2(TimeDelta::FromMinutes(10)); 447 TimeDelta throttle2(TimeDelta::FromMinutes(10));
439 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 448 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
440 449
441 ::testing::InSequence seq; 450 ::testing::InSequence seq;
442 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 451 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
443 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) 452 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)))
444 .RetiresOnSaturation(); 453 .RetiresOnSaturation();
445 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 454 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
446 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 455 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
447 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); 456 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done))));
448 457
449 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; 458 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
450 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 459 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
451 done.TimedWait(timeout()); 460 done.TimedWait(timeout());
452 syncer_thread()->Stop(); 461 syncer_thread()->Stop();
453 462
454 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); 463 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll);
455 } 464 }
456 465
457 // Test nudges / polls don't run in config mode and config tasks do. 466 // Test nudges / polls don't run in config mode and config tasks do.
458 TEST_F(SyncerThread2Test, ConfigurationMode) { 467 TEST_F(SyncerThread2Test, ConfigurationMode) {
459 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 468 TimeDelta poll(TimeDelta::FromMilliseconds(15));
460 SyncShareRecords records; 469 SyncShareRecords records;
461 base::WaitableEvent done(false, false); 470 base::WaitableEvent done(false, false);
462 base::WaitableEvent* dummy = NULL; 471 base::WaitableEvent* dummy = NULL;
463 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 472 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
464 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 473 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
465 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 474 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
466 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))); 475 WithArg<0>(RecordSyncShare(&records, 1U, dummy))));
467 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); 476 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL);
468 syncable::ModelTypeBitSet nudge_types; 477 syncable::ModelTypeBitSet nudge_types;
469 nudge_types[syncable::AUTOFILL] = true; 478 nudge_types[syncable::AUTOFILL] = true;
470 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); 479 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types);
471 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); 480 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types);
472 481
473 syncable::ModelTypeBitSet config_types; 482 syncable::ModelTypeBitSet config_types;
474 config_types[syncable::BOOKMARKS] = true; 483 config_types[syncable::BOOKMARKS] = true;
475 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update 484 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update
476 // the EXPECT when that happens. 485 // the EXPECT when that happens.
477 syncer_thread()->ScheduleConfig(config_types); 486 syncer_thread()->ScheduleConfig(config_types);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 types[syncable::BOOKMARKS] = true; 542 types[syncable::BOOKMARKS] = true;
534 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 543 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
535 UseMockDelayProvider(); 544 UseMockDelayProvider();
536 545
537 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2) 546 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2)
538 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 547 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
539 RecordSyncShareAndPostSignal(&r, 2U, this, &done))); 548 RecordSyncShareAndPostSignal(&r, 2U, this, &done)));
540 EXPECT_CALL(*delay(), GetDelay(_)) 549 EXPECT_CALL(*delay(), GetDelay(_))
541 .WillRepeatedly(Return(TimeDelta::FromDays(1))); 550 .WillRepeatedly(Return(TimeDelta::FromDays(1)));
542 551
543 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 552 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
544 ASSERT_TRUE(done.TimedWait(timeout())); 553 ASSERT_TRUE(done.TimedWait(timeout()));
545 done.Reset(); 554 done.Reset();
546 555
547 Mock::VerifyAndClearExpectations(syncer()); 556 Mock::VerifyAndClearExpectations(syncer());
548 EXPECT_EQ(2U, r.snapshots.size()); 557 EXPECT_EQ(2U, r.snapshots.size());
549 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 558 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
550 r.snapshots[0]->source.updates_source); 559 r.snapshots[0]->source.updates_source);
551 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, 560 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION,
552 r.snapshots[1]->source.updates_source); 561 r.snapshots[1]->source.updates_source);
553 562
554 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) 563 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1)
555 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 564 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
556 RecordSyncShareAndPostSignal(&r, 1U, this, &done))); 565 RecordSyncShareAndPostSignal(&r, 1U, this, &done)));
557 566
558 // We schedule a nudge with enough delay (10X poll interval) that at least 567 // We schedule a nudge with enough delay (10X poll interval) that at least
559 // one or two polls would have taken place. The nudge should succeed. 568 // one or two polls would have taken place. The nudge should succeed.
560 syncer_thread()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types); 569 syncer_thread()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types);
561 ASSERT_TRUE(done.TimedWait(timeout())); 570 ASSERT_TRUE(done.TimedWait(timeout()));
562 done.Reset(); 571 done.Reset();
563 572
564 Mock::VerifyAndClearExpectations(syncer()); 573 Mock::VerifyAndClearExpectations(syncer());
565 Mock::VerifyAndClearExpectations(delay()); 574 Mock::VerifyAndClearExpectations(delay());
566 EXPECT_EQ(3U, r.snapshots.size()); 575 EXPECT_EQ(3U, r.snapshots.size());
567 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 576 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
568 r.snapshots[2]->source.updates_source); 577 r.snapshots[2]->source.updates_source);
569 578
570 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); 579 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0);
571 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 580 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
572 581
573 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); 582 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL);
574 syncer_thread()->ScheduleConfig(types); 583 syncer_thread()->ScheduleConfig(types);
575 FlushLastTask(&done); 584 FlushLastTask(&done);
576 585
577 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 586 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
578 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); 587 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types);
579 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); 588 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types);
580 FlushLastTask(&done); 589 FlushLastTask(&done);
581 } 590 }
582 591
583 // Test that backoff is shaping traffic properly with consecutive errors. 592 // Test that backoff is shaping traffic properly with consecutive errors.
584 TEST_F(SyncerThread2Test, BackoffElevation) { 593 TEST_F(SyncerThread2Test, BackoffElevation) {
585 SyncShareRecords r; 594 SyncShareRecords r;
586 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 595 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
587 base::WaitableEvent done(false, false); 596 base::WaitableEvent done(false, false);
(...skipping 11 matching lines...) Expand all
599 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); 608 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done)));
600 609
601 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) 610 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second))
602 .RetiresOnSaturation(); 611 .RetiresOnSaturation();
603 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) 612 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third))
604 .RetiresOnSaturation(); 613 .RetiresOnSaturation();
605 EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth)) 614 EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth))
606 .RetiresOnSaturation(); 615 .RetiresOnSaturation();
607 EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth)); 616 EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth));
608 617
609 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 618 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
610 ASSERT_TRUE(done.TimedWait(timeout())); 619 ASSERT_TRUE(done.TimedWait(timeout()));
611 620
612 EXPECT_GE(r.times[2] - r.times[1], second); 621 EXPECT_GE(r.times[2] - r.times[1], second);
613 EXPECT_GE(r.times[3] - r.times[2], third); 622 EXPECT_GE(r.times[3] - r.times[2], third);
614 EXPECT_GE(r.times[4] - r.times[3], fourth); 623 EXPECT_GE(r.times[4] - r.times[3], fourth);
615 } 624 }
616 625
617 // Test that things go back to normal once a canary task makes forward progress 626 // Test that things go back to normal once a canary task makes forward progress
618 // following a succession of failures. 627 // following a succession of failures.
619 TEST_F(SyncerThread2Test, BackoffRelief) { 628 TEST_F(SyncerThread2Test, BackoffRelief) {
620 SyncShareRecords r; 629 SyncShareRecords r;
621 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 630 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
622 base::WaitableEvent done(false, false); 631 base::WaitableEvent done(false, false);
623 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 632 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
624 UseMockDelayProvider(); 633 UseMockDelayProvider();
625 634
626 const TimeDelta backoff = TimeDelta::FromMilliseconds(100); 635 const TimeDelta backoff = TimeDelta::FromMilliseconds(100);
627 636
628 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 637 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
629 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 638 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed))
630 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 639 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed))
631 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 640 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
632 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); 641 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done)));
633 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); 642 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
634 643
635 // Optimal start for the post-backoff poll party. 644 // Optimal start for the post-backoff poll party.
636 TimeTicks optimal_start = TimeTicks::Now() + poll + backoff; 645 TimeTicks optimal_start = TimeTicks::Now() + poll + backoff;
637 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 646 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
638 done.TimedWait(timeout()); 647 done.TimedWait(timeout());
639 syncer_thread()->Stop(); 648 syncer_thread()->Stop();
640 649
641 // Check for healthy polling after backoff is relieved. 650 // Check for healthy polling after backoff is relieved.
642 // Can't use AnalyzePollRun because first sync is a continuation. Bleh. 651 // Can't use AnalyzePollRun because first sync is a continuation. Bleh.
643 for (size_t i = 0; i < r.times.size(); i++) { 652 for (size_t i = 0; i < r.times.size(); i++) {
644 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); 653 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
645 TimeTicks optimal_next_sync = optimal_start + poll * i; 654 TimeTicks optimal_next_sync = optimal_start + poll * i;
646 EXPECT_GE(r.times[i], optimal_next_sync); 655 EXPECT_GE(r.times[i], optimal_next_sync);
647 EXPECT_EQ(i == 0 ? GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION 656 EXPECT_EQ(i == 0 ? GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION
(...skipping 18 matching lines...) Expand all
666 SyncerThread::GetRecommendedDelay( 675 SyncerThread::GetRecommendedDelay(
667 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); 676 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1)));
668 } 677 }
669 678
670 // Test that appropriate syncer steps are requested for each job type. 679 // Test that appropriate syncer steps are requested for each job type.
671 TEST_F(SyncerThread2Test, SyncerSteps) { 680 TEST_F(SyncerThread2Test, SyncerSteps) {
672 // Nudges. 681 // Nudges.
673 base::WaitableEvent done(false, false); 682 base::WaitableEvent done(false, false);
674 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 683 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
675 .Times(1); 684 .Times(1);
676 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 685 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
677 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); 686 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet());
678 FlushLastTask(&done); 687 FlushLastTask(&done);
679 syncer_thread()->Stop(); 688 syncer_thread()->Stop();
680 Mock::VerifyAndClearExpectations(syncer()); 689 Mock::VerifyAndClearExpectations(syncer());
681 690
682 // ClearUserData. 691 // ClearUserData.
683 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, SYNCER_END)) 692 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, SYNCER_END))
684 .Times(1); 693 .Times(1);
685 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 694 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
686 syncer_thread()->ScheduleClearUserData(); 695 syncer_thread()->ScheduleClearUserData();
687 FlushLastTask(&done); 696 FlushLastTask(&done);
688 syncer_thread()->Stop(); 697 syncer_thread()->Stop();
689 Mock::VerifyAndClearExpectations(syncer()); 698 Mock::VerifyAndClearExpectations(syncer());
690
691 // Configuration. 699 // Configuration.
692 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); 700 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES));
693 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); 701 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL);
694 syncer_thread()->ScheduleConfig(ModelTypeBitSet()); 702 syncer_thread()->ScheduleConfig(ModelTypeBitSet());
695 FlushLastTask(&done); 703 FlushLastTask(&done);
696 syncer_thread()->Stop(); 704 syncer_thread()->Stop();
697 Mock::VerifyAndClearExpectations(syncer()); 705 Mock::VerifyAndClearExpectations(syncer());
698 706
699 // Poll. 707 // Poll.
700 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 708 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
701 .Times(AtLeast(1)) 709 .Times(AtLeast(1))
702 .WillRepeatedly(SignalEvent(&done)); 710 .WillRepeatedly(SignalEvent(&done));
703 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 711 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
704 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); 712 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll);
705 syncer_thread()->Start(SyncerThread::NORMAL_MODE); 713 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
706 done.TimedWait(timeout()); 714 done.TimedWait(timeout());
707 syncer_thread()->Stop(); 715 syncer_thread()->Stop();
708 Mock::VerifyAndClearExpectations(syncer()); 716 Mock::VerifyAndClearExpectations(syncer());
709 done.Reset(); 717 done.Reset();
710 } 718 }
711 719
712 // Test config tasks don't run during normal mode. 720 // Test config tasks don't run during normal mode.
713 // TODO(tim): Implement this test and then the functionality! 721 // TODO(tim): Implement this test and then the functionality!
714 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { 722 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) {
715 } 723 }
716 724
717 // Test that starting the syncer thread without a valid connection doesn't 725 // Test that starting the syncer thread without a valid connection doesn't
718 // break things when a connection is detected. 726 // break things when a connection is detected.
719 // Test config tasks don't run during normal mode. 727 TEST_F(SyncerThread2Test, StartWhenNotConnected) {
720 // TODO(tim): Implement this test and then the functionality! 728 base::WaitableEvent done(false, false);
721 TEST_F(SyncerThread2Test, DISABLED_StartWhenNotConnected) { 729 MessageLoop cur;
730 connection()->SetServerNotReachable();
731 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
732 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet());
733 FlushLastTask(&done);
722 734
735 connection()->SetServerReachable();
736 cur.PostTask(FROM_HERE, NewRunnableFunction(
737 &SyncerThread2Test::QuitMessageLoop));
738 cur.Run();
739
740 // By now, the server connection event should have been posted to the
741 // SyncerThread.
742 FlushLastTask(&done);
743 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(SignalEvent(&done));
744 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet());
745 done.TimedWait(timeout());
746 }
747
748 TEST_F(SyncerThread2Test, SetsPreviousRoutingInfo) {
749 base::WaitableEvent done(false, false);
750 ModelSafeRoutingInfo info;
751 EXPECT_TRUE(info == context()->previous_session_routing_info());
752 ModelSafeRoutingInfo expected;
753 context()->registrar()->GetModelSafeRoutingInfo(&expected);
754 ASSERT_FALSE(expected.empty());
755 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1);
756
757 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
758 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet());
759 FlushLastTask(&done);
760 syncer_thread()->Stop();
761
762 EXPECT_TRUE(expected == context()->previous_session_routing_info());
723 } 763 }
724 764
725 } // namespace s3 765 } // namespace s3
726 } // namespace browser_sync 766 } // namespace browser_sync
727 767
728 // SyncerThread won't outlive the test! 768 // SyncerThread won't outlive the test!
729 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); 769 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test);
730
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_thread2.cc ('k') | chrome/browser/sync/engine/syncer_thread_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698