OLD | NEW |
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/notifier/invalidation_util.h" | 8 #include "sync/notifier/invalidation_util.h" |
9 #include "sync/notifier/mock_ack_handler.h" | 9 #include "sync/notifier/mock_ack_handler.h" |
10 #include "sync/notifier/object_id_invalidation_map.h" | 10 #include "sync/notifier/object_id_invalidation_map.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NudgeTracker nudge_tracker_; | 76 NudgeTracker nudge_tracker_; |
77 }; | 77 }; |
78 | 78 |
79 // Exercise an empty NudgeTracker. | 79 // Exercise an empty NudgeTracker. |
80 // Use with valgrind to detect uninitialized members. | 80 // Use with valgrind to detect uninitialized members. |
81 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { | 81 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { |
82 // Now we're at the normal, "idle" state. | 82 // Now we're at the normal, "idle" state. |
83 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 83 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
84 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 84 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
85 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, | 85 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, |
86 nudge_tracker_.updates_source()); | 86 nudge_tracker_.GetLegacySource()); |
87 | 87 |
88 sync_pb::GetUpdateTriggers gu_trigger; | 88 sync_pb::GetUpdateTriggers gu_trigger; |
89 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 89 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
90 | 90 |
91 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, | 91 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, |
92 nudge_tracker_.updates_source()); | 92 nudge_tracker_.GetLegacySource()); |
93 } | 93 } |
94 | 94 |
95 // Verify that nudges override each other based on a priority order. | 95 // Verify that nudges override each other based on a priority order. |
96 // LOCAL < DATATYPE_REFRESH < NOTIFICATION | 96 // RETRY < LOCAL < DATATYPE_REFRESH < NOTIFICATION |
97 TEST_F(NudgeTrackerTest, SourcePriorities) { | 97 TEST_F(NudgeTrackerTest, SourcePriorities) { |
| 98 // Start with a retry request. |
| 99 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); |
| 100 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(10); |
| 101 nudge_tracker_.SetNextRetryTime(t0); |
| 102 nudge_tracker_.SetSyncCycleStartTime(t1); |
| 103 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, |
| 104 nudge_tracker_.GetLegacySource()); |
| 105 |
98 // Track a local nudge. | 106 // Track a local nudge. |
99 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 107 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
100 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, | 108 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, |
101 nudge_tracker_.updates_source()); | 109 nudge_tracker_.GetLegacySource()); |
102 | 110 |
103 // A refresh request will override it. | 111 // A refresh request will override it. |
104 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); | 112 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); |
105 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, | 113 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, |
106 nudge_tracker_.updates_source()); | 114 nudge_tracker_.GetLegacySource()); |
107 | 115 |
108 // Another local nudge will not be enough to change it. | 116 // Another local nudge will not be enough to change it. |
109 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 117 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
110 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, | 118 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, |
111 nudge_tracker_.updates_source()); | 119 nudge_tracker_.GetLegacySource()); |
112 | 120 |
113 // An invalidation will override the refresh request source. | 121 // An invalidation will override the refresh request source. |
114 ObjectIdInvalidationMap invalidation_map = | 122 ObjectIdInvalidationMap invalidation_map = |
115 BuildInvalidationMap(PREFERENCES, 1, "hint"); | 123 BuildInvalidationMap(PREFERENCES, 1, "hint"); |
116 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 124 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
117 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 125 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
118 nudge_tracker_.updates_source()); | 126 nudge_tracker_.GetLegacySource()); |
119 | 127 |
120 // Neither local nudges nor refresh requests will override it. | 128 // Neither local nudges nor refresh requests will override it. |
121 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 129 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
122 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 130 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
123 nudge_tracker_.updates_source()); | 131 nudge_tracker_.GetLegacySource()); |
124 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); | 132 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); |
125 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 133 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
126 nudge_tracker_.updates_source()); | 134 nudge_tracker_.GetLegacySource()); |
127 } | 135 } |
128 | 136 |
129 // Verifies the management of invalidation hints and GU trigger fields. | 137 // Verifies the management of invalidation hints and GU trigger fields. |
130 TEST_F(NudgeTrackerTest, HintCoalescing) { | 138 TEST_F(NudgeTrackerTest, HintCoalescing) { |
131 // Easy case: record one hint. | 139 // Easy case: record one hint. |
132 { | 140 { |
133 ObjectIdInvalidationMap invalidation_map = | 141 ObjectIdInvalidationMap invalidation_map = |
134 BuildInvalidationMap(BOOKMARKS, 1, "bm_hint_1"); | 142 BuildInvalidationMap(BOOKMARKS, 1, "bm_hint_1"); |
135 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 143 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
136 | 144 |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); | 907 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); |
900 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); | 908 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); |
901 EXPECT_TRUE(IsInvalidationAcknowledged(inv4)); | 909 EXPECT_TRUE(IsInvalidationAcknowledged(inv4)); |
902 EXPECT_TRUE(IsInvalidationAcknowledged(inv5)); | 910 EXPECT_TRUE(IsInvalidationAcknowledged(inv5)); |
903 | 911 |
904 EXPECT_TRUE(AllInvalidationsAccountedFor()); | 912 EXPECT_TRUE(AllInvalidationsAccountedFor()); |
905 } | 913 } |
906 | 914 |
907 } // namespace sessions | 915 } // namespace sessions |
908 } // namespace syncer | 916 } // namespace syncer |
OLD | NEW |