OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 "1.5"); | 625 "1.5"); |
626 | 626 |
627 // Schedule() should get called for the second time after params have changed. | 627 // Schedule() should get called for the second time after params have changed. |
628 ActivateProvider(); | 628 ActivateProvider(); |
629 } | 629 } |
630 | 630 |
631 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForSoftTriggerOnWifi) { | 631 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForSoftTriggerOnWifi) { |
632 // Pretend we are on WiFi (already done in ctor, we make it explicit here). | 632 // Pretend we are on WiFi (already done in ctor, we make it explicit here). |
633 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) | 633 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
634 .WillRepeatedly(Return(true)); | 634 .WillRepeatedly(Return(true)); |
635 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time | 635 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 3h time |
636 // interval by default for soft background fetches on WiFi. | 636 // interval by default for soft background fetches on WiFi. |
637 | 637 |
638 // Initial scheduling after being enabled. | 638 // Initial scheduling after being enabled. |
639 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 639 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
640 ActivateProvider(); | 640 ActivateProvider(); |
641 | 641 |
642 // The first call to NTPOpened results in a fetch. | 642 // The first call to NTPOpened results in a fetch. |
643 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 643 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
644 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | 644 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
645 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 645 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
646 scheduler()->OnNTPOpened(); | 646 scheduler()->OnNTPOpened(); |
647 // Rescheduling after a succesful fetch. | 647 // Rescheduling after a succesful fetch. |
648 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 648 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
649 signal_fetch_done.Run(Status::Success()); | 649 signal_fetch_done.Run(Status::Success()); |
650 | 650 |
651 // Open NTP again after too short delay. This time no fetch is executed. | 651 // Open NTP again after too short delay. This time no fetch is executed. |
652 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); | 652 test_clock()->Advance(base::TimeDelta::FromMinutes(30)); |
653 scheduler()->OnNTPOpened(); | 653 scheduler()->OnNTPOpened(); |
654 | 654 |
655 // Open NTP after another delay, now together long enough to issue a fetch. | 655 // Open NTP after another delay, now together long enough to issue a fetch. |
656 test_clock()->Advance(base::TimeDelta::FromMinutes(100)); | 656 test_clock()->Advance(base::TimeDelta::FromMinutes(150)); |
657 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | 657 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
658 scheduler()->OnNTPOpened(); | 658 scheduler()->OnNTPOpened(); |
659 } | 659 } |
660 | 660 |
661 TEST_F(RemoteSuggestionsSchedulerImplTest, | 661 TEST_F(RemoteSuggestionsSchedulerImplTest, |
662 OverrideFetchIntervalForSoftTriggerOnWifi) { | 662 OverrideFetchIntervalForSoftTriggerOnWifi) { |
663 // Pretend we are on WiFi (already done in ctor, we make it explicit here). | 663 // Pretend we are on WiFi (already done in ctor, we make it explicit here). |
664 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) | 664 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
665 .WillRepeatedly(Return(true)); | 665 .WillRepeatedly(Return(true)); |
666 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 666 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
(...skipping 22 matching lines...) Expand all Loading... |
689 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); | 689 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); |
690 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | 690 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
691 scheduler()->OnNTPOpened(); | 691 scheduler()->OnNTPOpened(); |
692 } | 692 } |
693 | 693 |
694 TEST_F(RemoteSuggestionsSchedulerImplTest, | 694 TEST_F(RemoteSuggestionsSchedulerImplTest, |
695 FetchIntervalForSoftTriggerOnFallback) { | 695 FetchIntervalForSoftTriggerOnFallback) { |
696 // Pretend we are not on wifi -> fallback connection. | 696 // Pretend we are not on wifi -> fallback connection. |
697 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) | 697 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
698 .WillRepeatedly(Return(false)); | 698 .WillRepeatedly(Return(false)); |
699 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 4h time | 699 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 6h time |
700 // interval by default for soft background fetches not on WiFi. | 700 // interval by default for soft background fetches not on WiFi. |
701 | 701 |
702 // Initial scheduling after being enabled. | 702 // Initial scheduling after being enabled. |
703 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 703 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
704 ActivateProvider(); | 704 ActivateProvider(); |
705 | 705 |
706 // The first call to NTPOpened results in a fetch. | 706 // The first call to NTPOpened results in a fetch. |
707 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 707 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
708 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | 708 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
709 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 709 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
710 scheduler()->OnNTPOpened(); | 710 scheduler()->OnNTPOpened(); |
711 // Rescheduling after a succesful fetch. | 711 // Rescheduling after a succesful fetch. |
712 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 712 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
713 signal_fetch_done.Run(Status::Success()); | 713 signal_fetch_done.Run(Status::Success()); |
714 | 714 |
715 // Open NTP again after too short delay. This time no fetch is executed. | 715 // Open NTP again after too short delay. This time no fetch is executed. |
716 test_clock()->Advance(base::TimeDelta::FromMinutes(180)); | 716 test_clock()->Advance(base::TimeDelta::FromMinutes(300)); |
717 scheduler()->OnNTPOpened(); | 717 scheduler()->OnNTPOpened(); |
718 | 718 |
719 // Open NTP after another delay, now together long enough to issue a fetch. | 719 // Open NTP after another delay, now together long enough to issue a fetch. |
720 test_clock()->Advance(base::TimeDelta::FromMinutes(60)); | 720 test_clock()->Advance(base::TimeDelta::FromMinutes(60)); |
721 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | 721 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
722 scheduler()->OnNTPOpened(); | 722 scheduler()->OnNTPOpened(); |
723 } | 723 } |
724 | 724 |
725 TEST_F(RemoteSuggestionsSchedulerImplTest, | 725 TEST_F(RemoteSuggestionsSchedulerImplTest, |
726 OverrideFetchIntervalForSoftTriggerOnFallback) { | 726 OverrideFetchIntervalForSoftTriggerOnFallback) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 for (int x = 0; x < 5; ++x) { | 831 for (int x = 0; x < 5; ++x) { |
832 scheduler()->OnPersistentSchedulerWakeUp(); | 832 scheduler()->OnPersistentSchedulerWakeUp(); |
833 signal_fetch_done.Run(Status::Success()); | 833 signal_fetch_done.Run(Status::Success()); |
834 } | 834 } |
835 | 835 |
836 // For the 6th time, it is blocked by the scheduling provider. | 836 // For the 6th time, it is blocked by the scheduling provider. |
837 scheduler()->OnPersistentSchedulerWakeUp(); | 837 scheduler()->OnPersistentSchedulerWakeUp(); |
838 } | 838 } |
839 | 839 |
840 } // namespace ntp_snippets | 840 } // namespace ntp_snippets |
OLD | NEW |