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

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

Issue 23238005: sync: Remove ModelTypeInvalidationMap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort entries in gyp files Created 7 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
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sessions/sync_session_unittest.cc » ('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 "sync/internal_api/public/base/model_type_test_util.h"
5 #include "sync/sessions/nudge_tracker.h" 6 #include "sync/sessions/nudge_tracker.h"
6
7 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
8 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
9 8
10 namespace syncer { 9 namespace syncer {
11 10
12 namespace { 11 namespace {
13 12
14 testing::AssertionResult ModelTypeSetEquals(ModelTypeSet a, ModelTypeSet b) { 13 testing::AssertionResult ModelTypeSetEquals(ModelTypeSet a, ModelTypeSet b) {
15 if (a.Equals(b)) { 14 if (a.Equals(b)) {
16 return testing::AssertionSuccess(); 15 return testing::AssertionSuccess();
17 } else { 16 } else {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); 84 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS));
86 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, 85 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
87 nudge_tracker.updates_source()); 86 nudge_tracker.updates_source());
88 87
89 // Another local nudge will not be enough to change it. 88 // Another local nudge will not be enough to change it.
90 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 89 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
91 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, 90 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
92 nudge_tracker.updates_source()); 91 nudge_tracker.updates_source());
93 92
94 // An invalidation will override the refresh request source. 93 // An invalidation will override the refresh request source.
95 ModelTypeInvalidationMap invalidation_map = 94 ObjectIdInvalidationMap invalidation_map =
96 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES), 95 BuildInvalidationMap(PREFERENCES, 1, "hint");
97 std::string("hint"));
98 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 96 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
99 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, 97 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
100 nudge_tracker.updates_source()); 98 nudge_tracker.updates_source());
101 99
102 // Neither local nudges nor refresh requests will override it. 100 // Neither local nudges nor refresh requests will override it.
103 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 101 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
104 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, 102 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
105 nudge_tracker.updates_source()); 103 nudge_tracker.updates_source());
106 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); 104 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS));
107 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, 105 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
108 nudge_tracker.updates_source()); 106 nudge_tracker.updates_source());
109 } 107 }
110 108
111 TEST_F(NudgeTrackerTest, HintCoalescing) { 109 TEST_F(NudgeTrackerTest, HintCoalescing) {
112 NudgeTracker nudge_tracker; 110 NudgeTracker nudge_tracker;
113 111
114 // Easy case: record one hint. 112 // Easy case: record one hint.
115 { 113 {
116 ModelTypeInvalidationMap invalidation_map = 114 ObjectIdInvalidationMap invalidation_map =
117 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 115 BuildInvalidationMap(BOOKMARKS, 1, "bm_hint_1");
118 std::string("bm_hint_1"));
119 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 116 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
120 117
121 sync_pb::GetUpdateTriggers gu_trigger; 118 sync_pb::GetUpdateTriggers gu_trigger;
122 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); 119 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger);
123 ASSERT_EQ(1, gu_trigger.notification_hint_size()); 120 ASSERT_EQ(1, gu_trigger.notification_hint_size());
124 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0)); 121 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0));
125 EXPECT_FALSE(gu_trigger.client_dropped_hints()); 122 EXPECT_FALSE(gu_trigger.client_dropped_hints());
126 } 123 }
127 124
128 // Record a second hint for the same type. 125 // Record a second hint for the same type.
129 { 126 {
130 ModelTypeInvalidationMap invalidation_map = 127 ObjectIdInvalidationMap invalidation_map =
131 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 128 BuildInvalidationMap(BOOKMARKS, 2, "bm_hint_2");
132 std::string("bm_hint_2"));
133 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 129 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
134 130
135 sync_pb::GetUpdateTriggers gu_trigger; 131 sync_pb::GetUpdateTriggers gu_trigger;
136 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); 132 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger);
137 ASSERT_EQ(2, gu_trigger.notification_hint_size()); 133 ASSERT_EQ(2, gu_trigger.notification_hint_size());
138 134
139 // Expect the most hint recent is last in the list. 135 // Expect the most hint recent is last in the list.
140 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0)); 136 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0));
141 EXPECT_EQ("bm_hint_2", gu_trigger.notification_hint(1)); 137 EXPECT_EQ("bm_hint_2", gu_trigger.notification_hint(1));
142 EXPECT_FALSE(gu_trigger.client_dropped_hints()); 138 EXPECT_FALSE(gu_trigger.client_dropped_hints());
143 } 139 }
144 140
145 // Record a hint for a different type. 141 // Record a hint for a different type.
146 { 142 {
147 ModelTypeInvalidationMap invalidation_map = 143 ObjectIdInvalidationMap invalidation_map =
148 ModelTypeSetToInvalidationMap(ModelTypeSet(PASSWORDS), 144 BuildInvalidationMap(PASSWORDS, 1, "pw_hint_1");
149 std::string("pw_hint_1"));
150 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 145 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
151 146
152 // Re-verify the bookmarks to make sure they're unaffected. 147 // Re-verify the bookmarks to make sure they're unaffected.
153 sync_pb::GetUpdateTriggers bm_gu_trigger; 148 sync_pb::GetUpdateTriggers bm_gu_trigger;
154 nudge_tracker.FillProtoMessage(BOOKMARKS, &bm_gu_trigger); 149 nudge_tracker.FillProtoMessage(BOOKMARKS, &bm_gu_trigger);
155 ASSERT_EQ(2, bm_gu_trigger.notification_hint_size()); 150 ASSERT_EQ(2, bm_gu_trigger.notification_hint_size());
156 EXPECT_EQ("bm_hint_1", bm_gu_trigger.notification_hint(0)); 151 EXPECT_EQ("bm_hint_1", bm_gu_trigger.notification_hint(0));
157 EXPECT_EQ("bm_hint_2", 152 EXPECT_EQ("bm_hint_2",
158 bm_gu_trigger.notification_hint(1)); // most recent last. 153 bm_gu_trigger.notification_hint(1)); // most recent last.
159 EXPECT_FALSE(bm_gu_trigger.client_dropped_hints()); 154 EXPECT_FALSE(bm_gu_trigger.client_dropped_hints());
160 155
161 // Verify the new type, too. 156 // Verify the new type, too.
162 sync_pb::GetUpdateTriggers pw_gu_trigger; 157 sync_pb::GetUpdateTriggers pw_gu_trigger;
163 nudge_tracker.FillProtoMessage(PASSWORDS, &pw_gu_trigger); 158 nudge_tracker.FillProtoMessage(PASSWORDS, &pw_gu_trigger);
164 ASSERT_EQ(1, pw_gu_trigger.notification_hint_size()); 159 ASSERT_EQ(1, pw_gu_trigger.notification_hint_size());
165 EXPECT_EQ("pw_hint_1", pw_gu_trigger.notification_hint(0)); 160 EXPECT_EQ("pw_hint_1", pw_gu_trigger.notification_hint(0));
166 EXPECT_FALSE(pw_gu_trigger.client_dropped_hints()); 161 EXPECT_FALSE(pw_gu_trigger.client_dropped_hints());
167 } 162 }
168 } 163 }
169 164
170 TEST_F(NudgeTrackerTest, DropHintsLocally) { 165 TEST_F(NudgeTrackerTest, DropHintsLocally) {
171 NudgeTracker nudge_tracker; 166 NudgeTracker nudge_tracker;
172 ModelTypeInvalidationMap invalidation_map = 167 ObjectIdInvalidationMap invalidation_map =
173 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 168 BuildInvalidationMap(BOOKMARKS, 1, "hint");
174 std::string("hint"));
175 169
176 for (size_t i = 0; i < GetHintBufferSize(); ++i) { 170 for (size_t i = 0; i < GetHintBufferSize(); ++i) {
177 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 171 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
178 } 172 }
179 { 173 {
180 sync_pb::GetUpdateTriggers gu_trigger; 174 sync_pb::GetUpdateTriggers gu_trigger;
181 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); 175 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger);
182 EXPECT_EQ(GetHintBufferSize(), 176 EXPECT_EQ(GetHintBufferSize(),
183 static_cast<size_t>(gu_trigger.notification_hint_size())); 177 static_cast<size_t>(gu_trigger.notification_hint_size()));
184 EXPECT_FALSE(gu_trigger.client_dropped_hints()); 178 EXPECT_FALSE(gu_trigger.client_dropped_hints());
185 } 179 }
186 180
187 // Force an overflow. 181 // Force an overflow.
188 ModelTypeInvalidationMap invalidation_map2 = 182 ObjectIdInvalidationMap invalidation_map2 =
189 ModelTypeSetToInvalidationMap(ModelTypeSet(BOOKMARKS), 183 BuildInvalidationMap(BOOKMARKS, 1000, "new_hint");
190 std::string("new_hint"));
191 nudge_tracker.RecordRemoteInvalidation(invalidation_map2); 184 nudge_tracker.RecordRemoteInvalidation(invalidation_map2);
192 185
193 { 186 {
194 sync_pb::GetUpdateTriggers gu_trigger; 187 sync_pb::GetUpdateTriggers gu_trigger;
195 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); 188 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger);
196 EXPECT_EQ(GetHintBufferSize(), 189 EXPECT_EQ(GetHintBufferSize(),
197 static_cast<size_t>(gu_trigger.notification_hint_size())); 190 static_cast<size_t>(gu_trigger.notification_hint_size()));
198 EXPECT_TRUE(gu_trigger.client_dropped_hints()); 191 EXPECT_TRUE(gu_trigger.client_dropped_hints());
199 192
200 // Verify the newest hint was not dropped and is the last in the list. 193 // Verify the newest hint was not dropped and is the last in the list.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 nudge_tracker.RecordSuccessfulSyncCycle(); 276 nudge_tracker.RecordSuccessfulSyncCycle();
284 EXPECT_FALSE(nudge_tracker.IsSyncRequired()); 277 EXPECT_FALSE(nudge_tracker.IsSyncRequired());
285 278
286 // Refresh requests. 279 // Refresh requests.
287 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); 280 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
288 EXPECT_TRUE(nudge_tracker.IsSyncRequired()); 281 EXPECT_TRUE(nudge_tracker.IsSyncRequired());
289 nudge_tracker.RecordSuccessfulSyncCycle(); 282 nudge_tracker.RecordSuccessfulSyncCycle();
290 EXPECT_FALSE(nudge_tracker.IsSyncRequired()); 283 EXPECT_FALSE(nudge_tracker.IsSyncRequired());
291 284
292 // Invalidations. 285 // Invalidations.
293 ModelTypeInvalidationMap invalidation_map = 286 ObjectIdInvalidationMap invalidation_map =
294 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES), 287 BuildInvalidationMap(PREFERENCES, 1, "hint");
295 std::string("hint"));
296 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 288 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
297 EXPECT_TRUE(nudge_tracker.IsSyncRequired()); 289 EXPECT_TRUE(nudge_tracker.IsSyncRequired());
298 nudge_tracker.RecordSuccessfulSyncCycle(); 290 nudge_tracker.RecordSuccessfulSyncCycle();
299 EXPECT_FALSE(nudge_tracker.IsSyncRequired()); 291 EXPECT_FALSE(nudge_tracker.IsSyncRequired());
300 } 292 }
301 293
302 // Basic tests for the IsGetUpdatesRequired() flag. 294 // Basic tests for the IsGetUpdatesRequired() flag.
303 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) { 295 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) {
304 NudgeTracker nudge_tracker; 296 NudgeTracker nudge_tracker;
305 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired()); 297 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired());
306 298
307 // Local changes. 299 // Local changes.
308 nudge_tracker.RecordLocalChange(ModelTypeSet(SESSIONS)); 300 nudge_tracker.RecordLocalChange(ModelTypeSet(SESSIONS));
309 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired()); 301 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired());
310 nudge_tracker.RecordSuccessfulSyncCycle(); 302 nudge_tracker.RecordSuccessfulSyncCycle();
311 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired()); 303 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired());
312 304
313 // Refresh requests. 305 // Refresh requests.
314 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); 306 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
315 EXPECT_TRUE(nudge_tracker.IsGetUpdatesRequired()); 307 EXPECT_TRUE(nudge_tracker.IsGetUpdatesRequired());
316 nudge_tracker.RecordSuccessfulSyncCycle(); 308 nudge_tracker.RecordSuccessfulSyncCycle();
317 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired()); 309 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired());
318 310
319 // Invalidations. 311 // Invalidations.
320 ModelTypeInvalidationMap invalidation_map = 312 ObjectIdInvalidationMap invalidation_map =
321 ModelTypeSetToInvalidationMap(ModelTypeSet(PREFERENCES), 313 BuildInvalidationMap(PREFERENCES, 1, "hint");
322 std::string("hint"));
323 nudge_tracker.RecordRemoteInvalidation(invalidation_map); 314 nudge_tracker.RecordRemoteInvalidation(invalidation_map);
324 EXPECT_TRUE(nudge_tracker.IsGetUpdatesRequired()); 315 EXPECT_TRUE(nudge_tracker.IsGetUpdatesRequired());
325 nudge_tracker.RecordSuccessfulSyncCycle(); 316 nudge_tracker.RecordSuccessfulSyncCycle();
326 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired()); 317 EXPECT_FALSE(nudge_tracker.IsGetUpdatesRequired());
327 } 318 }
328 319
329 // Test IsSyncRequired() responds correctly to data type throttling. 320 // Test IsSyncRequired() responds correctly to data type throttling.
330 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) { 321 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) {
331 NudgeTracker nudge_tracker; 322 NudgeTracker nudge_tracker;
332 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); 323 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 EXPECT_EQ(throttle2_length - throttle1_length, 459 EXPECT_EQ(throttle2_length - throttle1_length,
469 nudge_tracker.GetTimeUntilNextUnthrottle(t1)); 460 nudge_tracker.GetTimeUntilNextUnthrottle(t1));
470 461
471 // Expire the second interval. 462 // Expire the second interval.
472 nudge_tracker.UpdateTypeThrottlingState(t2); 463 nudge_tracker.UpdateTypeThrottlingState(t2);
473 EXPECT_TRUE(nudge_tracker.GetThrottledTypes().Empty()); 464 EXPECT_TRUE(nudge_tracker.GetThrottledTypes().Empty());
474 } 465 }
475 466
476 } // namespace sessions 467 } // namespace sessions
477 } // namespace syncer 468 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sessions/sync_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698