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)); | |
|
tim (not reviewing)
2011/04/12 06:09:29
SetPassiveTypes?
lipalani1
2011/04/13 00:07:29
Done.
| |
| 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 protected: | |
| 174 scoped_ptr<SyncerThread> syncer_thread_; | |
|
tim (not reviewing)
2011/04/12 06:09:29
this change isn't necessary?
lipalani1
2011/04/13 00:07:29
Done.
| |
| 175 | |
| 158 private: | 176 private: |
| 159 scoped_ptr<SyncerThread> syncer_thread_; | |
| 160 scoped_ptr<MockConnectionManager> connection_; | 177 scoped_ptr<MockConnectionManager> connection_; |
| 161 SyncSessionContext* context_; | 178 SyncSessionContext* context_; |
| 162 MockSyncer* syncer_; | 179 MockSyncer* syncer_; |
| 163 MockDelayProvider* delay_; | 180 MockDelayProvider* delay_; |
| 164 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_; | 181 scoped_ptr<MockModelSafeWorkerRegistrar> registrar_; |
| 165 MockDirectorySetterUpper syncdb_; | 182 MockDirectorySetterUpper syncdb_; |
| 166 }; | 183 }; |
| 167 | 184 |
| 168 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record, | 185 bool RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record, |
| 169 size_t signal_after) { | 186 size_t signal_after) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 FROM_HERE); | 237 FROM_HERE); |
| 221 done.TimedWait(timeout()); | 238 done.TimedWait(timeout()); |
| 222 | 239 |
| 223 EXPECT_EQ(1U, records2.snapshots.size()); | 240 EXPECT_EQ(1U, records2.snapshots.size()); |
| 224 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | 241 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, |
| 225 records2.snapshots[0]->source.types)); | 242 records2.snapshots[0]->source.types)); |
| 226 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 243 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 227 records2.snapshots[0]->source.updates_source); | 244 records2.snapshots[0]->source.updates_source); |
| 228 } | 245 } |
| 229 | 246 |
| 247 TEST_F(SyncerThread2Test, Config) { | |
| 248 base::WaitableEvent done(false, false); | |
| 249 SyncShareRecords records; | |
| 250 syncable::ModelTypeBitSet model_types; | |
| 251 model_types[syncable::BOOKMARKS] = true; | |
| 252 | |
| 253 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 254 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 255 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 256 | |
| 257 // Make sure a regular config command is scheduled fine in the absence of any | |
| 258 // errors. | |
| 259 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 260 | |
| 261 syncer_thread()->ScheduleConfig(model_types); | |
| 262 done.TimedWait(timeout()); | |
| 263 | |
| 264 EXPECT_EQ(1U, records.snapshots.size()); | |
| 265 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 266 records.snapshots[0]->source.types)); | |
| 267 EXPECT_EQ(GetUpdatesCallerInfo::FIRST_UPDATE, | |
| 268 records.snapshots[0]->source.updates_source); | |
| 269 } | |
| 270 | |
| 271 TEST_F(SyncerThread2Test, ConfigWithBackingOff) { | |
|
tim (not reviewing)
2011/04/12 06:09:29
still missing comments.
lipalani1
2011/04/13 00:07:29
Done.
| |
| 272 base::WaitableEvent done(false, false); | |
| 273 base::WaitableEvent* dummy = NULL; | |
| 274 UseMockDelayProvider(); | |
| 275 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 276 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | |
| 277 SyncShareRecords records; | |
| 278 syncable::ModelTypeBitSet model_types; | |
| 279 model_types[syncable::BOOKMARKS] = true; | |
| 280 | |
| 281 // Simulate a failure and make sure the config request is retried. | |
| 282 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 283 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 284 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 285 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 286 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 287 | |
| 288 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 289 | |
| 290 syncer_thread()->ScheduleConfig(model_types); | |
| 291 done.TimedWait(timeout()); | |
| 292 | |
| 293 EXPECT_EQ(2U, records.snapshots.size()); | |
| 294 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 295 records.snapshots[1]->source.types)); | |
| 296 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | |
|
tim (not reviewing)
2011/04/12 06:09:29
what about snapshots [0]?
lipalani1
2011/04/13 00:07:29
I added the comments inside the TC. Moved them up
| |
| 297 records.snapshots[1]->source.updates_source); | |
| 298 } | |
| 299 | |
| 300 TEST_F(SyncerThread2Test, MultipleConfigWithBackingOff) { | |
| 301 syncable::ModelTypeBitSet model_types1, model_types2; | |
| 302 model_types1[syncable::BOOKMARKS] = true; | |
| 303 model_types2[syncable::AUTOFILL] = true; | |
| 304 SetUpWithTypes(model_types1 | model_types2); | |
| 305 base::WaitableEvent done(false, false); | |
| 306 base::WaitableEvent done1(false, false); | |
| 307 base::WaitableEvent* dummy = NULL; | |
| 308 UseMockDelayProvider(); | |
| 309 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 310 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); | |
| 311 SyncShareRecords records; | |
| 312 | |
| 313 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 314 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 315 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 316 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 317 WithArg<0>(RecordSyncShare(&records, 1U, &done1)))) | |
| 318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 319 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 320 | |
| 321 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 322 | |
| 323 // Issue 2 config commands. Second one right after the first has failed | |
| 324 // and make sure LATEST is executed. | |
| 325 syncer_thread()->ScheduleConfig(model_types1); | |
| 326 | |
| 327 // done1 indicates the first config failed. | |
| 328 done1.TimedWait(timeout()); | |
| 329 syncer_thread()->ScheduleConfig(model_types2); | |
| 330 done.TimedWait(timeout()); | |
| 331 | |
| 332 EXPECT_EQ(3U, records.snapshots.size()); | |
| 333 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types2, | |
| 334 records.snapshots[2]->source.types)); | |
| 335 EXPECT_EQ(GetUpdatesCallerInfo::FIRST_UPDATE, | |
| 336 records.snapshots[2]->source.updates_source); | |
| 337 } | |
| 338 | |
| 339 TEST_F(SyncerThread2Test, NudgeWithConfigWithBackingOff) { | |
| 340 syncable::ModelTypeBitSet model_types; | |
| 341 model_types[syncable::BOOKMARKS] = true; | |
| 342 base::WaitableEvent done(false, false); | |
| 343 base::WaitableEvent done1(false, false); | |
| 344 base::WaitableEvent done2(false, false); | |
| 345 base::WaitableEvent* dummy = NULL; | |
| 346 UseMockDelayProvider(); | |
| 347 EXPECT_CALL(*delay(), GetDelay(_)) | |
| 348 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | |
| 349 SyncShareRecords records; | |
| 350 | |
| 351 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
| 352 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 353 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))) | |
| 354 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 355 WithArg<0>(RecordSyncShare(&records, 1U, &done1)))) | |
| 356 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 357 WithArg<0>(RecordSyncShare(&records, 1U, &done2)))) | |
| 358 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
| 359 WithArg<0>(RecordSyncShare(&records, 1U, &done)))); | |
| 360 | |
| 361 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | |
| 362 | |
| 363 // Issue a nudge when the config has failed. Make sure both the config and | |
| 364 // nudge are executed. | |
| 365 syncer_thread()->ScheduleConfig(model_types); | |
| 366 done1.TimedWait(timeout()); | |
| 367 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types, | |
| 368 FROM_HERE); | |
| 369 | |
| 370 // done2 indicates config suceeded. Now change the mode so nudge can execute. | |
| 371 done2.TimedWait(timeout()); | |
| 372 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | |
| 373 done.TimedWait(timeout()); | |
| 374 EXPECT_EQ(4U, records.snapshots.size()); | |
| 375 | |
| 376 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 377 records.snapshots[2]->source.types)); | |
| 378 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | |
| 379 records.snapshots[2]->source.updates_source); | |
| 380 | |
| 381 EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types, | |
| 382 records.snapshots[3]->source.types)); | |
| 383 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 384 records.snapshots[3]->source.updates_source); | |
| 385 | |
| 386 } | |
| 387 | |
| 388 | |
| 230 // Test that nudges are coalesced. | 389 // Test that nudges are coalesced. |
| 231 TEST_F(SyncerThread2Test, NudgeCoalescing) { | 390 TEST_F(SyncerThread2Test, NudgeCoalescing) { |
| 232 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 391 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 233 base::WaitableEvent done(false, false); | 392 base::WaitableEvent done(false, false); |
| 234 SyncShareRecords r; | 393 SyncShareRecords r; |
| 235 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 394 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 236 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 395 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 237 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); | 396 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); |
| 238 syncable::ModelTypeBitSet types1, types2, types3; | 397 syncable::ModelTypeBitSet types1, types2, types3; |
| 239 types1[syncable::BOOKMARKS] = true; | 398 types1[syncable::BOOKMARKS] = true; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 } | 632 } |
| 474 | 633 |
| 475 // Test nudges / polls don't run in config mode and config tasks do. | 634 // Test nudges / polls don't run in config mode and config tasks do. |
| 476 TEST_F(SyncerThread2Test, ConfigurationMode) { | 635 TEST_F(SyncerThread2Test, ConfigurationMode) { |
| 477 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 636 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 478 SyncShareRecords records; | 637 SyncShareRecords records; |
| 479 base::WaitableEvent done(false, false); | 638 base::WaitableEvent done(false, false); |
| 480 base::WaitableEvent* dummy = NULL; | 639 base::WaitableEvent* dummy = NULL; |
| 481 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 640 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 482 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 641 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 483 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 642 .WillOnce((Invoke(sessions::test_util::SimulateSuccess), |
| 484 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))); | 643 WithArg<0>(RecordSyncShare(&records, 1U, dummy)))); |
| 485 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); | 644 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE, NULL); |
| 486 syncable::ModelTypeBitSet nudge_types; | 645 syncable::ModelTypeBitSet nudge_types; |
| 487 nudge_types[syncable::AUTOFILL] = true; | 646 nudge_types[syncable::AUTOFILL] = true; |
| 488 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, | 647 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, |
| 489 FROM_HERE); | 648 FROM_HERE); |
| 490 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, | 649 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types, |
| 491 FROM_HERE); | 650 FROM_HERE); |
| 492 | 651 |
| 493 syncable::ModelTypeBitSet config_types; | 652 syncable::ModelTypeBitSet config_types; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 // TODO(tim): Implement this test and then the functionality! | 895 // TODO(tim): Implement this test and then the functionality! |
| 737 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { | 896 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { |
| 738 } | 897 } |
| 739 | 898 |
| 740 // Test that starting the syncer thread without a valid connection doesn't | 899 // Test that starting the syncer thread without a valid connection doesn't |
| 741 // break things when a connection is detected. | 900 // break things when a connection is detected. |
| 742 TEST_F(SyncerThread2Test, StartWhenNotConnected) { | 901 TEST_F(SyncerThread2Test, StartWhenNotConnected) { |
| 743 base::WaitableEvent done(false, false); | 902 base::WaitableEvent done(false, false); |
| 744 MessageLoop cur; | 903 MessageLoop cur; |
| 745 connection()->SetServerNotReachable(); | 904 connection()->SetServerNotReachable(); |
| 905 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).WillOnce(SignalEvent(&done)); | |
|
tim (not reviewing)
2011/04/12 06:09:29
hmm... if the server is not reachable, we shouldn'
lipalani1
2011/04/13 00:07:29
I think the intention of the old and new models ar
| |
| 746 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 906 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 747 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), | 907 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), |
| 748 FROM_HERE); | 908 FROM_HERE); |
| 749 FlushLastTask(&done); | 909 FlushLastTask(&done); |
| 750 | 910 |
| 751 connection()->SetServerReachable(); | 911 connection()->SetServerReachable(); |
| 752 cur.PostTask(FROM_HERE, NewRunnableFunction( | 912 cur.PostTask(FROM_HERE, NewRunnableFunction( |
| 753 &SyncerThread2Test::QuitMessageLoop)); | 913 &SyncerThread2Test::QuitMessageLoop)); |
| 754 cur.Run(); | 914 cur.Run(); |
| 755 | 915 |
| 756 // By now, the server connection event should have been posted to the | 916 // By now, the server connection event should have been posted to the |
| 757 // SyncerThread. | 917 // SyncerThread. |
| 758 FlushLastTask(&done); | 918 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()); | 919 done.TimedWait(timeout()); |
| 763 } | 920 } |
| 764 | 921 |
| 765 TEST_F(SyncerThread2Test, SetsPreviousRoutingInfo) { | 922 TEST_F(SyncerThread2Test, SetsPreviousRoutingInfo) { |
| 766 base::WaitableEvent done(false, false); | 923 base::WaitableEvent done(false, false); |
| 767 ModelSafeRoutingInfo info; | 924 ModelSafeRoutingInfo info; |
| 768 EXPECT_TRUE(info == context()->previous_session_routing_info()); | 925 EXPECT_TRUE(info == context()->previous_session_routing_info()); |
| 769 ModelSafeRoutingInfo expected; | 926 ModelSafeRoutingInfo expected; |
| 770 context()->registrar()->GetModelSafeRoutingInfo(&expected); | 927 context()->registrar()->GetModelSafeRoutingInfo(&expected); |
| 771 ASSERT_FALSE(expected.empty()); | 928 ASSERT_FALSE(expected.empty()); |
| 772 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); | 929 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1); |
| 773 | 930 |
| 774 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); | 931 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL); |
| 775 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), | 932 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet(), |
| 776 FROM_HERE); | 933 FROM_HERE); |
| 777 FlushLastTask(&done); | 934 FlushLastTask(&done); |
| 778 syncer_thread()->Stop(); | 935 syncer_thread()->Stop(); |
| 779 | 936 |
| 780 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 937 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
| 781 } | 938 } |
| 782 | 939 |
| 783 } // namespace s3 | 940 } // namespace s3 |
| 784 } // namespace browser_sync | 941 } // namespace browser_sync |
| 785 | 942 |
| 786 // SyncerThread won't outlive the test! | 943 // SyncerThread won't outlive the test! |
| 787 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); | 944 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); |
| OLD | NEW |