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

Unified Diff: components/ntp_tiles/metrics_unittest.cc

Issue 2557513007: ntp_tiles::metrics: Add rappor metrics for impression URLs per icon type. (Closed)
Patch Set: Rebased. Created 4 years 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
« no previous file with comments | « components/ntp_tiles/metrics.cc ('k') | tools/metrics/rappor/rappor.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_tiles/metrics_unittest.cc
diff --git a/components/ntp_tiles/metrics_unittest.cc b/components/ntp_tiles/metrics_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53438777ee560b72fdfd6210b9b186f482013f4b
--- /dev/null
+++ b/components/ntp_tiles/metrics_unittest.cc
@@ -0,0 +1,163 @@
+// Copyright 2016 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_tiles/metrics.h"
+
+#include <stddef.h>
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/test/histogram_tester.h"
+#include "components/rappor/test_rappor_service.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ntp_tiles {
+namespace metrics {
+namespace {
+
+using testing::ElementsAre;
+using testing::IsEmpty;
+
+TEST(RecordPageImpressionTest, ShouldRecordUmaForIcons) {
+ base::HistogramTester histogram_tester;
+ RecordPageImpression(
+ {{NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
+ {NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
+ {NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
+ {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()},
+ {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()},
+ {NTPTileSource::SUGGESTIONS_SERVICE, ICON_REAL, GURL()},
+ {NTPTileSource::SUGGESTIONS_SERVICE, ICON_DEFAULT, GURL()},
+ {NTPTileSource::POPULAR, ICON_COLOR, GURL()}},
+ /*rappor_service=*/nullptr);
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
+ ElementsAre(base::Bucket(/*min=*/8, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
+ base::Bucket(/*min=*/1, /*count=*/1),
+ base::Bucket(/*min=*/2, /*count=*/1),
+ base::Bucket(/*min=*/3, /*count=*/1),
+ base::Bucket(/*min=*/4, /*count=*/1),
+ base::Bucket(/*min=*/5, /*count=*/1),
+ base::Bucket(/*min=*/6, /*count=*/1),
+ base::Bucket(/*min=*/7, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
+ ElementsAre(base::Bucket(/*min=*/5, /*count=*/1),
+ base::Bucket(/*min=*/6, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
+ base::Bucket(/*min=*/1, /*count=*/1),
+ base::Bucket(/*min=*/2, /*count=*/1),
+ base::Bucket(/*min=*/3, /*count=*/1),
+ base::Bucket(/*min=*/4, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.SuggestionsImpression.popular"),
+ ElementsAre(base::Bucket(/*min=*/7, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"),
+ ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/4),
+ base::Bucket(/*min=*/ICON_COLOR, /*count=*/3),
+ base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
+ ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/1),
+ base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
+ ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/3),
+ base::Bucket(/*min=*/ICON_COLOR, /*count=*/2)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
+ ElementsAre(base::Bucket(/*min=*/ICON_COLOR, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
+ ElementsAre(base::Bucket(/*min=*/4, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
+ ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
+ ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
+}
+
+TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) {
+ base::HistogramTester histogram_tester;
+ RecordPageImpression({{NTPTileSource::TOP_SITES, THUMBNAIL, GURL()},
+ {NTPTileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()},
+ {NTPTileSource::POPULAR, THUMBNAIL, GURL()}},
+ /*rappor_service=*/nullptr);
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
+ ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
+ base::Bucket(/*min=*/1, /*count=*/1),
+ base::Bucket(/*min=*/2, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
+ ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
+ ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples(
+ "NewTabPage.SuggestionsImpression.popular"),
+ ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
+ IsEmpty());
+}
+
+TEST(RecordPageImpressionTest, ShouldRecordRappor) {
+ rappor::TestRapporServiceImpl rappor_service;
+
+ RecordPageImpression(
+ {{NTPTileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")},
+ {NTPTileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")},
+ {NTPTileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")},
+ {NTPTileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}},
+ &rappor_service);
+
+ // Thumbnail shouldn't get reported.
+ EXPECT_EQ(3, rappor_service.GetReportsCount());
+
+ {
+ std::string sample;
+ rappor::RapporType type;
+ EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
+ "NTP.SuggestionsImpressions.IconsReal", &sample, &type));
+ EXPECT_EQ("site1.com", sample);
+ EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
+ }
+
+ {
+ std::string sample;
+ rappor::RapporType type;
+ EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
+ "NTP.SuggestionsImpressions.IconsColor", &sample, &type));
+ EXPECT_EQ("site2.com", sample);
+ EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
+ }
+
+ {
+ std::string sample;
+ rappor::RapporType type;
+ EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
+ "NTP.SuggestionsImpressions.IconsGray", &sample, &type));
+ EXPECT_EQ("site3.com", sample);
+ EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
+ }
+}
+
+} // namespace
+} // namespace metrics
+} // namespace ntp_tiles
« no previous file with comments | « components/ntp_tiles/metrics.cc ('k') | tools/metrics/rappor/rappor.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698