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