| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/test/histogram_tester.h" | 6 #include "base/test/histogram_tester.h" |
| 7 #include "base/test/simple_test_clock.h" | 7 #include "base/test/simple_test_clock.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/engagement/site_engagement_helper.h" | 9 #include "chrome/browser/engagement/site_engagement_helper.h" |
| 10 #include "chrome/browser/engagement/site_engagement_metrics.h" | 10 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 EXPECT_TRUE(initial_score.UpdateScoreDict(score_dict)); | 84 EXPECT_TRUE(initial_score.UpdateScoreDict(score_dict)); |
| 85 SiteEngagementScore updated_score(&test_clock_, *score_dict); | 85 SiteEngagementScore updated_score(&test_clock_, *score_dict); |
| 86 VerifyScore(updated_score, 5, 10, different_day); | 86 VerifyScore(updated_score, 5, 10, different_day); |
| 87 } | 87 } |
| 88 | 88 |
| 89 base::SimpleTestClock test_clock_; | 89 base::SimpleTestClock test_clock_; |
| 90 SiteEngagementScore score_; | 90 SiteEngagementScore score_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // Accumulate score many times on the same day. Ensure each time the score goes | 93 // Accumulate score many times on the same day. Ensure each time the score goes |
| 94 // up by kNavigationPoints, but not more than kMaxPointsPerDay. | 94 // up by gNavigationPoints, but not more than gMaxPointsPerDay. |
| 95 TEST_F(SiteEngagementScoreTest, AccumulateOnSameDay) { | 95 TEST_F(SiteEngagementScoreTest, AccumulateOnSameDay) { |
| 96 base::Time reference_time = GetReferenceTime(); | 96 base::Time reference_time = GetReferenceTime(); |
| 97 | 97 |
| 98 test_clock_.SetNow(reference_time); | 98 test_clock_.SetNow(reference_time); |
| 99 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { | 99 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { |
| 100 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 100 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 101 EXPECT_EQ(std::min(SiteEngagementScore::kMaxPointsPerDay, | 101 EXPECT_EQ(std::min(SiteEngagementScore::gMaxPointsPerDay, |
| 102 (i + 1) * SiteEngagementScore::kNavigationPoints), | 102 (i + 1) * SiteEngagementScore::gNavigationPoints), |
| 103 score_.Score()); | 103 score_.Score()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 EXPECT_EQ(SiteEngagementScore::kMaxPointsPerDay, score_.Score()); | 106 EXPECT_EQ(SiteEngagementScore::gMaxPointsPerDay, score_.Score()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Accumulate on the first day to max that day's engagement, then accumulate on | 109 // Accumulate on the first day to max that day's engagement, then accumulate on |
| 110 // a different day. | 110 // a different day. |
| 111 TEST_F(SiteEngagementScoreTest, AccumulateOnTwoDays) { | 111 TEST_F(SiteEngagementScoreTest, AccumulateOnTwoDays) { |
| 112 base::Time reference_time = GetReferenceTime(); | 112 base::Time reference_time = GetReferenceTime(); |
| 113 base::Time later_date = reference_time + base::TimeDelta::FromDays(2); | 113 base::Time later_date = reference_time + base::TimeDelta::FromDays(2); |
| 114 | 114 |
| 115 test_clock_.SetNow(reference_time); | 115 test_clock_.SetNow(reference_time); |
| 116 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) | 116 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) |
| 117 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 117 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 118 | 118 |
| 119 EXPECT_EQ(SiteEngagementScore::kMaxPointsPerDay, score_.Score()); | 119 EXPECT_EQ(SiteEngagementScore::gMaxPointsPerDay, score_.Score()); |
| 120 | 120 |
| 121 test_clock_.SetNow(later_date); | 121 test_clock_.SetNow(later_date); |
| 122 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { | 122 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { |
| 123 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 123 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 124 double day_score = | 124 double day_score = |
| 125 std::min(SiteEngagementScore::kMaxPointsPerDay, | 125 std::min(SiteEngagementScore::gMaxPointsPerDay, |
| 126 (i + 1) * SiteEngagementScore::kNavigationPoints); | 126 (i + 1) * SiteEngagementScore::gNavigationPoints); |
| 127 EXPECT_EQ(day_score + SiteEngagementScore::kMaxPointsPerDay, | 127 EXPECT_EQ(day_score + SiteEngagementScore::gMaxPointsPerDay, |
| 128 score_.Score()); | 128 score_.Score()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 EXPECT_EQ(2 * SiteEngagementScore::kMaxPointsPerDay, score_.Score()); | 131 EXPECT_EQ(2 * SiteEngagementScore::gMaxPointsPerDay, score_.Score()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Accumulate score on many consecutive days and ensure the score doesn't exceed | 134 // Accumulate score on many consecutive days and ensure the score doesn't exceed |
| 135 // the maximum allowed. | 135 // the maximum allowed. |
| 136 TEST_F(SiteEngagementScoreTest, AccumulateALotOnManyDays) { | 136 TEST_F(SiteEngagementScoreTest, AccumulateALotOnManyDays) { |
| 137 base::Time current_day = GetReferenceTime(); | 137 base::Time current_day = GetReferenceTime(); |
| 138 | 138 |
| 139 for (int i = 0; i < kMoreDaysThanNeededToMaxTotalEngagement; ++i) { | 139 for (int i = 0; i < kMoreDaysThanNeededToMaxTotalEngagement; ++i) { |
| 140 current_day += base::TimeDelta::FromDays(1); | 140 current_day += base::TimeDelta::FromDays(1); |
| 141 test_clock_.SetNow(current_day); | 141 test_clock_.SetNow(current_day); |
| 142 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) | 142 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) |
| 143 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 143 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 144 | 144 |
| 145 EXPECT_EQ(std::min(SiteEngagementScore::kMaxPoints, | 145 EXPECT_EQ(std::min(SiteEngagementScore::kMaxPoints, |
| 146 (i + 1) * SiteEngagementScore::kMaxPointsPerDay), | 146 (i + 1) * SiteEngagementScore::gMaxPointsPerDay), |
| 147 score_.Score()); | 147 score_.Score()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); | 150 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Accumulate a little on many consecutive days and ensure the score doesn't | 153 // Accumulate a little on many consecutive days and ensure the score doesn't |
| 154 // exceed the maximum allowed. | 154 // exceed the maximum allowed. |
| 155 TEST_F(SiteEngagementScoreTest, AccumulateALittleOnManyDays) { | 155 TEST_F(SiteEngagementScoreTest, AccumulateALittleOnManyDays) { |
| 156 base::Time current_day = GetReferenceTime(); | 156 base::Time current_day = GetReferenceTime(); |
| 157 | 157 |
| 158 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxTotalEngagement; ++i) { | 158 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxTotalEngagement; ++i) { |
| 159 current_day += base::TimeDelta::FromDays(1); | 159 current_day += base::TimeDelta::FromDays(1); |
| 160 test_clock_.SetNow(current_day); | 160 test_clock_.SetNow(current_day); |
| 161 | 161 |
| 162 for (int j = 0; j < kLessAccumulationsThanNeededToMaxDailyEngagement; ++j) | 162 for (int j = 0; j < kLessAccumulationsThanNeededToMaxDailyEngagement; ++j) |
| 163 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 163 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 164 | 164 |
| 165 EXPECT_EQ( | 165 EXPECT_EQ( |
| 166 std::min(SiteEngagementScore::kMaxPoints, | 166 std::min(SiteEngagementScore::kMaxPoints, |
| 167 (i + 1) * kLessAccumulationsThanNeededToMaxDailyEngagement * | 167 (i + 1) * kLessAccumulationsThanNeededToMaxDailyEngagement * |
| 168 SiteEngagementScore::kNavigationPoints), | 168 SiteEngagementScore::gNavigationPoints), |
| 169 score_.Score()); | 169 score_.Score()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); | 172 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Accumulate a bit, then check the score decays properly for a range of times. | 175 // Accumulate a bit, then check the score decays properly for a range of times. |
| 176 TEST_F(SiteEngagementScoreTest, ScoresDecayOverTime) { | 176 TEST_F(SiteEngagementScoreTest, ScoresDecayOverTime) { |
| 177 base::Time current_day = GetReferenceTime(); | 177 base::Time current_day = GetReferenceTime(); |
| 178 | 178 |
| 179 // First max the score. | 179 // First max the score. |
| 180 for (int i = 0; i < kMoreDaysThanNeededToMaxTotalEngagement; ++i) { | 180 for (int i = 0; i < kMoreDaysThanNeededToMaxTotalEngagement; ++i) { |
| 181 current_day += base::TimeDelta::FromDays(1); | 181 current_day += base::TimeDelta::FromDays(1); |
| 182 test_clock_.SetNow(current_day); | 182 test_clock_.SetNow(current_day); |
| 183 | 183 |
| 184 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) | 184 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) |
| 185 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 185 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 186 } | 186 } |
| 187 | 187 |
| 188 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); | 188 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); |
| 189 | 189 |
| 190 // The score should not have decayed before the first decay period has | 190 // The score should not have decayed before the first decay period has |
| 191 // elapsed. | 191 // elapsed. |
| 192 test_clock_.SetNow( | 192 test_clock_.SetNow( |
| 193 current_day + | 193 current_day + |
| 194 base::TimeDelta::FromDays(SiteEngagementScore::kDecayPeriodInDays - 1)); | 194 base::TimeDelta::FromDays(SiteEngagementScore::gDecayPeriodInDays - 1)); |
| 195 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); | 195 EXPECT_EQ(SiteEngagementScore::kMaxPoints, score_.Score()); |
| 196 | 196 |
| 197 // The score should have decayed by one chunk after one decay period has | 197 // The score should have decayed by one chunk after one decay period has |
| 198 // elapsed. | 198 // elapsed. |
| 199 test_clock_.SetNow( | 199 test_clock_.SetNow( |
| 200 current_day + | 200 current_day + |
| 201 base::TimeDelta::FromDays(SiteEngagementScore::kDecayPeriodInDays)); | 201 base::TimeDelta::FromDays(SiteEngagementScore::gDecayPeriodInDays)); |
| 202 EXPECT_EQ(SiteEngagementScore::kMaxPoints - SiteEngagementScore::kDecayPoints, | 202 EXPECT_EQ(SiteEngagementScore::kMaxPoints - SiteEngagementScore::gDecayPoints, |
| 203 score_.Score()); | 203 score_.Score()); |
| 204 | 204 |
| 205 // The score should have decayed by the right number of chunks after a few | 205 // The score should have decayed by the right number of chunks after a few |
| 206 // decay periods have elapsed. | 206 // decay periods have elapsed. |
| 207 test_clock_.SetNow( | 207 test_clock_.SetNow( |
| 208 current_day + | 208 current_day + |
| 209 base::TimeDelta::FromDays(kLessPeriodsThanNeededToDecayMaxScore * | 209 base::TimeDelta::FromDays(kLessPeriodsThanNeededToDecayMaxScore * |
| 210 SiteEngagementScore::kDecayPeriodInDays)); | 210 SiteEngagementScore::gDecayPeriodInDays)); |
| 211 EXPECT_EQ(SiteEngagementScore::kMaxPoints - | 211 EXPECT_EQ(SiteEngagementScore::kMaxPoints - |
| 212 kLessPeriodsThanNeededToDecayMaxScore * | 212 kLessPeriodsThanNeededToDecayMaxScore * |
| 213 SiteEngagementScore::kDecayPoints, | 213 SiteEngagementScore::gDecayPoints, |
| 214 score_.Score()); | 214 score_.Score()); |
| 215 | 215 |
| 216 // The score should not decay below zero. | 216 // The score should not decay below zero. |
| 217 test_clock_.SetNow( | 217 test_clock_.SetNow( |
| 218 current_day + | 218 current_day + |
| 219 base::TimeDelta::FromDays(kMorePeriodsThanNeededToDecayMaxScore * | 219 base::TimeDelta::FromDays(kMorePeriodsThanNeededToDecayMaxScore * |
| 220 SiteEngagementScore::kDecayPeriodInDays)); | 220 SiteEngagementScore::gDecayPeriodInDays)); |
| 221 EXPECT_EQ(0, score_.Score()); | 221 EXPECT_EQ(0, score_.Score()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Test that any expected decays are applied before adding points. | 224 // Test that any expected decays are applied before adding points. |
| 225 TEST_F(SiteEngagementScoreTest, DecaysAppliedBeforeAdd) { | 225 TEST_F(SiteEngagementScoreTest, DecaysAppliedBeforeAdd) { |
| 226 base::Time current_day = GetReferenceTime(); | 226 base::Time current_day = GetReferenceTime(); |
| 227 | 227 |
| 228 // Get the score up to something that can handle a bit of decay before | 228 // Get the score up to something that can handle a bit of decay before |
| 229 for (int i = 0; i < kLessDaysThanNeededToMaxTotalEngagement; ++i) { | 229 for (int i = 0; i < kLessDaysThanNeededToMaxTotalEngagement; ++i) { |
| 230 current_day += base::TimeDelta::FromDays(1); | 230 current_day += base::TimeDelta::FromDays(1); |
| 231 test_clock_.SetNow(current_day); | 231 test_clock_.SetNow(current_day); |
| 232 | 232 |
| 233 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) | 233 for (int j = 0; j < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++j) |
| 234 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 234 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 235 } | 235 } |
| 236 | 236 |
| 237 double initial_score = kLessDaysThanNeededToMaxTotalEngagement * | 237 double initial_score = kLessDaysThanNeededToMaxTotalEngagement * |
| 238 SiteEngagementScore::kMaxPointsPerDay; | 238 SiteEngagementScore::gMaxPointsPerDay; |
| 239 EXPECT_EQ(initial_score, score_.Score()); | 239 EXPECT_EQ(initial_score, score_.Score()); |
| 240 | 240 |
| 241 // Go forward a few decay periods. | 241 // Go forward a few decay periods. |
| 242 test_clock_.SetNow( | 242 test_clock_.SetNow( |
| 243 current_day + | 243 current_day + |
| 244 base::TimeDelta::FromDays(kLessPeriodsThanNeededToDecayMaxScore * | 244 base::TimeDelta::FromDays(kLessPeriodsThanNeededToDecayMaxScore * |
| 245 SiteEngagementScore::kDecayPeriodInDays)); | 245 SiteEngagementScore::gDecayPeriodInDays)); |
| 246 | 246 |
| 247 double decayed_score = | 247 double decayed_score = |
| 248 initial_score - | 248 initial_score - |
| 249 kLessPeriodsThanNeededToDecayMaxScore * SiteEngagementScore::kDecayPoints; | 249 kLessPeriodsThanNeededToDecayMaxScore * SiteEngagementScore::gDecayPoints; |
| 250 EXPECT_EQ(decayed_score, score_.Score()); | 250 EXPECT_EQ(decayed_score, score_.Score()); |
| 251 | 251 |
| 252 // Now add some points. | 252 // Now add some points. |
| 253 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 253 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 254 EXPECT_EQ(decayed_score + SiteEngagementScore::kNavigationPoints, | 254 EXPECT_EQ(decayed_score + SiteEngagementScore::gNavigationPoints, |
| 255 score_.Score()); | 255 score_.Score()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Test that going back in time is handled properly. | 258 // Test that going back in time is handled properly. |
| 259 TEST_F(SiteEngagementScoreTest, GoBackInTime) { | 259 TEST_F(SiteEngagementScoreTest, GoBackInTime) { |
| 260 base::Time current_day = GetReferenceTime(); | 260 base::Time current_day = GetReferenceTime(); |
| 261 | 261 |
| 262 test_clock_.SetNow(current_day); | 262 test_clock_.SetNow(current_day); |
| 263 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) | 263 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) |
| 264 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 264 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 265 | 265 |
| 266 EXPECT_EQ(SiteEngagementScore::kMaxPointsPerDay, score_.Score()); | 266 EXPECT_EQ(SiteEngagementScore::gMaxPointsPerDay, score_.Score()); |
| 267 | 267 |
| 268 // Adding to the score on an earlier date should be treated like another day, | 268 // Adding to the score on an earlier date should be treated like another day, |
| 269 // and should not cause any decay. | 269 // and should not cause any decay. |
| 270 test_clock_.SetNow(current_day - base::TimeDelta::FromDays( | 270 test_clock_.SetNow(current_day - base::TimeDelta::FromDays( |
| 271 kMorePeriodsThanNeededToDecayMaxScore * | 271 kMorePeriodsThanNeededToDecayMaxScore * |
| 272 SiteEngagementScore::kDecayPoints)); | 272 SiteEngagementScore::gDecayPoints)); |
| 273 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { | 273 for (int i = 0; i < kMoreAccumulationsThanNeededToMaxDailyEngagement; ++i) { |
| 274 score_.AddPoints(SiteEngagementScore::kNavigationPoints); | 274 score_.AddPoints(SiteEngagementScore::gNavigationPoints); |
| 275 double day_score = | 275 double day_score = |
| 276 std::min(SiteEngagementScore::kMaxPointsPerDay, | 276 std::min(SiteEngagementScore::gMaxPointsPerDay, |
| 277 (i + 1) * SiteEngagementScore::kNavigationPoints); | 277 (i + 1) * SiteEngagementScore::gNavigationPoints); |
| 278 EXPECT_EQ(day_score + SiteEngagementScore::kMaxPointsPerDay, | 278 EXPECT_EQ(day_score + SiteEngagementScore::gMaxPointsPerDay, |
| 279 score_.Score()); | 279 score_.Score()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 EXPECT_EQ(2 * SiteEngagementScore::kMaxPointsPerDay, score_.Score()); | 282 EXPECT_EQ(2 * SiteEngagementScore::gMaxPointsPerDay, score_.Score()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Test that scores are read / written correctly from / to empty score | 285 // Test that scores are read / written correctly from / to empty score |
| 286 // dictionaries. | 286 // dictionaries. |
| 287 TEST_F(SiteEngagementScoreTest, EmptyDictionary) { | 287 TEST_F(SiteEngagementScoreTest, EmptyDictionary) { |
| 288 base::DictionaryValue dict; | 288 base::DictionaryValue dict; |
| 289 TestScoreInitializesAndUpdates(&dict, 0, 0, base::Time()); | 289 TestScoreInitializesAndUpdates(&dict, 0, 0, base::Time()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Test that scores are read / written correctly from / to partially empty | 292 // Test that scores are read / written correctly from / to partially empty |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 741 |
| 742 service->AddPoints(url1, 5.0); | 742 service->AddPoints(url1, 5.0); |
| 743 EXPECT_EQ(10.0, service->GetScore(url1)); | 743 EXPECT_EQ(10.0, service->GetScore(url1)); |
| 744 | 744 |
| 745 { | 745 { |
| 746 // Decay one origin to zero by advancing time and expect the engagement | 746 // Decay one origin to zero by advancing time and expect the engagement |
| 747 // score to be cleaned up. The other score was changed a day later so it | 747 // score to be cleaned up. The other score was changed a day later so it |
| 748 // will not have decayed at all. | 748 // will not have decayed at all. |
| 749 clock->SetNow( | 749 clock->SetNow( |
| 750 GetReferenceTime() + | 750 GetReferenceTime() + |
| 751 base::TimeDelta::FromDays(SiteEngagementScore::kDecayPeriodInDays)); | 751 base::TimeDelta::FromDays(SiteEngagementScore::gDecayPeriodInDays)); |
| 752 | 752 |
| 753 std::map<GURL, double> score_map = service->GetScoreMap(); | 753 std::map<GURL, double> score_map = service->GetScoreMap(); |
| 754 EXPECT_EQ(2u, score_map.size()); | 754 EXPECT_EQ(2u, score_map.size()); |
| 755 EXPECT_EQ(10, score_map[url1]); | 755 EXPECT_EQ(10, score_map[url1]); |
| 756 EXPECT_EQ(0, score_map[url2]); | 756 EXPECT_EQ(0, score_map[url2]); |
| 757 | 757 |
| 758 service->CleanupEngagementScores(); | 758 service->CleanupEngagementScores(); |
| 759 | 759 |
| 760 score_map = service->GetScoreMap(); | 760 score_map = service->GetScoreMap(); |
| 761 EXPECT_EQ(1u, score_map.size()); | 761 EXPECT_EQ(1u, score_map.size()); |
| 762 EXPECT_EQ(10, score_map[url1]); | 762 EXPECT_EQ(10, score_map[url1]); |
| 763 EXPECT_EQ(0, service->GetScore(url2)); | 763 EXPECT_EQ(0, service->GetScore(url2)); |
| 764 } | 764 } |
| 765 | 765 |
| 766 { | 766 { |
| 767 // Decay the other origin to zero by advancing time and expect the | 767 // Decay the other origin to zero by advancing time and expect the |
| 768 // engagement score to be cleaned up. | 768 // engagement score to be cleaned up. |
| 769 clock->SetNow( | 769 clock->SetNow( |
| 770 GetReferenceTime() + | 770 GetReferenceTime() + |
| 771 base::TimeDelta::FromDays(3 * SiteEngagementScore::kDecayPeriodInDays)); | 771 base::TimeDelta::FromDays(3 * SiteEngagementScore::gDecayPeriodInDays)); |
| 772 | 772 |
| 773 std::map<GURL, double> score_map = service->GetScoreMap(); | 773 std::map<GURL, double> score_map = service->GetScoreMap(); |
| 774 EXPECT_EQ(1u, score_map.size()); | 774 EXPECT_EQ(1u, score_map.size()); |
| 775 EXPECT_EQ(0, score_map[url1]); | 775 EXPECT_EQ(0, score_map[url1]); |
| 776 | 776 |
| 777 service->CleanupEngagementScores(); | 777 service->CleanupEngagementScores(); |
| 778 | 778 |
| 779 score_map = service->GetScoreMap(); | 779 score_map = service->GetScoreMap(); |
| 780 EXPECT_EQ(0u, score_map.size()); | 780 EXPECT_EQ(0u, score_map.size()); |
| 781 EXPECT_EQ(0, service->GetScore(url1)); | 781 EXPECT_EQ(0, service->GetScore(url1)); |
| 782 } | 782 } |
| 783 } | 783 } |
| OLD | NEW |