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/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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 412 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 
| 413 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 413 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 
| 414 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 414 scheduling_provider_->OnPersistentSchedulerWakeUp(); | 
| 415 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); | 415 signal_fetch_done.Run(Status(StatusCode::PERMANENT_ERROR, "")); | 
| 416 | 416 | 
| 417 // The second call is ignored if it happens right after the first one. | 417 // The second call is ignored if it happens right after the first one. | 
| 418 scheduling_provider_->OnNTPOpened(); | 418 scheduling_provider_->OnNTPOpened(); | 
| 419 } | 419 } | 
| 420 | 420 | 
| 421 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 421 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 
| 422 ShouldFetchAgainOnNTPOpenedLaterAgain) { | 422 ShouldFetchAgainOnNTPOpenedLaterAgain) { | 
| 
 
jkrcal
2017/02/16 14:02:16
nit: Can you please:
 - either merge this test wit
 
markusheintz_
2017/02/17 12:58:04
Done.
 
 | |
| 423 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 423 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | 
| 424 { | 424 { | 
| 425 InSequence s; | 425 InSequence s; | 
| 426 // Initial scheduling after being enabled. | 426 // Initial scheduling after being enabled. | 
| 427 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 427 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 
| 428 // The first call to NTPOpened results in a fetch. | 428 // The first call to NTPOpened results in a fetch. | 
| 429 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 429 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | 
| 430 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 430 .WillOnce(SaveArg<0>(&signal_fetch_done)); | 
| 431 // Rescheduling after a succesful fetch. | 431 // Rescheduling after a succesful fetch. | 
| 432 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 432 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 // null. Change the fallback interval for this class. | 564 // null. Change the fallback interval for this class. | 
| 565 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", | 565 SetVariationParameter("fetching_interval_hours-fallback-active_ntp_user", | 
| 566 "1.5"); | 566 "1.5"); | 
| 567 | 567 | 
| 568 // Schedule() should get called for the second time after params have changed. | 568 // Schedule() should get called for the second time after params have changed. | 
| 569 ChangeStatusOfUnderlyingProvider( | 569 ChangeStatusOfUnderlyingProvider( | 
| 570 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 570 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 
| 571 } | 571 } | 
| 572 | 572 | 
| 573 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 573 TEST_F(SchedulingRemoteSuggestionsProviderTest, | 
| 574 ReschedulesWhenOnUsageEventParamChanges) { | 574 ReschedulesWhenOnUsageEventParamChanges) { | 
| 
 
jkrcal
2017/02/16 14:02:16
nit: Can you please also create an analogous fourt
 
markusheintz_
2017/02/17 12:58:04
Done.
 
 | |
| 575 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 575 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2); | 
| 576 ChangeStatusOfUnderlyingProvider( | 576 ChangeStatusOfUnderlyingProvider( | 
| 577 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 577 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 
| 578 | 578 | 
| 579 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 579 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | 
| 580 // null. Change the on usage interval for this class. | 580 // null. Change the on usage interval for this class. | 
| 581 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", | 581 SetVariationParameter("soft_fetching_interval_hours-active-active_ntp_user", | 
| 582 "1.5"); | 582 "1.5"); | 
| 583 | 583 | 
| 584 // Schedule() should get called for the second time after params have changed. | 584 // Schedule() should get called for the second time after params have changed. | 
| 585 ChangeStatusOfUnderlyingProvider( | 585 ChangeStatusOfUnderlyingProvider( | 
| 586 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 586 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | 
| 587 } | 587 } | 
| 588 | 588 | 
| 589 TEST_F(SchedulingRemoteSuggestionsProviderTest, | |
| 590 FetchIntervalForNtpOpenedTrigger) { | |
| 591 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 592 { | |
| 593 InSequence s; | |
| 594 // Initial scheduling after being enabled. | |
| 595 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | |
| 596 // The first call to NTPOpened results in a fetch. | |
| 597 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | |
| 598 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 599 // Rescheduling after a succesful fetch. | |
| 600 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | |
| 601 // The third call to NTPOpened 35min later again results in a fetch. | |
| 602 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | |
| 603 } | |
| 604 | |
| 605 ChangeStatusOfUnderlyingProvider( | |
| 606 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | |
| 607 | |
| 608 scheduling_provider_->OnNTPOpened(); | |
| 609 signal_fetch_done.Run(Status::Success()); | |
| 610 | |
| 611 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time | |
| 612 // interval by default for soft backgroudn fetches on ntp open events. | |
| 613 | |
| 614 // Open NTP again after 20min. This time no fetch is executed. | |
| 615 test_clock_->Advance(base::TimeDelta::FromMinutes(20)); | |
| 616 scheduling_provider_->OnNTPOpened(); | |
| 617 | |
| 618 // Open NTP again after 101min (121min since first opened). Since the default | |
| 619 // time interval has passed refetch again. | |
| 620 test_clock_->Advance(base::TimeDelta::FromMinutes(101)); | |
| 621 scheduling_provider_->OnNTPOpened(); | |
| 622 } | |
| 623 | |
| 624 TEST_F(SchedulingRemoteSuggestionsProviderTest, | |
| 625 OverrideFetchIntervalForNtpOpenedTrigger) { | |
| 626 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is | |
| 627 // null. Change the on usage interval for this class from 2h to 30min. | |
| 628 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user", | |
| 629 "0.5"); | |
| 630 | |
| 631 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done; | |
| 632 { | |
| 633 InSequence s; | |
| 634 // Initial scheduling after being enabled. | |
| 635 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | |
| 636 // The first call to NTPOpened results in a fetch. | |
| 637 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)) | |
| 638 .WillOnce(SaveArg<0>(&signal_fetch_done)); | |
| 639 // Rescheduling after a succesful fetch. | |
| 640 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); | |
| 641 // The third call to NTPOpened 35min later again results in a fetch. | |
| 642 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); | |
| 643 } | |
| 644 | |
| 645 ChangeStatusOfUnderlyingProvider( | |
| 646 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); | |
| 647 | |
| 648 scheduling_provider_->OnNTPOpened(); | |
| 649 signal_fetch_done.Run(Status::Success()); | |
| 650 | |
| 651 // Open NTP again after 20min. No fetch request is issues since the 30 min | |
| 652 // time interval has not passed yet. | |
| 653 test_clock_->Advance(base::TimeDelta::FromMinutes(20)); | |
| 654 scheduling_provider_->OnNTPOpened(); | |
| 655 | |
| 656 // Open NTP again after 15min (35min since first opened) | |
| 657 test_clock_->Advance(base::TimeDelta::FromMinutes(15)); | |
| 658 scheduling_provider_->OnNTPOpened(); | |
| 659 } | |
| 660 | |
| 589 } // namespace ntp_snippets | 661 } // namespace ntp_snippets | 
| OLD | NEW |