| 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 "components/sync/engine_impl/cycle/nudge_tracker.h" | 5 #include "components/sync/engine_impl/cycle/nudge_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int64_t version, | 71 int64_t version, |
| 72 const std::string& payload) { | 72 const std::string& payload) { |
| 73 return MockInvalidation::Build(version, payload); | 73 return MockInvalidation::Build(version, payload); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static std::unique_ptr<InvalidationInterface> | 76 static std::unique_ptr<InvalidationInterface> |
| 77 BuildUnknownVersionInvalidation() { | 77 BuildUnknownVersionInvalidation() { |
| 78 return MockInvalidation::BuildUnknownVersion(); | 78 return MockInvalidation::BuildUnknownVersion(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool IsTypeThrottled(ModelType type) { |
| 82 return nudge_tracker_.GetTypeBlockingMode(type) == WaitInterval::THROTTLED; |
| 83 } |
| 84 |
| 85 bool IsTypeBackedOff(ModelType type) { |
| 86 return nudge_tracker_.GetTypeBlockingMode(type) == |
| 87 WaitInterval::EXPONENTIAL_BACKOFF; |
| 88 } |
| 89 |
| 81 protected: | 90 protected: |
| 82 NudgeTracker nudge_tracker_; | 91 NudgeTracker nudge_tracker_; |
| 83 }; | 92 }; |
| 84 | 93 |
| 85 // Exercise an empty NudgeTracker. | 94 // Exercise an empty NudgeTracker. |
| 86 // Use with valgrind to detect uninitialized members. | 95 // Use with valgrind to detect uninitialized members. |
| 87 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { | 96 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { |
| 88 // Now we're at the normal, "idle" state. | 97 // Now we're at the normal, "idle" state. |
| 89 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 98 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 90 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 99 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 432 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 424 | 433 |
| 425 // Invalidations. | 434 // Invalidations. |
| 426 nudge_tracker_.RecordRemoteInvalidation(PREFERENCES, | 435 nudge_tracker_.RecordRemoteInvalidation(PREFERENCES, |
| 427 BuildInvalidation(1, "hint")); | 436 BuildInvalidation(1, "hint")); |
| 428 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 437 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 429 nudge_tracker_.RecordSuccessfulSyncCycle(); | 438 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 430 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 439 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 431 } | 440 } |
| 432 | 441 |
| 433 // Test IsSyncRequired() responds correctly to data type throttling. | 442 // Test IsSyncRequired() responds correctly to data type throttling and backoff. |
| 434 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) { | 443 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling_Backoff) { |
| 435 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 444 const base::TimeTicks now = base::TimeTicks::Now(); |
| 436 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); | 445 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(0); |
| 437 const base::TimeTicks t1 = t0 + throttle_length; | |
| 438 | 446 |
| 439 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 447 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 440 | 448 |
| 441 // A local change to sessions enables the flag. | 449 // A local change to sessions enables the flag. |
| 442 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); | 450 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); |
| 443 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 451 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 444 | 452 |
| 445 // But the throttling of sessions unsets it. | 453 // But the throttling of sessions unsets it. |
| 446 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length, | 454 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length, |
| 447 t0); | 455 now); |
| 456 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 448 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 457 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 449 | 458 |
| 450 // A refresh request for bookmarks means we have reason to sync again. | 459 // A refresh request for bookmarks means we have reason to sync again. |
| 451 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); | 460 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); |
| 452 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 461 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 453 | 462 |
| 454 // A successful sync cycle means we took care of bookmarks. | 463 // But the backoff of bookmarks unsets it. |
| 464 nudge_tracker_.SetTypeBackedOff(BOOKMARKS, throttle_length, now); |
| 465 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 466 EXPECT_TRUE(IsTypeBackedOff(BOOKMARKS)); |
| 467 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 468 |
| 469 // A refresh request for preferences means we have reason to sync again. |
| 470 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(PREFERENCES)); |
| 471 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 472 |
| 473 // A successful sync cycle means we took care of preferences. |
| 455 nudge_tracker_.RecordSuccessfulSyncCycle(); | 474 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 456 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 475 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 457 | 476 |
| 458 // But we still haven't dealt with sessions. We'll need to remember | 477 // But we still haven't dealt with sessions and bookmarks. We'll need to |
| 459 // that sessions are out of sync and re-enable the flag when their | 478 // remember that sessions and bookmarks are out of sync and re-enable the flag |
| 460 // throttling interval expires. | 479 // when their throttling and backoff interval expires. |
| 461 nudge_tracker_.UpdateTypeThrottlingState(t1); | 480 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 462 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 481 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(SESSIONS)); |
| 482 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(BOOKMARKS)); |
| 463 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 483 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 464 } | 484 } |
| 465 | 485 |
| 466 // Test IsGetUpdatesRequired() responds correctly to data type throttling. | 486 // Test IsGetUpdatesRequired() responds correctly to data type throttling and |
| 467 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired_Throttling) { | 487 // backoff. |
| 468 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 488 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired_Throttling_Backoff) { |
| 469 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); | 489 const base::TimeTicks now = base::TimeTicks::Now(); |
| 470 const base::TimeTicks t1 = t0 + throttle_length; | 490 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(0); |
| 471 | 491 |
| 472 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 492 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 473 | 493 |
| 474 // A refresh request to sessions enables the flag. | 494 // A refresh request to sessions enables the flag. |
| 475 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); | 495 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); |
| 476 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 496 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 477 | 497 |
| 478 // But the throttling of sessions unsets it. | 498 // But the throttling of sessions unsets it. |
| 479 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length, | 499 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), throttle_length, |
| 480 t0); | 500 now); |
| 481 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 501 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 482 | 502 |
| 483 // A refresh request for bookmarks means we have reason to sync again. | 503 // A refresh request for bookmarks means we have reason to sync again. |
| 484 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); | 504 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); |
| 485 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 505 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 486 | 506 |
| 487 // A successful sync cycle means we took care of bookmarks. | 507 // But the backoff of bookmarks unsets it. |
| 508 nudge_tracker_.SetTypeBackedOff(BOOKMARKS, throttle_length, now); |
| 509 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 510 EXPECT_TRUE(IsTypeBackedOff(BOOKMARKS)); |
| 511 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 512 |
| 513 // A refresh request for preferences means we have reason to sync again. |
| 514 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(PREFERENCES)); |
| 515 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 516 |
| 517 // A successful sync cycle means we took care of preferences. |
| 488 nudge_tracker_.RecordSuccessfulSyncCycle(); | 518 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 489 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 519 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 490 | 520 |
| 491 // But we still haven't dealt with sessions. We'll need to remember | 521 // But we still haven't dealt with sessions and bookmarks. We'll need to |
| 492 // that sessions are out of sync and re-enable the flag when their | 522 // remember that sessions and bookmarks are out of sync and re-enable the flag |
| 493 // throttling interval expires. | 523 // when their throttling and backoff interval expires. |
| 494 nudge_tracker_.UpdateTypeThrottlingState(t1); | 524 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 495 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 525 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(SESSIONS)); |
| 526 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(BOOKMARKS)); |
| 496 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 527 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 497 } | 528 } |
| 498 | 529 |
| 499 // Tests throttling-related getter functions when no types are throttled. | 530 // Tests blocking-related getter functions when no types are blocked. |
| 500 TEST_F(NudgeTrackerTest, NoTypesThrottled) { | 531 TEST_F(NudgeTrackerTest, NoTypesBlocked) { |
| 501 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled()); | 532 EXPECT_FALSE(nudge_tracker_.IsAnyTypeBlocked()); |
| 502 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 533 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(SESSIONS)); |
| 503 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); | 534 EXPECT_TRUE(nudge_tracker_.GetBlockedTypes().Empty()); |
| 504 } | 535 } |
| 505 | 536 |
| 506 // Tests throttling-related getter functions when some types are throttled. | 537 // Tests throttling-related getter functions when some types are throttled. |
| 507 TEST_F(NudgeTrackerTest, ThrottleAndUnthrottle) { | 538 TEST_F(NudgeTrackerTest, ThrottleAndUnthrottle) { |
| 508 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 539 const base::TimeTicks now = base::TimeTicks::Now(); |
| 509 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); | 540 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(0); |
| 510 const base::TimeTicks t1 = t0 + throttle_length; | |
| 511 | 541 |
| 512 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES), | 542 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES), |
| 513 throttle_length, t0); | 543 throttle_length, now); |
| 514 | 544 |
| 515 EXPECT_TRUE(nudge_tracker_.IsAnyTypeThrottled()); | 545 EXPECT_TRUE(nudge_tracker_.IsAnyTypeBlocked()); |
| 516 EXPECT_TRUE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 546 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 517 EXPECT_TRUE(nudge_tracker_.IsTypeThrottled(PREFERENCES)); | 547 EXPECT_TRUE(IsTypeThrottled(PREFERENCES)); |
| 518 EXPECT_FALSE(nudge_tracker_.GetThrottledTypes().Empty()); | 548 EXPECT_FALSE(nudge_tracker_.GetBlockedTypes().Empty()); |
| 519 EXPECT_EQ(throttle_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0)); | 549 EXPECT_EQ(throttle_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 520 | 550 |
| 521 nudge_tracker_.UpdateTypeThrottlingState(t1); | 551 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 522 | 552 |
| 523 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled()); | 553 EXPECT_FALSE(nudge_tracker_.IsAnyTypeBlocked()); |
| 524 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 554 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(SESSIONS)); |
| 525 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); | 555 EXPECT_TRUE(nudge_tracker_.GetBlockedTypes().Empty()); |
| 556 } |
| 557 |
| 558 // Tests backoff-related getter functions when some types are backed off. |
| 559 TEST_F(NudgeTrackerTest, BackoffAndUnbackoff) { |
| 560 const base::TimeTicks now = base::TimeTicks::Now(); |
| 561 const base::TimeDelta backoff_length = base::TimeDelta::FromMinutes(0); |
| 562 |
| 563 nudge_tracker_.SetTypeBackedOff(SESSIONS, backoff_length, now); |
| 564 nudge_tracker_.SetTypeBackedOff(PREFERENCES, backoff_length, now); |
| 565 |
| 566 EXPECT_TRUE(nudge_tracker_.IsAnyTypeBlocked()); |
| 567 EXPECT_TRUE(IsTypeBackedOff(SESSIONS)); |
| 568 EXPECT_TRUE(IsTypeBackedOff(PREFERENCES)); |
| 569 EXPECT_FALSE(nudge_tracker_.GetBlockedTypes().Empty()); |
| 570 EXPECT_EQ(backoff_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 571 |
| 572 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 573 |
| 574 EXPECT_FALSE(nudge_tracker_.IsAnyTypeBlocked()); |
| 575 EXPECT_FALSE(nudge_tracker_.IsTypeBlocked(SESSIONS)); |
| 576 EXPECT_TRUE(nudge_tracker_.GetBlockedTypes().Empty()); |
| 526 } | 577 } |
| 527 | 578 |
| 528 TEST_F(NudgeTrackerTest, OverlappingThrottleIntervals) { | 579 TEST_F(NudgeTrackerTest, OverlappingThrottleIntervals) { |
| 529 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 580 const base::TimeTicks now = base::TimeTicks::Now(); |
| 530 const base::TimeDelta throttle1_length = base::TimeDelta::FromMinutes(10); | 581 const base::TimeDelta throttle1_length = base::TimeDelta::FromMinutes(0); |
| 531 const base::TimeDelta throttle2_length = base::TimeDelta::FromMinutes(20); | 582 const base::TimeDelta throttle2_length = base::TimeDelta::FromMinutes(20); |
| 532 const base::TimeTicks t1 = t0 + throttle1_length; | |
| 533 const base::TimeTicks t2 = t0 + throttle2_length; | |
| 534 | 583 |
| 535 // Setup the longer of two intervals. | 584 // Setup the longer of two intervals. |
| 536 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES), | 585 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, PREFERENCES), |
| 537 throttle2_length, t0); | 586 throttle2_length, now); |
| 538 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), | 587 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), |
| 539 nudge_tracker_.GetThrottledTypes())); | 588 nudge_tracker_.GetBlockedTypes())); |
| 540 EXPECT_EQ(throttle2_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0)); | 589 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 590 EXPECT_TRUE(IsTypeThrottled(PREFERENCES)); |
| 591 EXPECT_GE(throttle2_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 541 | 592 |
| 542 // Setup the shorter interval. | 593 // Setup the shorter interval. |
| 543 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, BOOKMARKS), | 594 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS, BOOKMARKS), |
| 544 throttle1_length, t0); | 595 throttle1_length, now); |
| 545 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES, BOOKMARKS), | 596 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES, BOOKMARKS), |
| 546 nudge_tracker_.GetThrottledTypes())); | 597 nudge_tracker_.GetBlockedTypes())); |
| 547 EXPECT_EQ(throttle1_length, nudge_tracker_.GetTimeUntilNextUnthrottle(t0)); | 598 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 599 EXPECT_TRUE(IsTypeThrottled(PREFERENCES)); |
| 600 EXPECT_TRUE(IsTypeThrottled(BOOKMARKS)); |
| 601 EXPECT_GE(throttle1_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 548 | 602 |
| 549 // Expire the first interval. | 603 // Expire the first interval. |
| 550 nudge_tracker_.UpdateTypeThrottlingState(t1); | 604 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 551 | 605 |
| 552 // SESSIONS appeared in both intervals. We expect it will be throttled for | 606 // SESSIONS appeared in both intervals. We expect it will be throttled for |
| 553 // the longer of the two, so it's still throttled at time t1. | 607 // the longer of the two, so it's still throttled at time t1. |
| 554 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), | 608 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), |
| 555 nudge_tracker_.GetThrottledTypes())); | 609 nudge_tracker_.GetBlockedTypes())); |
| 556 EXPECT_EQ(throttle2_length - throttle1_length, | 610 EXPECT_TRUE(IsTypeThrottled(SESSIONS)); |
| 557 nudge_tracker_.GetTimeUntilNextUnthrottle(t1)); | 611 EXPECT_TRUE(IsTypeThrottled(PREFERENCES)); |
| 612 EXPECT_FALSE(IsTypeThrottled(BOOKMARKS)); |
| 613 EXPECT_GE(throttle2_length - throttle1_length, |
| 614 nudge_tracker_.GetTimeUntilNextUnblock()); |
| 615 } |
| 558 | 616 |
| 559 // Expire the second interval. | 617 TEST_F(NudgeTrackerTest, OverlappingBackoffIntervals) { |
| 560 nudge_tracker_.UpdateTypeThrottlingState(t2); | 618 const base::TimeTicks now = base::TimeTicks::Now(); |
| 561 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); | 619 const base::TimeDelta backoff1_length = base::TimeDelta::FromMinutes(0); |
| 620 const base::TimeDelta backoff2_length = base::TimeDelta::FromMinutes(20); |
| 621 |
| 622 // Setup the longer of two intervals. |
| 623 nudge_tracker_.SetTypeBackedOff(SESSIONS, backoff2_length, now); |
| 624 nudge_tracker_.SetTypeBackedOff(PREFERENCES, backoff2_length, now); |
| 625 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), |
| 626 nudge_tracker_.GetBlockedTypes())); |
| 627 EXPECT_TRUE(IsTypeBackedOff(SESSIONS)); |
| 628 EXPECT_TRUE(IsTypeBackedOff(PREFERENCES)); |
| 629 EXPECT_GE(backoff2_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 630 |
| 631 // Setup the shorter interval. |
| 632 nudge_tracker_.SetTypeBackedOff(SESSIONS, backoff1_length, now); |
| 633 nudge_tracker_.SetTypeBackedOff(BOOKMARKS, backoff1_length, now); |
| 634 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES, BOOKMARKS), |
| 635 nudge_tracker_.GetBlockedTypes())); |
| 636 EXPECT_TRUE(IsTypeBackedOff(SESSIONS)); |
| 637 EXPECT_TRUE(IsTypeBackedOff(PREFERENCES)); |
| 638 EXPECT_TRUE(IsTypeBackedOff(BOOKMARKS)); |
| 639 EXPECT_GE(backoff1_length, nudge_tracker_.GetTimeUntilNextUnblock()); |
| 640 |
| 641 // Expire the first interval. |
| 642 nudge_tracker_.UpdateTypeThrottlingAndBackoffState(); |
| 643 |
| 644 // SESSIONS appeared in both intervals. We expect it will be backed off for |
| 645 // the longer of the two, so it's still backed off at time t1. |
| 646 EXPECT_TRUE(ModelTypeSetEquals(ModelTypeSet(SESSIONS, PREFERENCES), |
| 647 nudge_tracker_.GetBlockedTypes())); |
| 648 EXPECT_TRUE(IsTypeBackedOff(SESSIONS)); |
| 649 EXPECT_TRUE(IsTypeBackedOff(PREFERENCES)); |
| 650 EXPECT_FALSE(IsTypeBackedOff(BOOKMARKS)); |
| 651 EXPECT_GE(backoff2_length - backoff1_length, |
| 652 nudge_tracker_.GetTimeUntilNextUnblock()); |
| 562 } | 653 } |
| 563 | 654 |
| 564 TEST_F(NudgeTrackerTest, Retry) { | 655 TEST_F(NudgeTrackerTest, Retry) { |
| 565 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345); | 656 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(12345); |
| 566 const base::TimeTicks t3 = t0 + base::TimeDelta::FromSeconds(3); | 657 const base::TimeTicks t3 = t0 + base::TimeDelta::FromSeconds(3); |
| 567 const base::TimeTicks t4 = t0 + base::TimeDelta::FromSeconds(4); | 658 const base::TimeTicks t4 = t0 + base::TimeDelta::FromSeconds(4); |
| 568 | 659 |
| 569 // Set retry for t3. | 660 // Set retry for t3. |
| 570 nudge_tracker_.SetNextRetryTime(t3); | 661 nudge_tracker_.SetNextRetryTime(t3); |
| 571 | 662 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 EXPECT_TRUE(IsInvalidationAcknowledged(inv1_id)); | 1048 EXPECT_TRUE(IsInvalidationAcknowledged(inv1_id)); |
| 958 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id)); | 1049 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id)); |
| 959 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id)); | 1050 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id)); |
| 960 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id)); | 1051 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id)); |
| 961 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id)); | 1052 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id)); |
| 962 | 1053 |
| 963 EXPECT_TRUE(AllInvalidationsAccountedFor()); | 1054 EXPECT_TRUE(AllInvalidationsAccountedFor()); |
| 964 } | 1055 } |
| 965 | 1056 |
| 966 } // namespace syncer | 1057 } // namespace syncer |
| OLD | NEW |