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

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

Issue 1919383005: Small cleanup of SiteEngagementService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 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 "chrome/browser/engagement/site_engagement_service.h" 5 #include "chrome/browser/engagement/site_engagement_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 TEST_F(SiteEngagementScoreTest, Reset) { 426 TEST_F(SiteEngagementScoreTest, Reset) {
427 base::Time current_day = GetReferenceTime(); 427 base::Time current_day = GetReferenceTime();
428 428
429 test_clock_.SetNow(current_day); 429 test_clock_.SetNow(current_day);
430 score_.AddPoints(SiteEngagementScore::GetNavigationPoints()); 430 score_.AddPoints(SiteEngagementScore::GetNavigationPoints());
431 EXPECT_EQ(SiteEngagementScore::GetNavigationPoints(), score_.Score()); 431 EXPECT_EQ(SiteEngagementScore::GetNavigationPoints(), score_.Score());
432 432
433 current_day += base::TimeDelta::FromDays(7); 433 current_day += base::TimeDelta::FromDays(7);
434 test_clock_.SetNow(current_day); 434 test_clock_.SetNow(current_day);
435 435
436 score_.Reset(20.0, nullptr); 436 score_.Reset(20.0, test_clock_.Now());
437 EXPECT_DOUBLE_EQ(20.0, score_.Score()); 437 EXPECT_DOUBLE_EQ(20.0, score_.Score());
438 EXPECT_DOUBLE_EQ(0, score_.points_added_today_); 438 EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
439 EXPECT_EQ(current_day, score_.last_engagement_time_); 439 EXPECT_EQ(current_day, score_.last_engagement_time_);
440 EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null()); 440 EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null());
441 441
442 // Adding points after the reset should work as normal. 442 // Adding points after the reset should work as normal.
443 score_.AddPoints(5); 443 score_.AddPoints(5);
444 EXPECT_EQ(25.0, score_.Score()); 444 EXPECT_EQ(25.0, score_.Score());
445 445
446 // The decay should happen one decay period from the current time. 446 // The decay should happen one decay period from the current time.
447 test_clock_.SetNow(current_day + 447 test_clock_.SetNow(current_day +
448 base::TimeDelta::FromDays( 448 base::TimeDelta::FromDays(
449 SiteEngagementScore::GetDecayPeriodInDays() + 1)); 449 SiteEngagementScore::GetDecayPeriodInDays() + 1));
450 EXPECT_EQ(25.0 - SiteEngagementScore::GetDecayPoints(), score_.Score()); 450 EXPECT_EQ(25.0 - SiteEngagementScore::GetDecayPoints(), score_.Score());
451 451
452 // Ensure that manually setting a time works as expected. 452 // Ensure that manually setting a time works as expected.
453 score_.AddPoints(5); 453 score_.AddPoints(5);
454 test_clock_.SetNow(GetReferenceTime()); 454 test_clock_.SetNow(GetReferenceTime());
455 base::Time now = test_clock_.Now(); 455 base::Time now = test_clock_.Now();
456 score_.Reset(10.0, &now); 456 score_.Reset(10.0, now);
457 457
458 EXPECT_DOUBLE_EQ(10.0, score_.Score()); 458 EXPECT_DOUBLE_EQ(10.0, score_.Score());
459 EXPECT_DOUBLE_EQ(0, score_.points_added_today_); 459 EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
460 EXPECT_EQ(now, score_.last_engagement_time_); 460 EXPECT_EQ(now, score_.last_engagement_time_);
461 EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null()); 461 EXPECT_TRUE(score_.last_shortcut_launch_time_.is_null());
462 462
463 score_.set_last_shortcut_launch_time(test_clock_.Now()); 463 score_.set_last_shortcut_launch_time(test_clock_.Now());
464 base::Time old_now = test_clock_.Now();
464 test_clock_.SetNow(GetReferenceTime() + base::TimeDelta::FromDays(3)); 465 test_clock_.SetNow(GetReferenceTime() + base::TimeDelta::FromDays(3));
465 now = test_clock_.Now(); 466 now = test_clock_.Now();
466 score_.Reset(15.0, &now); 467 score_.Reset(15.0, now);
467 468
468 // 5 bonus from the last shortcut launch. 469 // 5 bonus from the last shortcut launch.
469 EXPECT_DOUBLE_EQ(20.0, score_.Score()); 470 EXPECT_DOUBLE_EQ(20.0, score_.Score());
470 EXPECT_DOUBLE_EQ(0, score_.points_added_today_); 471 EXPECT_DOUBLE_EQ(0, score_.points_added_today_);
471 EXPECT_EQ(now, score_.last_engagement_time_); 472 EXPECT_EQ(now, score_.last_engagement_time_);
472 EXPECT_EQ(now, score_.last_shortcut_launch_time_); 473 EXPECT_EQ(old_now, score_.last_shortcut_launch_time_);
473 } 474 }
474 475
475 class SiteEngagementServiceTest : public ChromeRenderViewHostTestHarness { 476 class SiteEngagementServiceTest : public ChromeRenderViewHostTestHarness {
476 public: 477 public:
477 void SetUp() override { 478 void SetUp() override {
478 ChromeRenderViewHostTestHarness::SetUp(); 479 ChromeRenderViewHostTestHarness::SetUp();
479 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 480 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
480 g_temp_history_dir = temp_dir_.path(); 481 g_temp_history_dir = temp_dir_.path();
481 HistoryServiceFactory::GetInstance()->SetTestingFactory( 482 HistoryServiceFactory::GetInstance()->SetTestingFactory(
482 profile(), &BuildTestHistoryService); 483 profile(), &BuildTestHistoryService);
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 0, 2); 1446 0, 2);
1446 1447
1447 // Add more points and ensure no more samples are present. 1448 // Add more points and ensure no more samples are present.
1448 service->AddPoints(origin1, 0.01); 1449 service->AddPoints(origin1, 0.01);
1449 service->AddPoints(origin2, 0.01); 1450 service->AddPoints(origin2, 0.01);
1450 histograms.ExpectTotalCount(SiteEngagementMetrics::kScoreDecayedFromHistogram, 1451 histograms.ExpectTotalCount(SiteEngagementMetrics::kScoreDecayedFromHistogram,
1451 4); 1452 4);
1452 histograms.ExpectTotalCount(SiteEngagementMetrics::kScoreDecayedToHistogram, 1453 histograms.ExpectTotalCount(SiteEngagementMetrics::kScoreDecayedToHistogram,
1453 4); 1454 4);
1454 } 1455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698