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

Side by Side Diff: sync/notifier/sync_invalidation_listener_unittest.cc

Issue 19381005: Add version field to syncer::Invalidation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
« no previous file with comments | « sync/notifier/sync_invalidation_listener.cc ('k') | no next file » | 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 <cstddef> 5 #include <cstddef>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 explicit FakeDelegate(SyncInvalidationListener* listener) 139 explicit FakeDelegate(SyncInvalidationListener* listener)
140 : listener_(listener), 140 : listener_(listener),
141 state_(TRANSIENT_INVALIDATION_ERROR) {} 141 state_(TRANSIENT_INVALIDATION_ERROR) {}
142 virtual ~FakeDelegate() {} 142 virtual ~FakeDelegate() {}
143 143
144 int GetInvalidationCount(const ObjectId& id) const { 144 int GetInvalidationCount(const ObjectId& id) const {
145 ObjectIdCountMap::const_iterator it = invalidation_counts_.find(id); 145 ObjectIdCountMap::const_iterator it = invalidation_counts_.find(id);
146 return (it == invalidation_counts_.end()) ? 0 : it->second; 146 return (it == invalidation_counts_.end()) ? 0 : it->second;
147 } 147 }
148 148
149 int64 GetVersion(const ObjectId& id) const {
150 ObjectIdInvalidationMap::const_iterator it = invalidations_.find(id);
151 return (it == invalidations_.end()) ? 0 : it->second.version;
152 }
153
149 std::string GetPayload(const ObjectId& id) const { 154 std::string GetPayload(const ObjectId& id) const {
150 ObjectIdInvalidationMap::const_iterator it = invalidations_.find(id); 155 ObjectIdInvalidationMap::const_iterator it = invalidations_.find(id);
151 return (it == invalidations_.end()) ? std::string() : it->second.payload; 156 return (it == invalidations_.end()) ? std::string() : it->second.payload;
152 } 157 }
153 158
154 InvalidatorState GetInvalidatorState() const { 159 InvalidatorState GetInvalidatorState() const {
155 return state_; 160 return state_;
156 } 161 }
157 162
158 void Acknowledge(const ObjectId& id) { 163 void Acknowledge(const ObjectId& id) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // drain the task queue before calling it. 293 // drain the task queue before calling it.
289 message_loop_.RunUntilIdle(); 294 message_loop_.RunUntilIdle();
290 fake_invalidation_client_ = NULL; 295 fake_invalidation_client_ = NULL;
291 listener_.StopForTest(); 296 listener_.StopForTest();
292 } 297 }
293 298
294 int GetInvalidationCount(const ObjectId& id) const { 299 int GetInvalidationCount(const ObjectId& id) const {
295 return fake_delegate_.GetInvalidationCount(id); 300 return fake_delegate_.GetInvalidationCount(id);
296 } 301 }
297 302
303 int64 GetVersion(const ObjectId& id) const {
304 return fake_delegate_.GetVersion(id);
305 }
306
298 std::string GetPayload(const ObjectId& id) const { 307 std::string GetPayload(const ObjectId& id) const {
299 return fake_delegate_.GetPayload(id); 308 return fake_delegate_.GetPayload(id);
300 } 309 }
301 310
302 InvalidatorState GetInvalidatorState() const { 311 InvalidatorState GetInvalidatorState() const {
303 return fake_delegate_.GetInvalidatorState(); 312 return fake_delegate_.GetInvalidatorState();
304 } 313 }
305 314
306 int64 GetMaxVersion(const ObjectId& id) const { 315 int64 GetMaxVersion(const ObjectId& id) const {
307 return fake_tracker_.GetMaxVersion(id); 316 return fake_tracker_.GetMaxVersion(id);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // Invalidation tests. 439 // Invalidation tests.
431 440
432 // Fire an invalidation without a payload. It should be processed, 441 // Fire an invalidation without a payload. It should be processed,
433 // the payload should remain empty, and the version should be updated. 442 // the payload should remain empty, and the version should be updated.
434 TEST_F(SyncInvalidationListenerTest, InvalidateNoPayload) { 443 TEST_F(SyncInvalidationListenerTest, InvalidateNoPayload) {
435 const ObjectId& id = kBookmarksId_; 444 const ObjectId& id = kBookmarksId_;
436 445
437 FireInvalidate(id, kVersion1, NULL); 446 FireInvalidate(id, kVersion1, NULL);
438 447
439 EXPECT_EQ(1, GetInvalidationCount(id)); 448 EXPECT_EQ(1, GetInvalidationCount(id));
449 EXPECT_EQ(kVersion1, GetVersion(id));
440 EXPECT_EQ("", GetPayload(id)); 450 EXPECT_EQ("", GetPayload(id));
441 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 451 EXPECT_EQ(kVersion1, GetMaxVersion(id));
442 AcknowledgeAndVerify(id); 452 AcknowledgeAndVerify(id);
443 } 453 }
444 454
445 // Fire an invalidation with an empty payload. It should be 455 // Fire an invalidation with an empty payload. It should be
446 // processed, the payload should remain empty, and the version should 456 // processed, the payload should remain empty, and the version should
447 // be updated. 457 // be updated.
448 TEST_F(SyncInvalidationListenerTest, InvalidateEmptyPayload) { 458 TEST_F(SyncInvalidationListenerTest, InvalidateEmptyPayload) {
449 const ObjectId& id = kBookmarksId_; 459 const ObjectId& id = kBookmarksId_;
450 460
451 FireInvalidate(id, kVersion1, ""); 461 FireInvalidate(id, kVersion1, "");
452 462
453 EXPECT_EQ(1, GetInvalidationCount(id)); 463 EXPECT_EQ(1, GetInvalidationCount(id));
464 EXPECT_EQ(kVersion1, GetVersion(id));
454 EXPECT_EQ("", GetPayload(id)); 465 EXPECT_EQ("", GetPayload(id));
455 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 466 EXPECT_EQ(kVersion1, GetMaxVersion(id));
456 AcknowledgeAndVerify(id); 467 AcknowledgeAndVerify(id);
457 } 468 }
458 469
459 // Fire an invalidation with a payload. It should be processed, and 470 // Fire an invalidation with a payload. It should be processed, and
460 // both the payload and the version should be updated. 471 // both the payload and the version should be updated.
461 TEST_F(SyncInvalidationListenerTest, InvalidateWithPayload) { 472 TEST_F(SyncInvalidationListenerTest, InvalidateWithPayload) {
462 const ObjectId& id = kPreferencesId_; 473 const ObjectId& id = kPreferencesId_;
463 474
464 FireInvalidate(id, kVersion1, kPayload1); 475 FireInvalidate(id, kVersion1, kPayload1);
465 476
466 EXPECT_EQ(1, GetInvalidationCount(id)); 477 EXPECT_EQ(1, GetInvalidationCount(id));
478 EXPECT_EQ(kVersion1, GetVersion(id));
467 EXPECT_EQ(kPayload1, GetPayload(id)); 479 EXPECT_EQ(kPayload1, GetPayload(id));
468 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 480 EXPECT_EQ(kVersion1, GetMaxVersion(id));
469 AcknowledgeAndVerify(id); 481 AcknowledgeAndVerify(id);
470 } 482 }
471 483
472 // Fire an invalidation for an unregistered object ID with a payload. It should 484 // Fire an invalidation for an unregistered object ID with a payload. It should
473 // still be processed, and both the payload and the version should be updated. 485 // still be processed, and both the payload and the version should be updated.
474 TEST_F(SyncInvalidationListenerTest, InvalidateUnregisteredWithPayload) { 486 TEST_F(SyncInvalidationListenerTest, InvalidateUnregisteredWithPayload) {
475 const ObjectId kUnregisteredId( 487 const ObjectId kUnregisteredId(
476 kChromeSyncSourceId, "unregistered"); 488 kChromeSyncSourceId, "unregistered");
477 const ObjectId& id = kUnregisteredId; 489 const ObjectId& id = kUnregisteredId;
478 490
479 EXPECT_EQ(0, GetInvalidationCount(id)); 491 EXPECT_EQ(0, GetInvalidationCount(id));
480 EXPECT_EQ("", GetPayload(id)); 492 EXPECT_EQ("", GetPayload(id));
481 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 493 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
482 494
483 FireInvalidate(id, kVersion1, "unregistered payload"); 495 FireInvalidate(id, kVersion1, "unregistered payload");
484 496
485 EXPECT_EQ(1, GetInvalidationCount(id)); 497 EXPECT_EQ(1, GetInvalidationCount(id));
498 EXPECT_EQ(kVersion1, GetVersion(id));
486 EXPECT_EQ("unregistered payload", GetPayload(id)); 499 EXPECT_EQ("unregistered payload", GetPayload(id));
487 EXPECT_EQ(kVersion1, GetMaxVersion(id)); 500 EXPECT_EQ(kVersion1, GetMaxVersion(id));
488 AcknowledgeAndVerify(id); 501 AcknowledgeAndVerify(id);
489 } 502 }
490 503
491 // Fire an invalidation, then fire another one with a lower version. 504 // Fire an invalidation, then fire another one with a lower version.
492 // The first one should be processed and should update the payload and 505 // The first one should be processed and should update the payload and
493 // version, but the second one shouldn't. 506 // version, but the second one shouldn't.
494 TEST_F(SyncInvalidationListenerTest, InvalidateVersion) { 507 TEST_F(SyncInvalidationListenerTest, InvalidateVersion) {
495 const ObjectId& id = kPreferencesId_; 508 const ObjectId& id = kPreferencesId_;
496 509
497 FireInvalidate(id, kVersion2, kPayload2); 510 FireInvalidate(id, kVersion2, kPayload2);
498 511
499 EXPECT_EQ(1, GetInvalidationCount(id)); 512 EXPECT_EQ(1, GetInvalidationCount(id));
513 EXPECT_EQ(kVersion2, GetVersion(id));
500 EXPECT_EQ(kPayload2, GetPayload(id)); 514 EXPECT_EQ(kPayload2, GetPayload(id));
501 EXPECT_EQ(kVersion2, GetMaxVersion(id)); 515 EXPECT_EQ(kVersion2, GetMaxVersion(id));
502 AcknowledgeAndVerify(id); 516 AcknowledgeAndVerify(id);
503 517
504 FireInvalidate(id, kVersion1, kPayload1); 518 FireInvalidate(id, kVersion1, kPayload1);
505 519
506 EXPECT_EQ(1, GetInvalidationCount(id)); 520 EXPECT_EQ(1, GetInvalidationCount(id));
521 EXPECT_EQ(kVersion2, GetVersion(id));
507 EXPECT_EQ(kPayload2, GetPayload(id)); 522 EXPECT_EQ(kPayload2, GetPayload(id));
508 EXPECT_EQ(kVersion2, GetMaxVersion(id)); 523 EXPECT_EQ(kVersion2, GetMaxVersion(id));
509 VerifyAcknowledged(id); 524 VerifyAcknowledged(id);
510 } 525 }
511 526
512 // Fire an invalidation with an unknown version twice. It shouldn't 527 // Fire an invalidation with an unknown version twice. It shouldn't
513 // update the payload or version either time, but it should still be 528 // update the payload or version either time, but it should still be
514 // processed. 529 // processed.
515 TEST_F(SyncInvalidationListenerTest, InvalidateUnknownVersion) { 530 TEST_F(SyncInvalidationListenerTest, InvalidateUnknownVersion) {
516 const ObjectId& id = kBookmarksId_; 531 const ObjectId& id = kBookmarksId_;
517 532
518 FireInvalidateUnknownVersion(id); 533 FireInvalidateUnknownVersion(id);
519 534
520 EXPECT_EQ(1, GetInvalidationCount(id)); 535 EXPECT_EQ(1, GetInvalidationCount(id));
536 EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(id));
521 EXPECT_EQ("", GetPayload(id)); 537 EXPECT_EQ("", GetPayload(id));
522 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 538 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
523 AcknowledgeAndVerify(id); 539 AcknowledgeAndVerify(id);
524 540
525 FireInvalidateUnknownVersion(id); 541 FireInvalidateUnknownVersion(id);
526 542
527 EXPECT_EQ(2, GetInvalidationCount(id)); 543 EXPECT_EQ(2, GetInvalidationCount(id));
544 EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(id));
528 EXPECT_EQ("", GetPayload(id)); 545 EXPECT_EQ("", GetPayload(id));
529 EXPECT_EQ(kMinVersion, GetMaxVersion(id)); 546 EXPECT_EQ(kMinVersion, GetMaxVersion(id));
530 AcknowledgeAndVerify(id); 547 AcknowledgeAndVerify(id);
531 } 548 }
532 549
533 // Fire an invalidation for all enabled IDs. It shouldn't update the 550 // Fire an invalidation for all enabled IDs. It shouldn't update the
534 // payload or version, but it should still invalidate the IDs. 551 // payload or version, but it should still invalidate the IDs.
535 TEST_F(SyncInvalidationListenerTest, InvalidateAll) { 552 TEST_F(SyncInvalidationListenerTest, InvalidateAll) {
536 FireInvalidateAll(); 553 FireInvalidateAll();
537 554
538 for (ObjectIdSet::const_iterator it = registered_ids_.begin(); 555 for (ObjectIdSet::const_iterator it = registered_ids_.begin();
539 it != registered_ids_.end(); ++it) { 556 it != registered_ids_.end(); ++it) {
540 EXPECT_EQ(1, GetInvalidationCount(*it)); 557 EXPECT_EQ(1, GetInvalidationCount(*it));
558 EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(*it));
541 EXPECT_EQ("", GetPayload(*it)); 559 EXPECT_EQ("", GetPayload(*it));
542 EXPECT_EQ(kMinVersion, GetMaxVersion(*it)); 560 EXPECT_EQ(kMinVersion, GetMaxVersion(*it));
543 AcknowledgeAndVerify(*it); 561 AcknowledgeAndVerify(*it);
544 } 562 }
545 } 563 }
546 564
547 // Comprehensive test of various scenarios for multiple IDs. 565 // Comprehensive test of various scenarios for multiple IDs.
548 TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { 566 TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) {
549 FireInvalidate(kBookmarksId_, 3, NULL); 567 FireInvalidate(kBookmarksId_, 3, NULL);
550 568
551 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); 569 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_));
570 EXPECT_EQ(3, GetVersion(kBookmarksId_));
552 EXPECT_EQ("", GetPayload(kBookmarksId_)); 571 EXPECT_EQ("", GetPayload(kBookmarksId_));
553 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 572 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
554 AcknowledgeAndVerify(kBookmarksId_); 573 AcknowledgeAndVerify(kBookmarksId_);
555 574
556 FireInvalidate(kExtensionsId_, 2, NULL); 575 FireInvalidate(kExtensionsId_, 2, NULL);
557 576
558 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); 577 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_));
578 EXPECT_EQ(2, GetVersion(kExtensionsId_));
559 EXPECT_EQ("", GetPayload(kExtensionsId_)); 579 EXPECT_EQ("", GetPayload(kExtensionsId_));
560 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); 580 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_));
561 AcknowledgeAndVerify(kExtensionsId_); 581 AcknowledgeAndVerify(kExtensionsId_);
562 582
563 // Invalidations with lower version numbers should be ignored. 583 // Invalidations with lower version numbers should be ignored.
564 584
565 FireInvalidate(kBookmarksId_, 1, NULL); 585 FireInvalidate(kBookmarksId_, 1, NULL);
566 586
567 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); 587 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_));
588 EXPECT_EQ(3, GetVersion(kBookmarksId_));
568 EXPECT_EQ("", GetPayload(kBookmarksId_)); 589 EXPECT_EQ("", GetPayload(kBookmarksId_));
569 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 590 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
570 591
571 FireInvalidate(kExtensionsId_, 1, NULL); 592 FireInvalidate(kExtensionsId_, 1, NULL);
572 593
573 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); 594 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_));
595 EXPECT_EQ(2, GetVersion(kExtensionsId_));
574 EXPECT_EQ("", GetPayload(kExtensionsId_)); 596 EXPECT_EQ("", GetPayload(kExtensionsId_));
575 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); 597 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_));
576 598
577 // InvalidateAll shouldn't change any version state. 599 // InvalidateAll shouldn't change any version state.
578 600
579 FireInvalidateAll(); 601 FireInvalidateAll();
580 602
581 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); 603 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_));
604 EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(kBookmarksId_));
582 EXPECT_EQ("", GetPayload(kBookmarksId_)); 605 EXPECT_EQ("", GetPayload(kBookmarksId_));
583 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 606 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
584 AcknowledgeAndVerify(kBookmarksId_); 607 AcknowledgeAndVerify(kBookmarksId_);
585 608
586 EXPECT_EQ(1, GetInvalidationCount(kPreferencesId_)); 609 EXPECT_EQ(1, GetInvalidationCount(kPreferencesId_));
610 EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(kPreferencesId_));
587 EXPECT_EQ("", GetPayload(kPreferencesId_)); 611 EXPECT_EQ("", GetPayload(kPreferencesId_));
588 EXPECT_EQ(kMinVersion, GetMaxVersion(kPreferencesId_)); 612 EXPECT_EQ(kMinVersion, GetMaxVersion(kPreferencesId_));
589 AcknowledgeAndVerify(kPreferencesId_); 613 AcknowledgeAndVerify(kPreferencesId_);
590 614
591 // Note that kExtensionsId_ is not registered, so InvalidateAll() shouldn't 615 // Note that kExtensionsId_ is not registered, so InvalidateAll() shouldn't
592 // affect it. 616 // affect it.
593 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); 617 EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_));
618 EXPECT_EQ(2, GetVersion(kExtensionsId_));
594 EXPECT_EQ("", GetPayload(kExtensionsId_)); 619 EXPECT_EQ("", GetPayload(kExtensionsId_));
595 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); 620 EXPECT_EQ(2, GetMaxVersion(kExtensionsId_));
596 VerifyAcknowledged(kExtensionsId_); 621 VerifyAcknowledged(kExtensionsId_);
597 622
598 // Invalidations with higher version numbers should be processed. 623 // Invalidations with higher version numbers should be processed.
599 624
600 FireInvalidate(kPreferencesId_, 5, NULL); 625 FireInvalidate(kPreferencesId_, 5, NULL);
601 EXPECT_EQ(2, GetInvalidationCount(kPreferencesId_)); 626 EXPECT_EQ(2, GetInvalidationCount(kPreferencesId_));
627 EXPECT_EQ(5, GetVersion(kPreferencesId_));
602 EXPECT_EQ("", GetPayload(kPreferencesId_)); 628 EXPECT_EQ("", GetPayload(kPreferencesId_));
603 EXPECT_EQ(5, GetMaxVersion(kPreferencesId_)); 629 EXPECT_EQ(5, GetMaxVersion(kPreferencesId_));
604 AcknowledgeAndVerify(kPreferencesId_); 630 AcknowledgeAndVerify(kPreferencesId_);
605 631
606 FireInvalidate(kExtensionsId_, 3, NULL); 632 FireInvalidate(kExtensionsId_, 3, NULL);
607 EXPECT_EQ(2, GetInvalidationCount(kExtensionsId_)); 633 EXPECT_EQ(2, GetInvalidationCount(kExtensionsId_));
634 EXPECT_EQ(3, GetVersion(kExtensionsId_));
608 EXPECT_EQ("", GetPayload(kExtensionsId_)); 635 EXPECT_EQ("", GetPayload(kExtensionsId_));
609 EXPECT_EQ(3, GetMaxVersion(kExtensionsId_)); 636 EXPECT_EQ(3, GetMaxVersion(kExtensionsId_));
610 AcknowledgeAndVerify(kExtensionsId_); 637 AcknowledgeAndVerify(kExtensionsId_);
611 638
612 FireInvalidate(kBookmarksId_, 4, NULL); 639 FireInvalidate(kBookmarksId_, 4, NULL);
613 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_)); 640 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_));
641 EXPECT_EQ(4, GetVersion(kBookmarksId_));
614 EXPECT_EQ("", GetPayload(kBookmarksId_)); 642 EXPECT_EQ("", GetPayload(kBookmarksId_));
615 EXPECT_EQ(4, GetMaxVersion(kBookmarksId_)); 643 EXPECT_EQ(4, GetMaxVersion(kBookmarksId_));
616 AcknowledgeAndVerify(kBookmarksId_); 644 AcknowledgeAndVerify(kBookmarksId_);
617 } 645 }
618 646
619 // Various tests for the local invalidation feature. 647 // Various tests for the local invalidation feature.
620 // Tests a "normal" scenario. We allow one timeout period to expire by sending 648 // Tests a "normal" scenario. We allow one timeout period to expire by sending
621 // ack handles that are not the "latest" ack handle. Once the timeout expires, 649 // ack handles that are not the "latest" ack handle. Once the timeout expires,
622 // we verify that we get a second callback and then acknowledge it. Once 650 // we verify that we get a second callback and then acknowledge it. Once
623 // acknowledged, no further timeouts should occur. 651 // acknowledged, no further timeouts should occur.
624 TEST_F(SyncInvalidationListenerTest, InvalidateOneTimeout) { 652 TEST_F(SyncInvalidationListenerTest, InvalidateOneTimeout) {
625 listener_.GetAckTrackerForTest()->SetCreateBackoffEntryCallbackForTest( 653 listener_.GetAckTrackerForTest()->SetCreateBackoffEntryCallbackForTest(
626 base::Bind(&CreateMockEntry, &tick_clock_)); 654 base::Bind(&CreateMockEntry, &tick_clock_));
627 655
628 // Trigger the initial invalidation. 656 // Trigger the initial invalidation.
629 FireInvalidate(kBookmarksId_, 3, NULL); 657 FireInvalidate(kBookmarksId_, 3, NULL);
630 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); 658 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_));
659 EXPECT_EQ(3, GetVersion(kBookmarksId_));
631 EXPECT_EQ("", GetPayload(kBookmarksId_)); 660 EXPECT_EQ("", GetPayload(kBookmarksId_));
632 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 661 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
633 VerifyUnacknowledged(kBookmarksId_); 662 VerifyUnacknowledged(kBookmarksId_);
634 663
635 // Trigger one timeout. 664 // Trigger one timeout.
636 tick_clock_.LeapForward(60); 665 tick_clock_.LeapForward(60);
637 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest( 666 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest(
638 tick_clock_.NowTicks())); 667 tick_clock_.NowTicks()));
639 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); 668 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_));
640 // Other properties should remain the same. 669 // Other properties should remain the same.
670 EXPECT_EQ(3, GetVersion(kBookmarksId_));
641 EXPECT_EQ("", GetPayload(kBookmarksId_)); 671 EXPECT_EQ("", GetPayload(kBookmarksId_));
642 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 672 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
643 673
644 AcknowledgeAndVerify(kBookmarksId_); 674 AcknowledgeAndVerify(kBookmarksId_);
645 675
646 // No more invalidations should remain in the queue. 676 // No more invalidations should remain in the queue.
647 EXPECT_TRUE(listener_.GetAckTrackerForTest()->IsQueueEmptyForTest()); 677 EXPECT_TRUE(listener_.GetAckTrackerForTest()->IsQueueEmptyForTest());
648 } 678 }
649 679
650 // Test that an unacknowledged invalidation triggers reminders if the listener 680 // Test that an unacknowledged invalidation triggers reminders if the listener
651 // is restarted. 681 // is restarted.
652 TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) { 682 TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) {
653 listener_.GetAckTrackerForTest()->SetCreateBackoffEntryCallbackForTest( 683 listener_.GetAckTrackerForTest()->SetCreateBackoffEntryCallbackForTest(
654 base::Bind(&CreateMockEntry, &tick_clock_)); 684 base::Bind(&CreateMockEntry, &tick_clock_));
655 685
656 FireInvalidate(kBookmarksId_, 3, NULL); 686 FireInvalidate(kBookmarksId_, 3, NULL);
657 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); 687 EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_));
688 EXPECT_EQ(3, GetVersion(kBookmarksId_));
658 EXPECT_EQ("", GetPayload(kBookmarksId_)); 689 EXPECT_EQ("", GetPayload(kBookmarksId_));
659 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 690 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
660 691
661 // Trigger one timeout. 692 // Trigger one timeout.
662 tick_clock_.LeapForward(60); 693 tick_clock_.LeapForward(60);
663 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest( 694 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest(
664 tick_clock_.NowTicks())); 695 tick_clock_.NowTicks()));
665 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); 696 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_));
666 // Other properties should remain the same. 697 // Other properties should remain the same.
698 EXPECT_EQ(3, GetVersion(kBookmarksId_));
667 EXPECT_EQ("", GetPayload(kBookmarksId_)); 699 EXPECT_EQ("", GetPayload(kBookmarksId_));
668 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 700 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
669 701
670 // Restarting the client should reset the retry count and the timeout period 702 // Restarting the client should reset the retry count and the timeout period
671 // (e.g. it shouldn't increase to 120 seconds). Skip ahead 1200 seconds to be 703 // (e.g. it shouldn't increase to 120 seconds). Skip ahead 1200 seconds to be
672 // on the safe side. 704 // on the safe side.
673 StopClient(); 705 StopClient();
674 tick_clock_.LeapForward(1200); 706 tick_clock_.LeapForward(1200);
675 StartClient(); 707 StartClient();
676 708
677 // The bookmark invalidation state should not have changed. 709 // The bookmark invalidation state should not have changed.
678 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); 710 EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_));
711 EXPECT_EQ(3, GetVersion(kBookmarksId_));
679 EXPECT_EQ("", GetPayload(kBookmarksId_)); 712 EXPECT_EQ("", GetPayload(kBookmarksId_));
680 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 713 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
681 714
682 // Now trigger the invalidation reminder after the client restarts. 715 // Now trigger the invalidation reminder after the client restarts.
683 tick_clock_.LeapForward(60); 716 tick_clock_.LeapForward(60);
684 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest( 717 EXPECT_TRUE(listener_.GetAckTrackerForTest()->TriggerTimeoutAtForTest(
685 tick_clock_.NowTicks())); 718 tick_clock_.NowTicks()));
686 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_)); 719 EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_));
687 // Other properties should remain the same. 720 // Other properties should remain the same.
721 EXPECT_EQ(3, GetVersion(kBookmarksId_));
688 EXPECT_EQ("", GetPayload(kBookmarksId_)); 722 EXPECT_EQ("", GetPayload(kBookmarksId_));
689 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); 723 EXPECT_EQ(3, GetMaxVersion(kBookmarksId_));
690 724
691 AcknowledgeAndVerify(kBookmarksId_); 725 AcknowledgeAndVerify(kBookmarksId_);
692 726
693 // No more invalidations should remain in the queue. 727 // No more invalidations should remain in the queue.
694 EXPECT_TRUE(listener_.GetAckTrackerForTest()->IsQueueEmptyForTest()); 728 EXPECT_TRUE(listener_.GetAckTrackerForTest()->IsQueueEmptyForTest());
695 729
696 // The queue should remain empty when we restart now. 730 // The queue should remain empty when we restart now.
697 RestartClient(); 731 RestartClient();
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED, GetInvalidatorState()); 989 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED, GetInvalidatorState());
956 990
957 listener_.Ready(fake_invalidation_client_); 991 listener_.Ready(fake_invalidation_client_);
958 992
959 EXPECT_EQ(INVALIDATIONS_ENABLED, GetInvalidatorState()); 993 EXPECT_EQ(INVALIDATIONS_ENABLED, GetInvalidatorState());
960 } 994 }
961 995
962 } // namespace 996 } // namespace
963 997
964 } // namespace syncer 998 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/sync_invalidation_listener.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698