| 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/scheduling_remote_suggestions_provider.
h" | 5 #include "components/ntp_snippets/remote/scheduling_remote_suggestions_provider.
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 10 matching lines...) Expand all Loading... |
| 21 #include "base/time/default_clock.h" | 21 #include "base/time/default_clock.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "components/ntp_snippets/features.h" | 23 #include "components/ntp_snippets/features.h" |
| 24 #include "components/ntp_snippets/ntp_snippets_constants.h" | 24 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 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/testing_pref_service.h" | 32 #include "components/prefs/testing_pref_service.h" |
| 32 #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" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 37 |
| 36 using testing::ElementsAre; | 38 using testing::ElementsAre; |
| 37 using testing::Eq; | 39 using testing::Eq; |
| 38 using testing::Field; | 40 using testing::Field; |
| 39 using testing::InSequence; | 41 using testing::InSequence; |
| 40 using testing::Invoke; | 42 using testing::Invoke; |
| 41 using testing::IsEmpty; | 43 using testing::IsEmpty; |
| 42 using testing::Mock; | 44 using testing::Mock; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 class SchedulingRemoteSuggestionsProviderTest : public ::testing::Test { | 118 class SchedulingRemoteSuggestionsProviderTest : public ::testing::Test { |
| 117 public: | 119 public: |
| 118 SchedulingRemoteSuggestionsProviderTest() | 120 SchedulingRemoteSuggestionsProviderTest() |
| 119 : // For the test we enabled all trigger types. | 121 : // For the test we enabled all trigger types. |
| 120 default_variation_params_{{"scheduler_trigger_types", | 122 default_variation_params_{{"scheduler_trigger_types", |
| 121 "persistent_scheduler_wake_up,ntp_opened," | 123 "persistent_scheduler_wake_up,ntp_opened," |
| 122 "browser_foregrounded,browser_cold_start"}}, | 124 "browser_foregrounded,browser_cold_start"}}, |
| 123 params_manager_(ntp_snippets::kStudyName, | 125 params_manager_(ntp_snippets::kStudyName, |
| 124 default_variation_params_, | 126 default_variation_params_, |
| 125 {kArticleSuggestionsFeature.name}), | 127 {kArticleSuggestionsFeature.name}), |
| 126 underlying_provider_(nullptr), | |
| 127 scheduling_provider_(nullptr), | |
| 128 user_classifier_(/*pref_service=*/nullptr, | 128 user_classifier_(/*pref_service=*/nullptr, |
| 129 base::MakeUnique<base::DefaultClock>()) { | 129 base::MakeUnique<base::DefaultClock>()) { |
| 130 SchedulingRemoteSuggestionsProvider::RegisterProfilePrefs( | 130 SchedulingRemoteSuggestionsProvider::RegisterProfilePrefs( |
| 131 utils_.pref_service()->registry()); | 131 utils_.pref_service()->registry()); |
| 132 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); | 132 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| 133 // TODO(jkrcal) Create a static function in EulaAcceptedNotifier that |
| 134 // registers this pref and replace the call in browser_process_impl.cc & in |
| 135 // eula_accepted_notifier_unittest.cc with the new static function. |
| 136 local_state_.registry()->RegisterBooleanPref(::prefs::kEulaAccepted, false); |
| 133 ResetProvider(); | 137 ResetProvider(); |
| 134 } | 138 } |
| 135 | 139 |
| 136 void ResetProvider() { | 140 void ResetProvider() { |
| 137 auto underlying_provider = | 141 auto underlying_provider = |
| 138 base::MakeUnique<StrictMock<MockRemoteSuggestionsProvider>>( | 142 base::MakeUnique<StrictMock<MockRemoteSuggestionsProvider>>( |
| 139 /*observer=*/nullptr); | 143 /*observer=*/nullptr); |
| 140 underlying_provider_ = underlying_provider.get(); | 144 underlying_provider_ = underlying_provider.get(); |
| 141 | 145 |
| 142 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); | 146 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
| 143 test_clock_ = test_clock.get(); | 147 test_clock_ = test_clock.get(); |
| 144 test_clock_->SetNow(base::Time::Now()); | 148 test_clock_->SetNow(base::Time::Now()); |
| 145 | 149 |
| 146 scheduling_provider_ = | 150 scheduling_provider_ = |
| 147 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( | 151 base::MakeUnique<SchedulingRemoteSuggestionsProvider>( |
| 148 /*observer=*/nullptr, std::move(underlying_provider), | 152 /*observer=*/nullptr, std::move(underlying_provider), |
| 149 &persistent_scheduler_, &user_classifier_, utils_.pref_service(), | 153 &persistent_scheduler_, &user_classifier_, utils_.pref_service(), |
| 150 std::move(test_clock)); | 154 &local_state_, std::move(test_clock)); |
| 151 } | 155 } |
| 152 | 156 |
| 153 void SetVariationParameter(const std::string& param_name, | 157 void SetVariationParameter(const std::string& param_name, |
| 154 const std::string& param_value) { | 158 const std::string& param_value) { |
| 155 std::map<std::string, std::string> params = default_variation_params_; | 159 std::map<std::string, std::string> params = default_variation_params_; |
| 156 params[param_name] = param_value; | 160 params[param_name] = param_value; |
| 157 | 161 |
| 158 params_manager_.ClearAllVariationParams(); | 162 params_manager_.ClearAllVariationParams(); |
| 159 params_manager_.SetVariationParamsWithFeatureAssociations( | 163 params_manager_.SetVariationParamsWithFeatureAssociations( |
| 160 ntp_snippets::kStudyName, params, | 164 ntp_snippets::kStudyName, params, |
| 161 {ntp_snippets::kArticleSuggestionsFeature.name}); | 165 {ntp_snippets::kArticleSuggestionsFeature.name}); |
| 162 } | 166 } |
| 163 | 167 |
| 168 bool IsEulaNotifierAvailable() { |
| 169 // Create() returns a unique_ptr, so this is no leak. |
| 170 return web_resource::EulaAcceptedNotifier::Create(&local_state_) != nullptr; |
| 171 } |
| 172 |
| 173 void SetEulaAcceptedPref() { |
| 174 local_state_.SetBoolean(::prefs::kEulaAccepted, true); |
| 175 } |
| 176 |
| 164 // GMock cannot deal with move-only types. We need to pass the vector to the | 177 // GMock cannot deal with move-only types. We need to pass the vector to the |
| 165 // mock function as const ref using this wrapper callback. | 178 // mock function as const ref using this wrapper callback. |
| 166 void FetchDoneWrapper( | 179 void FetchDoneWrapper( |
| 167 MockFunction<void(Status status_code, | 180 MockFunction<void(Status status_code, |
| 168 const std::vector<ContentSuggestion>& suggestions)>* | 181 const std::vector<ContentSuggestion>& suggestions)>* |
| 169 fetch_done, | 182 fetch_done, |
| 170 Status status_code, | 183 Status status_code, |
| 171 std::vector<ContentSuggestion> suggestions) { | 184 std::vector<ContentSuggestion> suggestions) { |
| 172 fetch_done->Call(status_code, suggestions); | 185 fetch_done->Call(status_code, suggestions); |
| 173 } | 186 } |
| 174 | 187 |
| 175 protected: | 188 protected: |
| 176 std::map<std::string, std::string> default_variation_params_; | 189 std::map<std::string, std::string> default_variation_params_; |
| 177 variations::testing::VariationParamsManager params_manager_; | 190 variations::testing::VariationParamsManager params_manager_; |
| 178 StrictMock<MockPersistentScheduler> persistent_scheduler_; | |
| 179 StrictMock<MockRemoteSuggestionsProvider>* underlying_provider_; | |
| 180 std::unique_ptr<SchedulingRemoteSuggestionsProvider> scheduling_provider_; | |
| 181 base::SimpleTestClock* test_clock_; | |
| 182 | 191 |
| 183 void ActivateUnderlyingProvider() { | 192 void ActivateUnderlyingProvider() { |
| 184 scheduling_provider_->OnProviderActivated(); | 193 SetEulaAcceptedPref(); |
| 194 scheduling_provider()->OnProviderActivated(); |
| 185 } | 195 } |
| 186 | 196 |
| 187 void InactivateUnderlyingProvider() { | 197 void InactivateUnderlyingProvider() { |
| 188 scheduling_provider_->OnProviderDeactivated(); | 198 scheduling_provider()->OnProviderDeactivated(); |
| 199 } |
| 200 |
| 201 MockPersistentScheduler* persistent_scheduler() { |
| 202 return &persistent_scheduler_; |
| 203 } |
| 204 base::SimpleTestClock* test_clock() { return test_clock_; } |
| 205 MockRemoteSuggestionsProvider* underlying_provider() { |
| 206 return underlying_provider_; |
| 207 } |
| 208 SchedulingRemoteSuggestionsProvider* scheduling_provider() { |
| 209 return scheduling_provider_.get(); |
| 189 } | 210 } |
| 190 | 211 |
| 191 private: | 212 private: |
| 192 test::RemoteSuggestionsTestUtils utils_; | 213 test::RemoteSuggestionsTestUtils utils_; |
| 193 UserClassifier user_classifier_; | 214 UserClassifier user_classifier_; |
| 215 TestingPrefServiceSimple local_state_; |
| 216 StrictMock<MockPersistentScheduler> persistent_scheduler_; |
| 217 base::SimpleTestClock* test_clock_; |
| 218 StrictMock<MockRemoteSuggestionsProvider>* underlying_provider_; |
| 219 std::unique_ptr<SchedulingRemoteSuggestionsProvider> scheduling_provider_; |
| 194 | 220 |
| 195 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProviderTest); | 221 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProviderTest); |
| 196 }; | 222 }; |
| 197 | 223 |
| 198 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 224 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 199 ShouldIgnoreSignalsWhenNotEnabled) { | 225 ShouldIgnoreSignalsWhenNotEnabled) { |
| 200 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 226 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 201 scheduling_provider_->OnNTPOpened(); | 227 scheduling_provider()->OnNTPOpened(); |
| 202 scheduling_provider_->OnBrowserForegrounded(); | 228 scheduling_provider()->OnBrowserForegrounded(); |
| 203 scheduling_provider_->OnBrowserColdStart(); | 229 scheduling_provider()->OnBrowserColdStart(); |
| 204 } | 230 } |
| 205 | 231 |
| 206 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 232 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 233 ShouldIgnoreEulaStateOnPlatformsWhereNotAvaiable) { |
| 234 // Only run this tests on platforms that don't support Eula. |
| 235 if (IsEulaNotifierAvailable()) { |
| 236 return; |
| 237 } |
| 238 |
| 239 // Activating the provider should schedule the persistent background fetches. |
| 240 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 241 scheduling_provider()->OnProviderActivated(); |
| 242 |
| 243 // Verify fetches get triggered. |
| 244 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 245 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 246 } |
| 247 |
| 248 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 249 ShouldIgnoreSignalsWhenEulaNotAccepted) { |
| 250 // Only run this tests on platforms supporting Eula. |
| 251 if (!IsEulaNotifierAvailable()) { |
| 252 return; |
| 253 } |
| 254 // Activating the provider should schedule the persistent background fetches. |
| 255 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 256 scheduling_provider()->OnProviderActivated(); |
| 257 |
| 258 // All signals are ignored because of Eula not being accepted. |
| 259 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 260 scheduling_provider()->OnNTPOpened(); |
| 261 scheduling_provider()->OnBrowserForegrounded(); |
| 262 scheduling_provider()->OnBrowserColdStart(); |
| 263 } |
| 264 |
| 265 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 266 ShouldFetchWhenEulaGetsAccepted) { |
| 267 // Only run this tests on platforms supporting Eula. |
| 268 if (!IsEulaNotifierAvailable()) { |
| 269 return; |
| 270 } |
| 271 // Activating the provider should schedule the persistent background fetches. |
| 272 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 273 scheduling_provider()->OnProviderActivated(); |
| 274 |
| 275 // Make one (ignored) call to make sure we are interested in eula state. |
| 276 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 277 |
| 278 // Accepting Eula afterwards results in a background fetch. |
| 279 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 280 SetEulaAcceptedPref(); |
| 281 } |
| 282 |
| 283 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 207 ShouldIgnoreSignalsWhenDisabledByParam) { | 284 ShouldIgnoreSignalsWhenDisabledByParam) { |
| 208 // First set an empty list of allowed trigger types. | 285 // First set an empty list of allowed trigger types. |
| 209 SetVariationParameter("scheduler_trigger_types", "-"); | 286 SetVariationParameter("scheduler_trigger_types", "-"); |
| 210 ResetProvider(); | 287 ResetProvider(); |
| 211 | 288 |
| 212 // Then enable the scheduler. | 289 // Then enable the scheduler. |
| 213 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 290 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 214 ActivateUnderlyingProvider(); | 291 ActivateUnderlyingProvider(); |
| 215 | 292 |
| 216 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 293 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 217 scheduling_provider_->OnNTPOpened(); | 294 scheduling_provider()->OnNTPOpened(); |
| 218 scheduling_provider_->OnBrowserForegrounded(); | 295 scheduling_provider()->OnBrowserForegrounded(); |
| 219 scheduling_provider_->OnBrowserColdStart(); | 296 scheduling_provider()->OnBrowserColdStart(); |
| 220 } | 297 } |
| 221 | 298 |
| 222 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 299 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 223 ShouldHandleEmptyParamForTriggerTypes) { | 300 ShouldHandleEmptyParamForTriggerTypes) { |
| 224 // First set an empty param for allowed trigger types -> should result in the | 301 // First set an empty param for allowed trigger types -> should result in the |
| 225 // default list. | 302 // default list. |
| 226 SetVariationParameter("scheduler_trigger_types", ""); | 303 SetVariationParameter("scheduler_trigger_types", ""); |
| 227 ResetProvider(); | 304 ResetProvider(); |
| 228 | 305 |
| 229 // Then enable the scheduler. | 306 // Then enable the scheduler. |
| 230 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 307 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 231 ActivateUnderlyingProvider(); | 308 ActivateUnderlyingProvider(); |
| 232 | 309 |
| 233 // For instance, persistent scheduler wake up should be enabled by default. | 310 // For instance, persistent scheduler wake up should be enabled by default. |
| 234 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 311 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 235 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 312 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 236 } | 313 } |
| 237 | 314 |
| 238 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 315 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 239 ShouldHandleIncorrentParamForTriggerTypes) { | 316 ShouldHandleIncorrentParamForTriggerTypes) { |
| 240 // First set an invalid list of allowed trigger types. | 317 // First set an invalid list of allowed trigger types. |
| 241 SetVariationParameter("scheduler_trigger_types", "ntp_opened,foo;"); | 318 SetVariationParameter("scheduler_trigger_types", "ntp_opened,foo;"); |
| 242 ResetProvider(); | 319 ResetProvider(); |
| 243 | 320 |
| 244 // Then enable the scheduler. | 321 // Then enable the scheduler. |
| 245 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 322 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 246 ActivateUnderlyingProvider(); | 323 ActivateUnderlyingProvider(); |
| 247 | 324 |
| 248 // For instance, persistent scheduler wake up should be enabled by default. | 325 // For instance, persistent scheduler wake up should be enabled by default. |
| 249 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 326 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 250 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 327 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 251 } | 328 } |
| 252 | 329 |
| 253 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 330 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 254 ShouldFetchOnPersistentSchedulerWakeUp) { | 331 ShouldFetchOnPersistentSchedulerWakeUp) { |
| 255 // First set only this type to be allowed. | 332 // First set only this type to be allowed. |
| 256 SetVariationParameter("scheduler_trigger_types", | 333 SetVariationParameter("scheduler_trigger_types", |
| 257 "persistent_scheduler_wake_up"); | 334 "*persistent_scheduler()wake_up"); |
| 258 ResetProvider(); | 335 ResetProvider(); |
| 259 | 336 |
| 260 // Then enable the scheduler. | 337 // Then enable the scheduler. |
| 261 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 338 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 262 ActivateUnderlyingProvider(); | 339 ActivateUnderlyingProvider(); |
| 263 | 340 |
| 264 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 341 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 265 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 342 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 266 } | 343 } |
| 267 | 344 |
| 268 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 345 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 269 ShouldFetchOnPersistentSchedulerWakeUpRepeated) { | 346 ShouldFetchOnPersistentSchedulerWakeUpRepeated) { |
| 270 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 347 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 271 { | 348 { |
| 272 InSequence s; | 349 InSequence s; |
| 273 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 350 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 274 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 351 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 275 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 352 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 276 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 353 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 277 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 354 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 278 } | 355 } |
| 279 // First enable the scheduler -- calling Schedule() for the first time. | 356 // First enable the scheduler -- calling Schedule() for the first time. |
| 280 ActivateUnderlyingProvider(); | 357 ActivateUnderlyingProvider(); |
| 281 // Make the first persistent fetch successful -- calling Schedule() again. | 358 // Make the first persistent fetch successful -- calling Schedule() again. |
| 282 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 359 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 283 signal_fetch_done.Run(Status::Success()); | 360 signal_fetch_done.Run(Status::Success()); |
| 284 // Make the second fetch. | 361 // Make the second fetch. |
| 285 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 362 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 286 } | 363 } |
| 287 | 364 |
| 288 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 365 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 289 ShouldNotTriggerBackgroundFetchIfAlreadyInProgess) { | 366 ShouldNotTriggerBackgroundFetchIfAlreadyInProgess) { |
| 290 { | 367 { |
| 291 InSequence s; | 368 InSequence s; |
| 292 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 369 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 293 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 370 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 294 // RefetchInTheBackground is not called after the second trigger. | 371 // RefetchInTheBackground is not called after the second trigger. |
| 295 } | 372 } |
| 296 // First enable the scheduler -- calling Schedule() for the first time. | 373 // First enable the scheduler -- calling Schedule() for the first time. |
| 297 ActivateUnderlyingProvider(); | 374 ActivateUnderlyingProvider(); |
| 298 // Make the first persistent fetch never finish. | 375 // Make the first persistent fetch never finish. |
| 299 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 376 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 300 // Make the second fetch. | 377 // Make the second fetch. |
| 301 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 378 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 302 } | 379 } |
| 303 | 380 |
| 304 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 381 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 305 ShouldFetchOnNTPOpenedForTheFirstTime) { | 382 ShouldFetchOnNTPOpenedForTheFirstTime) { |
| 306 // First set only this type to be allowed. | 383 // First set only this type to be allowed. |
| 307 SetVariationParameter("scheduler_trigger_types", "ntp_opened"); | 384 SetVariationParameter("scheduler_trigger_types", "ntp_opened"); |
| 308 ResetProvider(); | 385 ResetProvider(); |
| 309 | 386 |
| 310 // Then enable the scheduler. | 387 // Then enable the scheduler. |
| 311 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 388 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 312 ActivateUnderlyingProvider(); | 389 ActivateUnderlyingProvider(); |
| 313 | 390 |
| 314 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 391 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 315 scheduling_provider_->OnNTPOpened(); | 392 scheduling_provider()->OnNTPOpened(); |
| 316 } | 393 } |
| 317 | 394 |
| 318 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 395 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 319 ShouldFetchOnBrowserForegroundedForTheFirstTime) { | 396 ShouldFetchOnBrowserForegroundedForTheFirstTime) { |
| 320 // First set only this type to be allowed. | 397 // First set only this type to be allowed. |
| 321 SetVariationParameter("scheduler_trigger_types", "browser_foregrounded"); | 398 SetVariationParameter("scheduler_trigger_types", "browser_foregrounded"); |
| 322 ResetProvider(); | 399 ResetProvider(); |
| 323 | 400 |
| 324 // Then enable the scheduler. | 401 // Then enable the scheduler. |
| 325 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 402 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 326 ActivateUnderlyingProvider(); | 403 ActivateUnderlyingProvider(); |
| 327 | 404 |
| 328 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 405 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 329 scheduling_provider_->OnBrowserForegrounded(); | 406 scheduling_provider()->OnBrowserForegrounded(); |
| 330 } | 407 } |
| 331 | 408 |
| 332 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 409 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 333 ShouldFetchOnBrowserColdStartForTheFirstTime) { | 410 ShouldFetchOnBrowserColdStartForTheFirstTime) { |
| 334 // First set only this type to be allowed. | 411 // First set only this type to be allowed. |
| 335 SetVariationParameter("scheduler_trigger_types", "browser_cold_start"); | 412 SetVariationParameter("scheduler_trigger_types", "browser_cold_start"); |
| 336 ResetProvider(); | 413 ResetProvider(); |
| 337 | 414 |
| 338 // Then enable the scheduler. | 415 // Then enable the scheduler. |
| 339 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 416 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 340 ActivateUnderlyingProvider(); | 417 ActivateUnderlyingProvider(); |
| 341 | 418 |
| 342 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 419 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 343 scheduling_provider_->OnBrowserColdStart(); | 420 scheduling_provider()->OnBrowserColdStart(); |
| 344 } | 421 } |
| 345 | 422 |
| 346 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 423 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 347 ShouldNotFetchOnNTPOpenedAfterSuccessfulSoftFetch) { | 424 ShouldNotFetchOnNTPOpenedAfterSuccessfulSoftFetch) { |
| 348 // First enable the scheduler; the second Schedule is called after the | 425 // First enable the scheduler; the second Schedule is called after the |
| 349 // successful fetch. | 426 // successful fetch. |
| 350 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 427 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 351 ActivateUnderlyingProvider(); | 428 ActivateUnderlyingProvider(); |
| 352 | 429 |
| 353 // Make the first soft fetch successful. | 430 // Make the first soft fetch successful. |
| 354 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 431 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 355 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 432 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 356 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 433 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 357 scheduling_provider_->OnNTPOpened(); | 434 scheduling_provider()->OnNTPOpened(); |
| 358 signal_fetch_done.Run(Status::Success()); | 435 signal_fetch_done.Run(Status::Success()); |
| 359 // The second call is ignored if it happens right after the first one. | 436 // The second call is ignored if it happens right after the first one. |
| 360 scheduling_provider_->OnNTPOpened(); | 437 scheduling_provider()->OnNTPOpened(); |
| 361 } | 438 } |
| 362 | 439 |
| 363 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 440 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 364 ShouldNotFetchOnNTPOpenedAfterSuccessfulPersistentFetch) { | 441 ShouldNotFetchOnNTPOpenedAfterSuccessfulPersistentFetch) { |
| 365 // First enable the scheduler; the second Schedule is called after the | 442 // First enable the scheduler; the second Schedule is called after the |
| 366 // successful fetch. | 443 // successful fetch. |
| 367 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 444 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 368 ActivateUnderlyingProvider(); | 445 ActivateUnderlyingProvider(); |
| 369 | 446 |
| 370 // Make the first persistent fetch successful. | 447 // Make the first persistent fetch successful. |
| 371 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 448 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 372 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 449 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 373 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 450 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 374 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 451 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 375 signal_fetch_done.Run(Status::Success()); | 452 signal_fetch_done.Run(Status::Success()); |
| 376 // The second call is ignored if it happens right after the first one. | 453 // The second call is ignored if it happens right after the first one. |
| 377 scheduling_provider_->OnNTPOpened(); | 454 scheduling_provider()->OnNTPOpened(); |
| 378 } | 455 } |
| 379 | 456 |
| 380 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 457 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 381 ShouldNotFetchOnNTPOpenedAfterFailedSoftFetch) { | 458 ShouldNotFetchOnNTPOpenedAfterFailedSoftFetch) { |
| 382 // First enable the scheduler. | 459 // First enable the scheduler. |
| 383 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 460 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 384 ActivateUnderlyingProvider(); | 461 ActivateUnderlyingProvider(); |
| 385 | 462 |
| 386 // Make the first soft fetch failed. | 463 // Make the first soft fetch failed. |
| 387 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 464 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 388 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 465 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 389 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 466 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 390 scheduling_provider_->OnNTPOpened(); | 467 scheduling_provider()->OnNTPOpened(); |
| 391 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); | 468 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); |
| 392 | 469 |
| 393 // The second call is ignored if it happens right after the first one. | 470 // The second call is ignored if it happens right after the first one. |
| 394 scheduling_provider_->OnNTPOpened(); | 471 scheduling_provider()->OnNTPOpened(); |
| 395 } | 472 } |
| 396 | 473 |
| 397 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 474 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 398 ShouldNotFetchOnNTPOpenedAfterFailedPersistentFetch) { | 475 ShouldNotFetchOnNTPOpenedAfterFailedPersistentFetch) { |
| 399 // First enable the scheduler. | 476 // First enable the scheduler. |
| 400 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 477 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 401 ActivateUnderlyingProvider(); | 478 ActivateUnderlyingProvider(); |
| 402 | 479 |
| 403 // Make the first persistent fetch failed. | 480 // Make the first persistent fetch failed. |
| 404 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 481 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 405 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 482 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 406 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 483 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 407 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 484 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 408 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); | 485 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); |
| 409 | 486 |
| 410 // The second call is ignored if it happens right after the first one. | 487 // The second call is ignored if it happens right after the first one. |
| 411 scheduling_provider_->OnNTPOpened(); | 488 scheduling_provider()->OnNTPOpened(); |
| 412 } | 489 } |
| 413 | 490 |
| 414 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 491 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 415 ShouldFetchAgainOnBrowserForgroundLaterAgain) { | 492 ShouldFetchAgainOnBrowserForgroundLaterAgain) { |
| 416 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 493 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 417 { | 494 { |
| 418 InSequence s; | 495 InSequence s; |
| 419 // Initial scheduling after being enabled. | 496 // Initial scheduling after being enabled. |
| 420 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 497 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 421 // The first call to NTPOpened results in a fetch. | 498 // The first call to NTPOpened results in a fetch. |
| 422 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 499 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 423 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 500 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 424 // Rescheduling after a succesful fetch. | 501 // Rescheduling after a succesful fetch. |
| 425 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 502 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 426 // The second call to NTPOpened 2hrs later again results in a fetch. | 503 // The second call to NTPOpened 2hrs later again results in a fetch. |
| 427 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 504 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 428 } | 505 } |
| 429 | 506 |
| 430 // First enable the scheduler. | 507 // First enable the scheduler. |
| 431 ActivateUnderlyingProvider(); | 508 ActivateUnderlyingProvider(); |
| 432 // Make the first soft fetch successful. | 509 // Make the first soft fetch successful. |
| 433 scheduling_provider_->OnBrowserForegrounded(); | 510 scheduling_provider()->OnBrowserForegrounded(); |
| 434 signal_fetch_done.Run(Status::Success()); | 511 signal_fetch_done.Run(Status::Success()); |
| 435 // Open NTP again after 2hrs. | 512 // Open NTP again after 2hrs. |
| 436 test_clock_->Advance(base::TimeDelta::FromHours(2)); | 513 test_clock()->Advance(base::TimeDelta::FromHours(2)); |
| 437 scheduling_provider_->OnBrowserForegrounded(); | 514 scheduling_provider()->OnBrowserForegrounded(); |
| 438 } | 515 } |
| 439 | 516 |
| 440 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 517 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 441 ShouldRescheduleOnRescheduleFetching) { | 518 ShouldRescheduleOnRescheduleFetching) { |
| 442 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 519 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 443 scheduling_provider_->RescheduleFetching(); | 520 scheduling_provider()->RescheduleFetching(); |
| 444 } | 521 } |
| 445 | 522 |
| 446 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnActivation) { | 523 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnActivation) { |
| 447 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 524 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 448 ActivateUnderlyingProvider(); | 525 ActivateUnderlyingProvider(); |
| 449 } | 526 } |
| 450 | 527 |
| 451 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 528 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 452 ShouldUnscheduleOnLaterInactivation) { | 529 ShouldUnscheduleOnLaterInactivation) { |
| 453 { | 530 { |
| 454 InSequence s; | 531 InSequence s; |
| 455 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 532 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 456 EXPECT_CALL(persistent_scheduler_, Unschedule()); | 533 EXPECT_CALL(*persistent_scheduler(), Unschedule()); |
| 457 } | 534 } |
| 458 ActivateUnderlyingProvider(); | 535 ActivateUnderlyingProvider(); |
| 459 InactivateUnderlyingProvider(); | 536 InactivateUnderlyingProvider(); |
| 460 } | 537 } |
| 461 | 538 |
| 462 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 539 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 463 ShouldScheduleOnLaterActivation) { | 540 ShouldScheduleOnLaterActivation) { |
| 464 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 541 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 465 // There is no schedule yet, so inactivation does not trigger unschedule. | 542 // There is no schedule yet, so inactivation does not trigger unschedule. |
| 466 InactivateUnderlyingProvider(); | 543 InactivateUnderlyingProvider(); |
| 467 ActivateUnderlyingProvider(); | 544 ActivateUnderlyingProvider(); |
| 468 } | 545 } |
| 469 | 546 |
| 470 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 547 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 471 ShouldRescheduleAfterSuccessfulFetch) { | 548 ShouldRescheduleAfterSuccessfulFetch) { |
| 472 // First reschedule on becoming active. | 549 // First reschedule on becoming active. |
| 473 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 550 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 474 ActivateUnderlyingProvider(); | 551 ActivateUnderlyingProvider(); |
| 475 | 552 |
| 476 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 553 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 477 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 554 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 478 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 555 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 479 | 556 |
| 480 // Trigger a fetch. | 557 // Trigger a fetch. |
| 481 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 558 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 482 // Second reschedule after a successful fetch. | 559 // Second reschedule after a successful fetch. |
| 483 signal_fetch_done.Run(Status::Success()); | 560 signal_fetch_done.Run(Status::Success()); |
| 484 } | 561 } |
| 485 | 562 |
| 486 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 563 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 487 ShouldNotRescheduleAfterFailedFetch) { | 564 ShouldNotRescheduleAfterFailedFetch) { |
| 488 // Only reschedule on becoming active. | 565 // Only reschedule on becoming active. |
| 489 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 566 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 490 ActivateUnderlyingProvider(); | 567 ActivateUnderlyingProvider(); |
| 491 | 568 |
| 492 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 569 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 493 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 570 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 494 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 571 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 495 | 572 |
| 496 // Trigger a fetch. | 573 // Trigger a fetch. |
| 497 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 574 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 498 // No furter reschedule after a failure. | 575 // No furter reschedule after a failure. |
| 499 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); | 576 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); |
| 500 } | 577 } |
| 501 | 578 |
| 502 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnlyOnce) { | 579 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnlyOnce) { |
| 503 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 580 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 504 ActivateUnderlyingProvider(); | 581 ActivateUnderlyingProvider(); |
| 505 // No further call to Schedule on a second status callback. | 582 // No further call to Schedule on a second status callback. |
| 506 ActivateUnderlyingProvider(); | 583 ActivateUnderlyingProvider(); |
| 507 } | 584 } |
| 508 | 585 |
| 509 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldUnscheduleOnlyOnce) { | 586 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldUnscheduleOnlyOnce) { |
| 510 { | 587 { |
| 511 InSequence s; | 588 InSequence s; |
| 512 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 589 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 513 EXPECT_CALL(persistent_scheduler_, Unschedule()); | 590 EXPECT_CALL(*persistent_scheduler(), Unschedule()); |
| 514 } | 591 } |
| 515 // First schedule so that later we really unschedule. | 592 // First schedule so that later we really unschedule. |
| 516 ActivateUnderlyingProvider(); | 593 ActivateUnderlyingProvider(); |
| 517 InactivateUnderlyingProvider(); | 594 InactivateUnderlyingProvider(); |
| 518 // No further call to Unschedule on second status callback. | 595 // No further call to Unschedule on second status callback. |
| 519 InactivateUnderlyingProvider(); | 596 InactivateUnderlyingProvider(); |
| 520 } | 597 } |
| 521 | 598 |
| 522 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 599 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 523 ReschedulesWhenWifiParamChanges) { | 600 ReschedulesWhenWifiParamChanges) { |
| 524 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 601 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 525 ActivateUnderlyingProvider(); | 602 ActivateUnderlyingProvider(); |
| 526 | 603 |
| 527 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 604 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 528 // null. Change the wifi interval for this class. | 605 // null. Change the wifi interval for this class. |
| 529 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); | 606 SetVariationParameter("fetching_interval_hours-wifi-active_ntp_user", "1.5"); |
| 530 | 607 |
| 531 // Schedule() should get called for the second time after params have changed. | 608 // Schedule() should get called for the second time after params have changed. |
| 532 ActivateUnderlyingProvider(); | 609 ActivateUnderlyingProvider(); |
| 533 } | 610 } |
| 534 | 611 |
| 535 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 612 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 536 ReschedulesWhenFallbackParamChanges) { | 613 ReschedulesWhenFallbackParamChanges) { |
| 537 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 614 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 538 ActivateUnderlyingProvider(); | 615 ActivateUnderlyingProvider(); |
| 539 | 616 |
| 540 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 617 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 541 // null. Change the fallback interval for this class. | 618 // null. Change the fallback interval for this class. |
| 542 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", | 619 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", |
| 543 "1.5"); | 620 "1.5"); |
| 544 | 621 |
| 545 // Schedule() should get called for the second time after params have changed. | 622 // Schedule() should get called for the second time after params have changed. |
| 546 ActivateUnderlyingProvider(); | 623 ActivateUnderlyingProvider(); |
| 547 } | 624 } |
| 548 | 625 |
| 549 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 626 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 550 ReschedulesWhenOnUsageEventParamChanges) { | 627 ReschedulesWhenOnUsageEventParamChanges) { |
| 551 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 628 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 552 ActivateUnderlyingProvider(); | 629 ActivateUnderlyingProvider(); |
| 553 | 630 |
| 554 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 631 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 555 // null. Change the on usage interval for this class. | 632 // null. Change the on usage interval for this class. |
| 556 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", | 633 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", |
| 557 "1.5"); | 634 "1.5"); |
| 558 | 635 |
| 559 // Schedule() should get called for the second time after params have changed. | 636 // Schedule() should get called for the second time after params have changed. |
| 560 ActivateUnderlyingProvider(); | 637 ActivateUnderlyingProvider(); |
| 561 } | 638 } |
| 562 | 639 |
| 563 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 640 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 564 ReschedulesWhenOnNtpOpenedParamChanges) { | 641 ReschedulesWhenOnNtpOpenedParamChanges) { |
| 565 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 642 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(2); |
| 566 ActivateUnderlyingProvider(); | 643 ActivateUnderlyingProvider(); |
| 567 | 644 |
| 568 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 645 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 569 // null. Change the fallback interval for this class. | 646 // null. Change the fallback interval for this class. |
| 570 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 647 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", |
| 571 "1.5"); | 648 "1.5"); |
| 572 | 649 |
| 573 // Schedule() should get called for the second time after params have changed. | 650 // Schedule() should get called for the second time after params have changed. |
| 574 ActivateUnderlyingProvider(); | 651 ActivateUnderlyingProvider(); |
| 575 } | 652 } |
| 576 | 653 |
| 577 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 654 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 578 FetchIntervalForNtpOpenedTrigger) { | 655 FetchIntervalForNtpOpenedTrigger) { |
| 579 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 656 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 580 { | 657 { |
| 581 InSequence s; | 658 InSequence s; |
| 582 // Initial scheduling after being enabled. | 659 // Initial scheduling after being enabled. |
| 583 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 660 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 584 // The first call to NTPOpened results in a fetch. | 661 // The first call to NTPOpened results in a fetch. |
| 585 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 662 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 586 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 663 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 587 // Rescheduling after a succesful fetch. | 664 // Rescheduling after a succesful fetch. |
| 588 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 665 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 589 // The third call to NTPOpened 35min later again results in a fetch. | 666 // The third call to NTPOpened 35min later again results in a fetch. |
| 590 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 667 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 591 } | 668 } |
| 592 | 669 |
| 593 ActivateUnderlyingProvider(); | 670 ActivateUnderlyingProvider(); |
| 594 | 671 |
| 595 scheduling_provider_->OnNTPOpened(); | 672 scheduling_provider()->OnNTPOpened(); |
| 596 signal_fetch_done.Run(Status::Success()); | 673 signal_fetch_done.Run(Status::Success()); |
| 597 | 674 |
| 598 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time | 675 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time |
| 599 // interval by default for soft backgroudn fetches on ntp open events. | 676 // interval by default for soft backgroudn fetches on ntp open events. |
| 600 | 677 |
| 601 // Open NTP again after 20min. This time no fetch is executed. | 678 // Open NTP again after 20min. This time no fetch is executed. |
| 602 test_clock_->Advance(base::TimeDelta::FromMinutes(20)); | 679 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
| 603 scheduling_provider_->OnNTPOpened(); | 680 scheduling_provider()->OnNTPOpened(); |
| 604 | 681 |
| 605 // Open NTP again after 101min (121min since first opened). Since the default | 682 // Open NTP again after 101min (121min since first opened). Since the default |
| 606 // time interval has passed refetch again. | 683 // time interval has passed refetch again. |
| 607 test_clock_->Advance(base::TimeDelta::FromMinutes(101)); | 684 test_clock()->Advance(base::TimeDelta::FromMinutes(101)); |
| 608 scheduling_provider_->OnNTPOpened(); | 685 scheduling_provider()->OnNTPOpened(); |
| 609 } | 686 } |
| 610 | 687 |
| 611 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 688 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 612 OverrideFetchIntervalForNtpOpenedTrigger) { | 689 OverrideFetchIntervalForNtpOpenedTrigger) { |
| 613 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 690 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is |
| 614 // null. Change the on usage interval for this class from 2h to 30min. | 691 // null. Change the on usage interval for this class from 2h to 30min. |
| 615 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | 692 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", |
| 616 "0.5"); | 693 "0.5"); |
| 617 | 694 |
| 618 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 695 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 619 { | 696 { |
| 620 InSequence s; | 697 InSequence s; |
| 621 // Initial scheduling after being enabled. | 698 // Initial scheduling after being enabled. |
| 622 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 699 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 623 // The first call to NTPOpened results in a fetch. | 700 // The first call to NTPOpened results in a fetch. |
| 624 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 701 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 625 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 702 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 626 // Rescheduling after a succesful fetch. | 703 // Rescheduling after a succesful fetch. |
| 627 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 704 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 628 // The third call to NTPOpened 35min later again results in a fetch. | 705 // The third call to NTPOpened 35min later again results in a fetch. |
| 629 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 706 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 630 } | 707 } |
| 631 | 708 |
| 632 ActivateUnderlyingProvider(); | 709 ActivateUnderlyingProvider(); |
| 633 | 710 |
| 634 scheduling_provider_->OnNTPOpened(); | 711 scheduling_provider()->OnNTPOpened(); |
| 635 signal_fetch_done.Run(Status::Success()); | 712 signal_fetch_done.Run(Status::Success()); |
| 636 | 713 |
| 637 // Open NTP again after 20min. No fetch request is issues since the 30 min | 714 // Open NTP again after 20min. No fetch request is issues since the 30 min |
| 638 // time interval has not passed yet. | 715 // time interval has not passed yet. |
| 639 test_clock_->Advance(base::TimeDelta::FromMinutes(20)); | 716 test_clock()->Advance(base::TimeDelta::FromMinutes(20)); |
| 640 scheduling_provider_->OnNTPOpened(); | 717 scheduling_provider()->OnNTPOpened(); |
| 641 | 718 |
| 642 // Open NTP again after 15min (35min since first opened) | 719 // Open NTP again after 15min (35min since first opened) |
| 643 test_clock_->Advance(base::TimeDelta::FromMinutes(15)); | 720 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); |
| 644 scheduling_provider_->OnNTPOpened(); | 721 scheduling_provider()->OnNTPOpened(); |
| 645 } | 722 } |
| 646 | 723 |
| 647 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 724 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 648 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { | 725 ShouldBlockFetchingForSomeTimeAfterHistoryCleared) { |
| 649 // First enable the scheduler -- this will trigger the persistent scheduling. | 726 // First enable the scheduler -- this will trigger the persistent scheduling. |
| 650 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 727 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 651 ActivateUnderlyingProvider(); | 728 ActivateUnderlyingProvider(); |
| 652 // Clear the history. | 729 // Clear the history. |
| 653 scheduling_provider_->OnHistoryCleared(); | 730 scheduling_provider()->OnHistoryCleared(); |
| 654 | 731 |
| 655 // A trigger after 15 minutes is ignored. | 732 // A trigger after 15 minutes is ignored. |
| 656 test_clock_->Advance(base::TimeDelta::FromMinutes(15)); | 733 test_clock()->Advance(base::TimeDelta::FromMinutes(15)); |
| 657 scheduling_provider_->OnBrowserForegrounded(); | 734 scheduling_provider()->OnBrowserForegrounded(); |
| 658 | 735 |
| 659 // A trigger after another 16 minutes is performed (more than 30m after | 736 // A trigger after another 16 minutes is performed (more than 30m after |
| 660 // clearing the history). | 737 // clearing the history). |
| 661 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | 738 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)); |
| 662 test_clock_->Advance(base::TimeDelta::FromMinutes(16)); | 739 test_clock()->Advance(base::TimeDelta::FromMinutes(16)); |
| 663 scheduling_provider_->OnBrowserForegrounded(); | 740 scheduling_provider()->OnBrowserForegrounded(); |
| 664 } | 741 } |
| 665 | 742 |
| 666 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 743 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 667 ShouldImmediatelyFetchAfterSuggestionsCleared) { | 744 ShouldImmediatelyFetchAfterSuggestionsCleared) { |
| 668 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 745 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 669 | 746 |
| 670 // First enable the scheduler -- this will trigger the persistent scheduling. | 747 // First enable the scheduler -- this will trigger the persistent scheduling. |
| 671 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 748 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 672 ActivateUnderlyingProvider(); | 749 ActivateUnderlyingProvider(); |
| 673 | 750 |
| 674 // The first trigger results in a fetch. | 751 // The first trigger results in a fetch. |
| 675 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 752 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 676 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 753 .WillOnce(SaveArg<0>(&signal_fetch_done)); |
| 677 scheduling_provider_->OnBrowserForegrounded(); | 754 scheduling_provider()->OnBrowserForegrounded(); |
| 678 // Make the fetch successful -- this results in rescheduling. | 755 // Make the fetch successful -- this results in rescheduling. |
| 679 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 756 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)); |
| 680 signal_fetch_done.Run(Status::Success()); | 757 signal_fetch_done.Run(Status::Success()); |
| 681 | 758 |
| 682 // Clear the suggestions - results in an immediate fetch. | 759 // Clear the suggestions - results in an immediate fetch. |
| 683 EXPECT_CALL(*underlying_provider_, ReloadSuggestions()); | 760 EXPECT_CALL(*underlying_provider(), ReloadSuggestions()); |
| 684 scheduling_provider_->OnSuggestionsCleared(); | 761 scheduling_provider()->OnSuggestionsCleared(); |
| 685 } | 762 } |
| 686 | 763 |
| 687 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 764 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 688 ShouldThrottleInteractiveRequests) { | 765 ShouldThrottleInteractiveRequests) { |
| 689 // Change the quota for interactive requests ("active NTP user" is the default | 766 // Change the quota for interactive requests ("active NTP user" is the default |
| 690 // class in tests). | 767 // class in tests). |
| 691 SetVariationParameter("interactive_quota_SuggestionFetcherActiveNTPUser", | 768 SetVariationParameter("interactive_quota_SuggestionFetcherActiveNTPUser", |
| 692 "10"); | 769 "10"); |
| 693 ResetProvider(); | 770 ResetProvider(); |
| 694 | 771 |
| 695 Category category = Category::FromKnownCategory(KnownCategories::ARTICLES); | 772 Category category = Category::FromKnownCategory(KnownCategories::ARTICLES); |
| 696 std::set<std::string> known_suggestions; | 773 std::set<std::string> known_suggestions; |
| 697 | 774 |
| 698 // Both Fetch(..) and ReloadSuggestions() consume the same quota. As long as | 775 // Both Fetch(..) and ReloadSuggestions() consume the same quota. As long as |
| 699 // the quota suffices, the call gets through. | 776 // the quota suffices, the call gets through. |
| 700 EXPECT_CALL(*underlying_provider_, ReloadSuggestions()).Times(5); | 777 EXPECT_CALL(*underlying_provider(), ReloadSuggestions()).Times(5); |
| 701 for (int x = 0; x < 5; ++x) { | 778 for (int x = 0; x < 5; ++x) { |
| 702 scheduling_provider_->ReloadSuggestions(); | 779 scheduling_provider()->ReloadSuggestions(); |
| 703 } | 780 } |
| 704 | 781 |
| 705 // Expect underlying provider being called and store the callback to inform | 782 // Expect underlying provider being called and store the callback to inform |
| 706 // scheduling provider. | 783 // scheduling provider. |
| 707 FetchDoneCallback signal_fetch_done_from_underlying_provider; | 784 FetchDoneCallback signal_fetch_done_from_underlying_provider; |
| 708 EXPECT_CALL(*underlying_provider_, Fetch(_, _, _)) | 785 EXPECT_CALL(*underlying_provider(), Fetch(_, _, _)) |
| 709 .Times(5) | 786 .Times(5) |
| 710 .WillRepeatedly(SaveArg<2>(&signal_fetch_done_from_underlying_provider)); | 787 .WillRepeatedly(SaveArg<2>(&signal_fetch_done_from_underlying_provider)); |
| 711 // Expect scheduling provider to pass the information through. | 788 // Expect scheduling provider to pass the information through. |
| 712 MockFunction<void(Status status_code, | 789 MockFunction<void(Status status_code, |
| 713 const std::vector<ContentSuggestion>& suggestions)> | 790 const std::vector<ContentSuggestion>& suggestions)> |
| 714 fetch_done_from_scheduling_provider; | 791 fetch_done_from_scheduling_provider; |
| 715 EXPECT_CALL(fetch_done_from_scheduling_provider, | 792 EXPECT_CALL(fetch_done_from_scheduling_provider, |
| 716 Call(Field(&Status::code, StatusCode::SUCCESS), _)) | 793 Call(Field(&Status::code, StatusCode::SUCCESS), _)) |
| 717 .Times(5); | 794 .Times(5); |
| 718 // Scheduling is not activated, each successful fetch results in Unschedule(). | 795 // Scheduling is not activated, each successful fetch results in Unschedule(). |
| 719 EXPECT_CALL(persistent_scheduler_, Unschedule()).Times(5); | 796 EXPECT_CALL(*persistent_scheduler(), Unschedule()).Times(5); |
| 720 for (int x = 0; x < 5; ++x) { | 797 for (int x = 0; x < 5; ++x) { |
| 721 scheduling_provider_->Fetch( | 798 scheduling_provider()->Fetch( |
| 722 category, known_suggestions, | 799 category, known_suggestions, |
| 723 base::Bind(&SchedulingRemoteSuggestionsProviderTest::FetchDoneWrapper, | 800 base::Bind(&SchedulingRemoteSuggestionsProviderTest::FetchDoneWrapper, |
| 724 base::Unretained(this), | 801 base::Unretained(this), |
| 725 &fetch_done_from_scheduling_provider)); | 802 &fetch_done_from_scheduling_provider)); |
| 726 // Inform scheduling provider the fetc is successful (with no suggestions). | 803 // Inform scheduling provider the fetc is successful (with no suggestions). |
| 727 signal_fetch_done_from_underlying_provider.Run( | 804 signal_fetch_done_from_underlying_provider.Run( |
| 728 Status::Success(), std::vector<ContentSuggestion>{}); | 805 Status::Success(), std::vector<ContentSuggestion>{}); |
| 729 } | 806 } |
| 730 | 807 |
| 731 // When the quota expires, it is blocked by the scheduling provider, directly | 808 // When the quota expires, it is blocked by the scheduling provider, directly |
| 732 // calling the callback. | 809 // calling the callback. |
| 733 EXPECT_CALL(fetch_done_from_scheduling_provider, | 810 EXPECT_CALL(fetch_done_from_scheduling_provider, |
| 734 Call(Field(&Status::code, StatusCode::TEMPORARY_ERROR), _)); | 811 Call(Field(&Status::code, StatusCode::TEMPORARY_ERROR), _)); |
| 735 scheduling_provider_->ReloadSuggestions(); | 812 scheduling_provider()->ReloadSuggestions(); |
| 736 scheduling_provider_->Fetch( | 813 scheduling_provider()->Fetch( |
| 737 category, known_suggestions, | 814 category, known_suggestions, |
| 738 base::Bind(&SchedulingRemoteSuggestionsProviderTest::FetchDoneWrapper, | 815 base::Bind(&SchedulingRemoteSuggestionsProviderTest::FetchDoneWrapper, |
| 739 base::Unretained(this), &fetch_done_from_scheduling_provider)); | 816 base::Unretained(this), &fetch_done_from_scheduling_provider)); |
| 740 } | 817 } |
| 741 | 818 |
| 742 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 819 TEST_F(SchedulingRemoteSuggestionsProviderTest, |
| 743 ShouldThrottleNonInteractiveRequests) { | 820 ShouldThrottleNonInteractiveRequests) { |
| 744 // Change the quota for interactive requests ("active NTP user" is the default | 821 // Change the quota for interactive requests ("active NTP user" is the default |
| 745 // class in tests). | 822 // class in tests). |
| 746 SetVariationParameter("quota_SuggestionFetcherActiveNTPUser", "5"); | 823 SetVariationParameter("quota_SuggestionFetcherActiveNTPUser", "5"); |
| 747 ResetProvider(); | 824 ResetProvider(); |
| 748 | 825 |
| 749 // One scheduling on start, 5 times after successful fetches. | 826 // One scheduling on start, 5 times after successful fetches. |
| 750 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(6); | 827 EXPECT_CALL(*persistent_scheduler(), Schedule(_, _)).Times(6); |
| 751 | 828 |
| 752 // First enable the scheduler -- this will trigger the persistent scheduling. | 829 // First enable the scheduler -- this will trigger the persistent scheduling. |
| 753 ActivateUnderlyingProvider(); | 830 ActivateUnderlyingProvider(); |
| 754 | 831 |
| 755 // As long as the quota suffices, the call gets through. | 832 // As long as the quota suffices, the call gets through. |
| 756 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 833 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; |
| 757 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 834 EXPECT_CALL(*underlying_provider(), RefetchInTheBackground(_)) |
| 758 .Times(5) | 835 .Times(5) |
| 759 .WillRepeatedly(SaveArg<0>(&signal_fetch_done)); | 836 .WillRepeatedly(SaveArg<0>(&signal_fetch_done)); |
| 760 for (int x = 0; x < 5; ++x) { | 837 for (int x = 0; x < 5; ++x) { |
| 761 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 838 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 762 signal_fetch_done.Run(Status::Success()); | 839 signal_fetch_done.Run(Status::Success()); |
| 763 } | 840 } |
| 764 | 841 |
| 765 // For the 6th time, it is blocked by the scheduling provider. | 842 // For the 6th time, it is blocked by the scheduling provider. |
| 766 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 843 scheduling_provider()->OnPersistentSchedulerWakeUp(); |
| 767 } | 844 } |
| 768 | 845 |
| 769 } // namespace ntp_snippets | 846 } // namespace ntp_snippets |
| OLD | NEW |