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

Unified Diff: components/ntp_snippets/content_suggestions_metrics_unittest.cc

Issue 2619203007: Log suggestion scores in 10 discrete buckets. (Closed)
Patch Set: more comments Created 3 years, 11 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: components/ntp_snippets/content_suggestions_metrics_unittest.cc
diff --git a/components/ntp_snippets/content_suggestions_metrics_unittest.cc b/components/ntp_snippets/content_suggestions_metrics_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2424d503e8b683f4c15ec0d5a0dcbc954e2b688b
--- /dev/null
+++ b/components/ntp_snippets/content_suggestions_metrics_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/ntp_snippets/content_suggestions_metrics.h"
+
+#include "base/test/histogram_tester.h"
+#include "base/time/time.h"
+#include "components/ntp_snippets/category.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ntp_snippets {
+namespace metrics {
+namespace {
+
+using testing::ElementsAre;
+
+TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) {
+ base::HistogramTester histogram_tester;
+ OnSuggestionShown(/*global_position=*/1,
+ Category::FromKnownCategory(KnownCategories::ARTICLES),
+ /*category_position=*/3,
+ base::Time::Now(),
+ base::Time::Now() - base::TimeDelta::FromHours(2),
+ 0.01f);
+ // Test corner cases for score.
+ OnSuggestionShown(/*global_position=*/1,
+ Category::FromKnownCategory(KnownCategories::ARTICLES),
+ /*category_position=*/3, base::Time::Now(),
+ base::Time::Now() - base::TimeDelta::FromHours(2), 0.0f);
+ OnSuggestionShown(/*global_position=*/1,
+ Category::FromKnownCategory(KnownCategories::ARTICLES),
+ /*category_position=*/3, base::Time::Now(),
+ base::Time::Now() - base::TimeDelta::FromHours(2), 1.0f);
+ OnSuggestionShown(/*global_position=*/1,
+ Category::FromKnownCategory(KnownCategories::ARTICLES),
+ /*category_position=*/3, base::Time::Now(),
+ base::Time::Now() - base::TimeDelta::FromHours(2), 8.0f);
+
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.ShownScoreNormalized.Articles"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
+ base::Bucket(/*min=*/1, /*count=*/1),
+ base::Bucket(/*min=*/10, /*count=*/1),
+ base::Bucket(/*min=*/11, /*count=*/1)));
+}
+
+} // namespace
+} // namespace metrics
+} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698