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

Side by Side Diff: sync/sessions/nudge_tracker_unittest.cc

Issue 488843002: [Sync] Add support for server controlled nudge delays (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sessions/sync_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "sync/internal_api/public/base/model_type_test_util.h" 7 #include "sync/internal_api/public/base/model_type_test_util.h"
8 #include "sync/sessions/nudge_tracker.h" 8 #include "sync/sessions/nudge_tracker.h"
9 #include "sync/test/mock_invalidation.h" 9 #include "sync/test/mock_invalidation.h"
10 #include "sync/test/mock_invalidation_tracker.h" 10 #include "sync/test/mock_invalidation_tracker.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 EXPECT_FALSE(nudge_tracker_.IsRetryRequired()); 721 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
722 nudge_tracker_.RecordSuccessfulSyncCycle(); 722 nudge_tracker_.RecordSuccessfulSyncCycle();
723 723
724 // The retry scheduled way back during the first cycle of this test finally 724 // The retry scheduled way back during the first cycle of this test finally
725 // becomes due. Perform a successful sync cycle to service it. 725 // becomes due. Perform a successful sync cycle to service it.
726 nudge_tracker_.SetSyncCycleStartTime(t6); 726 nudge_tracker_.SetSyncCycleStartTime(t6);
727 EXPECT_TRUE(nudge_tracker_.IsRetryRequired()); 727 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
728 nudge_tracker_.RecordSuccessfulSyncCycle(); 728 nudge_tracker_.RecordSuccessfulSyncCycle();
729 } 729 }
730 730
731 // Test the default nudge delays for various types.
732 TEST_F(NudgeTrackerTest, NudgeDelayTest) {
733 // Set to a known value to compare against.
734 nudge_tracker_.SetDefaultNudgeDelay(base::TimeDelta());
735
736 // Bookmarks and preference both have "slow nudge" delays.
737 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
738 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)));
739
740 // Typed URLs has a default delay.
741 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS)),
742 base::TimeDelta());
743
744 // "Slow nudge" delays are longer than the default.
745 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
746 base::TimeDelta());
747
748 // Sessions is longer than "slow nudge".
749 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)),
750 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)));
751
752 // Favicons have the same delay as sessions.
753 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)),
754 nudge_tracker_.RecordLocalChange(ModelTypeSet(FAVICON_TRACKING)));
755
756 // Autofill has the longer delay of all.
757 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(AUTOFILL)),
758 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)));
759
760 // A nudge with no types takes the longest delay.
761 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(AUTOFILL)),
762 nudge_tracker_.RecordLocalChange(ModelTypeSet()));
763
764 // The actual nudge delay should be the shortest of the set.
765 EXPECT_EQ(
766 nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS)),
767 nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS, AUTOFILL)));
768 }
769
770 // Test that custom nudge delays are used over the defaults.
771 TEST_F(NudgeTrackerTest, CustomDelayTest) {
772 // Set some custom delays.
773 std::map<ModelType, base::TimeDelta> delay_map;
774 delay_map[BOOKMARKS] = base::TimeDelta::FromSeconds(10);
775 delay_map[SESSIONS] = base::TimeDelta::FromSeconds(2);
776 nudge_tracker_.OnReceivedCustomNudgeDelays(delay_map);
777
778 // Only those with custom delays should be affected, not another type.
779 EXPECT_NE(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
780 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)));
781
782 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
783 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)));
784 EXPECT_EQ(base::TimeDelta::FromSeconds(2),
785 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)));
786 }
787
788 // Check that custom nudge delays can never result in a value shorter than the
789 // minimum nudge delay.
790 TEST_F(NudgeTrackerTest, NoTypesShorterThanDefault) {
791 // Set delay to a known value.
792 nudge_tracker_.SetDefaultNudgeDelay(base::TimeDelta::FromMilliseconds(500));
793
794 std::map<ModelType, base::TimeDelta> delay_map;
795 ModelTypeSet protocol_types = syncer::ProtocolTypes();
796 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
797 iter.Inc()) {
798 delay_map[iter.Get()] = base::TimeDelta();
799 }
800 nudge_tracker_.OnReceivedCustomNudgeDelays(delay_map);
801
802 // All types should still have a nudge greater than or equal to the minimum.
803 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
804 iter.Inc()) {
805 EXPECT_GE(nudge_tracker_.RecordLocalChange(ModelTypeSet(iter.Get())),
806 base::TimeDelta::FromMilliseconds(500));
807 }
808 }
809
731 class NudgeTrackerAckTrackingTest : public NudgeTrackerTest { 810 class NudgeTrackerAckTrackingTest : public NudgeTrackerTest {
732 public: 811 public:
733 NudgeTrackerAckTrackingTest() {} 812 NudgeTrackerAckTrackingTest() {}
734 813
735 bool IsInvalidationUnacknowledged(int tracking_id) { 814 bool IsInvalidationUnacknowledged(int tracking_id) {
736 return tracker_.IsUnacked(tracking_id); 815 return tracker_.IsUnacked(tracking_id);
737 } 816 }
738 817
739 bool IsInvalidationAcknowledged(int tracking_id) { 818 bool IsInvalidationAcknowledged(int tracking_id) {
740 return tracker_.IsAcknowledged(tracking_id); 819 return tracker_.IsAcknowledged(tracking_id);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id)); 963 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id));
885 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id)); 964 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id));
886 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id)); 965 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id));
887 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id)); 966 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id));
888 967
889 EXPECT_TRUE(AllInvalidationsAccountedFor()); 968 EXPECT_TRUE(AllInvalidationsAccountedFor());
890 } 969 }
891 970
892 } // namespace sessions 971 } // namespace sessions
893 } // namespace syncer 972 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sessions/sync_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698