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

Unified Diff: chrome/browser/engagement/site_engagement_service_unittest.cc

Issue 2748103011: Grant origins engagement for having interactions on their notifications. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/engagement/site_engagement_service_unittest.cc
diff --git a/chrome/browser/engagement/site_engagement_service_unittest.cc b/chrome/browser/engagement/site_engagement_service_unittest.cc
index 95c77a3c4986313a91977e8b00e3d7005526ae4e..4e8b8189a4e4eebe6f6f0d0f18f8587697e12683 100644
--- a/chrome/browser/engagement/site_engagement_service_unittest.cc
+++ b/chrome/browser/engagement/site_engagement_service_unittest.cc
@@ -391,6 +391,49 @@ TEST_F(SiteEngagementServiceTest, GetTotalUserInputPoints) {
EXPECT_DOUBLE_EQ(0.4, service->GetTotalEngagementPoints());
}
+TEST_F(SiteEngagementServiceTest, GetTotalNotificationPoints) {
+ SiteEngagementService* service = SiteEngagementService::Get(profile());
+ ASSERT_TRUE(service);
+ base::HistogramTester histograms;
+
+ // The https and http versions of www.google.com should be separate.
+ GURL url1("https://www.google.com/");
+ GURL url2("http://www.google.com/");
+ GURL url3("http://drive.google.com/");
+
+ EXPECT_EQ(0, service->GetScore(url1));
+ EXPECT_EQ(0, service->GetScore(url2));
+ EXPECT_EQ(0, service->GetScore(url3));
+
+ service->HandleNotificationInteraction(url1);
+ EXPECT_DOUBLE_EQ(1.0, service->GetScore(url1));
+ EXPECT_DOUBLE_EQ(1.0, service->GetTotalEngagementPoints());
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_NOTIFICATION_INTERACTION, 1);
+
+ service->HandleNotificationInteraction(url2);
+ EXPECT_DOUBLE_EQ(1.0, service->GetScore(url2));
+ EXPECT_DOUBLE_EQ(2.0, service->GetTotalEngagementPoints());
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_NOTIFICATION_INTERACTION, 2);
+
+ service->HandleNotificationInteraction(url1);
+ EXPECT_DOUBLE_EQ(2.0, service->GetScore(url1));
+ EXPECT_DOUBLE_EQ(3.0, service->GetTotalEngagementPoints());
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_NOTIFICATION_INTERACTION, 3);
+
+ service->HandleNotificationInteraction(url3);
+ EXPECT_DOUBLE_EQ(1.0, service->GetScore(url3));
+ EXPECT_DOUBLE_EQ(4.0, service->GetTotalEngagementPoints());
+ histograms.ExpectBucketCount(
+ SiteEngagementMetrics::kEngagementTypeHistogram,
+ SiteEngagementMetrics::ENGAGEMENT_NOTIFICATION_INTERACTION, 4);
+}
+
TEST_F(SiteEngagementServiceTest, RestrictedToHTTPAndHTTPS) {
SiteEngagementService* service = SiteEngagementService::Get(profile());
ASSERT_TRUE(service);
@@ -1390,6 +1433,7 @@ TEST_F(SiteEngagementServiceTest, Observers) {
GURL url_score_1("http://www.google.com/maps");
GURL url_score_2("http://www.google.com/drive");
GURL url_score_3("http://www.google.com/");
+ GURL url_score_4("http://maps.google.com/");
GURL url_not_called("https://www.google.com/");
// Create an observer and Observe(nullptr).
@@ -1445,6 +1489,17 @@ TEST_F(SiteEngagementServiceTest, Observers) {
EXPECT_FALSE(tester_not_called.callback_called());
tester.Observe(nullptr);
}
+
+ // Add an observer for notifications.
+ {
+ ObserverTester tester(service, nullptr, url_score_4, 1.0);
+ service->HandleNotificationInteraction(url_score_4);
+ tester.Wait();
+
+ EXPECT_TRUE(tester.callback_called());
+ EXPECT_FALSE(tester_not_called.callback_called());
+ tester.Observe(nullptr);
+ }
}
TEST_F(SiteEngagementServiceTest, ScoreDecayHistograms) {

Powered by Google App Engine
This is Rietveld 408576698