Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: components/ntp_snippets/remote/scheduling_remote_suggestions_provider_unittest.cc

Issue 2699613002: [remote suggestions] Add separte fetch interval for NTP open trigger (Closed)
Patch Set: remove extra test - will have a separate CL Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ShouldFetchAgainOnBrowserForgroundLaterAgain) {
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(_, _));
433 // The second call to NTPOpened 2hrs later again results in a fetch. 433 // The second call to NTPOpened 2hrs later again results in a fetch.
434 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_)); 434 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_));
435 } 435 }
436 436
437 // First enable the scheduler. 437 // First enable the scheduler.
438 ChangeStatusOfUnderlyingProvider( 438 ChangeStatusOfUnderlyingProvider(
439 RemoteSuggestionsProvider::ProviderStatus::ACTIVE); 439 RemoteSuggestionsProvider::ProviderStatus::ACTIVE);
440 // Make the first soft fetch successful. 440 // Make the first soft fetch successful.
441 scheduling_provider_->OnNTPOpened(); 441 scheduling_provider_->OnBrowserForegrounded();
442 signal_fetch_done.Run(Status::Success()); 442 signal_fetch_done.Run(Status::Success());
443 // Open NTP again after 2hrs. 443 // Open NTP again after 2hrs.
444 test_clock_->Advance(base::TimeDelta::FromHours(2)); 444 test_clock_->Advance(base::TimeDelta::FromHours(2));
445 scheduling_provider_->OnNTPOpened(); 445 scheduling_provider_->OnBrowserForegrounded();
446 } 446 }
447 447
448 TEST_F(SchedulingRemoteSuggestionsProviderTest, 448 TEST_F(SchedulingRemoteSuggestionsProviderTest,
449 ShouldRescheduleOnRescheduleFetching) { 449 ShouldRescheduleOnRescheduleFetching) {
450 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); 450 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
451 scheduling_provider_->RescheduleFetching(); 451 scheduling_provider_->RescheduleFetching();
452 } 452 }
453 453
454 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnActivation) { 454 TEST_F(SchedulingRemoteSuggestionsProviderTest, ShouldScheduleOnActivation) {
455 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)); 455 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ReschedulesWhenOnNtpOpenedParamChanges) {
591 EXPECT_CALL(persistent_scheduler_, Schedule(_, _)).Times(2);
592 ChangeStatusOfUnderlyingProvider(
593 RemoteSuggestionsProvider::ProviderStatus::ACTIVE);
594
595 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is
596 // null. Change the fallback interval for this class.
597 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user",
598 "1.5");
599
600 // Schedule() should get called for the second time after params have changed.
601 ChangeStatusOfUnderlyingProvider(
602 RemoteSuggestionsProvider::ProviderStatus::ACTIVE);
603 }
604
605 TEST_F(SchedulingRemoteSuggestionsProviderTest,
606 FetchIntervalForNtpOpenedTrigger) {
607 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done;
608 {
609 InSequence s;
610 // Initial scheduling after being enabled.
611 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
612 // The first call to NTPOpened results in a fetch.
613 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_))
614 .WillOnce(SaveArg<0>(&signal_fetch_done));
615 // Rescheduling after a succesful fetch.
616 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
617 // The third call to NTPOpened 35min later again results in a fetch.
618 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_));
619 }
620
621 ChangeStatusOfUnderlyingProvider(
622 RemoteSuggestionsProvider::ProviderStatus::ACTIVE);
623
624 scheduling_provider_->OnNTPOpened();
625 signal_fetch_done.Run(Status::Success());
626
627 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER which uses a 2h time
628 // interval by default for soft backgroudn fetches on ntp open events.
629
630 // Open NTP again after 20min. This time no fetch is executed.
631 test_clock_->Advance(base::TimeDelta::FromMinutes(20));
632 scheduling_provider_->OnNTPOpened();
633
634 // Open NTP again after 101min (121min since first opened). Since the default
635 // time interval has passed refetch again.
636 test_clock_->Advance(base::TimeDelta::FromMinutes(101));
637 scheduling_provider_->OnNTPOpened();
638 }
639
640 TEST_F(SchedulingRemoteSuggestionsProviderTest,
641 OverrideFetchIntervalForNtpOpenedTrigger) {
642 // UserClassifier defaults to UserClass::ACTIVE_NTP_USER if PrefService is
643 // null. Change the on usage interval for this class from 2h to 30min.
644 SetVariationParameter("soft_on_ntp_opened_interval_hours-active_ntp_user",
645 "0.5");
646
647 RemoteSuggestionsProvider::FetchStatusCallback signal_fetch_done;
648 {
649 InSequence s;
650 // Initial scheduling after being enabled.
651 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
652 // The first call to NTPOpened results in a fetch.
653 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_))
654 .WillOnce(SaveArg<0>(&signal_fetch_done));
655 // Rescheduling after a succesful fetch.
656 EXPECT_CALL(persistent_scheduler_, Schedule(_, _));
657 // The third call to NTPOpened 35min later again results in a fetch.
658 EXPECT_CALL(*underlying_provider_, RefetchInTheBackground(_));
659 }
660
661 ChangeStatusOfUnderlyingProvider(
662 RemoteSuggestionsProvider::ProviderStatus::ACTIVE);
663
664 scheduling_provider_->OnNTPOpened();
665 signal_fetch_done.Run(Status::Success());
666
667 // Open NTP again after 20min. No fetch request is issues since the 30 min
668 // time interval has not passed yet.
669 test_clock_->Advance(base::TimeDelta::FromMinutes(20));
670 scheduling_provider_->OnNTPOpened();
671
672 // Open NTP again after 15min (35min since first opened)
673 test_clock_->Advance(base::TimeDelta::FromMinutes(15));
674 scheduling_provider_->OnNTPOpened();
675 }
676
589 } // namespace ntp_snippets 677 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698