Chromium Code Reviews| Index: components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc |
| diff --git a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc |
| index 904d11da60aabfe93366777eb6c1bdf683348b7c..e628d8d530afb292114c7716cdd9d9159cdecff2 100644 |
| --- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc |
| +++ b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc |
| @@ -98,6 +98,7 @@ class MockRemoteSuggestionsProvider : public RemoteSuggestionsProvider { |
| void(const Category&, |
| const std::set<std::string>&, |
| const FetchDoneCallback&)); |
| + MOCK_METHOD0(ReloadSuggestions, void()); |
| MOCK_METHOD1(ClearCachedSuggestions, void(Category)); |
| MOCK_METHOD1(ClearDismissedSuggestionsForDebugging, void(Category)); |
| MOCK_METHOD1(DismissSuggestion, void(const ContentSuggestion::ID&)); |
| @@ -126,6 +127,7 @@ class SchedulingRemoteSuggestionsProviderTest |
| user_classifier_(/*pref_service=*/nullptr) { |
| SchedulingRemoteSuggestionsProvider::RegisterProfilePrefs( |
| utils_.pref_service()->registry()); |
| + RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| ResetProvider(); |
| } |
| @@ -677,4 +679,56 @@ TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| scheduling_provider_->OnBrowserForegrounded(); |
| } |
| +TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| + ShouldThrottleInteractiveRequests) { |
| + // Change the quota for interactive requests ("active NTP user" is the default |
| + // class in tests). |
| + SetVariationParameter("interactive_quota_SuggestionFetcherActiveNTPUser", |
| + "10"); |
| + ResetProvider(); |
| + |
| + Category category = Category::FromKnownCategory(KnownCategories::ARTICLES); |
| + std::set<std::string> known_suggestions; |
| + |
| + // As long as the quota suffices, the call gets through. |
|
Marc Treib
2017/02/24 15:50:35
Maybe mention that both ReloadSuggestions and Fetc
jkrcal
2017/02/27 10:26:23
Added a comment. The reason to mix these two is to
|
| + EXPECT_CALL(*underlying_provider_, ReloadSuggestions()).Times(5); |
| + EXPECT_CALL(*underlying_provider_, Fetch(_, _, _)).Times(5); |
| + for (int x = 0; x < 5; ++x) { |
| + scheduling_provider_->ReloadSuggestions(); |
| + scheduling_provider_->Fetch(category, known_suggestions, |
| + FetchDoneCallback()); |
| + } |
| + |
| + // When the quota expires, it is blocked by the scheduling provider. |
| + scheduling_provider_->ReloadSuggestions(); |
| + scheduling_provider_->Fetch(category, known_suggestions, FetchDoneCallback()); |
|
tschumann
2017/02/24 10:18:08
shouldn't we verify the result codes?
jkrcal
2017/02/27 10:26:23
Done.
|
| +} |
| + |
| +TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| + ShouldThrottleNonInteractiveRequests) { |
| + // Change the quota for interactive requests ("active NTP user" is the default |
| + // class in tests). |
| + SetVariationParameter("quota_SuggestionFetcherActiveNTPUser", "5"); |
| + ResetProvider(); |
| + |
| + // One scheduling on start, 5 times after successful fetches. |
| + EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(6); |
| + |
| + // First enable the scheduler -- this will trigger the persistent scheduling. |
| + ActivateUnderlyingProvider(); |
| + |
| + // As long as the quota suffices, the call gets through. |
| + RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| + EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) |
| + .Times(5) |
| + .WillRepeatedly(SaveArg<0>(&signal_fetch_done)); |
| + for (int x = 0; x < 5; ++x) { |
| + scheduling_provider_->OnPersistentSchedulerWakeUp(); |
| + signal_fetch_done.Run(Status::Success()); |
| + } |
| + |
| + // For the 6th time, it is blocked by the scheduling provider. |
| + scheduling_provider_->OnPersistentSchedulerWakeUp(); |
| +} |
| + |
| } // namespace ntp_snippets |