| 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 "chrome/browser/engagement/site_engagement_score.h" | 5 #include "chrome/browser/engagement/site_engagement_score.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/engagement/site_engagement_service.h" | 12 #include "chrome/browser/engagement/site_engagement_service.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int kLessAccumulationsThanNeededToMaxDailyEngagement = 2; | 17 const int kLessAccumulationsThanNeededToMaxDailyEngagement = 2; |
| 18 const int kMoreAccumulationsThanNeededToMaxDailyEngagement = 40; | 18 const int kMoreAccumulationsThanNeededToMaxDailyEngagement = 40; |
| 19 const int kMoreAccumulationsThanNeededToMaxTotalEngagement = 200; | 19 const int kMoreAccumulationsThanNeededToMaxTotalEngagement = 200; |
| 20 const int kLessDaysThanNeededToMaxTotalEngagement = 4; | 20 const int kLessDaysThanNeededToMaxTotalEngagement = 4; |
| 21 const int kMoreDaysThanNeededToMaxTotalEngagement = 40; | 21 const int kMoreDaysThanNeededToMaxTotalEngagement = 40; |
| 22 const int kLessPeriodsThanNeededToDecayMaxScore = 2; | 22 const int kLessPeriodsThanNeededToDecayMaxScore = 2; |
| 23 const int kMorePeriodsThanNeededToDecayMaxScore = 40; | 23 const int kMorePeriodsThanNeededToDecayMaxScore = 40; |
| 24 const double kMaxRoundingDeviation = 0.0001; |
| 24 | 25 |
| 25 base::Time GetReferenceTime() { | 26 base::Time GetReferenceTime() { |
| 26 base::Time::Exploded exploded_reference_time; | 27 base::Time::Exploded exploded_reference_time; |
| 27 exploded_reference_time.year = 2015; | 28 exploded_reference_time.year = 2015; |
| 28 exploded_reference_time.month = 1; | 29 exploded_reference_time.month = 1; |
| 29 exploded_reference_time.day_of_month = 30; | 30 exploded_reference_time.day_of_month = 30; |
| 30 exploded_reference_time.day_of_week = 5; | 31 exploded_reference_time.day_of_week = 5; |
| 31 exploded_reference_time.hour = 11; | 32 exploded_reference_time.hour = 11; |
| 32 exploded_reference_time.minute = 0; | 33 exploded_reference_time.minute = 0; |
| 33 exploded_reference_time.second = 0; | 34 exploded_reference_time.second = 0; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 current_day += base::TimeDelta::FromDays(21); | 437 current_day += base::TimeDelta::FromDays(21); |
| 437 test_clock_.SetNow(current_day); | 438 test_clock_.SetNow(current_day); |
| 438 EXPECT_DOUBLE_EQ(2.0, score_.GetScore()); | 439 EXPECT_DOUBLE_EQ(2.0, score_.GetScore()); |
| 439 | 440 |
| 440 // Ensure point removal happens after proportional decay. | 441 // Ensure point removal happens after proportional decay. |
| 441 score_.AddPoints(4.0); | 442 score_.AddPoints(4.0); |
| 442 EXPECT_DOUBLE_EQ(6.0, score_.GetScore()); | 443 EXPECT_DOUBLE_EQ(6.0, score_.GetScore()); |
| 443 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0); | 444 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0); |
| 444 current_day += base::TimeDelta::FromDays(7); | 445 current_day += base::TimeDelta::FromDays(7); |
| 445 test_clock_.SetNow(current_day); | 446 test_clock_.SetNow(current_day); |
| 446 EXPECT_DOUBLE_EQ(1.0, score_.GetScore()); | 447 EXPECT_NEAR(1.0, score_.GetScore(), kMaxRoundingDeviation); |
| 447 } | 448 } |
| OLD | NEW |