Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 namespace s3 { | 40 namespace s3 { |
| 41 | 41 |
| 42 // Used when tests want to record syncing activity to examine later. | 42 // Used when tests want to record syncing activity to examine later. |
| 43 struct SyncShareRecords { | 43 struct SyncShareRecords { |
| 44 std::vector<TimeTicks> times; | 44 std::vector<TimeTicks> times; |
| 45 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; | 45 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 48 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
| 49 static const size_t kMinNumSamples = 5; | 49 static const size_t kMinNumSamples = 5; |
| 50 | 50 struct SyncerThread::SyncSessionJob; |
| 51 struct SyncerThread::WaitInterval; | |
| 51 class SyncerThread2Test : public testing::Test { | 52 class SyncerThread2Test : public testing::Test { |
| 52 public: | 53 public: |
| 53 class MockDelayProvider : public SyncerThread::DelayProvider { | 54 class MockDelayProvider : public SyncerThread::DelayProvider { |
| 54 public: | 55 public: |
| 55 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 56 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 virtual void SetUp() { | 59 virtual void SetUp() { |
| 59 syncdb_.SetUp(); | 60 syncdb_.SetUp(); |
| 60 syncer_ = new MockSyncer(); | 61 syncer_ = new MockSyncer(); |
| 61 delay_ = NULL; | 62 delay_ = NULL; |
| 62 registrar_.reset(MockModelSafeWorkerRegistrar::PassiveBookmarks()); | 63 registrar_.reset(MockModelSafeWorkerRegistrar::PassiveBookmarks()); |
| 63 connection_.reset(new MockConnectionManager(syncdb_.manager(), "Test")); | 64 connection_.reset(new MockConnectionManager(syncdb_.manager(), "Test")); |
| 64 connection_->SetServerReachable(); | 65 connection_->SetServerReachable(); |
| 65 context_ = new SyncSessionContext(connection_.get(), syncdb_.manager(), | 66 context_ = new SyncSessionContext(connection_.get(), syncdb_.manager(), |
| 66 registrar_.get(), std::vector<SyncEngineEventListener*>()); | 67 registrar_.get(), std::vector<SyncEngineEventListener*>()); |
| 67 context_->set_notifications_enabled(true); | 68 context_->set_notifications_enabled(true); |
| 68 context_->set_account_name("Test"); | 69 context_->set_account_name("Test"); |
| 69 syncer_thread_.reset(new SyncerThread(context_, syncer_)); | 70 syncer_thread_.reset(new SyncerThread(context_, syncer_)); |
| 70 } | 71 } |
| 71 | 72 |
| 73 virtual void SetUpWithTypes(syncable::ModelTypeBitSet types) { | |
| 74 syncdb_.SetUp(); | |
| 75 syncer_ = new MockSyncer(); | |
| 76 delay_ = NULL; | |
| 77 registrar_.reset(MockModelSafeWorkerRegistrar::SetPassiveTypes(types)); | |
| 78 connection_.reset(new MockConnectionManager(syncdb_.manager(), "Test")); | |
| 79 connection_->SetServerReachable(); | |
| 80 context_ = new SyncSessionContext(connection_.get(), syncdb_.manager(), | |
| 81 registrar_.get(), std::vector<SyncEngineEventListener*>()); | |
| 82 context_->set_notifications_enabled(true); | |
| 83 context_->set_account_name("Test"); | |
| 84 syncer_thread_.reset(new SyncerThread(context_, syncer_)); | |
| 85 } | |
| 86 | |
| 72 SyncerThread* syncer_thread() { return syncer_thread_.get(); } | 87 SyncerThread* syncer_thread() { return syncer_thread_.get(); } |
| 73 MockSyncer* syncer() { return syncer_; } | 88 MockSyncer* syncer() { return syncer_; } |
| 74 MockDelayProvider* delay() { return delay_; } | 89 MockDelayProvider* delay() { return delay_; } |
| 75 MockConnectionManager* connection() { return connection_.get(); } | 90 MockConnectionManager* connection() { return connection_.get(); } |
| 76 TimeDelta zero() { return TimeDelta::FromSeconds(0); } | 91 TimeDelta zero() { return TimeDelta::FromSeconds(0); } |
| 77 TimeDelta timeout() { | 92 TimeDelta timeout() { |
| 78 return TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()); | 93 return TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()); |
| 79 } | 94 } |
| 80 | 95 |
| 81 virtual void TearDown() { | 96 virtual void TearDown() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 if (!lhs.test(i->first)) | 163 if (!lhs.test(i->first)) |
| 149 return false; | 164 return false; |
| 150 } | 165 } |
| 151 if (lhs.count() != count) | 166 if (lhs.count() != count) |
| 152 return false; | 167 return false; |
| 153 return true; | 168 return true; |
| 154 } | 169 } |
| 155 | 170 |
| 156 SyncSessionContext* context() { return context_; } | 171 SyncSessionContext* context() { return context_; } |
| 157 | 172 |
| 173 void SetMode(SyncerThread::Mode mode) { | |
| 174 syncer_thread_->mode_ = mode; | |
|
tim (not reviewing)
2011/04/09 23:52:58
it seems bad / dangerous to have all these setters
lipalani1
2011/04/12 02:33:00
Moved to a different file.
On 2011/04/09 23:52:58,
| |
| 175 } | |
| 176 | |
| 177 void SetLastSyncedTime(base::TimeTicks ticks) { | |
| 178 syncer_thread_->last_sync_session_end_time_ = ticks; | |
| 179 } | |
| 180 | |
| 181 void SetServerConnection(bool connected) { | |
| 182 syncer_thread_->server_connection_ok_ = connected; | |
| 183 } | |
| 184 | |
| 185 void ResetWaitInterval() { | |
| 186 syncer_thread_->wait_interval_.reset(); | |
| 187 } | |
| 188 | |
| 189 void SetWaitIntervalToThrottled() { | |
|
tim (not reviewing)
2011/04/09 23:52:58
the existing tests would set this state naturally
lipalani1
2011/04/12 02:33:00
This is moved to a different file. It is needed th
| |
| 190 syncer_thread_->wait_interval_.reset(new SyncerThread::WaitInterval( | |
| 191 SyncerThread::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); | |
| 192 } | |
| 193 | |
| 194 void SetWaitIntervalToExponentialBackoff() { | |
| 195 syncer_thread_->wait_interval_.reset( | |
| 196 new SyncerThread::WaitInterval( | |
| 197 SyncerThread::WaitInterval::EXPONENTIAL_BACKOFF, | |
| 198 TimeDelta::FromSeconds(1))); | |
| 199 } | |
| 200 | |
| 201 SyncerThread::JobProcessDecision DecideOnJob( | |
| 202 const SyncerThread::SyncSessionJob& job) { | |
| 203 return syncer_thread_->DecideOnJob(job); | |
| 204 } | |
| 205 | |
| 206 void InitializeSyncerOnNormalMode() { | |
| 207 SetMode(SyncerThread::NORMAL_MODE); | |
| 208 ResetWaitInterval(); | |
| 209 SetServerConnection(true); | |
| 210 SetLastSyncedTime(base::TimeTicks::Now()); | |
| 211 } | |
| 212 | |
| 213 SyncerThread::JobProcessDecision CreateAndDecideJob( | |
| 214 SyncerThread::SyncSessionJobPurpose purpose) { | |
| 215 struct SyncerThread::SyncSessionJob job; | |
| 216 job.purpose = purpose; | |
| 217 job.scheduled_start = TimeTicks::Now(); | |
| 218 return DecideOnJob(job); | |
| 219 } | |
| 220 | |
| 221 protected: | |
| 222 scoped_ptr<SyncerThread> syncer_thread_; | |
| 223 | |
| 158 private: | 224 private: |
| 159 scoped_ptr<SyncerThread> syncer_thread_; | |
| 160 scoped_ptr<MockConnectionManager> connection_; | 225 scoped_ptr<MockConnectionManager> connection_; |
| 161 SyncSessionContext* context_; | 226 SyncSessionContext* context_; |
| 162 MockSyncer* syncer_; | 227 MockSyncer* syncer_; |
| 163 MockDelayProvider* delay_; | 228 MockDelayProvider* delay_; |
| 164 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_; | 229 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_; |
| 165 MockDirectorySetterUpper syncdb_; | 230 MockDirectorySetterUpper syncdb_; |
| 166 }; | 231 }; |
| 167 | 232 |
| 168 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record, | 233 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record, |
| 169 size_t signal_after) { | 234 size_t signal_after) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 FROM_HERE); | 285 FROM_HERE); |
| 221 done.TimedWait(timeout()); | 286 done.TimedWait(timeout()); |
| 222 | 287 |
| 223 EXPECT_EQ(1U, records2.snapshots.size()); | 288 EXPECT_EQ(1U, records2.snapshots.size()); |
| 224 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | 289 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, |
| 225 records2.snapshots[0]->source.types)); | 290 records2.snapshots[0]->source.types)); |
| 226 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 291 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 227 records2.snapshots[0]->source.updates_source); | 292 records2.snapshots[0]->source.updates_source); |
| 228 } | 293 } |
| 229 | 294 |
| 295 TEST_F(SyncerThread2Test, Config) { | |
| 296 base::WaitableEvent done(false, false); | |
| 297 SyncShareRecords records; | |
| 298 syncable::ModelTypeBitSet model_types; | |
| 299 model_types[syncable::BOOKMARKS] = true; | |
| 300 | |
| 301 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 302 | |
| 303 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
|
tim (not reviewing)
2011/04/09 23:52:58
In general it's bad to have the expectations befor
lipalani1
2011/04/12 02:33:00
Good point. Even if they were thread safe expectat
| |
| 304 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 305 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 306 syncer_thread()->ScheduleConfig(model_types); | |
| 307 done.TimedWait(timeout()); | |
| 308 | |
| 309 EXPECT_EQ(1U, records.snapshots.size()); | |
| 310 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 311 records.snapshots[0]->source.types)); | |
| 312 EXPECT_EQ(GetUpdatesCallerInfo::FIRST_UPDATE, | |
| 313 records.snapshots[0]->source.updates_source); | |
| 314 } | |
| 315 | |
| 316 TEST_F(SyncerThread2Test, ConfigWithBackingOff) { | |
| 317 base::WaitableEvent done(false, false); | |
| 318 base::WaitableEvent* dummy = NULL; | |
| 319 UseMockDelayProvider(); | |
| 320 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 321 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | |
| 322 SyncShareRecords records; | |
| 323 syncable::ModelTypeBitSet model_types; | |
| 324 model_types[syncable::BOOKMARKS] = true; | |
| 325 | |
| 326 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 327 | |
| 328 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 329 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 330 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 331 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 332 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 333 syncer_thread()->ScheduleConfig(model_types); | |
| 334 done.TimedWait(timeout()); | |
| 335 | |
| 336 EXPECT_EQ(2U, records.snapshots.size()); | |
| 337 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 338 records.snapshots[1]->source.types)); | |
| 339 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | |
| 340 records.snapshots[1]->source.updates_source); | |
| 341 } | |
| 342 | |
| 343 TEST_F(SyncerThread2Test, MultipleConfigWithBackingOff) { | |
| 344 syncable::ModelTypeBitSet model_types1, model_types2; | |
| 345 model_types1[syncable::BOOKMARKS] = true; | |
| 346 model_types2[syncable::AUTOFILL] = true; | |
| 347 SetUpWithTypes(model_types1 | model_types2); | |
| 348 base::WaitableEvent done(false, false); | |
| 349 base::WaitableEvent done1(false, false); | |
| 350 base::WaitableEvent* dummy = NULL; | |
| 351 UseMockDelayProvider(); | |
| 352 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 353 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); | |
| 354 SyncShareRecords records; | |
| 355 | |
| 356 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 357 | |
| 358 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 359 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 360 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 361 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 362 WithArg<0>(RecordSyncShare(&records, 1U, &done1)))) | |
| 363 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 364 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 365 syncer_thread()->ScheduleConfig(model_types1); | |
| 366 done1.TimedWait(timeout()); | |
| 367 syncer_thread()->ScheduleConfig(model_types2); | |
| 368 done.TimedWait(timeout()); | |
| 369 | |
|
tim (not reviewing)
2011/04/09 23:52:58
how come all these tests now wait after each post.
lipalani1
2011/04/12 02:33:00
Comments added explaining the rationale for them.
| |
| 370 EXPECT_EQ(3U, records.snapshots.size()); | |
| 371 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types2, | |
| 372 records.snapshots[2]->source.types)); | |
| 373 EXPECT_EQ(GetUpdatesCallerInfo::FIRST_UPDATE, | |
| 374 records.snapshots[2]->source.updates_source); | |
| 375 } | |
| 376 | |
| 377 TEST_F(SyncerThread2Test, NudgeWithConfigWithBackingOff) { | |
|
tim (not reviewing)
2011/04/09 23:52:58
it's not clear what is being tested here versus Ba
lipalani1
2011/04/12 02:33:00
I have added comments. In short backoffdropjobs te
| |
| 378 syncable::ModelTypeBitSet model_types; | |
| 379 model_types[syncable::BOOKMARKS] = true; | |
| 380 base::WaitableEvent done(false, false); | |
| 381 base::WaitableEvent done1(false, false); | |
| 382 base::WaitableEvent done2(false, false); | |
| 383 base::WaitableEvent* dummy = NULL; | |
| 384 UseMockDelayProvider(); | |
| 385 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 386 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | |
| 387 SyncShareRecords records; | |
| 388 | |
| 389 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 390 | |
| 391 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 393 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 394 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 395 WithArg<0>(RecordSyncShare(&records, 1U, &done1)))) | |
| 396 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 397 WithArg<0>(RecordSyncShare(&records, 1U, &done2)))) | |
| 398 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 399 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 400 | |
| 401 syncer_thread()->ScheduleConfig(model_types); | |
| 402 done1.TimedWait(timeout()); | |
| 403 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types, | |
| 404 FROM_HERE); | |
| 405 done2.TimedWait(timeout()); | |
| 406 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | |
| 407 done.TimedWait(timeout()); | |
| 408 EXPECT_EQ(4U, records.snapshots.size()); | |
| 409 | |
| 410 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 411 records.snapshots[2]->source.types)); | |
| 412 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | |
| 413 records.snapshots[2]->source.updates_source); | |
| 414 | |
| 415 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 416 records.snapshots[3]->source.types)); | |
| 417 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 418 records.snapshots[3]->source.updates_source); | |
| 419 | |
| 420 } | |
| 421 | |
| 422 | |
| 230 // Test that nudges are coalesced. | 423 // Test that nudges are coalesced. |
| 231 TEST_F(SyncerThread2Test, NudgeCoalescing) { | 424 TEST_F(SyncerThread2Test, NudgeCoalescing) { |
| 232 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 425 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 233 base::WaitableEvent done(false, false); | 426 base::WaitableEvent done(false, false); |
| 234 SyncShareRecords r; | 427 SyncShareRecords r; |
| 235 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 428 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 236 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 429 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 237 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); | 430 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); |
| 238 syncable::ModelTypeBitSet types1, types2, types3; | 431 syncable::ModelTypeBitSet types1, types2, types3; |
| 239 types1[syncable::BOOKMARKS] = true; | 432 types1[syncable::BOOKMARKS] = true; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 } | 666 } |
| 474 | 667 |
| 475 // Test nudges / polls don't run in config mode and config tasks do. | 668 // Test nudges / polls don't run in config mode and config tasks do. |
| 476 TEST_F(SyncerThread2Test, ConfigurationMode) { | 669 TEST_F(SyncerThread2Test, ConfigurationMode) { |
| 477 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 670 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 478 SyncShareRecords records; | 671 SyncShareRecords records; |
| 479 base::WaitableEvent done(false, false); | 672 base::WaitableEvent done(false, false); |
| 480 base::WaitableEvent* dummy = NULL; | 673 base::WaitableEvent* dummy = NULL; |
| 481 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 674 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 482 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 675 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 483 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 676 .WillOnce((Invoke(sessions::test_util::SimulateSuccess), |
| 484 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))); | 677 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))); |
| 485 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | 678 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); |
| 679 FlushLastTask(&done); | |
|
tim (not reviewing)
2011/04/09 23:52:58
Why are there calls to this sprinkled over this te
lipalani1
2011/04/12 02:33:00
argh. failed to remove something I was playing wit
| |
| 486 syncable::ModelTypeBitSet nudge_types; | 680 syncable::ModelTypeBitSet nudge_types; |
| 487 nudge_types[syncable::AUTOFILL] = true; | 681 nudge_types[syncable::AUTOFILL] = true; |
| 488 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, | 682 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, |
| 489 FROM_HERE); | 683 FROM_HERE); |
| 684 FlushLastTask(&done); | |
| 490 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, | 685 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, |
| 491 FROM_HERE); | 686 FROM_HERE); |
| 492 | 687 |
| 688 FlushLastTask(&done); | |
| 493 syncable::ModelTypeBitSet config_types; | 689 syncable::ModelTypeBitSet config_types; |
| 494 config_types[syncable::BOOKMARKS] = true; | 690 config_types[syncable::BOOKMARKS] = true; |
| 495 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update | 691 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update |
| 496 // the EXPECT when that happens. | 692 // the EXPECT when that happens. |
| 497 syncer_thread()->ScheduleConfig(config_types); | 693 syncer_thread()->ScheduleConfig(config_types); |
| 498 FlushLastTask(&done); | 694 FlushLastTask(&done); |
| 499 syncer_thread()->Stop(); | 695 syncer_thread()->Stop(); |
| 500 | 696 |
| 501 EXPECT_EQ(1U, records.snapshots.size()); | 697 EXPECT_EQ(1U, records.snapshots.size()); |
| 502 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(config_types, | 698 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(config_types, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 // TODO(tim): Implement this test and then the functionality! | 932 // TODO(tim): Implement this test and then the functionality! |
| 737 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { | 933 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { |
| 738 } | 934 } |
| 739 | 935 |
| 740 // Test that starting the syncer thread without a valid connection doesn't | 936 // Test that starting the syncer thread without a valid connection doesn't |
| 741 // break things when a connection is detected. | 937 // break things when a connection is detected. |
| 742 TEST_F(SyncerThread2Test, StartWhenNotConnected) { | 938 TEST_F(SyncerThread2Test, StartWhenNotConnected) { |
| 743 base::WaitableEvent done(false, false); | 939 base::WaitableEvent done(false, false); |
| 744 MessageLoop cur; | 940 MessageLoop cur; |
| 745 connection()->SetServerNotReachable(); | 941 connection()->SetServerNotReachable(); |
| 942 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(SignalEvent(&done)); | |
| 746 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 943 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 747 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), | 944 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), |
| 748 FROM_HERE); | 945 FROM_HERE); |
| 749 FlushLastTask(&done); | 946 FlushLastTask(&done); |
| 750 | 947 |
| 751 connection()->SetServerReachable(); | 948 connection()->SetServerReachable(); |
| 752 cur.PostTask(FROM_HERE, NewRunnableFunction( | 949 cur.PostTask(FROM_HERE, NewRunnableFunction( |
| 753 &SyncerThread2Test::QuitMessageLoop)); | 950 &SyncerThread2Test::QuitMessageLoop)); |
| 754 cur.Run(); | 951 cur.Run(); |
| 755 | 952 |
| 756 // By now, the server connection event should have been posted to the | 953 // By now, the server connection event should have been posted to the |
| 757 // SyncerThread. | 954 // SyncerThread. |
| 758 FlushLastTask(&done); | 955 FlushLastTask(&done); |
| 759 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(SignalEvent(&done)); | |
| 760 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), | |
| 761 FROM_HERE); | |
| 762 done.TimedWait(timeout()); | 956 done.TimedWait(timeout()); |
| 763 } | 957 } |
| 764 | 958 |
| 765 TEST_F(SyncerThread2Test, SetsPreviousRoutingInfo) { | 959 TEST_F(SyncerThread2Test, SetsPreviousRoutingInfo) { |
| 766 base::WaitableEvent done(false, false); | 960 base::WaitableEvent done(false, false); |
| 767 ModelSafeRoutingInfo info; | 961 ModelSafeRoutingInfo info; |
| 768 EXPECT_TRUE(info == context()->previous_session_routing_info()); | 962 EXPECT_TRUE(info == context()->previous_session_routing_info()); |
| 769 ModelSafeRoutingInfo expected; | 963 ModelSafeRoutingInfo expected; |
| 770 context()->registrar()->GetModelSafeRoutingInfo(&expected); | 964 context()->registrar()->GetModelSafeRoutingInfo(&expected); |
| 771 ASSERT_FALSE(expected.empty()); | 965 ASSERT_FALSE(expected.empty()); |
| 772 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); | 966 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); |
| 773 | 967 |
| 774 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 968 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 775 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), | 969 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), |
| 776 FROM_HERE); | 970 FROM_HERE); |
| 777 FlushLastTask(&done); | 971 FlushLastTask(&done); |
| 778 syncer_thread()->Stop(); | 972 syncer_thread()->Stop(); |
| 779 | 973 |
| 780 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 974 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
| 781 } | 975 } |
| 782 | 976 |
| 977 TEST_F(SyncerThread2Test, SaveNudge) { | |
| 978 InitializeSyncerOnNormalMode(); | |
| 979 | |
| 980 // Now set the mode to configure. | |
| 981 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 982 | |
| 983 SyncerThread::JobProcessDecision decision = | |
| 984 CreateAndDecideJob(SyncerThread::NUDGE); | |
| 985 | |
| 986 DCHECK_EQ(decision, SyncerThread::SAVE); | |
| 987 } | |
| 988 | |
| 989 TEST_F(SyncerThread2Test, ContinueNudge) { | |
| 990 InitializeSyncerOnNormalMode(); | |
| 991 | |
| 992 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 993 SyncerThread::NUDGE); | |
| 994 | |
| 995 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 996 } | |
| 997 | |
| 998 TEST_F(SyncerThread2Test, DropPoll) { | |
| 999 InitializeSyncerOnNormalMode(); | |
| 1000 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1001 | |
| 1002 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1003 SyncerThread::POLL); | |
| 1004 | |
| 1005 DCHECK_EQ(decision, SyncerThread::DROP); | |
| 1006 } | |
| 1007 | |
| 1008 TEST_F(SyncerThread2Test, ContinuePoll) { | |
| 1009 InitializeSyncerOnNormalMode(); | |
| 1010 | |
| 1011 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1012 SyncerThread::POLL); | |
| 1013 | |
| 1014 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1015 } | |
| 1016 | |
| 1017 TEST_F(SyncerThread2Test, ContinueConfiguration) { | |
| 1018 InitializeSyncerOnNormalMode(); | |
| 1019 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1020 | |
| 1021 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1022 SyncerThread::CONFIGURATION); | |
| 1023 | |
| 1024 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1025 } | |
| 1026 | |
| 1027 TEST_F(SyncerThread2Test, SaveConfigurationWhileThrottled) { | |
| 1028 InitializeSyncerOnNormalMode(); | |
| 1029 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1030 | |
| 1031 SetWaitIntervalToThrottled(); | |
| 1032 | |
| 1033 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1034 SyncerThread::CONFIGURATION); | |
| 1035 | |
| 1036 DCHECK_EQ(decision, SyncerThread::SAVE); | |
| 1037 } | |
| 1038 | |
| 1039 TEST_F(SyncerThread2Test, SaveNudgeWhileThrottled) { | |
| 1040 InitializeSyncerOnNormalMode(); | |
| 1041 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1042 | |
| 1043 SetWaitIntervalToThrottled(); | |
| 1044 | |
| 1045 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1046 SyncerThread::NUDGE); | |
| 1047 | |
| 1048 DCHECK_EQ(decision, SyncerThread::SAVE); | |
| 1049 | |
| 1050 } | |
| 1051 | |
| 1052 TEST_F(SyncerThread2Test, ContinueClearUserDataUnderAllCircumstances) { | |
| 1053 InitializeSyncerOnNormalMode(); | |
| 1054 | |
| 1055 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1056 SetWaitIntervalToThrottled(); | |
| 1057 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1058 SyncerThread::CLEAR_USER_DATA); | |
| 1059 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1060 | |
| 1061 SetMode(SyncerThread::NORMAL_MODE); | |
| 1062 SetWaitIntervalToExponentialBackoff(); | |
| 1063 decision = CreateAndDecideJob( | |
| 1064 SyncerThread::CLEAR_USER_DATA); | |
| 1065 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1066 } | |
| 1067 | |
| 1068 TEST_F(SyncerThread2Test, ContinueNudgeWhileExponentialBackOff) { | |
| 1069 InitializeSyncerOnNormalMode(); | |
| 1070 SetMode(SyncerThread::NORMAL_MODE); | |
| 1071 SetWaitIntervalToExponentialBackoff(); | |
| 1072 | |
| 1073 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1074 SyncerThread::NUDGE); | |
| 1075 | |
| 1076 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1077 } | |
| 1078 | |
| 1079 TEST_F(SyncerThread2Test, DropNudgeWhileExponentialBackOff) { | |
| 1080 InitializeSyncerOnNormalMode(); | |
| 1081 SetMode(SyncerThread::NORMAL_MODE); | |
| 1082 SetWaitIntervalToExponentialBackoff(); | |
| 1083 | |
| 1084 syncer_thread_->wait_interval_->had_nudge = true; | |
| 1085 | |
| 1086 SyncerThread::JobProcessDecision decision = CreateAndDecideJob( | |
| 1087 SyncerThread::NUDGE); | |
| 1088 | |
| 1089 DCHECK_EQ(decision, SyncerThread::DROP); | |
| 1090 } | |
| 1091 | |
| 1092 TEST_F(SyncerThread2Test, ContinueCanaryJobConfig) { | |
| 1093 InitializeSyncerOnNormalMode(); | |
| 1094 SetMode(SyncerThread::CONFIGURATION_MODE); | |
| 1095 SetWaitIntervalToExponentialBackoff(); | |
| 1096 | |
| 1097 struct SyncerThread::SyncSessionJob job; | |
| 1098 job.purpose = SyncerThread::CONFIGURATION; | |
| 1099 job.scheduled_start = TimeTicks::Now(); | |
| 1100 job.is_canary_job = true; | |
| 1101 SyncerThread::JobProcessDecision decision = DecideOnJob(job); | |
| 1102 | |
| 1103 DCHECK_EQ(decision, SyncerThread::CONTINUE); | |
| 1104 } | |
| 1105 | |
| 783 } // namespace s3 | 1106 } // namespace s3 |
| 784 } // namespace browser_sync | 1107 } // namespace browser_sync |
| 785 | 1108 |
| 786 // SyncerThread won't outlive the test! | 1109 // SyncerThread won't outlive the test! |
| 787 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); | 1110 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); |
| OLD | NEW |