| Index: chrome/browser/engagement/site_engagement_score_unittest.cc
|
| diff --git a/chrome/browser/engagement/site_engagement_score_unittest.cc b/chrome/browser/engagement/site_engagement_score_unittest.cc
|
| index 51e32258e4281638f5359e992ca2bc9a20e57f65..be7cb7dd6693dfa4de5120f7897a1982de3d24b3 100644
|
| --- a/chrome/browser/engagement/site_engagement_score_unittest.cc
|
| +++ b/chrome/browser/engagement/site_engagement_score_unittest.cc
|
| @@ -114,10 +114,10 @@ TEST_F(SiteEngagementScoreTest, AccumulateOnSameDay) {
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
| EXPECT_EQ(std::min(SiteEngagementScore::GetMaxPointsPerDay(),
|
| (i + 1) * SiteEngagementScore::GetNavigationPoints()),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| - EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetTotal());
|
| }
|
|
|
| // Accumulate on the first day to max that day's engagement, then accumulate on
|
| @@ -130,7 +130,7 @@ TEST_F(SiteEngagementScoreTest, AccumulateOnTwoDays) {
|
| for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i)
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
|
|
| - EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetTotal());
|
|
|
| test_clock_.SetNow(later_date);
|
| for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) {
|
| @@ -139,10 +139,10 @@ TEST_F(SiteEngagementScoreTest, AccumulateOnTwoDays) {
|
| std::min(SiteEngagementScore::GetMaxPointsPerDay(),
|
| (i + 1) * SiteEngagementScore::GetNavigationPoints());
|
| EXPECT_EQ(day_score + SiteEngagementScore::GetMaxPointsPerDay(),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| - EXPECT_EQ(2 * SiteEngagementScore::GetMaxPointsPerDay(), score_.GetScore());
|
| + EXPECT_EQ(2 * SiteEngagementScore::GetMaxPointsPerDay(), score_.GetTotal());
|
| }
|
|
|
| // Accumulate score on many consecutive days and ensure the score doesn't exceed
|
| @@ -158,10 +158,10 @@ TEST_F(SiteEngagementScoreTest, AccumulateALotOnManyDays) {
|
|
|
| EXPECT_EQ(std::min(SiteEngagementScore::kMaxPoints,
|
| (i + 1) * SiteEngagementScore::GetMaxPointsPerDay()),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| - EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetTotal());
|
| }
|
|
|
| // Accumulate a little on many consecutive days and ensure the score doesn't
|
| @@ -180,10 +180,10 @@ TEST_F(SiteEngagementScoreTest, AccumulateALittleOnManyDays) {
|
| std::min(SiteEngagementScore::kMaxPoints,
|
| (i + 1) * kLessAccumulationsThanNeededToMaxDailyEngagement *
|
| SiteEngagementScore::GetNavigationPoints()),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| - EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetTotal());
|
| }
|
|
|
| // Accumulate a bit, then check the score decays properly for a range of times.
|
| @@ -199,14 +199,14 @@ TEST_F(SiteEngagementScoreTest, ScoresDecayOverTime) {
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
| }
|
|
|
| - EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetTotal());
|
|
|
| // The score should not have decayed before the first decay period has
|
| // elapsed.
|
| test_clock_.SetNow(current_day +
|
| base::TimeDelta::FromHours(
|
| SiteEngagementScore::GetDecayPeriodInHours() - 1));
|
| - EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.GetTotal());
|
|
|
| // The score should have decayed by one chunk after one decay period has
|
| // elapsed.
|
| @@ -215,7 +215,7 @@ TEST_F(SiteEngagementScoreTest, ScoresDecayOverTime) {
|
| base::TimeDelta::FromHours(SiteEngagementScore::GetDecayPeriodInHours()));
|
| EXPECT_EQ(
|
| SiteEngagementScore::kMaxPoints - SiteEngagementScore::GetDecayPoints(),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
|
|
| // The score should have decayed by the right number of chunks after a few
|
| // decay periods have elapsed.
|
| @@ -226,14 +226,14 @@ TEST_F(SiteEngagementScoreTest, ScoresDecayOverTime) {
|
| EXPECT_EQ(SiteEngagementScore::kMaxPoints -
|
| kLessPeriodsThanNeededToDecayMaxScore *
|
| SiteEngagementScore::GetDecayPoints(),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
|
|
| // The score should not decay below zero.
|
| test_clock_.SetNow(
|
| current_day +
|
| base::TimeDelta::FromHours(kMorePeriodsThanNeededToDecayMaxScore *
|
| SiteEngagementScore::GetDecayPeriodInHours()));
|
| - EXPECT_EQ(0, score_.GetScore());
|
| + EXPECT_EQ(0, score_.GetTotal());
|
| }
|
|
|
| // Test that any expected decays are applied before adding points.
|
| @@ -251,7 +251,7 @@ TEST_F(SiteEngagementScoreTest, DecaysAppliedBeforeAdd) {
|
|
|
| double initial_score = kLessDaysThanNeededToMaxTotalEngagement *
|
| SiteEngagementScore::GetMaxPointsPerDay();
|
| - EXPECT_EQ(initial_score, score_.GetScore());
|
| + EXPECT_EQ(initial_score, score_.GetTotal());
|
|
|
| // Go forward a few decay periods.
|
| test_clock_.SetNow(
|
| @@ -262,12 +262,12 @@ TEST_F(SiteEngagementScoreTest, DecaysAppliedBeforeAdd) {
|
| double decayed_score = initial_score -
|
| kLessPeriodsThanNeededToDecayMaxScore *
|
| SiteEngagementScore::GetDecayPoints();
|
| - EXPECT_EQ(decayed_score, score_.GetScore());
|
| + EXPECT_EQ(decayed_score, score_.GetTotal());
|
|
|
| // Now add some points.
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
| EXPECT_EQ(decayed_score + SiteEngagementScore::GetNavigationPoints(),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| // Test that going back in time is handled properly.
|
| @@ -278,7 +278,7 @@ TEST_F(SiteEngagementScoreTest, GoBackInTime) {
|
| for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i)
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
|
|
| - EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::GetMaxPointsPerDay(), score_.GetTotal());
|
|
|
| // Adding to the score on an earlier date should be treated like another day,
|
| // and should not cause any decay.
|
| @@ -291,10 +291,10 @@ TEST_F(SiteEngagementScoreTest, GoBackInTime) {
|
| std::min(SiteEngagementScore::GetMaxPointsPerDay(),
|
| (i + 1) * SiteEngagementScore::GetNavigationPoints());
|
| EXPECT_EQ(day_score + SiteEngagementScore::GetMaxPointsPerDay(),
|
| - score_.GetScore());
|
| + score_.GetTotal());
|
| }
|
|
|
| - EXPECT_EQ(2 * SiteEngagementScore::GetMaxPointsPerDay(), score_.GetScore());
|
| + EXPECT_EQ(2 * SiteEngagementScore::GetMaxPointsPerDay(), score_.GetTotal());
|
| }
|
|
|
| // Test that scores are read / written correctly from / to empty score
|
| @@ -339,32 +339,32 @@ TEST_F(SiteEngagementScoreTest, FirstDailyEngagementBonus) {
|
|
|
| // The first engagement event gets the bonus.
|
| score1.AddPoints(0.5);
|
| - EXPECT_EQ(1.0, score1.GetScore());
|
| + EXPECT_EQ(1.0, score1.GetTotal());
|
|
|
| // Subsequent events do not.
|
| score1.AddPoints(0.5);
|
| - EXPECT_EQ(1.5, score1.GetScore());
|
| + EXPECT_EQ(1.5, score1.GetTotal());
|
|
|
| // Bonuses are awarded independently between scores.
|
| score2.AddPoints(1.0);
|
| - EXPECT_EQ(1.5, score2.GetScore());
|
| + EXPECT_EQ(1.5, score2.GetTotal());
|
| score2.AddPoints(1.0);
|
| - EXPECT_EQ(2.5, score2.GetScore());
|
| + EXPECT_EQ(2.5, score2.GetTotal());
|
|
|
| test_clock_.SetNow(current_day + base::TimeDelta::FromDays(1));
|
|
|
| // The first event for the next day gets the bonus.
|
| score1.AddPoints(0.5);
|
| - EXPECT_EQ(2.5, score1.GetScore());
|
| + EXPECT_EQ(2.5, score1.GetTotal());
|
|
|
| // Subsequent events do not.
|
| score1.AddPoints(0.5);
|
| - EXPECT_EQ(3.0, score1.GetScore());
|
| + EXPECT_EQ(3.0, score1.GetTotal());
|
|
|
| score2.AddPoints(1.0);
|
| - EXPECT_EQ(4.0, score2.GetScore());
|
| + EXPECT_EQ(4.0, score2.GetTotal());
|
| score2.AddPoints(1.0);
|
| - EXPECT_EQ(5.0, score2.GetScore());
|
| + EXPECT_EQ(5.0, score2.GetTotal());
|
| }
|
|
|
| // Test that resetting a score has the correct properties.
|
| @@ -373,26 +373,26 @@ TEST_F(SiteEngagementScoreTest, Reset) {
|
|
|
| test_clock_.SetNow(current_day);
|
| score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
|
| - EXPECT_EQ(SiteEngagementScore::GetNavigationPoints(), score_.GetScore());
|
| + EXPECT_EQ(SiteEngagementScore::GetNavigationPoints(), score_.GetTotal());
|
|
|
| current_day += base::TimeDelta::FromDays(7);
|
| test_clock_.SetNow(current_day);
|
|
|
| score_.Reset(20.0, current_day);
|
| - EXPECT_DOUBLE_EQ(20.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(20.0, score_.GetTotal());
|
| EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
|
| EXPECT_EQ(current_day, score_.last_engagement_time_);
|
| EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null());
|
|
|
| // Adding points after the reset should work as normal.
|
| score_.AddPoints(5);
|
| - EXPECT_EQ(25.0, score_.GetScore());
|
| + EXPECT_EQ(25.0, score_.GetTotal());
|
|
|
| // The decay should happen one decay period from the current time.
|
| test_clock_.SetNow(current_day +
|
| base::TimeDelta::FromHours(
|
| SiteEngagementScore::GetDecayPeriodInHours() + 1));
|
| - EXPECT_EQ(25.0 - SiteEngagementScore::GetDecayPoints(), score_.GetScore());
|
| + EXPECT_EQ(25.0 - SiteEngagementScore::GetDecayPoints(), score_.GetTotal());
|
|
|
| // Ensure that manually setting a time works as expected.
|
| score_.AddPoints(5);
|
| @@ -400,7 +400,7 @@ TEST_F(SiteEngagementScoreTest, Reset) {
|
| base::Time now = test_clock_.Now();
|
| score_.Reset(10.0, now);
|
|
|
| - EXPECT_DOUBLE_EQ(10.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(10.0, score_.GetTotal());
|
| EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
|
| EXPECT_EQ(now, score_.last_engagement_time_);
|
| EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null());
|
| @@ -413,7 +413,7 @@ TEST_F(SiteEngagementScoreTest, Reset) {
|
| score_.Reset(15.0, now);
|
|
|
| // 5 bonus from the last shortcut launch.
|
| - EXPECT_DOUBLE_EQ(20.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(20.0, score_.GetTotal());
|
| EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
|
| EXPECT_EQ(now, score_.last_engagement_time_);
|
| EXPECT_EQ(old_now, score_.last_shortcut_launch_time_);
|
| @@ -431,19 +431,19 @@ TEST_F(SiteEngagementScoreTest, ProportionalDecay) {
|
| score_.AddPoints(2.0);
|
| current_day += base::TimeDelta::FromDays(7);
|
| test_clock_.SetNow(current_day);
|
| - EXPECT_DOUBLE_EQ(1.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(1.0, score_.GetTotal());
|
|
|
| // 3 decay periods, expect the score to be halved 3 times.
|
| score_.AddPoints(15.0);
|
| current_day += base::TimeDelta::FromDays(21);
|
| test_clock_.SetNow(current_day);
|
| - EXPECT_DOUBLE_EQ(2.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(2.0, score_.GetTotal());
|
|
|
| // Ensure point removal happens after proportional decay.
|
| score_.AddPoints(4.0);
|
| - EXPECT_DOUBLE_EQ(6.0, score_.GetScore());
|
| + EXPECT_DOUBLE_EQ(6.0, score_.GetTotal());
|
| SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0);
|
| current_day += base::TimeDelta::FromDays(7);
|
| test_clock_.SetNow(current_day);
|
| - EXPECT_NEAR(1.0, score_.GetScore(), kMaxRoundingDeviation);
|
| + EXPECT_NEAR(1.0, score_.GetTotal(), kMaxRoundingDeviation);
|
| }
|
|
|