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

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

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 8
9 #include "base/lock.h" 9 #include "base/lock.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 public: 59 public:
60 SyncerThreadWithSyncerTest() 60 SyncerThreadWithSyncerTest()
61 : max_wait_time_(TimeDelta::FromSeconds(10)), 61 : max_wait_time_(TimeDelta::FromSeconds(10)),
62 sync_cycle_ended_event_(false, false) {} 62 sync_cycle_ended_event_(false, false) {}
63 virtual void SetUp() { 63 virtual void SetUp() {
64 metadb_.SetUp(); 64 metadb_.SetUp();
65 connection_.reset(new MockConnectionManager(metadb_.manager(), 65 connection_.reset(new MockConnectionManager(metadb_.manager(),
66 metadb_.name())); 66 metadb_.name()));
67 worker_ = new ModelSafeWorker(); 67 worker_ = new ModelSafeWorker();
68 SyncSessionContext* context = new SyncSessionContext(connection_.get(), 68 SyncSessionContext* context = new SyncSessionContext(connection_.get(),
69 NULL, metadb_.manager(), this); 69 metadb_.manager(), this);
70 syncer_thread_ = new SyncerThread(context); 70 syncer_thread_ = new SyncerThread(context);
71 syncer_event_hookup_.reset( 71 syncer_event_hookup_.reset(
72 syncer_thread_->relay_channel()->AddObserver(this)); 72 syncer_thread_->relay_channel()->AddObserver(this));
73 syncer_thread_->SetConnected(true); 73 syncer_thread_->SetConnected(true);
74 syncable::ModelTypeBitSet expected_types; 74 syncable::ModelTypeBitSet expected_types;
75 expected_types[syncable::BOOKMARKS] = true; 75 expected_types[syncable::BOOKMARKS] = true;
76 connection_->ExpectGetUpdatesRequestTypes(expected_types); 76 connection_->ExpectGetUpdatesRequestTypes(expected_types);
77 } 77 }
78 virtual void TearDown() { 78 virtual void TearDown() {
79 syncer_event_hookup_.reset(); 79 syncer_event_hookup_.reset();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 sync_occured_.Reset(); 210 sync_occured_.Reset();
211 } 211 }
212 private: 212 private:
213 std::vector<TimeTicks> times_sync_occured_; 213 std::vector<TimeTicks> times_sync_occured_;
214 base::WaitableEvent sync_occured_; 214 base::WaitableEvent sync_occured_;
215 bool allow_multiple_interceptions_; 215 bool allow_multiple_interceptions_;
216 DISALLOW_COPY_AND_ASSIGN(SyncShareIntercept); 216 DISALLOW_COPY_AND_ASSIGN(SyncShareIntercept);
217 }; 217 };
218 218
219 TEST_F(SyncerThreadTest, Construction) { 219 TEST_F(SyncerThreadTest, Construction) {
220 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, NULL); 220 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL);
221 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); 221 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context));
222 } 222 }
223 223
224 TEST_F(SyncerThreadTest, StartStop) { 224 TEST_F(SyncerThreadTest, StartStop) {
225 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, NULL); 225 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL);
226 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); 226 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context));
227 EXPECT_TRUE(syncer_thread->Start()); 227 EXPECT_TRUE(syncer_thread->Start());
228 EXPECT_TRUE(syncer_thread->Stop(2000)); 228 EXPECT_TRUE(syncer_thread->Stop(2000));
229 229
230 // Do it again for good measure. I caught some bugs by adding this so 230 // Do it again for good measure. I caught some bugs by adding this so
231 // I would recommend keeping it. 231 // I would recommend keeping it.
232 EXPECT_TRUE(syncer_thread->Start()); 232 EXPECT_TRUE(syncer_thread->Start());
233 EXPECT_TRUE(syncer_thread->Stop(2000)); 233 EXPECT_TRUE(syncer_thread->Stop(2000));
234 } 234 }
235 235
236 TEST(SyncerThread, GetRecommendedDelay) { 236 TEST(SyncerThread, GetRecommendedDelay) {
237 EXPECT_LE(0, SyncerThread::GetRecommendedDelaySeconds(0)); 237 EXPECT_LE(0, SyncerThread::GetRecommendedDelaySeconds(0));
238 EXPECT_LE(1, SyncerThread::GetRecommendedDelaySeconds(1)); 238 EXPECT_LE(1, SyncerThread::GetRecommendedDelaySeconds(1));
239 EXPECT_LE(50, SyncerThread::GetRecommendedDelaySeconds(50)); 239 EXPECT_LE(50, SyncerThread::GetRecommendedDelaySeconds(50));
240 EXPECT_LE(10, SyncerThread::GetRecommendedDelaySeconds(10)); 240 EXPECT_LE(10, SyncerThread::GetRecommendedDelaySeconds(10));
241 EXPECT_EQ(SyncerThread::kMaxBackoffSeconds, 241 EXPECT_EQ(SyncerThread::kMaxBackoffSeconds,
242 SyncerThread::GetRecommendedDelaySeconds( 242 SyncerThread::GetRecommendedDelaySeconds(
243 SyncerThread::kMaxBackoffSeconds)); 243 SyncerThread::kMaxBackoffSeconds));
244 EXPECT_EQ(SyncerThread::kMaxBackoffSeconds, 244 EXPECT_EQ(SyncerThread::kMaxBackoffSeconds,
245 SyncerThread::GetRecommendedDelaySeconds( 245 SyncerThread::GetRecommendedDelaySeconds(
246 SyncerThread::kMaxBackoffSeconds+1)); 246 SyncerThread::kMaxBackoffSeconds+1));
247 } 247 }
248 248
249 TEST_F(SyncerThreadTest, CalculateSyncWaitTime) { 249 TEST_F(SyncerThreadTest, CalculateSyncWaitTime) {
250 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, NULL); 250 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL);
251 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); 251 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context));
252 syncer_thread->DisableIdleDetection(); 252 syncer_thread->DisableIdleDetection();
253 253
254 // Syncer_polling_interval_ is less than max poll interval. 254 // Syncer_polling_interval_ is less than max poll interval.
255 TimeDelta syncer_polling_interval = TimeDelta::FromSeconds(1); 255 TimeDelta syncer_polling_interval = TimeDelta::FromSeconds(1);
256 256
257 syncer_thread->SetSyncerPollingInterval(syncer_polling_interval); 257 syncer_thread->SetSyncerPollingInterval(syncer_polling_interval);
258 258
259 // user_idle_ms is less than 10 * (syncer_polling_interval*1000). 259 // user_idle_ms is less than 10 * (syncer_polling_interval*1000).
260 ASSERT_EQ(syncer_polling_interval.InMilliseconds(), 260 ASSERT_EQ(syncer_polling_interval.InMilliseconds(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 syncer_thread->CalculateSyncWaitTime(last_poll_time, 300 syncer_thread->CalculateSyncWaitTime(last_poll_time,
301 over_sync_max_interval)); 301 over_sync_max_interval));
302 ASSERT_TRUE(last_poll_time * 3 >= 302 ASSERT_TRUE(last_poll_time * 3 >=
303 syncer_thread->CalculateSyncWaitTime(last_poll_time, 303 syncer_thread->CalculateSyncWaitTime(last_poll_time,
304 over_sync_max_interval)); 304 over_sync_max_interval));
305 } 305 }
306 306
307 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) { 307 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) {
308 // Set up the environment. 308 // Set up the environment.
309 int user_idle_milliseconds_param = 0; 309 int user_idle_milliseconds_param = 0;
310 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, NULL); 310 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL);
311 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); 311 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context));
312 syncer_thread->DisableIdleDetection(); 312 syncer_thread->DisableIdleDetection();
313 // Hold the lock to appease asserts in code. 313 // Hold the lock to appease asserts in code.
314 AutoLock lock(syncer_thread->lock_); 314 AutoLock lock(syncer_thread->lock_);
315 315
316 // Notifications disabled should result in a polling interval of 316 // Notifications disabled should result in a polling interval of
317 // kDefaultShortPollInterval. 317 // kDefaultShortPollInterval.
318 { 318 {
319 context->set_notifications_enabled(false); 319 context->set_notifications_enabled(false);
320 bool continue_sync_cycle_param = false; 320 bool continue_sync_cycle_param = false;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 632 }
633 633
634 TEST_F(SyncerThreadWithSyncerTest, Polling) { 634 TEST_F(SyncerThreadWithSyncerTest, Polling) {
635 SyncShareIntercept interceptor; 635 SyncShareIntercept interceptor;
636 connection()->SetMidCommitObserver(&interceptor); 636 connection()->SetMidCommitObserver(&interceptor);
637 637
638 const TimeDelta poll_interval = TimeDelta::FromSeconds(1); 638 const TimeDelta poll_interval = TimeDelta::FromSeconds(1);
639 syncer_thread()->SetSyncerShortPollInterval(poll_interval); 639 syncer_thread()->SetSyncerShortPollInterval(poll_interval);
640 EXPECT_TRUE(syncer_thread()->Start()); 640 EXPECT_TRUE(syncer_thread()->Start());
641 641
642 // Calling Open() should cause the SyncerThread to create a Syncer.
643 metadb()->Open(); 642 metadb()->Open();
643 syncer_thread()->CreateSyncer(metadb()->name());
644 644
645 TimeDelta two_polls = poll_interval + poll_interval; 645 TimeDelta two_polls = poll_interval + poll_interval;
646 // We could theoretically return immediately from the wait if the interceptor 646 // We could theoretically return immediately from the wait if the interceptor
647 // was already signaled for a SyncShare (the first one comes quick). 647 // was already signaled for a SyncShare (the first one comes quick).
648 interceptor.WaitForSyncShare(1, two_polls); 648 interceptor.WaitForSyncShare(1, two_polls);
649 EXPECT_FALSE(interceptor.times_sync_occured().empty()); 649 EXPECT_FALSE(interceptor.times_sync_occured().empty());
650 650
651 // Wait for at least 2 more SyncShare operations. 651 // Wait for at least 2 more SyncShare operations.
652 interceptor.WaitForSyncShare(2, two_polls); 652 interceptor.WaitForSyncShare(2, two_polls);
653 EXPECT_TRUE(syncer_thread()->Stop(2000)); 653 EXPECT_TRUE(syncer_thread()->Stop(2000));
(...skipping 12 matching lines...) Expand all
666 } 666 }
667 } 667 }
668 668
669 TEST_F(SyncerThreadWithSyncerTest, Nudge) { 669 TEST_F(SyncerThreadWithSyncerTest, Nudge) {
670 SyncShareIntercept interceptor; 670 SyncShareIntercept interceptor;
671 connection()->SetMidCommitObserver(&interceptor); 671 connection()->SetMidCommitObserver(&interceptor);
672 // We don't want a poll to happen during this test (except the first one). 672 // We don't want a poll to happen during this test (except the first one).
673 PreventThreadFromPolling(); 673 PreventThreadFromPolling();
674 EXPECT_TRUE(syncer_thread()->Start()); 674 EXPECT_TRUE(syncer_thread()->Start());
675 metadb()->Open(); 675 metadb()->Open();
676 syncer_thread()->CreateSyncer(metadb()->name());
676 const TimeDelta poll_interval = TimeDelta::FromMinutes(5); 677 const TimeDelta poll_interval = TimeDelta::FromMinutes(5);
677 interceptor.WaitForSyncShare(1, poll_interval + poll_interval); 678 interceptor.WaitForSyncShare(1, poll_interval + poll_interval);
678 679
679 EXPECT_EQ(static_cast<unsigned int>(1), 680 EXPECT_EQ(static_cast<unsigned int>(1),
680 interceptor.times_sync_occured().size()); 681 interceptor.times_sync_occured().size());
681 // The SyncerThread should be waiting for the poll now. Nudge it to sync 682 // The SyncerThread should be waiting for the poll now. Nudge it to sync
682 // immediately (5ms). 683 // immediately (5ms).
683 syncer_thread()->NudgeSyncer(5, SyncerThread::kUnknown); 684 syncer_thread()->NudgeSyncer(5, SyncerThread::kUnknown);
684 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); 685 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1));
685 EXPECT_EQ(static_cast<unsigned int>(2), 686 EXPECT_EQ(static_cast<unsigned int>(2),
686 interceptor.times_sync_occured().size()); 687 interceptor.times_sync_occured().size());
687 688
688 // SyncerThread should be waiting again. Signal it to stop. 689 // SyncerThread should be waiting again. Signal it to stop.
689 EXPECT_TRUE(syncer_thread()->Stop(2000)); 690 EXPECT_TRUE(syncer_thread()->Stop(2000));
690 } 691 }
691 692
692 TEST_F(SyncerThreadWithSyncerTest, Throttling) { 693 TEST_F(SyncerThreadWithSyncerTest, Throttling) {
693 SyncShareIntercept interceptor; 694 SyncShareIntercept interceptor;
694 connection()->SetMidCommitObserver(&interceptor); 695 connection()->SetMidCommitObserver(&interceptor);
695 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(10); 696 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(10);
696 syncer_thread()->SetSyncerShortPollInterval(poll_interval); 697 syncer_thread()->SetSyncerShortPollInterval(poll_interval);
697 698
698 EXPECT_TRUE(syncer_thread()->Start()); 699 EXPECT_TRUE(syncer_thread()->Start());
699 metadb()->Open(); 700 metadb()->Open();
701 syncer_thread()->CreateSyncer(metadb()->name());
700 702
701 // Wait for some healthy syncing. 703 // Wait for some healthy syncing.
702 interceptor.WaitForSyncShare(4, poll_interval + poll_interval); 704 interceptor.WaitForSyncShare(4, poll_interval + poll_interval);
703 705
704 // Tell the server to throttle a single request, which should be all it takes 706 // Tell the server to throttle a single request, which should be all it takes
705 // to silence our syncer (for 2 hours, so we shouldn't hit that in this test). 707 // to silence our syncer (for 2 hours, so we shouldn't hit that in this test).
706 // This will atomically visit the interceptor so it can switch to throttled 708 // This will atomically visit the interceptor so it can switch to throttled
707 // mode and fail on multiple requests. 709 // mode and fail on multiple requests.
708 connection()->ThrottleNextRequest(&interceptor); 710 connection()->ThrottleNextRequest(&interceptor);
709 711
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 745
744 EXPECT_CALL(listener, HandleChannelEvent( 746 EXPECT_CALL(listener, HandleChannelEvent(
745 Field(&SyncerEvent::what_happened, 747 Field(&SyncerEvent::what_happened,
746 SyncerEvent::STOP_SYNCING_PERMANENTLY))); 748 SyncerEvent::STOP_SYNCING_PERMANENTLY)));
747 EXPECT_CALL(listener, HandleChannelEvent( 749 EXPECT_CALL(listener, HandleChannelEvent(
748 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))). 750 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))).
749 WillOnce(SignalEvent(&syncer_thread_exiting_event)); 751 WillOnce(SignalEvent(&syncer_thread_exiting_event));
750 752
751 EXPECT_TRUE(syncer_thread()->Start()); 753 EXPECT_TRUE(syncer_thread()->Start());
752 metadb()->Open(); 754 metadb()->Open();
755 syncer_thread()->CreateSyncer(metadb()->name());
753 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 756 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
754 757
755 connection()->set_store_birthday("NotYourLuckyDay"); 758 connection()->set_store_birthday("NotYourLuckyDay");
756 ASSERT_TRUE(syncer_thread_exiting_event.TimedWait(max_wait_time_)); 759 ASSERT_TRUE(syncer_thread_exiting_event.TimedWait(max_wait_time_));
757 EXPECT_TRUE(syncer_thread()->Stop(0)); 760 EXPECT_TRUE(syncer_thread()->Stop(0));
758 } 761 }
759 762
760 TEST_F(SyncerThreadWithSyncerTest, AuthInvalid) { 763 TEST_F(SyncerThreadWithSyncerTest, AuthInvalid) {
761 SyncShareIntercept interceptor; 764 SyncShareIntercept interceptor;
762 connection()->SetMidCommitObserver(&interceptor); 765 connection()->SetMidCommitObserver(&interceptor);
763 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(1); 766 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(1);
764 767
765 syncer_thread()->SetSyncerShortPollInterval(poll_interval); 768 syncer_thread()->SetSyncerShortPollInterval(poll_interval);
766 EXPECT_TRUE(syncer_thread()->Start()); 769 EXPECT_TRUE(syncer_thread()->Start());
767 metadb()->Open(); 770 metadb()->Open();
771 syncer_thread()->CreateSyncer(metadb()->name());
768 772
769 // Wait for some healthy syncing. 773 // Wait for some healthy syncing.
770 interceptor.WaitForSyncShare(2, TimeDelta::FromSeconds(10)); 774 interceptor.WaitForSyncShare(2, TimeDelta::FromSeconds(10));
771 EXPECT_GE(interceptor.times_sync_occured().size(), 2U); 775 EXPECT_GE(interceptor.times_sync_occured().size(), 2U);
772 776
773 // Atomically start returning auth invalid and set the interceptor to fail 777 // Atomically start returning auth invalid and set the interceptor to fail
774 // on any sync. 778 // on any sync.
775 connection()->FailWithAuthInvalid(&interceptor); 779 connection()->FailWithAuthInvalid(&interceptor);
776 WaitForDisconnect(); 780 WaitForDisconnect();
777 781
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 Times(AnyNumber()); 823 Times(AnyNumber());
820 824
821 // Wait for the initial sync to complete. 825 // Wait for the initial sync to complete.
822 EXPECT_CALL(listener, HandleChannelEvent( 826 EXPECT_CALL(listener, HandleChannelEvent(
823 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). 827 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))).
824 WillOnce(SignalEvent(&sync_cycle_ended_event)); 828 WillOnce(SignalEvent(&sync_cycle_ended_event));
825 EXPECT_CALL(listener, HandleChannelEvent( 829 EXPECT_CALL(listener, HandleChannelEvent(
826 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); 830 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING)));
827 ASSERT_TRUE(syncer_thread()->Start()); 831 ASSERT_TRUE(syncer_thread()->Start());
828 metadb()->Open(); 832 metadb()->Open();
833 syncer_thread()->CreateSyncer(metadb()->name());
829 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 834 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
830 835
831 // Request a pause. 836 // Request a pause.
832 ASSERT_TRUE(Pause(&listener)); 837 ASSERT_TRUE(Pause(&listener));
833 838
834 // Resuming the pause. 839 // Resuming the pause.
835 ASSERT_TRUE(Resume(&listener)); 840 ASSERT_TRUE(Resume(&listener));
836 841
837 // Not paused, should fail. 842 // Not paused, should fail.
838 EXPECT_FALSE(syncer_thread()->RequestResume()); 843 EXPECT_FALSE(syncer_thread()->RequestResume());
(...skipping 23 matching lines...) Expand all
862 PreventThreadFromPolling(); 867 PreventThreadFromPolling();
863 868
864 EXPECT_CALL(listener, HandleChannelEvent( 869 EXPECT_CALL(listener, HandleChannelEvent(
865 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). 870 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))).
866 Times(AnyNumber()); 871 Times(AnyNumber());
867 EXPECT_CALL(listener, HandleChannelEvent( 872 EXPECT_CALL(listener, HandleChannelEvent(
868 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); 873 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING)));
869 874
870 connection()->SetServerNotReachable(); 875 connection()->SetServerNotReachable();
871 metadb()->Open(); 876 metadb()->Open();
877 syncer_thread()->CreateSyncer(metadb()->name());
872 878
873 // Syncer thread will always go through once cycle at the start, 879 // Syncer thread will always go through once cycle at the start,
874 // then it will wait for a connection. 880 // then it will wait for a connection.
875 EXPECT_CALL(listener, HandleChannelEvent( 881 EXPECT_CALL(listener, HandleChannelEvent(
876 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). 882 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))).
877 WillOnce(SignalEvent(&sync_cycle_ended_event)); 883 WillOnce(SignalEvent(&sync_cycle_ended_event));
878 EXPECT_CALL(listener, HandleChannelEvent( 884 EXPECT_CALL(listener, HandleChannelEvent(
879 Field(&SyncerEvent::what_happened, SyncerEvent::WAITING_FOR_CONNECTION))). 885 Field(&SyncerEvent::what_happened, SyncerEvent::WAITING_FOR_CONNECTION))).
880 WillOnce(SignalEvent(&event)); 886 WillOnce(SignalEvent(&event));
881 ASSERT_TRUE(syncer_thread()->Start()); 887 ASSERT_TRUE(syncer_thread()->Start());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 922
917 // Put the thread into a "waiting for connection" state. 923 // Put the thread into a "waiting for connection" state.
918 connection()->SetServerNotReachable(); 924 connection()->SetServerNotReachable();
919 EXPECT_CALL(listener, HandleChannelEvent( 925 EXPECT_CALL(listener, HandleChannelEvent(
920 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). 926 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))).
921 WillOnce(SignalEvent(&sync_cycle_ended_event)); 927 WillOnce(SignalEvent(&sync_cycle_ended_event));
922 EXPECT_CALL(listener, HandleChannelEvent( 928 EXPECT_CALL(listener, HandleChannelEvent(
923 Field(&SyncerEvent::what_happened, SyncerEvent::WAITING_FOR_CONNECTION))). 929 Field(&SyncerEvent::what_happened, SyncerEvent::WAITING_FOR_CONNECTION))).
924 WillOnce(SignalEvent(&event)); 930 WillOnce(SignalEvent(&event));
925 metadb()->Open(); 931 metadb()->Open();
932 syncer_thread()->CreateSyncer(metadb()->name());
933
926 ASSERT_TRUE(syncer_thread()->Start()); 934 ASSERT_TRUE(syncer_thread()->Start());
927 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 935 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
928 ASSERT_TRUE(event.TimedWait(max_wait_time_)); 936 ASSERT_TRUE(event.TimedWait(max_wait_time_));
929 937
930 // Pause and resume the thread while waiting for a connection. 938 // Pause and resume the thread while waiting for a connection.
931 ASSERT_TRUE(Pause(&listener)); 939 ASSERT_TRUE(Pause(&listener));
932 ASSERT_TRUE(Resume(&listener)); 940 ASSERT_TRUE(Resume(&listener));
933 941
934 // Make a connection and let the syncer cycle. 942 // Make a connection and let the syncer cycle.
935 EXPECT_CALL(listener, HandleChannelEvent( 943 EXPECT_CALL(listener, HandleChannelEvent(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). 995 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))).
988 Times(AnyNumber()); 996 Times(AnyNumber());
989 997
990 // Pause and resume the syncer while not running 998 // Pause and resume the syncer while not running
991 ASSERT_TRUE(Pause(&listener)); 999 ASSERT_TRUE(Pause(&listener));
992 ASSERT_TRUE(Resume(&listener)); 1000 ASSERT_TRUE(Resume(&listener));
993 1001
994 // Pause the thread then start the syncer. 1002 // Pause the thread then start the syncer.
995 ASSERT_TRUE(Pause(&listener)); 1003 ASSERT_TRUE(Pause(&listener));
996 metadb()->Open(); 1004 metadb()->Open();
1005 syncer_thread()->CreateSyncer(metadb()->name());
997 ASSERT_TRUE(syncer_thread()->Start()); 1006 ASSERT_TRUE(syncer_thread()->Start());
998 1007
999 // Resume and let the syncer cycle. 1008 // Resume and let the syncer cycle.
1000 EXPECT_CALL(listener, HandleChannelEvent( 1009 EXPECT_CALL(listener, HandleChannelEvent(
1001 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). 1010 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))).
1002 WillOnce(SignalEvent(&sync_cycle_ended_event)); 1011 WillOnce(SignalEvent(&sync_cycle_ended_event));
1003 EXPECT_CALL(listener, HandleChannelEvent( 1012 EXPECT_CALL(listener, HandleChannelEvent(
1004 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); 1013 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING)));
1005 1014
1006 ASSERT_TRUE(Resume(&listener)); 1015 ASSERT_TRUE(Resume(&listener));
1007 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); 1016 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_));
1008 EXPECT_TRUE(syncer_thread()->Stop(2000)); 1017 EXPECT_TRUE(syncer_thread()->Stop(2000));
1009 } 1018 }
1010 1019
1011 } // namespace browser_sync 1020 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698