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

Side by Side Diff: components/sync/sessions_impl/nudge_tracker_unittest.cc

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/sync/sessions_impl/nudge_tracker.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "components/sync/base/model_type_test_util.h"
17 #include "components/sync/test/mock_invalidation.h"
18 #include "components/sync/test/mock_invalidation_tracker.h"
19 #include "components/sync/test/trackable_mock_invalidation.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace syncer {
23
24 namespace {
25
26 testing::AssertionResult ModelTypeSetEquals(ModelTypeSet a, ModelTypeSet b) {
27 if (a == b) {
28 return testing::AssertionSuccess();
29 } else {
30 return testing::AssertionFailure()
31 << "Left side " << ModelTypeSetToString(a)
32 << ", does not match rigth side: " << ModelTypeSetToString(b);
33 }
34 }
35
36 } // namespace
37
38 namespace sessions {
39
40 class NudgeTrackerTest : public ::testing::Test {
41 public:
42 NudgeTrackerTest() { SetInvalidationsInSync(); }
43
44 static size_t GetHintBufferSize() {
45 // Assumes that no test has adjusted this size.
46 return NudgeTracker::kDefaultMaxPayloadsPerType;
47 }
48
49 bool InvalidationsOutOfSync() const {
50 // We don't currently track invalidations out of sync on a per-type basis.
51 sync_pb::GetUpdateTriggers gu_trigger;
52 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
53 return gu_trigger.invalidations_out_of_sync();
54 }
55
56 int ProtoLocallyModifiedCount(ModelType type) const {
57 sync_pb::GetUpdateTriggers gu_trigger;
58 nudge_tracker_.FillProtoMessage(type, &gu_trigger);
59 return gu_trigger.local_modification_nudges();
60 }
61
62 int ProtoRefreshRequestedCount(ModelType type) const {
63 sync_pb::GetUpdateTriggers gu_trigger;
64 nudge_tracker_.FillProtoMessage(type, &gu_trigger);
65 return gu_trigger.datatype_refresh_nudges();
66 }
67
68 void SetInvalidationsInSync() {
69 nudge_tracker_.OnInvalidationsEnabled();
70 nudge_tracker_.RecordSuccessfulSyncCycle();
71 }
72
73 std::unique_ptr<InvalidationInterface> BuildInvalidation(
74 int64_t version,
75 const std::string& payload) {
76 return MockInvalidation::Build(version, payload);
77 }
78
79 static std::unique_ptr<InvalidationInterface>
80 BuildUnknownVersionInvalidation() {
81 return MockInvalidation::BuildUnknownVersion();
82 }
83
84 protected:
85 NudgeTracker nudge_tracker_;
86 };
87
88 // Exercise an empty NudgeTracker.
89 // Use with valgrind to detect uninitialized members.
90 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) {
91 // Now we're at the normal, "idle" state.
92 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
93 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
94 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN,
95 nudge_tracker_.GetLegacySource());
96
97 sync_pb::GetUpdateTriggers gu_trigger;
98 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
99
100 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN,
101 nudge_tracker_.GetLegacySource());
102 }
103
104 // Verify that nudges override each other based on a priority order.
105 // RETRY < LOCAL < DATATYPE_REFRESH < NOTIFICATION
106 TEST_F(NudgeTrackerTest, SourcePriorities) {
107 // Start with a retry request.
108 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
109 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(10);
110 nudge_tracker_.SetNextRetryTime(t0);
111 nudge_tracker_.SetSyncCycleStartTime(t1);
112 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY,
113 nudge_tracker_.GetLegacySource());
114
115 // Track a local nudge.
116 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
117 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL,
118 nudge_tracker_.GetLegacySource());
119
120 // A refresh request will override it.
121 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS));
122 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
123 nudge_tracker_.GetLegacySource());
124
125 // Another local nudge will not be enough to change it.
126 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
127 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
128 nudge_tracker_.GetLegacySource());
129
130 // An invalidation will override the refresh request source.
131 nudge_tracker_.RecordRemoteInvalidation(PREFERENCES,
132 BuildInvalidation(1, "hint"));
133 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
134 nudge_tracker_.GetLegacySource());
135
136 // Neither local nudges nor refresh requests will override it.
137 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
138 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
139 nudge_tracker_.GetLegacySource());
140 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS));
141 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
142 nudge_tracker_.GetLegacySource());
143 }
144
145 TEST_F(NudgeTrackerTest, SourcePriority_InitialSyncRequest) {
146 nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
147
148 // For lack of a better source, we describe an initial sync request as having
149 // source DATATYPE_REFRESH.
150 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
151 nudge_tracker_.GetLegacySource());
152
153 // This should never happen in practice. But, if it did, we'd want the
154 // initial sync required to keep the source set to DATATYPE_REFRESH.
155 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
156 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
157 nudge_tracker_.GetLegacySource());
158
159 // It should be safe to let NOTIFICATIONs override it.
160 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
161 BuildInvalidation(1, "hint"));
162 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
163 nudge_tracker_.GetLegacySource());
164 }
165
166 // Verifies the management of invalidation hints and GU trigger fields.
167 TEST_F(NudgeTrackerTest, HintCoalescing) {
168 // Easy case: record one hint.
169 {
170 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
171 BuildInvalidation(1, "bm_hint_1"));
172
173 sync_pb::GetUpdateTriggers gu_trigger;
174 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
175 ASSERT_EQ(1, gu_trigger.notification_hint_size());
176 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0));
177 EXPECT_FALSE(gu_trigger.client_dropped_hints());
178 }
179
180 // Record a second hint for the same type.
181 {
182 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
183 BuildInvalidation(2, "bm_hint_2"));
184
185 sync_pb::GetUpdateTriggers gu_trigger;
186 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
187 ASSERT_EQ(2, gu_trigger.notification_hint_size());
188
189 // Expect the most hint recent is last in the list.
190 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0));
191 EXPECT_EQ("bm_hint_2", gu_trigger.notification_hint(1));
192 EXPECT_FALSE(gu_trigger.client_dropped_hints());
193 }
194
195 // Record a hint for a different type.
196 {
197 nudge_tracker_.RecordRemoteInvalidation(PASSWORDS,
198 BuildInvalidation(1, "pw_hint_1"));
199
200 // Re-verify the bookmarks to make sure they're unaffected.
201 sync_pb::GetUpdateTriggers bm_gu_trigger;
202 nudge_tracker_.FillProtoMessage(BOOKMARKS, &bm_gu_trigger);
203 ASSERT_EQ(2, bm_gu_trigger.notification_hint_size());
204 EXPECT_EQ("bm_hint_1", bm_gu_trigger.notification_hint(0));
205 EXPECT_EQ("bm_hint_2",
206 bm_gu_trigger.notification_hint(1)); // most recent last.
207 EXPECT_FALSE(bm_gu_trigger.client_dropped_hints());
208
209 // Verify the new type, too.
210 sync_pb::GetUpdateTriggers pw_gu_trigger;
211 nudge_tracker_.FillProtoMessage(PASSWORDS, &pw_gu_trigger);
212 ASSERT_EQ(1, pw_gu_trigger.notification_hint_size());
213 EXPECT_EQ("pw_hint_1", pw_gu_trigger.notification_hint(0));
214 EXPECT_FALSE(pw_gu_trigger.client_dropped_hints());
215 }
216 }
217
218 // Test the dropping of invalidation hints. Receives invalidations one by one.
219 TEST_F(NudgeTrackerTest, DropHintsLocally_OneAtATime) {
220 for (size_t i = 0; i < GetHintBufferSize(); ++i) {
221 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
222 BuildInvalidation(i, "hint"));
223 }
224 {
225 sync_pb::GetUpdateTriggers gu_trigger;
226 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
227 EXPECT_EQ(GetHintBufferSize(),
228 static_cast<size_t>(gu_trigger.notification_hint_size()));
229 EXPECT_FALSE(gu_trigger.client_dropped_hints());
230 }
231
232 // Force an overflow.
233 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
234 BuildInvalidation(1000, "new_hint"));
235
236 {
237 sync_pb::GetUpdateTriggers gu_trigger;
238 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
239 EXPECT_TRUE(gu_trigger.client_dropped_hints());
240 ASSERT_EQ(GetHintBufferSize(),
241 static_cast<size_t>(gu_trigger.notification_hint_size()));
242
243 // Verify the newest hint was not dropped and is the last in the list.
244 EXPECT_EQ("new_hint",
245 gu_trigger.notification_hint(GetHintBufferSize() - 1));
246
247 // Verify the oldest hint, too.
248 EXPECT_EQ("hint", gu_trigger.notification_hint(0));
249 }
250 }
251
252 // Tests the receipt of 'unknown version' invalidations.
253 TEST_F(NudgeTrackerTest, DropHintsAtServer_Alone) {
254 // Record the unknown version invalidation.
255 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
256 BuildUnknownVersionInvalidation());
257 {
258 sync_pb::GetUpdateTriggers gu_trigger;
259 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
260 EXPECT_TRUE(gu_trigger.server_dropped_hints());
261 EXPECT_FALSE(gu_trigger.client_dropped_hints());
262 ASSERT_EQ(0, gu_trigger.notification_hint_size());
263 }
264
265 // Clear status then verify.
266 nudge_tracker_.RecordSuccessfulSyncCycle();
267 {
268 sync_pb::GetUpdateTriggers gu_trigger;
269 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
270 EXPECT_FALSE(gu_trigger.client_dropped_hints());
271 EXPECT_FALSE(gu_trigger.server_dropped_hints());
272 ASSERT_EQ(0, gu_trigger.notification_hint_size());
273 }
274 }
275
276 // Tests the receipt of 'unknown version' invalidations. This test also
277 // includes a known version invalidation to mix things up a bit.
278 TEST_F(NudgeTrackerTest, DropHintsAtServer_WithOtherInvalidations) {
279 // Record the two invalidations, one with unknown version, the other known.
280 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
281 BuildUnknownVersionInvalidation());
282 nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
283 BuildInvalidation(10, "hint"));
284
285 {
286 sync_pb::GetUpdateTriggers gu_trigger;
287 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
288 EXPECT_TRUE(gu_trigger.server_dropped_hints());
289 EXPECT_FALSE(gu_trigger.client_dropped_hints());
290 ASSERT_EQ(1, gu_trigger.notification_hint_size());
291 EXPECT_EQ("hint", gu_trigger.notification_hint(0));
292 }
293
294 // Clear status then verify.
295 nudge_tracker_.RecordSuccessfulSyncCycle();
296 {
297 sync_pb::GetUpdateTriggers gu_trigger;
298 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger);
299 EXPECT_FALSE(gu_trigger.client_dropped_hints());
300 EXPECT_FALSE(gu_trigger.server_dropped_hints());
301 ASSERT_EQ(0, gu_trigger.notification_hint_size());
302 }
303 }
304
305 // Checks the behaviour of the invalidations-out-of-sync flag.
306 TEST_F(NudgeTrackerTest, EnableDisableInvalidations) {
307 // Start with invalidations offline.
308 nudge_tracker_.OnInvalidationsDisabled();
309 EXPECT_TRUE(InvalidationsOutOfSync());
310 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
311
312 // Simply enabling invalidations does not bring us back into sync.
313 nudge_tracker_.OnInvalidationsEnabled();
314 EXPECT_TRUE(InvalidationsOutOfSync());
315 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
316
317 // We must successfully complete a sync cycle while invalidations are enabled
318 // to be sure that we're in sync.
319 nudge_tracker_.RecordSuccessfulSyncCycle();
320 EXPECT_FALSE(InvalidationsOutOfSync());
321 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
322
323 // If the invalidator malfunctions, we go become unsynced again.
324 nudge_tracker_.OnInvalidationsDisabled();
325 EXPECT_TRUE(InvalidationsOutOfSync());
326 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
327
328 // A sync cycle while invalidations are disabled won't reset the flag.
329 nudge_tracker_.RecordSuccessfulSyncCycle();
330 EXPECT_TRUE(InvalidationsOutOfSync());
331 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
332
333 // Nor will the re-enabling of invalidations be sufficient, even now that
334 // we've had a successful sync cycle.
335 nudge_tracker_.RecordSuccessfulSyncCycle();
336 EXPECT_TRUE(InvalidationsOutOfSync());
337 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
338 }
339
340 // Tests that locally modified types are correctly written out to the
341 // GetUpdateTriggers proto.
342 TEST_F(NudgeTrackerTest, WriteLocallyModifiedTypesToProto) {
343 // Should not be locally modified by default.
344 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES));
345
346 // Record a local bookmark change. Verify it was registered correctly.
347 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES));
348 EXPECT_EQ(1, ProtoLocallyModifiedCount(PREFERENCES));
349
350 // Record a successful sync cycle. Verify the count is cleared.
351 nudge_tracker_.RecordSuccessfulSyncCycle();
352 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES));
353 }
354
355 // Tests that refresh requested types are correctly written out to the
356 // GetUpdateTriggers proto.
357 TEST_F(NudgeTrackerTest, WriteRefreshRequestedTypesToProto) {
358 // There should be no refresh requested by default.
359 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS));
360
361 // Record a local refresh request. Verify it was registered correctly.
362 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
363 EXPECT_EQ(1, ProtoRefreshRequestedCount(SESSIONS));
364
365 // Record a successful sync cycle. Verify the count is cleared.
366 nudge_tracker_.RecordSuccessfulSyncCycle();
367 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS));
368 }
369
370 // Basic tests for the IsSyncRequired() flag.
371 TEST_F(NudgeTrackerTest, IsSyncRequired) {
372 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
373
374 // Initial sync request.
375 nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
376 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
377 nudge_tracker_.RecordSuccessfulSyncCycle();
378 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
379
380 // Sync request for resolve conflict.
381 nudge_tracker_.RecordCommitConflict(BOOKMARKS);
382 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
383 nudge_tracker_.RecordSuccessfulSyncCycle();
384 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
385
386 // Local changes.
387 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS));
388 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
389 nudge_tracker_.RecordSuccessfulSyncCycle();
390 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
391
392 // Refresh requests.
393 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
394 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
395 nudge_tracker_.RecordSuccessfulSyncCycle();
396 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
397
398 // Invalidations.
399 nudge_tracker_.RecordRemoteInvalidation(PREFERENCES,
400 BuildInvalidation(1, "hint"));
401 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
402 nudge_tracker_.RecordSuccessfulSyncCycle();
403 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
404 }
405
406 // Basic tests for the IsGetUpdatesRequired() flag.
407 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) {
408 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
409
410 // Initial sync request.
411 nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
412 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
413 nudge_tracker_.RecordSuccessfulSyncCycle();
414 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
415
416 // Local changes.
417 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS));
418 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
419 nudge_tracker_.RecordSuccessfulSyncCycle();
420 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
421
422 // Refresh requests.
423 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
424 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
425 nudge_tracker_.RecordSuccessfulSyncCycle();
426 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
427
428 // Invalidations.
429 nudge_tracker_.RecordRemoteInvalidation(PREFERENCES,
430 BuildInvalidation(1, "hint"));
431 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
432 nudge_tracker_.RecordSuccessfulSyncCycle();
433 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
434 }
435
436 // Test IsSyncRequired() responds correctly to data type throttling.
437 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) {
438 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
439 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10);
440 const base::TimeTicks t1 = t0 + throttle_length;
441
442 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
443
444 // A local change to sessions enables the flag.
445 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS));
446 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
447
448 // But the throttling of sessions unsets it.
449 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length,
450 t0);
451 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
452
453 // A refresh request for bookmarks means we have reason to sync again.
454 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS));
455 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
456
457 // A successful sync cycle means we took care of bookmarks.
458 nudge_tracker_.RecordSuccessfulSyncCycle();
459 EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
460
461 // But we still haven't dealt with sessions. We'll need to remember
462 // that sessions are out of sync and re-enable the flag when their
463 // throttling interval expires.
464 nudge_tracker_.UpdateTypeThrottlingState(t1);
465 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS));
466 EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
467 }
468
469 // Test IsGetUpdatesRequired() responds correctly to data type throttling.
470 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired_Throttling) {
471 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
472 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10);
473 const base::TimeTicks t1 = t0 + throttle_length;
474
475 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
476
477 // A refresh request to sessions enables the flag.
478 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS));
479 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
480
481 // But the throttling of sessions unsets it.
482 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length,
483 t0);
484 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
485
486 // A refresh request for bookmarks means we have reason to sync again.
487 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS));
488 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
489
490 // A successful sync cycle means we took care of bookmarks.
491 nudge_tracker_.RecordSuccessfulSyncCycle();
492 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
493
494 // But we still haven't dealt with sessions. We'll need to remember
495 // that sessions are out of sync and re-enable the flag when their
496 // throttling interval expires.
497 nudge_tracker_.UpdateTypeThrottlingState(t1);
498 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS));
499 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
500 }
501
502 // Tests throttling-related getter functions when no types are throttled.
503 TEST_F(NudgeTrackerTest, NoTypesThrottled) {
504 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled());
505 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS));
506 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty());
507 }
508
509 // Tests throttling-related getter functions when some types are throttled.
510 TEST_F(NudgeTrackerTest, ThrottleAndUnthrottle) {
511 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
512 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10);
513 const base::TimeTicks t1 = t0 + throttle_length;
514
515 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES),
516 throttle_length, t0);
517
518 EXPECT_TRUE(nudge_tracker_.IsAnyTypeThrottled());
519 EXPECT_TRUE(nudge_tracker_.IsTypeThrottled(SESSIONS));
520 EXPECT_TRUE(nudge_tracker_.IsTypeThrottled(PREFERENCES));
521 EXPECT_FALSE(nudge_tracker_.GetThrottledTypes().Empty());
522 EXPECT_EQ(throttle_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0));
523
524 nudge_tracker_.UpdateTypeThrottlingState(t1);
525
526 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled());
527 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS));
528 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty());
529 }
530
531 TEST_F(NudgeTrackerTest, OverlappingThrottleIntervals) {
532 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234);
533 const base::TimeDelta throttle1_length = base::TimeDelta::FromMinutes(10);
534 const base::TimeDelta throttle2_length = base::TimeDelta::FromMinutes(20);
535 const base::TimeTicks t1 = t0 + throttle1_length;
536 const base::TimeTicks t2 = t0 + throttle2_length;
537
538 // Setup the longer of two intervals.
539 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES),
540 throttle2_length, t0);
541 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES),
542 nudge_tracker_.GetThrottledTypes()));
543 EXPECT_EQ(throttle2_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0));
544
545 // Setup the shorter interval.
546 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, BOOKMARKS),
547 throttle1_length, t0);
548 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES, BOOKMARKS),
549 nudge_tracker_.GetThrottledTypes()));
550 EXPECT_EQ(throttle1_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0));
551
552 // Expire the first interval.
553 nudge_tracker_.UpdateTypeThrottlingState(t1);
554
555 // SESSIONS appeared in both intervals. We expect it will be throttled for
556 // the longer of the two, so it's still throttled at time t1.
557 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES),
558 nudge_tracker_.GetThrottledTypes()));
559 EXPECT_EQ(throttle2_length - throttle1_length,
560 nudge_tracker_.GetTimeUntilNextUnthrottle(t1));
561
562 // Expire the second interval.
563 nudge_tracker_.UpdateTypeThrottlingState(t2);
564 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty());
565 }
566
567 TEST_F(NudgeTrackerTest, Retry) {
568 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345);
569 const base::TimeTicks t3 = t0 + base::TimeDelta::FromSeconds(3);
570 const base::TimeTicks t4 = t0 + base::TimeDelta::FromSeconds(4);
571
572 // Set retry for t3.
573 nudge_tracker_.SetNextRetryTime(t3);
574
575 // Not due yet at t0.
576 nudge_tracker_.SetSyncCycleStartTime(t0);
577 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
578 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
579
580 // Successful sync cycle at t0 changes nothing.
581 nudge_tracker_.RecordSuccessfulSyncCycle();
582 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
583 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
584
585 // At t4, the retry becomes due.
586 nudge_tracker_.SetSyncCycleStartTime(t4);
587 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
588 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
589
590 // A sync cycle unsets the flag.
591 nudge_tracker_.RecordSuccessfulSyncCycle();
592 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
593
594 // It's still unset at the start of the next sync cycle.
595 nudge_tracker_.SetSyncCycleStartTime(t4);
596 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
597 }
598
599 // Test a mid-cycle update when IsRetryRequired() was true before the cycle
600 // began.
601 TEST_F(NudgeTrackerTest, IsRetryRequired_MidCycleUpdate1) {
602 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345);
603 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(1);
604 const base::TimeTicks t2 = t0 + base::TimeDelta::FromSeconds(2);
605 const base::TimeTicks t5 = t0 + base::TimeDelta::FromSeconds(5);
606 const base::TimeTicks t6 = t0 + base::TimeDelta::FromSeconds(6);
607
608 nudge_tracker_.SetNextRetryTime(t0);
609 nudge_tracker_.SetSyncCycleStartTime(t1);
610
611 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
612
613 // Pretend that we were updated mid-cycle. SetSyncCycleStartTime is
614 // called only at the start of the sync cycle, so don't call it here.
615 // The update should have no effect on IsRetryRequired().
616 nudge_tracker_.SetNextRetryTime(t5);
617
618 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
619
620 // Verify that the successful sync cycle clears the flag.
621 nudge_tracker_.RecordSuccessfulSyncCycle();
622 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
623
624 // Verify expecations around the new retry time.
625 nudge_tracker_.SetSyncCycleStartTime(t2);
626 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
627
628 nudge_tracker_.SetSyncCycleStartTime(t6);
629 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
630 }
631
632 // Test a mid-cycle update when IsRetryRequired() was false before the cycle
633 // began.
634 TEST_F(NudgeTrackerTest, IsRetryRequired_MidCycleUpdate2) {
635 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345);
636 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(1);
637 const base::TimeTicks t3 = t0 + base::TimeDelta::FromSeconds(3);
638 const base::TimeTicks t5 = t0 + base::TimeDelta::FromSeconds(5);
639 const base::TimeTicks t6 = t0 + base::TimeDelta::FromSeconds(6);
640
641 // Schedule a future retry, and a nudge unrelated to it.
642 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
643 nudge_tracker_.SetNextRetryTime(t1);
644 nudge_tracker_.SetSyncCycleStartTime(t0);
645 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
646
647 // Pretend this happened in mid-cycle. This should have no effect on
648 // IsRetryRequired().
649 nudge_tracker_.SetNextRetryTime(t5);
650 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
651
652 // The cycle succeeded.
653 nudge_tracker_.RecordSuccessfulSyncCycle();
654
655 // The time t3 is greater than the GU retry time scheduled at the beginning of
656 // the test, but later than the retry time that overwrote it during the
657 // pretend 'sync cycle'.
658 nudge_tracker_.SetSyncCycleStartTime(t3);
659 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
660
661 // Finally, the retry established during the sync cycle becomes due.
662 nudge_tracker_.SetSyncCycleStartTime(t6);
663 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
664 }
665
666 // Simulate the case where a sync cycle fails.
667 TEST_F(NudgeTrackerTest, IsRetryRequired_FailedCycle) {
668 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345);
669 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(1);
670 const base::TimeTicks t2 = t0 + base::TimeDelta::FromSeconds(2);
671
672 nudge_tracker_.SetNextRetryTime(t0);
673 nudge_tracker_.SetSyncCycleStartTime(t1);
674 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
675
676 // The nudge tracker receives no notifications for a failed sync cycle.
677 // Pretend one happened here.
678 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
679
680 // Think of this as the retry cycle.
681 nudge_tracker_.SetSyncCycleStartTime(t2);
682 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
683
684 // The second cycle is a success.
685 nudge_tracker_.RecordSuccessfulSyncCycle();
686 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
687 }
688
689 // Simulate a partially failed sync cycle. The callback to update the GU retry
690 // was invoked, but the sync cycle did not complete successfully.
691 TEST_F(NudgeTrackerTest, IsRetryRequired_FailedCycleIncludesUpdate) {
692 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345);
693 const base::TimeTicks t1 = t0 + base::TimeDelta::FromSeconds(1);
694 const base::TimeTicks t3 = t0 + base::TimeDelta::FromSeconds(3);
695 const base::TimeTicks t4 = t0 + base::TimeDelta::FromSeconds(4);
696 const base::TimeTicks t5 = t0 + base::TimeDelta::FromSeconds(5);
697 const base::TimeTicks t6 = t0 + base::TimeDelta::FromSeconds(6);
698
699 nudge_tracker_.SetNextRetryTime(t0);
700 nudge_tracker_.SetSyncCycleStartTime(t1);
701 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
702
703 // The cycle is in progress. A new GU Retry time is received.
704 // The flag is not because this cycle is still in progress.
705 nudge_tracker_.SetNextRetryTime(t5);
706 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
707
708 // The nudge tracker receives no notifications for a failed sync cycle.
709 // Pretend the cycle failed here.
710
711 // The next sync cycle starts. The new GU time has not taken effect by this
712 // time, but the NudgeTracker hasn't forgotten that we have not yet serviced
713 // the retry from the previous cycle.
714 nudge_tracker_.SetSyncCycleStartTime(t3);
715 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
716
717 // It succeeds. The retry time is not updated, so it should remain at t5.
718 nudge_tracker_.RecordSuccessfulSyncCycle();
719
720 // Another sync cycle. This one is still before the scheduled retry. It does
721 // not change the scheduled retry time.
722 nudge_tracker_.SetSyncCycleStartTime(t4);
723 EXPECT_FALSE(nudge_tracker_.IsRetryRequired());
724 nudge_tracker_.RecordSuccessfulSyncCycle();
725
726 // The retry scheduled way back during the first cycle of this test finally
727 // becomes due. Perform a successful sync cycle to service it.
728 nudge_tracker_.SetSyncCycleStartTime(t6);
729 EXPECT_TRUE(nudge_tracker_.IsRetryRequired());
730 nudge_tracker_.RecordSuccessfulSyncCycle();
731 }
732
733 // Test the default nudge delays for various types.
734 TEST_F(NudgeTrackerTest, NudgeDelayTest) {
735 // Set to a known value to compare against.
736 nudge_tracker_.SetDefaultNudgeDelay(base::TimeDelta());
737
738 // Bookmarks and preference both have "slow nudge" delays.
739 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
740 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)));
741
742 // Typed URLs has a default delay.
743 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS)),
744 base::TimeDelta());
745
746 // "Slow nudge" delays are longer than the default.
747 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
748 base::TimeDelta());
749
750 // Sessions is longer than "slow nudge".
751 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)),
752 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)));
753
754 // Favicons have the same delay as sessions.
755 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)),
756 nudge_tracker_.RecordLocalChange(ModelTypeSet(FAVICON_TRACKING)));
757
758 // Autofill has the longer delay of all.
759 EXPECT_GT(nudge_tracker_.RecordLocalChange(ModelTypeSet(AUTOFILL)),
760 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)));
761
762 // A nudge with no types takes the longest delay.
763 EXPECT_EQ(nudge_tracker_.RecordLocalChange(ModelTypeSet(AUTOFILL)),
764 nudge_tracker_.RecordLocalChange(ModelTypeSet()));
765
766 // The actual nudge delay should be the shortest of the set.
767 EXPECT_EQ(
768 nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS)),
769 nudge_tracker_.RecordLocalChange(ModelTypeSet(TYPED_URLS, AUTOFILL)));
770 }
771
772 // Test that custom nudge delays are used over the defaults.
773 TEST_F(NudgeTrackerTest, CustomDelayTest) {
774 // Set some custom delays.
775 std::map<ModelType, base::TimeDelta> delay_map;
776 delay_map[BOOKMARKS] = base::TimeDelta::FromSeconds(10);
777 delay_map[SESSIONS] = base::TimeDelta::FromSeconds(2);
778 nudge_tracker_.OnReceivedCustomNudgeDelays(delay_map);
779
780 // Only those with custom delays should be affected, not another type.
781 EXPECT_NE(nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)),
782 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)));
783
784 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
785 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)));
786 EXPECT_EQ(base::TimeDelta::FromSeconds(2),
787 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)));
788 }
789
790 // Check that custom nudge delays can never result in a value shorter than the
791 // minimum nudge delay.
792 TEST_F(NudgeTrackerTest, NoTypesShorterThanDefault) {
793 // Set delay to a known value.
794 nudge_tracker_.SetDefaultNudgeDelay(base::TimeDelta::FromMilliseconds(500));
795
796 std::map<ModelType, base::TimeDelta> delay_map;
797 ModelTypeSet protocol_types = syncer::ProtocolTypes();
798 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
799 iter.Inc()) {
800 delay_map[iter.Get()] = base::TimeDelta();
801 }
802 nudge_tracker_.OnReceivedCustomNudgeDelays(delay_map);
803
804 // All types should still have a nudge greater than or equal to the minimum.
805 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
806 iter.Inc()) {
807 EXPECT_GE(nudge_tracker_.RecordLocalChange(ModelTypeSet(iter.Get())),
808 base::TimeDelta::FromMilliseconds(500));
809 }
810 }
811
812 class NudgeTrackerAckTrackingTest : public NudgeTrackerTest {
813 public:
814 NudgeTrackerAckTrackingTest() {}
815
816 bool IsInvalidationUnacknowledged(int tracking_id) {
817 return tracker_.IsUnacked(tracking_id);
818 }
819
820 bool IsInvalidationAcknowledged(int tracking_id) {
821 return tracker_.IsAcknowledged(tracking_id);
822 }
823
824 bool IsInvalidationDropped(int tracking_id) {
825 return tracker_.IsDropped(tracking_id);
826 }
827
828 int SendInvalidation(ModelType type, int version, const std::string& hint) {
829 // Build and register the invalidation.
830 std::unique_ptr<TrackableMockInvalidation> inv =
831 tracker_.IssueInvalidation(version, hint);
832 int id = inv->GetTrackingId();
833
834 // Send it to the NudgeTracker.
835 nudge_tracker_.RecordRemoteInvalidation(type, std::move(inv));
836
837 // Return its ID to the test framework for use in assertions.
838 return id;
839 }
840
841 int SendUnknownVersionInvalidation(ModelType type) {
842 // Build and register the invalidation.
843 std::unique_ptr<TrackableMockInvalidation> inv =
844 tracker_.IssueUnknownVersionInvalidation();
845 int id = inv->GetTrackingId();
846
847 // Send it to the NudgeTracker.
848 nudge_tracker_.RecordRemoteInvalidation(type, std::move(inv));
849
850 // Return its ID to the test framework for use in assertions.
851 return id;
852 }
853
854 bool AllInvalidationsAccountedFor() const {
855 return tracker_.AllInvalidationsAccountedFor();
856 }
857
858 void RecordSuccessfulSyncCycle() {
859 nudge_tracker_.RecordSuccessfulSyncCycle();
860 }
861
862 private:
863 MockInvalidationTracker tracker_;
864 };
865
866 // Test the acknowledgement of a single invalidation.
867 TEST_F(NudgeTrackerAckTrackingTest, SimpleAcknowledgement) {
868 int inv_id = SendInvalidation(BOOKMARKS, 10, "hint");
869
870 EXPECT_TRUE(IsInvalidationUnacknowledged(inv_id));
871
872 RecordSuccessfulSyncCycle();
873 EXPECT_TRUE(IsInvalidationAcknowledged(inv_id));
874
875 EXPECT_TRUE(AllInvalidationsAccountedFor());
876 }
877
878 // Test the acknowledgement of many invalidations.
879 TEST_F(NudgeTrackerAckTrackingTest, ManyAcknowledgements) {
880 int inv1_id = SendInvalidation(BOOKMARKS, 10, "hint");
881 int inv2_id = SendInvalidation(BOOKMARKS, 14, "hint2");
882 int inv3_id = SendInvalidation(PREFERENCES, 8, "hint3");
883
884 EXPECT_TRUE(IsInvalidationUnacknowledged(inv1_id));
885 EXPECT_TRUE(IsInvalidationUnacknowledged(inv2_id));
886 EXPECT_TRUE(IsInvalidationUnacknowledged(inv3_id));
887
888 RecordSuccessfulSyncCycle();
889 EXPECT_TRUE(IsInvalidationAcknowledged(inv1_id));
890 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id));
891 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id));
892
893 EXPECT_TRUE(AllInvalidationsAccountedFor());
894 }
895
896 // Test dropping when the buffer overflows and subsequent drop recovery.
897 TEST_F(NudgeTrackerAckTrackingTest, OverflowAndRecover) {
898 std::vector<int> invalidation_ids;
899
900 int inv10_id = SendInvalidation(BOOKMARKS, 10, "hint");
901 for (size_t i = 1; i < GetHintBufferSize(); ++i) {
902 invalidation_ids.push_back(SendInvalidation(BOOKMARKS, i + 10, "hint"));
903 }
904
905 for (std::vector<int>::iterator it = invalidation_ids.begin();
906 it != invalidation_ids.end(); ++it) {
907 EXPECT_TRUE(IsInvalidationUnacknowledged(*it));
908 }
909
910 // This invalidation, though arriving the most recently, has the oldest
911 // version number so it should be dropped first.
912 int inv5_id = SendInvalidation(BOOKMARKS, 5, "old_hint");
913 EXPECT_TRUE(IsInvalidationDropped(inv5_id));
914
915 // This invalidation has a larger version number, so it will force a
916 // previously delivered invalidation to be dropped.
917 int inv100_id = SendInvalidation(BOOKMARKS, 100, "new_hint");
918 EXPECT_TRUE(IsInvalidationDropped(inv10_id));
919
920 // This should recover from the drop and bring us back into sync.
921 RecordSuccessfulSyncCycle();
922
923 for (std::vector<int>::iterator it = invalidation_ids.begin();
924 it != invalidation_ids.end(); ++it) {
925 EXPECT_TRUE(IsInvalidationAcknowledged(*it));
926 }
927 EXPECT_TRUE(IsInvalidationAcknowledged(inv100_id));
928
929 EXPECT_TRUE(AllInvalidationsAccountedFor());
930 }
931
932 // Test receipt of an unknown version invalidation from the server.
933 TEST_F(NudgeTrackerAckTrackingTest, UnknownVersionFromServer_Simple) {
934 int inv_id = SendUnknownVersionInvalidation(BOOKMARKS);
935 EXPECT_TRUE(IsInvalidationUnacknowledged(inv_id));
936 RecordSuccessfulSyncCycle();
937 EXPECT_TRUE(IsInvalidationAcknowledged(inv_id));
938 EXPECT_TRUE(AllInvalidationsAccountedFor());
939 }
940
941 // Test receipt of multiple unknown version invalidations from the server.
942 TEST_F(NudgeTrackerAckTrackingTest, UnknownVersionFromServer_Complex) {
943 int inv1_id = SendUnknownVersionInvalidation(BOOKMARKS);
944 int inv2_id = SendInvalidation(BOOKMARKS, 10, "hint");
945 int inv3_id = SendUnknownVersionInvalidation(BOOKMARKS);
946 int inv4_id = SendUnknownVersionInvalidation(BOOKMARKS);
947 int inv5_id = SendInvalidation(BOOKMARKS, 20, "hint2");
948
949 // These invalidations have been overridden, so they got acked early.
950 EXPECT_TRUE(IsInvalidationAcknowledged(inv1_id));
951 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id));
952
953 // These invalidations are still waiting to be used.
954 EXPECT_TRUE(IsInvalidationUnacknowledged(inv2_id));
955 EXPECT_TRUE(IsInvalidationUnacknowledged(inv4_id));
956 EXPECT_TRUE(IsInvalidationUnacknowledged(inv5_id));
957
958 // Finish the sync cycle and expect all remaining invalidations to be acked.
959 RecordSuccessfulSyncCycle();
960 EXPECT_TRUE(IsInvalidationAcknowledged(inv1_id));
961 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id));
962 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id));
963 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id));
964 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id));
965
966 EXPECT_TRUE(AllInvalidationsAccountedFor());
967 }
968
969 } // namespace sessions
970 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/sessions_impl/nudge_tracker.cc ('k') | components/sync/sessions_impl/status_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698