summaryrefslogtreecommitdiff
path: root/chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc')
-rw-r--r--chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc b/chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc
index fe8193e300f..fd636e4b967 100644
--- a/chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc
+++ b/chromium/components/ntp_snippets/content_suggestions_metrics_unittest.cc
@@ -15,6 +15,7 @@ namespace metrics {
namespace {
using testing::ElementsAre;
+using testing::IsEmpty;
TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) {
base::HistogramTester histogram_tester;
@@ -45,6 +46,87 @@ TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) {
base::Bucket(/*min=*/11, /*count=*/1)));
}
+TEST(ContentSuggestionsMetricsTest,
+ ShouldNotLogNotShownCategoriesWhenPageShown) {
+ base::HistogramTester histogram_tester;
+ OnPageShown(std::vector<Category>(
+ {Category::FromKnownCategory(KnownCategories::ARTICLES)}),
+ /*suggestions_per_category=*/{0},
+ /*is_category_visible=*/{false});
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible.Articles"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.SectionCountOnNtpOpened"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
+}
+
+TEST(ContentSuggestionsMetricsTest,
+ ShouldLogEmptyShownCategoriesWhenPageShown) {
+ base::HistogramTester histogram_tester;
+ OnPageShown(std::vector<Category>(
+ {Category::FromKnownCategory(KnownCategories::ARTICLES)}),
+ /*suggestions_per_category=*/{0},
+ /*is_category_visible=*/{true});
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible.Articles"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.SectionCountOnNtpOpened"),
+ ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
+}
+
+TEST(ContentSuggestionsMetricsTest,
+ ShouldLogNonEmptyShownCategoryWhenPageShown) {
+ base::HistogramTester histogram_tester;
+ OnPageShown(std::vector<Category>(
+ {Category::FromKnownCategory(KnownCategories::ARTICLES)}),
+ /*suggestions_per_category=*/{10},
+ /*is_category_visible=*/{true});
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible.Articles"),
+ ElementsAre(base::Bucket(/*min=*/10, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible"),
+ ElementsAre(base::Bucket(/*min=*/10, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.SectionCountOnNtpOpened"),
+ ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
+}
+
+TEST(ContentSuggestionsMetricsTest,
+ ShouldLogMultipleNonEmptyShownCategoriesWhenPageShown) {
+ base::HistogramTester histogram_tester;
+ OnPageShown(std::vector<Category>(
+ {Category::FromKnownCategory(KnownCategories::ARTICLES),
+ Category::FromKnownCategory(KnownCategories::BOOKMARKS)}),
+ /*suggestions_per_category=*/{10, 5},
+ /*is_category_visible=*/{true, true});
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible.Articles"),
+ ElementsAre(base::Bucket(/*min=*/10, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible.Bookmarks"),
+ ElementsAre(base::Bucket(/*min=*/5, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.CountOnNtpOpenedIfVisible"),
+ ElementsAre(base::Bucket(/*min=*/15, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.ContentSuggestions.SectionCountOnNtpOpened"),
+ ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
+}
+
} // namespace
} // namespace metrics
} // namespace ntp_snippets