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 14 matching lines...) Expand all Loading... |
25 #include "components/ntp_snippets/pref_names.h" | 25 #include "components/ntp_snippets/pref_names.h" |
26 #include "components/ntp_snippets/remote/persistent_scheduler.h" | 26 #include "components/ntp_snippets/remote/persistent_scheduler.h" |
27 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 27 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
28 #include "components/ntp_snippets/remote/test_utils.h" | 28 #include "components/ntp_snippets/remote/test_utils.h" |
29 #include "components/ntp_snippets/status.h" | 29 #include "components/ntp_snippets/status.h" |
30 #include "components/ntp_snippets/user_classifier.h" | 30 #include "components/ntp_snippets/user_classifier.h" |
31 #include "components/prefs/pref_registry_simple.h" | 31 #include "components/prefs/pref_registry_simple.h" |
32 #include "components/prefs/testing_pref_service.h" | 32 #include "components/prefs/testing_pref_service.h" |
33 #include "components/variations/variations_params_manager.h" | 33 #include "components/variations/variations_params_manager.h" |
34 #include "components/web_resource/web_resource_pref_names.h" | 34 #include "components/web_resource/web_resource_pref_names.h" |
| 35 #include "net/base/network_change_notifier.h" |
35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
37 | 38 |
38 using testing::ElementsAre; | 39 using testing::ElementsAre; |
39 using testing::Eq; | 40 using testing::Eq; |
40 using testing::Field; | 41 using testing::Field; |
41 using testing::InSequence; | 42 using testing::InSequence; |
42 using testing::Invoke; | 43 using testing::Invoke; |
43 using testing::IsEmpty; | 44 using testing::IsEmpty; |
44 using testing::Mock; | 45 using testing::Mock; |
(...skipping 13 matching lines...) Expand all Loading... |
58 class RemoteSuggestionsFetcher; | 59 class RemoteSuggestionsFetcher; |
59 | 60 |
60 namespace { | 61 namespace { |
61 | 62 |
62 class MockPersistentScheduler : public PersistentScheduler { | 63 class MockPersistentScheduler : public PersistentScheduler { |
63 public: | 64 public: |
64 MOCK_METHOD2(Schedule, | 65 MOCK_METHOD2(Schedule, |
65 bool(base::TimeDelta period_wifi, | 66 bool(base::TimeDelta period_wifi, |
66 base::TimeDelta period_fallback)); | 67 base::TimeDelta period_fallback)); |
67 MOCK_METHOD0(Unschedule, bool()); | 68 MOCK_METHOD0(Unschedule, bool()); |
| 69 MOCK_METHOD0(IsOnUnmeteredConnection, bool()); |
68 }; | 70 }; |
69 | 71 |
70 // TODO(jkrcal): Move into its own library to reuse in other unit-tests? | 72 // TODO(jkrcal): Move into its own library to reuse in other unit-tests? |
71 class MockRemoteSuggestionsProvider : public RemoteSuggestionsProvider { | 73 class MockRemoteSuggestionsProvider : public RemoteSuggestionsProvider { |
72 public: | 74 public: |
73 MockRemoteSuggestionsProvider(Observer* observer) | 75 MockRemoteSuggestionsProvider(Observer* observer) |
74 : RemoteSuggestionsProvider(observer) {} | 76 : RemoteSuggestionsProvider(observer) {} |
75 MOCK_METHOD1(RefetchInTheBackground, | 77 MOCK_METHOD1(RefetchInTheBackground, |
76 void(const RemoteSuggestionsProvider::FetchStatusCallback&)); | 78 void(const RemoteSuggestionsProvider::FetchStatusCallback&)); |
77 MOCK_CONST_METHOD0(suggestions_fetcher_for_debugging, | 79 MOCK_CONST_METHOD0(suggestions_fetcher_for_debugging, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 {kArticleSuggestionsFeature.name}), | 113 {kArticleSuggestionsFeature.name}), |
112 user_classifier_(/*pref_service=*/nullptr, | 114 user_classifier_(/*pref_service=*/nullptr, |
113 base::MakeUnique<base::DefaultClock>()) { | 115 base::MakeUnique<base::DefaultClock>()) { |
114 RemoteSuggestionsSchedulerImpl::RegisterProfilePrefs( | 116 RemoteSuggestionsSchedulerImpl::RegisterProfilePrefs( |
115 utils_.pref_service()->registry()); | 117 utils_.pref_service()->registry()); |
116 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); | 118 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
117 // TODO(jkrcal) Create a static function in EulaAcceptedNotifier that | 119 // TODO(jkrcal) Create a static function in EulaAcceptedNotifier that |
118 // registers this pref and replace the call in browser_process_impl.cc & in | 120 // registers this pref and replace the call in browser_process_impl.cc & in |
119 // eula_accepted_notifier_unittest.cc with the new static function. | 121 // eula_accepted_notifier_unittest.cc with the new static function. |
120 local_state_.registry()->RegisterBooleanPref(::prefs::kEulaAccepted, false); | 122 local_state_.registry()->RegisterBooleanPref(::prefs::kEulaAccepted, false); |
| 123 // By default pretend we are on WiFi. |
| 124 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
| 125 .WillRepeatedly(Return(true)); |
121 ResetProvider(); | 126 ResetProvider(); |
122 } | 127 } |
123 | 128 |
124 void ResetProvider() { | 129 void ResetProvider() { |
125 provider_ = base::MakeUnique<StrictMock<MockRemoteSuggestionsProvider>>( | 130 provider_ = base::MakeUnique<StrictMock<MockRemoteSuggestionsProvider>>( |
126 /*observer=*/nullptr); | 131 /*observer=*/nullptr); |
127 | 132 |
128 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); | 133 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
129 test_clock_ = test_clock.get(); | 134 test_clock_ = test_clock.get(); |
130 test_clock_->SetNow(base::Time::Now()); | 135 test_clock_->SetNow(base::Time::Now()); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 471 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
467 { | 472 { |
468 InSequence s; | 473 InSequence s; |
469 // Initial scheduling after being enabled. | 474 // Initial scheduling after being enabled. |
470 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 475 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
471 // The first call to NTPOpened results in a fetch. | 476 // The first call to NTPOpened results in a fetch. |
472 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | 477 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
473 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 478 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
474 // Rescheduling after a succesful fetch. | 479 // Rescheduling after a succesful fetch. |
475 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 480 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
476 // The second call to NTPOpened 2hrs later again results in a fetch. | 481 // The second call to NTPOpened 4hrs later again results in a fetch. |
477 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | 482 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
478 } | 483 } |
479 | 484 |
480 // First enable the scheduler. | 485 // First enable the scheduler. |
481 ActivateProvider(); | 486 ActivateProvider(); |
482 // Make the first soft fetch successful. | 487 // Make the first soft fetch successful. |
483 scheduler()->OnBrowserForegrounded(); | 488 scheduler()->OnBrowserForegrounded(); |
484 signal_fetch_done.Run(Status::Success()); | 489 signal_fetch_done.Run(Status::Success()); |
485 // Open NTP again after 2hrs. | 490 // Open NTP again after 4hrs. |
486 test_clock()->Advance(base::TimeDelta::FromHours(2)); | 491 test_clock()->Advance(base::TimeDelta::FromHours(4)); |
487 scheduler()->OnBrowserForegrounded(); | 492 scheduler()->OnBrowserForegrounded(); |
488 } | 493 } |
489 | 494 |
490 TEST_F(RemoteSuggestionsSchedulerImplTest, | 495 TEST_F(RemoteSuggestionsSchedulerImplTest, |
491 ShouldRescheduleOnRescheduleFetching) { | 496 ShouldRescheduleOnRescheduleFetching) { |
492 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 497 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
493 scheduler()->RescheduleFetching(); | 498 scheduler()->RescheduleFetching(); |
494 } | 499 } |
495 | 500 |
496 TEST_F(RemoteSuggestionsSchedulerImplTest, ShouldScheduleOnActivation) { | 501 TEST_F(RemoteSuggestionsSchedulerImplTest, ShouldScheduleOnActivation) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 566 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
562 EXPECT_CALL(*persistent_scheduler(), Unschedule()); | 567 EXPECT_CALL(*persistent_scheduler(), Unschedule()); |
563 } | 568 } |
564 // First schedule so that later we really unschedule. | 569 // First schedule so that later we really unschedule. |
565 ActivateProvider(); | 570 ActivateProvider(); |
566 DeactivateProvider(); | 571 DeactivateProvider(); |
567 // No further call to Unschedule on second status callback. | 572 // No further call to Unschedule on second status callback. |
568 DeactivateProvider(); | 573 DeactivateProvider(); |
569 } | 574 } |
570 | 575 |
571 TEST_F(RemoteSuggestionsSchedulerImplTest, ReschedulesWhenWifiParamChanges) { | 576 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 577 ReschedulesWhenPersistentWifiParamChanges) { |
572 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 578 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
573 ActivateProvider(); | 579 ActivateProvider(); |
574 | 580 |
575 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 581 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
576 // null. Change the wifi interval for this class. | 582 // null. Change the wifi interval for this class. |
577 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); | 583 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); |
578 | 584 |
579 // Schedule() should get called for the second time after params have changed. | 585 // Schedule() should get called for the second time after params have changed. |
580 ActivateProvider(); | 586 ActivateProvider(); |
581 } | 587 } |
582 | 588 |
583 TEST_F(RemoteSuggestionsSchedulerImplTest, | 589 TEST_F(RemoteSuggestionsSchedulerImplTest, |
584 ReschedulesWhenFallbackParamChanges) { | 590 ReschedulesWhenPersistentFallbackParamChanges) { |
585 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 591 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
586 ActivateProvider(); | 592 ActivateProvider(); |
587 | 593 |
588 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 594 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
589 // null. Change the fallback interval for this class. | 595 // null. Change the fallback interval for this class. |
590 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", | 596 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", |
591 "1.5"); | 597 "1.5"); |
592 | 598 |
593 // Schedule() should get called for the second time after params have changed. | 599 // Schedule() should get called for the second time after params have changed. |
594 ActivateProvider(); | 600 ActivateProvider(); |
595 } | 601 } |
596 | 602 |
597 TEST_F(RemoteSuggestionsSchedulerImplTest, | 603 TEST_F(RemoteSuggestionsSchedulerImplTest, |
598 ReschedulesWhenOnUsageEventParamChanges) { | 604 ReschedulesWhenSoftWifiParamChanges) { |
599 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 605 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
600 ActivateProvider(); | 606 ActivateProvider(); |
601 | 607 |
602 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 608 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
603 // null. Change the on usage interval for this class. | 609 // null. Change the on usage interval for this class. |
604 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", | 610 SetVariationParameter("soft_fetching_interval_hours-wifi-active_ntp_user", |
605 "1.5"); | 611 "1.5"); |
606 | 612 |
607 // Schedule() should get called for the second time after params have changed. | 613 // Schedule() should get called for the second time after params have changed. |
608 ActivateProvider(); | 614 ActivateProvider(); |
609 } | 615 } |
610 | 616 |
611 TEST_F(RemoteSuggestionsSchedulerImplTest, | 617 TEST_F(RemoteSuggestionsSchedulerImplTest, |
612 ReschedulesWhenOnNtpOpenedParamChanges) { | 618 ReschedulesWhenSoftFallbackParamChanges) { |
613 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 619 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
614 ActivateProvider(); | 620 ActivateProvider(); |
615 | 621 |
616 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 622 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
617 // null. Change the fallback interval for this class. | 623 // null. Change the fallback interval for this class. |
618 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 624 SetVariationParameter("soft_fetching_interval_hours-fallback-active_ntp_user", |
619 "1.5"); | 625 "1.5"); |
620 | 626 |
621 // 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. |
622 ActivateProvider(); | 628 ActivateProvider(); |
623 } | 629 } |
624 | 630 |
625 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForNtpOpenedTrigger) { | 631 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForSoftTriggerOnWifi) { |
626 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 632 // Pretend we are on WiFi (already done in ctor, we make it explicit here). |
627 { | 633 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
628 InSequence s; | 634 .WillRepeatedly(Return(true)); |
629 // Initial scheduling after being enabled. | 635 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time |
630 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 636 // interval by default for soft background fetches on WiFi. |
631 // The first call to NTPOpened results in a fetch. | |
632 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
633 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
634 // Rescheduling after a succesful fetch. | |
635 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
636 // The third call to NTPOpened 35min later again results in a fetch. | |
637 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | |
638 } | |
639 | 637 |
| 638 // Initial scheduling after being enabled. |
| 639 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
640 ActivateProvider(); | 640 ActivateProvider(); |
641 | 641 |
| 642 // The first call to NTPOpened results in a fetch. |
| 643 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 644 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
| 645 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
642 scheduler()->OnNTPOpened(); | 646 scheduler()->OnNTPOpened(); |
| 647 // Rescheduling after a succesful fetch. |
| 648 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
643 signal_fetch_done.Run(Status::Success()); | 649 signal_fetch_done.Run(Status::Success()); |
644 | 650 |
645 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time | 651 // Open NTP again after too short delay. This time no fetch is executed. |
646 // interval by default for soft backgroudn fetches on ntp open events. | |
647 | |
648 // Open NTP again after 20min. This time no fetch is executed. | |
649 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); | 652 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
650 scheduler()->OnNTPOpened(); | 653 scheduler()->OnNTPOpened(); |
651 | 654 |
652 // Open NTP again after 101min (121min since first opened). Since the default | 655 // Open NTP after another delay, now together long enough to issue a fetch. |
653 // time interval has passed refetch again. | 656 test_clock()->Advance(base::TimeDelta::FromMinutes(100)); |
654 test_clock()->Advance(base::TimeDelta::FromMinutes(101)); | 657 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
655 scheduler()->OnNTPOpened(); | 658 scheduler()->OnNTPOpened(); |
656 } | 659 } |
657 | 660 |
658 TEST_F(RemoteSuggestionsSchedulerImplTest, | 661 TEST_F(RemoteSuggestionsSchedulerImplTest, |
659 OverrideFetchIntervalForNtpOpenedTrigger) { | 662 OverrideFetchIntervalForSoftTriggerOnWifi) { |
| 663 // Pretend we are on WiFi (already done in ctor, we make it explicit here). |
| 664 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
| 665 .WillRepeatedly(Return(true)); |
660 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 666 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
661 // null. Change the on usage interval for this class from 2h to 30min. | 667 // null. Change the on usage interval for this class from 2h to 30min. |
662 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 668 SetVariationParameter("soft_fetching_interval_hours-wifi-active_ntp_user", |
663 "0.5"); | 669 "0.5"); |
664 | 670 |
665 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 671 // Initial scheduling after being enabled. |
666 { | 672 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
667 InSequence s; | |
668 // Initial scheduling after being enabled. | |
669 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
670 // The first call to NTPOpened results in a fetch. | |
671 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
672 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
673 // Rescheduling after a succesful fetch. | |
674 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
675 // The third call to NTPOpened 35min later again results in a fetch. | |
676 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | |
677 } | |
678 | |
679 ActivateProvider(); | 673 ActivateProvider(); |
680 | 674 |
| 675 // The first call to NTPOpened results in a fetch. |
| 676 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 677 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
| 678 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
681 scheduler()->OnNTPOpened(); | 679 scheduler()->OnNTPOpened(); |
| 680 // Rescheduling after a succesful fetch. |
| 681 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
682 signal_fetch_done.Run(Status::Success()); | 682 signal_fetch_done.Run(Status::Success()); |
683 | 683 |
684 // Open NTP again after 20min. No fetch request is issues since the 30 min | 684 // Open NTP again after too short delay. This time no fetch is executed. |
685 // time interval has not passed yet. | |
686 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); | 685 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
687 scheduler()->OnNTPOpened(); | 686 scheduler()->OnNTPOpened(); |
688 | 687 |
689 // Open NTP again after 15min (35min since first opened) | 688 // Open NTP after another delay, now together long enough to issue a fetch. |
690 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); | 689 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); |
| 690 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
691 scheduler()->OnNTPOpened(); | 691 scheduler()->OnNTPOpened(); |
692 } | 692 } |
693 | 693 |
| 694 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 695 FetchIntervalForSoftTriggerOnFallback) { |
| 696 // Pretend we are not on wifi -> fallback connection. |
| 697 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
| 698 .WillRepeatedly(Return(false)); |
| 699 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 4h time |
| 700 // interval by default for soft background fetches not on WiFi. |
| 701 |
| 702 // Initial scheduling after being enabled. |
| 703 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 704 ActivateProvider(); |
| 705 |
| 706 // The first call to NTPOpened results in a fetch. |
| 707 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 708 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
| 709 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 710 scheduler()->OnNTPOpened(); |
| 711 // Rescheduling after a succesful fetch. |
| 712 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 713 signal_fetch_done.Run(Status::Success()); |
| 714 |
| 715 // Open NTP again after too short delay. This time no fetch is executed. |
| 716 test_clock()->Advance(base::TimeDelta::FromMinutes(180)); |
| 717 scheduler()->OnNTPOpened(); |
| 718 |
| 719 // Open NTP after another delay, now together long enough to issue a fetch. |
| 720 test_clock()->Advance(base::TimeDelta::FromMinutes(60)); |
| 721 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
| 722 scheduler()->OnNTPOpened(); |
| 723 } |
| 724 |
| 725 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 726 OverrideFetchIntervalForSoftTriggerOnFallback) { |
| 727 // Pretend we are not on wifi -> fallback connection. |
| 728 EXPECT_CALL(*persistent_scheduler(), IsOnUnmeteredConnection()) |
| 729 .WillRepeatedly(Return(false)); |
| 730 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 731 // null. Change the on usage interval for this class from 4h to 30min. |
| 732 SetVariationParameter("soft_fetching_interval_hours-fallback-active_ntp_user", |
| 733 "0.5"); |
| 734 |
| 735 // Initial scheduling after being enabled. |
| 736 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 737 ActivateProvider(); |
| 738 |
| 739 // The first call to NTPOpened results in a fetch. |
| 740 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 741 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
| 742 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 743 scheduler()->OnNTPOpened(); |
| 744 // Rescheduling after a succesful fetch. |
| 745 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 746 signal_fetch_done.Run(Status::Success()); |
| 747 |
| 748 // Open NTP again after too short delay. This time no fetch is executed. |
| 749 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
| 750 scheduler()->OnNTPOpened(); |
| 751 |
| 752 // Open NTP after another delay, now together long enough to issue a fetch. |
| 753 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); |
| 754 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
| 755 scheduler()->OnNTPOpened(); |
| 756 } |
| 757 |
694 TEST_F(RemoteSuggestionsSchedulerImplTest, | 758 TEST_F(RemoteSuggestionsSchedulerImplTest, |
695 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { | 759 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { |
696 // First enable the scheduler -- this will trigger the persistent scheduling. | 760 // First enable the scheduler -- this will trigger the persistent scheduling. |
697 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 761 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
698 ActivateProvider(); | 762 ActivateProvider(); |
699 // Clear the history. | 763 // Clear the history. |
700 scheduler()->OnHistoryCleared(); | 764 scheduler()->OnHistoryCleared(); |
701 | 765 |
702 // A trigger after 15 minutes is ignored. | 766 // A trigger after 15 minutes is ignored. |
703 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); | 767 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 for (int x = 0; x < 5; ++x) { | 831 for (int x = 0; x < 5; ++x) { |
768 scheduler()->OnPersistentSchedulerWakeUp(); | 832 scheduler()->OnPersistentSchedulerWakeUp(); |
769 signal_fetch_done.Run(Status::Success()); | 833 signal_fetch_done.Run(Status::Success()); |
770 } | 834 } |
771 | 835 |
772 // For the 6th time, it is blocked by the scheduling provider. | 836 // For the 6th time, it is blocked by the scheduling provider. |
773 scheduler()->OnPersistentSchedulerWakeUp(); | 837 scheduler()->OnPersistentSchedulerWakeUp(); |
774 } | 838 } |
775 | 839 |
776 } // namespace ntp_snippets | 840 } // namespace ntp_snippets |
OLD | NEW |