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

Side by Side Diff: chrome/browser/engagement/site_engagement_score_unittest.cc

Issue 2285553002: [HBD] Gate the advertising of Flash on Site Engagement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit Created 4 years, 3 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
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 "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"
(...skipping 26 matching lines...) Expand all
37 base::Time out_time; 37 base::Time out_time;
38 EXPECT_TRUE( 38 EXPECT_TRUE(
39 base::Time::FromLocalExploded(exploded_reference_time, &out_time)); 39 base::Time::FromLocalExploded(exploded_reference_time, &out_time));
40 return out_time; 40 return out_time;
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 class SiteEngagementScoreTest : public testing::Test { 45 class SiteEngagementScoreTest : public testing::Test {
46 public: 46 public:
47 SiteEngagementScoreTest() : score_(&test_clock_, nullptr) {} 47 SiteEngagementScoreTest() : score_(&test_clock_, GURL(), nullptr) {}
48 48
49 void SetUp() override { 49 void SetUp() override {
50 testing::Test::SetUp(); 50 testing::Test::SetUp();
51 // Disable the first engagement bonus for tests. 51 // Disable the first engagement bonus for tests.
52 SiteEngagementScore::SetParamValuesForTesting(); 52 SiteEngagementScore::SetParamValuesForTesting();
53 } 53 }
54 54
55 protected: 55 protected:
56 void VerifyScore(const SiteEngagementScore& score, 56 void VerifyScore(const SiteEngagementScore& score,
57 double expected_raw_score, 57 double expected_raw_score,
(...skipping 12 matching lines...) Expand all
70 score->points_added_today_ = points_added_today; 70 score->points_added_today_ = points_added_today;
71 score->last_engagement_time_ = last_engagement_time; 71 score->last_engagement_time_ = last_engagement_time;
72 } 72 }
73 73
74 void TestScoreInitializesAndUpdates( 74 void TestScoreInitializesAndUpdates(
75 std::unique_ptr<base::DictionaryValue> score_dict, 75 std::unique_ptr<base::DictionaryValue> score_dict,
76 double expected_raw_score, 76 double expected_raw_score,
77 double expected_points_added_today, 77 double expected_points_added_today,
78 base::Time expected_last_engagement_time) { 78 base::Time expected_last_engagement_time) {
79 std::unique_ptr<base::DictionaryValue> copy(score_dict->DeepCopy()); 79 std::unique_ptr<base::DictionaryValue> copy(score_dict->DeepCopy());
80 SiteEngagementScore initial_score(&test_clock_, std::move(score_dict)); 80 SiteEngagementScore initial_score(&test_clock_, GURL(),
81 std::move(score_dict));
81 VerifyScore(initial_score, expected_raw_score, expected_points_added_today, 82 VerifyScore(initial_score, expected_raw_score, expected_points_added_today,
82 expected_last_engagement_time); 83 expected_last_engagement_time);
83 84
84 // Updating the score dict should return false, as the score shouldn't 85 // Updating the score dict should return false, as the score shouldn't
85 // have changed at this point. 86 // have changed at this point.
86 EXPECT_FALSE(initial_score.UpdateScoreDict(copy.get())); 87 EXPECT_FALSE(initial_score.UpdateScoreDict(copy.get()));
87 88
88 // Update the score to new values and verify it updates the score dict 89 // Update the score to new values and verify it updates the score dict
89 // correctly. 90 // correctly.
90 base::Time different_day = 91 base::Time different_day =
91 GetReferenceTime() + base::TimeDelta::FromDays(1); 92 GetReferenceTime() + base::TimeDelta::FromDays(1);
92 UpdateScore(&initial_score, 5, 10, different_day); 93 UpdateScore(&initial_score, 5, 10, different_day);
93 EXPECT_TRUE(initial_score.UpdateScoreDict(copy.get())); 94 EXPECT_TRUE(initial_score.UpdateScoreDict(copy.get()));
94 SiteEngagementScore updated_score(&test_clock_, std::move(copy)); 95 SiteEngagementScore updated_score(&test_clock_, GURL(), std::move(copy));
95 VerifyScore(updated_score, 5, 10, different_day); 96 VerifyScore(updated_score, 5, 10, different_day);
96 } 97 }
97 98
98 void SetParamValue(SiteEngagementScore::Variation variation, double value) { 99 void SetParamValue(SiteEngagementScore::Variation variation, double value) {
99 SiteEngagementScore::GetParamValues()[variation].second = value; 100 SiteEngagementScore::GetParamValues()[variation].second = value;
100 } 101 }
101 102
102 base::SimpleTestClock test_clock_; 103 base::SimpleTestClock test_clock_;
103 SiteEngagementScore score_; 104 SiteEngagementScore score_;
104 }; 105 };
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 dict->SetDouble(SiteEngagementScore::kLastEngagementTimeKey, 322 dict->SetDouble(SiteEngagementScore::kLastEngagementTimeKey,
322 GetReferenceTime().ToInternalValue()); 323 GetReferenceTime().ToInternalValue());
323 324
324 TestScoreInitializesAndUpdates(std::move(dict), 1, 2, GetReferenceTime()); 325 TestScoreInitializesAndUpdates(std::move(dict), 1, 2, GetReferenceTime());
325 } 326 }
326 327
327 // Ensure bonus engagement is awarded for the first engagement of a day. 328 // Ensure bonus engagement is awarded for the first engagement of a day.
328 TEST_F(SiteEngagementScoreTest, FirstDailyEngagementBonus) { 329 TEST_F(SiteEngagementScoreTest, FirstDailyEngagementBonus) {
329 SetParamValue(SiteEngagementScore::FIRST_DAILY_ENGAGEMENT, 0.5); 330 SetParamValue(SiteEngagementScore::FIRST_DAILY_ENGAGEMENT, 0.5);
330 331
331 SiteEngagementScore score1(&test_clock_, 332 SiteEngagementScore score1(&test_clock_, GURL(),
332 std::unique_ptr<base::DictionaryValue>()); 333 std::unique_ptr<base::DictionaryValue>());
333 SiteEngagementScore score2(&test_clock_, 334 SiteEngagementScore score2(&test_clock_, GURL(),
334 std::unique_ptr<base::DictionaryValue>()); 335 std::unique_ptr<base::DictionaryValue>());
335 base::Time current_day = GetReferenceTime(); 336 base::Time current_day = GetReferenceTime();
336 337
337 test_clock_.SetNow(current_day); 338 test_clock_.SetNow(current_day);
338 339
339 // The first engagement event gets the bonus. 340 // The first engagement event gets the bonus.
340 score1.AddPoints(0.5); 341 score1.AddPoints(0.5);
341 EXPECT_EQ(1.0, score1.GetScore()); 342 EXPECT_EQ(1.0, score1.GetScore());
342 343
343 // Subsequent events do not. 344 // Subsequent events do not.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 EXPECT_DOUBLE_EQ(2.0, score_.GetScore()); 440 EXPECT_DOUBLE_EQ(2.0, score_.GetScore());
440 441
441 // Ensure point removal happens after proportional decay. 442 // Ensure point removal happens after proportional decay.
442 score_.AddPoints(4.0); 443 score_.AddPoints(4.0);
443 EXPECT_DOUBLE_EQ(6.0, score_.GetScore()); 444 EXPECT_DOUBLE_EQ(6.0, score_.GetScore());
444 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0); 445 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0);
445 current_day += base::TimeDelta::FromDays(7); 446 current_day += base::TimeDelta::FromDays(7);
446 test_clock_.SetNow(current_day); 447 test_clock_.SetNow(current_day);
447 EXPECT_NEAR(1.0, score_.GetScore(), kMaxRoundingDeviation); 448 EXPECT_NEAR(1.0, score_.GetScore(), kMaxRoundingDeviation);
448 } 449 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_score.cc ('k') | chrome/browser/engagement/site_engagement_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698