OLD | NEW |
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/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 709 |
710 // Wait until the syncer thread reports that it is throttled. Any further | 710 // Wait until the syncer thread reports that it is throttled. Any further |
711 // sync share interceptions will result in failure. If things are broken, | 711 // sync share interceptions will result in failure. If things are broken, |
712 // we may never halt. | 712 // we may never halt. |
713 ASSERT_TRUE(WaitForThrottle()); | 713 ASSERT_TRUE(WaitForThrottle()); |
714 EXPECT_TRUE(syncer_thread()->IsSyncingCurrentlySilenced()); | 714 EXPECT_TRUE(syncer_thread()->IsSyncingCurrentlySilenced()); |
715 | 715 |
716 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 716 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
717 } | 717 } |
718 | 718 |
| 719 TEST_F(SyncerThreadWithSyncerTest, StopSyncPermanently) { |
| 720 // The SyncerThread should request an exit from the Syncer and set |
| 721 // conditions for termination. |
| 722 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(10); |
| 723 syncer_thread()->SetSyncerShortPollInterval(poll_interval); |
| 724 |
| 725 ListenerMock listener; |
| 726 WaitableEvent sync_cycle_ended_event(false, false); |
| 727 WaitableEvent syncer_thread_exiting_event(false, false); |
| 728 scoped_ptr<ChannelHookup<SyncerEvent> > hookup; |
| 729 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); |
| 730 |
| 731 EXPECT_CALL(listener, HandleChannelEvent( |
| 732 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). |
| 733 Times(AnyNumber()); |
| 734 |
| 735 EXPECT_CALL(listener, HandleChannelEvent( |
| 736 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). |
| 737 Times(AnyNumber()). |
| 738 WillOnce(SignalEvent(&sync_cycle_ended_event)); |
| 739 |
| 740 EXPECT_CALL(listener, HandleChannelEvent( |
| 741 Field(&SyncerEvent::what_happened, |
| 742 SyncerEvent::STOP_SYNCING_PERMANENTLY))); |
| 743 EXPECT_CALL(listener, HandleChannelEvent( |
| 744 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))). |
| 745 WillOnce(SignalEvent(&syncer_thread_exiting_event)); |
| 746 |
| 747 EXPECT_TRUE(syncer_thread()->Start()); |
| 748 metadb()->Open(); |
| 749 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
| 750 |
| 751 connection()->set_store_birthday("NotYourLuckyDay"); |
| 752 ASSERT_TRUE(syncer_thread_exiting_event.TimedWait(max_wait_time_)); |
| 753 EXPECT_TRUE(syncer_thread()->Stop(0)); |
| 754 } |
| 755 |
719 TEST_F(SyncerThreadWithSyncerTest, AuthInvalid) { | 756 TEST_F(SyncerThreadWithSyncerTest, AuthInvalid) { |
720 SyncShareIntercept interceptor; | 757 SyncShareIntercept interceptor; |
721 connection()->SetMidCommitObserver(&interceptor); | 758 connection()->SetMidCommitObserver(&interceptor); |
722 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(1); | 759 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(1); |
723 | 760 |
724 syncer_thread()->SetSyncerShortPollInterval(poll_interval); | 761 syncer_thread()->SetSyncerShortPollInterval(poll_interval); |
725 EXPECT_TRUE(syncer_thread()->Start()); | 762 EXPECT_TRUE(syncer_thread()->Start()); |
726 metadb()->Open(); | 763 metadb()->Open(); |
727 | 764 |
728 // Wait for some healthy syncing. | 765 // Wait for some healthy syncing. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); | 813 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); |
777 | 814 |
778 EXPECT_CALL(listener, HandleChannelEvent( | 815 EXPECT_CALL(listener, HandleChannelEvent( |
779 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). | 816 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). |
780 Times(AnyNumber()); | 817 Times(AnyNumber()); |
781 | 818 |
782 // Wait for the initial sync to complete. | 819 // Wait for the initial sync to complete. |
783 EXPECT_CALL(listener, HandleChannelEvent( | 820 EXPECT_CALL(listener, HandleChannelEvent( |
784 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). | 821 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). |
785 WillOnce(SignalEvent(&sync_cycle_ended_event)); | 822 WillOnce(SignalEvent(&sync_cycle_ended_event)); |
| 823 EXPECT_CALL(listener, HandleChannelEvent( |
| 824 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); |
786 ASSERT_TRUE(syncer_thread()->Start()); | 825 ASSERT_TRUE(syncer_thread()->Start()); |
787 metadb()->Open(); | 826 metadb()->Open(); |
788 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 827 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
789 | 828 |
790 // Request a pause. | 829 // Request a pause. |
791 ASSERT_TRUE(Pause(&listener)); | 830 ASSERT_TRUE(Pause(&listener)); |
792 | 831 |
793 // Resuming the pause. | 832 // Resuming the pause. |
794 ASSERT_TRUE(Resume(&listener)); | 833 ASSERT_TRUE(Resume(&listener)); |
795 | 834 |
(...skipping 20 matching lines...) Expand all Loading... |
816 WaitableEvent sync_cycle_ended_event(false, false); | 855 WaitableEvent sync_cycle_ended_event(false, false); |
817 WaitableEvent event(false, false); | 856 WaitableEvent event(false, false); |
818 ListenerMock listener; | 857 ListenerMock listener; |
819 scoped_ptr<ChannelHookup<SyncerEvent> > hookup; | 858 scoped_ptr<ChannelHookup<SyncerEvent> > hookup; |
820 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); | 859 hookup.reset(syncer_thread()->relay_channel()->AddObserver(&listener)); |
821 PreventThreadFromPolling(); | 860 PreventThreadFromPolling(); |
822 | 861 |
823 EXPECT_CALL(listener, HandleChannelEvent( | 862 EXPECT_CALL(listener, HandleChannelEvent( |
824 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). | 863 Field(&SyncerEvent::what_happened, SyncerEvent::STATUS_CHANGED))). |
825 Times(AnyNumber()); | 864 Times(AnyNumber()); |
| 865 EXPECT_CALL(listener, HandleChannelEvent( |
| 866 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); |
826 | 867 |
827 connection()->SetServerNotReachable(); | 868 connection()->SetServerNotReachable(); |
828 metadb()->Open(); | 869 metadb()->Open(); |
829 | 870 |
830 // Syncer thread will always go through once cycle at the start, | 871 // Syncer thread will always go through once cycle at the start, |
831 // then it will wait for a connection. | 872 // then it will wait for a connection. |
832 EXPECT_CALL(listener, HandleChannelEvent( | 873 EXPECT_CALL(listener, HandleChannelEvent( |
833 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). | 874 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). |
834 WillOnce(SignalEvent(&sync_cycle_ended_event)); | 875 WillOnce(SignalEvent(&sync_cycle_ended_event)); |
835 EXPECT_CALL(listener, HandleChannelEvent( | 876 EXPECT_CALL(listener, HandleChannelEvent( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 WillOnce(SignalEvent(&event)); | 956 WillOnce(SignalEvent(&event)); |
916 connection()->SetServerReachable(); | 957 connection()->SetServerReachable(); |
917 ASSERT_TRUE(event.TimedWait(max_wait_time_)); | 958 ASSERT_TRUE(event.TimedWait(max_wait_time_)); |
918 | 959 |
919 ASSERT_TRUE(Resume(&listener)); | 960 ASSERT_TRUE(Resume(&listener)); |
920 | 961 |
921 // Cycle the syncer to show we are not longer paused. | 962 // Cycle the syncer to show we are not longer paused. |
922 EXPECT_CALL(listener, HandleChannelEvent( | 963 EXPECT_CALL(listener, HandleChannelEvent( |
923 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). | 964 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). |
924 WillOnce(SignalEvent(&sync_cycle_ended_event)); | 965 WillOnce(SignalEvent(&sync_cycle_ended_event)); |
| 966 EXPECT_CALL(listener, HandleChannelEvent( |
| 967 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); |
| 968 |
925 syncer_thread()->NudgeSyncer(0, SyncerThread::kUnknown); | 969 syncer_thread()->NudgeSyncer(0, SyncerThread::kUnknown); |
926 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 970 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
927 | 971 |
928 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 972 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
929 } | 973 } |
930 | 974 |
931 TEST_F(SyncerThreadWithSyncerTest, PauseResumeWhenNotRunning) { | 975 TEST_F(SyncerThreadWithSyncerTest, PauseResumeWhenNotRunning) { |
932 WaitableEvent sync_cycle_ended_event(false, false); | 976 WaitableEvent sync_cycle_ended_event(false, false); |
933 WaitableEvent event(false, false); | 977 WaitableEvent event(false, false); |
934 ListenerMock listener; | 978 ListenerMock listener; |
(...skipping 11 matching lines...) Expand all Loading... |
946 | 990 |
947 // Pause the thread then start the syncer. | 991 // Pause the thread then start the syncer. |
948 ASSERT_TRUE(Pause(&listener)); | 992 ASSERT_TRUE(Pause(&listener)); |
949 metadb()->Open(); | 993 metadb()->Open(); |
950 ASSERT_TRUE(syncer_thread()->Start()); | 994 ASSERT_TRUE(syncer_thread()->Start()); |
951 | 995 |
952 // Resume and let the syncer cycle. | 996 // Resume and let the syncer cycle. |
953 EXPECT_CALL(listener, HandleChannelEvent( | 997 EXPECT_CALL(listener, HandleChannelEvent( |
954 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). | 998 Field(&SyncerEvent::what_happened, SyncerEvent::SYNC_CYCLE_ENDED))). |
955 WillOnce(SignalEvent(&sync_cycle_ended_event)); | 999 WillOnce(SignalEvent(&sync_cycle_ended_event)); |
| 1000 EXPECT_CALL(listener, HandleChannelEvent( |
| 1001 Field(&SyncerEvent::what_happened, SyncerEvent::SYNCER_THREAD_EXITING))); |
| 1002 |
956 ASSERT_TRUE(Resume(&listener)); | 1003 ASSERT_TRUE(Resume(&listener)); |
957 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 1004 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
958 | |
959 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 1005 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
960 } | 1006 } |
961 | 1007 |
962 } // namespace browser_sync | 1008 } // namespace browser_sync |
OLD | NEW |