Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 MOCK_METHOD1(ClearCachedSuggestions, void(Category)); | 91 MOCK_METHOD1(ClearCachedSuggestions, void(Category)); |
| 91 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category)); | 92 MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category)); |
| 92 MOCK_METHOD1(DismissSuggestion, void(const ContentSuggestion::ID&)); | 93 MOCK_METHOD1(DismissSuggestion, void(const ContentSuggestion::ID&)); |
| 93 MOCK_METHOD2(FetchSuggestionImage, | 94 MOCK_METHOD2(FetchSuggestionImage, |
| 94 void(const ContentSuggestion::ID&, const ImageFetchedCallback&)); | 95 void(const ContentSuggestion::ID&, const ImageFetchedCallback&)); |
| 95 MOCK_METHOD2(GetDismissedSuggestionsForDebugging, | 96 MOCK_METHOD2(GetDismissedSuggestionsForDebugging, |
| 96 void(Category, const DismissedSuggestionsCallback&)); | 97 void(Category, const DismissedSuggestionsCallback&)); |
| 97 MOCK_METHOD0(OnSignInStateChanged, void()); | 98 MOCK_METHOD0(OnSignInStateChanged, void()); |
| 98 }; | 99 }; |
| 99 | 100 |
| 101 class FakeNetworkChangeNotifierWIFI : public net::NetworkChangeNotifier { | |
|
Marc Treib
2017/04/04 13:28:16
s/WIFI/Wifi/ ?
optional: Merge the two classes an
jkrcal
2017/04/05 17:32:56
Not relevant any more.
| |
| 102 public: | |
| 103 ConnectionType GetCurrentConnectionType() const override { | |
| 104 return NetworkChangeNotifier::CONNECTION_WIFI; | |
| 105 } | |
| 106 }; | |
| 107 | |
| 108 class FakeNetworkChangeNotifier2G : public net::NetworkChangeNotifier { | |
| 109 public: | |
| 110 ConnectionType GetCurrentConnectionType() const override { | |
| 111 return NetworkChangeNotifier::CONNECTION_2G; | |
| 112 } | |
| 113 }; | |
| 114 | |
| 100 } // namespace | 115 } // namespace |
| 101 | 116 |
| 102 class RemoteSuggestionsSchedulerImplTest : public ::testing::Test { | 117 class RemoteSuggestionsSchedulerImplTest : public ::testing::Test { |
| 103 public: | 118 public: |
| 104 RemoteSuggestionsSchedulerImplTest() | 119 RemoteSuggestionsSchedulerImplTest() |
| 105 : // For the test we enabled all trigger types. | 120 : // For the test we enabled all trigger types. |
| 106 default_variation_params_{{"scheduler_trigger_types", | 121 default_variation_params_{{"scheduler_trigger_types", |
| 107 "persistent_scheduler_wake_up,ntp_opened," | 122 "persistent_scheduler_wake_up,ntp_opened," |
| 108 "browser_foregrounded,browser_cold_start"}}, | 123 "browser_foregrounded,browser_cold_start"}}, |
| 109 params_manager_(ntp_snippets::kArticleSuggestionsFeature.name, | 124 params_manager_(ntp_snippets::kArticleSuggestionsFeature.name, |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 481 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 467 { | 482 { |
| 468 InSequence s; | 483 InSequence s; |
| 469 // Initial scheduling after being enabled. | 484 // Initial scheduling after being enabled. |
| 470 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 485 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 471 // The first call to NTPOpened results in a fetch. | 486 // The first call to NTPOpened results in a fetch. |
| 472 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | 487 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) |
| 473 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 488 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 474 // Rescheduling after a succesful fetch. | 489 // Rescheduling after a succesful fetch. |
| 475 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 490 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 476 // The second call to NTPOpened 2hrs later again results in a fetch. | 491 // The second call to NTPOpened 4hrs later again results in a fetch. |
| 477 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | 492 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
| 478 } | 493 } |
| 479 | 494 |
| 480 // First enable the scheduler. | 495 // First enable the scheduler. |
| 481 ActivateProvider(); | 496 ActivateProvider(); |
| 482 // Make the first soft fetch successful. | 497 // Make the first soft fetch successful. |
| 483 scheduler()->OnBrowserForegrounded(); | 498 scheduler()->OnBrowserForegrounded(); |
| 484 signal_fetch_done.Run(Status::Success()); | 499 signal_fetch_done.Run(Status::Success()); |
| 485 // Open NTP again after 2hrs. | 500 // Open NTP again after 4hrs. |
| 486 test_clock()->Advance(base::TimeDelta::FromHours(2)); | 501 test_clock()->Advance(base::TimeDelta::FromHours(4)); |
| 487 scheduler()->OnBrowserForegrounded(); | 502 scheduler()->OnBrowserForegrounded(); |
| 488 } | 503 } |
| 489 | 504 |
| 490 TEST_F(RemoteSuggestionsSchedulerImplTest, | 505 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 491 ShouldRescheduleOnRescheduleFetching) { | 506 ShouldRescheduleOnRescheduleFetching) { |
| 492 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 507 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 493 scheduler()->RescheduleFetching(); | 508 scheduler()->RescheduleFetching(); |
| 494 } | 509 } |
| 495 | 510 |
| 496 TEST_F(RemoteSuggestionsSchedulerImplTest, ShouldScheduleOnActivation) { | 511 TEST_F(RemoteSuggestionsSchedulerImplTest, ShouldScheduleOnActivation) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 576 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 562 EXPECT_CALL(*persistent_scheduler(), Unschedule()); | 577 EXPECT_CALL(*persistent_scheduler(), Unschedule()); |
| 563 } | 578 } |
| 564 // First schedule so that later we really unschedule. | 579 // First schedule so that later we really unschedule. |
| 565 ActivateProvider(); | 580 ActivateProvider(); |
| 566 DeactivateProvider(); | 581 DeactivateProvider(); |
| 567 // No further call to Unschedule on second status callback. | 582 // No further call to Unschedule on second status callback. |
| 568 DeactivateProvider(); | 583 DeactivateProvider(); |
| 569 } | 584 } |
| 570 | 585 |
| 571 TEST_F(RemoteSuggestionsSchedulerImplTest, ReschedulesWhenWifiParamChanges) { | 586 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 587 ReschedulesWhenPersistentWifiParamChanges) { | |
| 572 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 588 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 573 ActivateProvider(); | 589 ActivateProvider(); |
| 574 | 590 |
| 575 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 591 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 576 // null. Change the wifi interval for this class. | 592 // null. Change the wifi interval for this class. |
| 577 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); | 593 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); |
| 578 | 594 |
| 579 // Schedule() should get called for the second time after params have changed. | 595 // Schedule() should get called for the second time after params have changed. |
| 580 ActivateProvider(); | 596 ActivateProvider(); |
| 581 } | 597 } |
| 582 | 598 |
| 583 TEST_F(RemoteSuggestionsSchedulerImplTest, | 599 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 584 ReschedulesWhenFallbackParamChanges) { | 600 ReschedulesWhenPersistentFallbackParamChanges) { |
| 585 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 601 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 586 ActivateProvider(); | 602 ActivateProvider(); |
| 587 | 603 |
| 588 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 604 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 589 // null. Change the fallback interval for this class. | 605 // null. Change the fallback interval for this class. |
| 590 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", | 606 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", |
| 591 "1.5"); | 607 "1.5"); |
| 592 | 608 |
| 593 // Schedule() should get called for the second time after params have changed. | 609 // Schedule() should get called for the second time after params have changed. |
| 594 ActivateProvider(); | 610 ActivateProvider(); |
| 595 } | 611 } |
| 596 | 612 |
| 597 TEST_F(RemoteSuggestionsSchedulerImplTest, | 613 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 598 ReschedulesWhenOnUsageEventParamChanges) { | 614 ReschedulesWhenSoftWifiParamChanges) { |
| 599 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 615 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 600 ActivateProvider(); | 616 ActivateProvider(); |
| 601 | 617 |
| 602 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 618 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 603 // null. Change the on usage interval for this class. | 619 // null. Change the on usage interval for this class. |
| 604 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", | 620 SetVariationParameter("soft_fetching_interval_hours-wifi-active_ntp_user", |
| 605 "1.5"); | 621 "1.5"); |
| 606 | 622 |
| 607 // Schedule() should get called for the second time after params have changed. | 623 // Schedule() should get called for the second time after params have changed. |
| 608 ActivateProvider(); | 624 ActivateProvider(); |
| 609 } | 625 } |
| 610 | 626 |
| 611 TEST_F(RemoteSuggestionsSchedulerImplTest, | 627 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 612 ReschedulesWhenOnNtpOpenedParamChanges) { | 628 ReschedulesWhenSoftFallbackParamChanges) { |
| 613 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); | 629 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 614 ActivateProvider(); | 630 ActivateProvider(); |
| 615 | 631 |
| 616 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 632 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 617 // null. Change the fallback interval for this class. | 633 // null. Change the fallback interval for this class. |
| 618 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 634 SetVariationParameter("soft_fetching_interval_hours-fallback-active_ntp_user", |
| 619 "1.5"); | 635 "1.5"); |
| 620 | 636 |
| 621 // Schedule() should get called for the second time after params have changed. | 637 // Schedule() should get called for the second time after params have changed. |
| 622 ActivateProvider(); | 638 ActivateProvider(); |
| 623 } | 639 } |
| 624 | 640 |
| 625 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForNtpOpenedTrigger) { | 641 TEST_F(RemoteSuggestionsSchedulerImplTest, FetchIntervalForSoftTriggerOnWifi) { |
| 626 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 642 // Pretend we are on WiFi. |
| 627 { | 643 FakeNetworkChangeNotifierWIFI fake_network_notifier; |
| 628 InSequence s; | 644 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time |
| 629 // Initial scheduling after being enabled. | 645 // interval by default for soft background fetches on WiFi. |
| 630 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 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 | 646 |
| 647 // Initial scheduling after being enabled. | |
| 648 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 640 ActivateProvider(); | 649 ActivateProvider(); |
| 641 | 650 |
| 651 // The first call to NTPOpened results in a fetch. | |
| 652 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 653 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
| 654 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 642 scheduler()->OnNTPOpened(); | 655 scheduler()->OnNTPOpened(); |
| 656 // Rescheduling after a succesful fetch. | |
| 657 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 643 signal_fetch_done.Run(Status::Success()); | 658 signal_fetch_done.Run(Status::Success()); |
| 644 | 659 |
| 645 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time | 660 // 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)); | 661 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
| 650 scheduler()->OnNTPOpened(); | 662 scheduler()->OnNTPOpened(); |
| 651 | 663 |
| 652 // Open NTP again after 101min (121min since first opened). Since the default | 664 // Open NTP after another delay, now together long enough to issue a fetch. |
| 653 // time interval has passed refetch again. | 665 test_clock()->Advance(base::TimeDelta::FromMinutes(100)); |
| 654 test_clock()->Advance(base::TimeDelta::FromMinutes(101)); | 666 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); |
| 655 scheduler()->OnNTPOpened(); | 667 scheduler()->OnNTPOpened(); |
| 656 } | 668 } |
| 657 | 669 |
| 658 TEST_F(RemoteSuggestionsSchedulerImplTest, | 670 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 659 OverrideFetchIntervalForNtpOpenedTrigger) { | 671 OverrideFetchIntervalForSoftTriggerOnWifi) { |
| 672 // Pretend we are on WiFi. | |
| 673 FakeNetworkChangeNotifierWIFI fake_network_notifier; | |
| 660 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 674 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 661 // null. Change the on usage interval for this class from 2h to 30min. | 675 // null. Change the on usage interval for this class from 2h to 30min. |
| 662 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 676 SetVariationParameter("soft_fetching_interval_hours-wifi-active_ntp_user", |
| 663 "0.5"); | 677 "0.5"); |
| 664 | 678 |
| 665 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 679 // Initial scheduling after being enabled. |
| 666 { | 680 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(); | 681 ActivateProvider(); |
| 680 | 682 |
| 683 // The first call to NTPOpened results in a fetch. | |
| 684 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 685 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
| 686 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 681 scheduler()->OnNTPOpened(); | 687 scheduler()->OnNTPOpened(); |
| 688 // Rescheduling after a succesful fetch. | |
| 689 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 682 signal_fetch_done.Run(Status::Success()); | 690 signal_fetch_done.Run(Status::Success()); |
| 683 | 691 |
| 684 // Open NTP again after 20min. No fetch request is issues since the 30 min | 692 // 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)); | 693 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
| 687 scheduler()->OnNTPOpened(); | 694 scheduler()->OnNTPOpened(); |
| 688 | 695 |
| 689 // Open NTP again after 15min (35min since first opened) | 696 // Open NTP after another delay, now together long enough to issue a fetch. |
| 690 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); | 697 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); |
| 698 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | |
| 691 scheduler()->OnNTPOpened(); | 699 scheduler()->OnNTPOpened(); |
| 692 } | 700 } |
| 693 | 701 |
| 702 TEST_F(RemoteSuggestionsSchedulerImplTest, | |
| 703 FetchIntervalForSoftTriggerOnFallback) { | |
| 704 // Pretend we are on 2G -> fallback connection. | |
| 705 FakeNetworkChangeNotifier2G fake_network_notifier; | |
| 706 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 4h time | |
| 707 // interval by default for soft background fetches not on WiFi. | |
| 708 | |
| 709 // Initial scheduling after being enabled. | |
| 710 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 711 ActivateProvider(); | |
| 712 | |
| 713 // The first call to NTPOpened results in a fetch. | |
| 714 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 715 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
| 716 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 717 scheduler()->OnNTPOpened(); | |
| 718 // Rescheduling after a succesful fetch. | |
| 719 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 720 signal_fetch_done.Run(Status::Success()); | |
| 721 | |
| 722 // Open NTP again after too short delay. This time no fetch is executed. | |
| 723 test_clock()->Advance(base::TimeDelta::FromMinutes(60)); | |
| 724 scheduler()->OnNTPOpened(); | |
| 725 | |
| 726 // Open NTP after another delay, now together long enough to issue a fetch. | |
| 727 test_clock()->Advance(base::TimeDelta::FromMinutes(180)); | |
| 728 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | |
| 729 scheduler()->OnNTPOpened(); | |
| 730 } | |
| 731 | |
| 732 TEST_F(RemoteSuggestionsSchedulerImplTest, | |
| 733 OverrideFetchIntervalForSoftTriggerOnFallback) { | |
| 734 // Pretend we are on 2G -> fallback connection. | |
| 735 FakeNetworkChangeNotifier2G fake_network_notifier; | |
| 736 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | |
| 737 // null. Change the on usage interval for this class from 4h to 30min. | |
| 738 SetVariationParameter("soft_fetching_interval_hours-fallback-active_ntp_user", | |
| 739 "0.5"); | |
| 740 | |
| 741 // Initial scheduling after being enabled. | |
| 742 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 743 ActivateProvider(); | |
| 744 | |
| 745 // The first call to NTPOpened results in a fetch. | |
| 746 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 747 EXPECT_CALL(*provider(), RefetchInTheBackground(_)) | |
| 748 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 749 scheduler()->OnNTPOpened(); | |
| 750 // Rescheduling after a succesful fetch. | |
| 751 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | |
| 752 signal_fetch_done.Run(Status::Success()); | |
| 753 | |
| 754 // Open NTP again after too short delay. This time no fetch is executed. | |
| 755 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); | |
| 756 scheduler()->OnNTPOpened(); | |
| 757 | |
| 758 // Open NTP after another delay, now together long enough to issue a fetch. | |
| 759 test_clock()->Advance(base::TimeDelta::FromMinutes(10)); | |
| 760 EXPECT_CALL(*provider(), RefetchInTheBackground(_)); | |
| 761 scheduler()->OnNTPOpened(); | |
| 762 } | |
| 763 | |
| 694 TEST_F(RemoteSuggestionsSchedulerImplTest, | 764 TEST_F(RemoteSuggestionsSchedulerImplTest, |
| 695 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { | 765 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { |
| 696 // First enable the scheduler -- this will trigger the persistent scheduling. | 766 // First enable the scheduler -- this will trigger the persistent scheduling. |
| 697 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); | 767 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 698 ActivateProvider(); | 768 ActivateProvider(); |
| 699 // Clear the history. | 769 // Clear the history. |
| 700 scheduler()->OnHistoryCleared(); | 770 scheduler()->OnHistoryCleared(); |
| 701 | 771 |
| 702 // A trigger after 15 minutes is ignored. | 772 // A trigger after 15 minutes is ignored. |
| 703 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); | 773 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) { | 837 for (int x = 0; x < 5; ++x) { |
| 768 scheduler()->OnPersistentSchedulerWakeUp(); | 838 scheduler()->OnPersistentSchedulerWakeUp(); |
| 769 signal_fetch_done.Run(Status::Success()); | 839 signal_fetch_done.Run(Status::Success()); |
| 770 } | 840 } |
| 771 | 841 |
| 772 // For the 6th time, it is blocked by the scheduling provider. | 842 // For the 6th time, it is blocked by the scheduling provider. |
| 773 scheduler()->OnPersistentSchedulerWakeUp(); | 843 scheduler()->OnPersistentSchedulerWakeUp(); |
| 774 } | 844 } |
| 775 | 845 |
| 776 } // namespace ntp_snippets | 846 } // namespace ntp_snippets |
| OLD | NEW |