| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/ntp_tiles/metrics.h" | 5 #include "components/ntp_tiles/metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 14 #include "components/rappor/test_rappor_service.h" | 14 #include "components/rappor/test_rappor_service.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace ntp_tiles { | 18 namespace ntp_tiles { |
| 19 namespace metrics { | 19 namespace metrics { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using testing::ElementsAre; | 22 using testing::ElementsAre; |
| 23 using testing::IsEmpty; | 23 using testing::IsEmpty; |
| 24 | 24 |
| 25 TEST(RecordPageImpressionTest, ShouldRecordUmaForIcons) { | 25 TEST(RecordPageImpressionTest, ShouldRecordUmaForIcons) { |
| 26 base::HistogramTester histogram_tester; | 26 base::HistogramTester histogram_tester; |
| 27 RecordPageImpression( | 27 RecordPageImpression({{TileSource::TOP_SITES, ICON_REAL, GURL()}, |
| 28 {{NTPTileSource::TOP_SITES, ICON_REAL, GURL()}, | 28 {TileSource::TOP_SITES, ICON_REAL, GURL()}, |
| 29 {NTPTileSource::TOP_SITES, ICON_REAL, GURL()}, | 29 {TileSource::TOP_SITES, ICON_REAL, GURL()}, |
| 30 {NTPTileSource::TOP_SITES, ICON_REAL, GURL()}, | 30 {TileSource::TOP_SITES, ICON_COLOR, GURL()}, |
| 31 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()}, | 31 {TileSource::TOP_SITES, ICON_COLOR, GURL()}, |
| 32 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()}, | 32 {TileSource::SUGGESTIONS_SERVICE, ICON_REAL, GURL()}, |
| 33 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_REAL, GURL()}, | 33 {TileSource::SUGGESTIONS_SERVICE, ICON_DEFAULT, GURL()}, |
| 34 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_DEFAULT, GURL()}, | 34 {TileSource::POPULAR, ICON_COLOR, GURL()}}, |
| 35 {NTPTileSource::POPULAR, ICON_COLOR, GURL()}}, | 35 /*rappor_service=*/nullptr); |
| 36 /*rappor_service=*/nullptr); | |
| 37 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), | 36 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), |
| 38 ElementsAre(base::Bucket(/*min=*/8, /*count=*/1))); | 37 ElementsAre(base::Bucket(/*min=*/8, /*count=*/1))); |
| 39 EXPECT_THAT( | 38 EXPECT_THAT( |
| 40 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), | 39 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), |
| 41 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | 40 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| 42 base::Bucket(/*min=*/1, /*count=*/1), | 41 base::Bucket(/*min=*/1, /*count=*/1), |
| 43 base::Bucket(/*min=*/2, /*count=*/1), | 42 base::Bucket(/*min=*/2, /*count=*/1), |
| 44 base::Bucket(/*min=*/3, /*count=*/1), | 43 base::Bucket(/*min=*/3, /*count=*/1), |
| 45 base::Bucket(/*min=*/4, /*count=*/1), | 44 base::Bucket(/*min=*/4, /*count=*/1), |
| 46 base::Bucket(/*min=*/5, /*count=*/1), | 45 base::Bucket(/*min=*/5, /*count=*/1), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/4), | 63 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/4), |
| 65 base::Bucket(/*min=*/ICON_COLOR, /*count=*/3), | 64 base::Bucket(/*min=*/ICON_COLOR, /*count=*/3), |
| 66 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1))); | 65 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1))); |
| 67 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), | 66 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), |
| 68 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/1), | 67 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/1), |
| 69 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1))); | 68 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1))); |
| 70 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), | 69 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), |
| 71 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/3), | 70 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/3), |
| 72 base::Bucket(/*min=*/ICON_COLOR, /*count=*/2))); | 71 base::Bucket(/*min=*/ICON_COLOR, /*count=*/2))); |
| 73 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), | 72 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), |
| 74 ElementsAre(base::Bucket(/*min=*/ICON_COLOR, /*count=*/1))); | 73 ElementsAre(base::Bucket(/*min=*/ICON_COLOR, |
| 74 /*count=*/1))); |
| 75 EXPECT_THAT(histogram_tester.GetAllSamples( | 75 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 76 "NewTabPage.SuggestionsImpression.IconsReal"), | 76 "NewTabPage.SuggestionsImpression.IconsReal"), |
| 77 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | 77 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| 78 base::Bucket(/*min=*/1, /*count=*/1), | 78 base::Bucket(/*min=*/1, /*count=*/1), |
| 79 base::Bucket(/*min=*/2, /*count=*/1), | 79 base::Bucket(/*min=*/2, /*count=*/1), |
| 80 base::Bucket(/*min=*/5, /*count=*/1))); | 80 base::Bucket(/*min=*/5, /*count=*/1))); |
| 81 EXPECT_THAT(histogram_tester.GetAllSamples( | 81 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 82 "NewTabPage.SuggestionsImpression.IconsColor"), | 82 "NewTabPage.SuggestionsImpression.IconsColor"), |
| 83 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1), | 83 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1), |
| 84 base::Bucket(/*min=*/4, /*count=*/1), | 84 base::Bucket(/*min=*/4, /*count=*/1), |
| 85 base::Bucket(/*min=*/7, /*count=*/1))); | 85 base::Bucket(/*min=*/7, /*count=*/1))); |
| 86 EXPECT_THAT(histogram_tester.GetAllSamples( | 86 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 87 "NewTabPage.SuggestionsImpression.IconsGray"), | 87 "NewTabPage.SuggestionsImpression.IconsGray"), |
| 88 ElementsAre(base::Bucket(/*min=*/6, /*count=*/1))); | 88 ElementsAre(base::Bucket(/*min=*/6, /*count=*/1))); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) { | 91 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) { |
| 92 base::HistogramTester histogram_tester; | 92 base::HistogramTester histogram_tester; |
| 93 RecordPageImpression({{NTPTileSource::TOP_SITES, THUMBNAIL, GURL()}, | 93 RecordPageImpression({{TileSource::TOP_SITES, THUMBNAIL, GURL()}, |
| 94 {NTPTileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, | 94 {TileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, |
| 95 {NTPTileSource::POPULAR, THUMBNAIL, GURL()}}, | 95 {TileSource::POPULAR, THUMBNAIL, GURL()}}, |
| 96 /*rappor_service=*/nullptr); | 96 /*rappor_service=*/nullptr); |
| 97 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), | 97 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), |
| 98 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 98 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 99 EXPECT_THAT( | 99 EXPECT_THAT( |
| 100 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), | 100 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), |
| 101 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | 101 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| 102 base::Bucket(/*min=*/1, /*count=*/1), | 102 base::Bucket(/*min=*/1, /*count=*/1), |
| 103 base::Bucket(/*min=*/2, /*count=*/1))); | 103 base::Bucket(/*min=*/2, /*count=*/1))); |
| 104 EXPECT_THAT( | 104 EXPECT_THAT( |
| 105 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"), | 105 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 123 EXPECT_THAT(histogram_tester.GetAllSamples( | 123 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 124 "NewTabPage.SuggestionsImpression.IconsColor"), | 124 "NewTabPage.SuggestionsImpression.IconsColor"), |
| 125 IsEmpty()); | 125 IsEmpty()); |
| 126 EXPECT_THAT(histogram_tester.GetAllSamples( | 126 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 127 "NewTabPage.SuggestionsImpression.IconsGray"), | 127 "NewTabPage.SuggestionsImpression.IconsGray"), |
| 128 IsEmpty()); | 128 IsEmpty()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST(RecordTileClickTest, ShouldRecordUma) { | 131 TEST(RecordTileClickTest, ShouldRecordUma) { |
| 132 base::HistogramTester histogram_tester; | 132 base::HistogramTester histogram_tester; |
| 133 RecordTileClick(3, NTPTileSource::TOP_SITES, ICON_REAL); | 133 RecordTileClick(3, TileSource::TOP_SITES, ICON_REAL); |
| 134 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), | 134 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), |
| 135 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 135 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 136 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), | 136 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), |
| 137 IsEmpty()); | 137 IsEmpty()); |
| 138 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), | 138 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), |
| 139 IsEmpty()); | 139 IsEmpty()); |
| 140 EXPECT_THAT( | 140 EXPECT_THAT( |
| 141 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), | 141 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), |
| 142 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 142 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 143 EXPECT_THAT( | 143 EXPECT_THAT( |
| 144 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), | 144 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), |
| 145 IsEmpty()); | 145 IsEmpty()); |
| 146 EXPECT_THAT( | 146 EXPECT_THAT( |
| 147 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), | 147 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), |
| 148 IsEmpty()); | 148 IsEmpty()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST(RecordTileClickTest, ShouldIgnoreThumbnails) { | 151 TEST(RecordTileClickTest, ShouldIgnoreThumbnails) { |
| 152 base::HistogramTester histogram_tester; | 152 base::HistogramTester histogram_tester; |
| 153 RecordTileClick(3, NTPTileSource::TOP_SITES, THUMBNAIL); | 153 RecordTileClick(3, TileSource::TOP_SITES, THUMBNAIL); |
| 154 EXPECT_THAT( | 154 EXPECT_THAT( |
| 155 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), | 155 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), |
| 156 IsEmpty()); | 156 IsEmpty()); |
| 157 EXPECT_THAT( | 157 EXPECT_THAT( |
| 158 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), | 158 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), |
| 159 IsEmpty()); | 159 IsEmpty()); |
| 160 EXPECT_THAT( | 160 EXPECT_THAT( |
| 161 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), | 161 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), |
| 162 IsEmpty()); | 162 IsEmpty()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST(RecordPageImpressionTest, ShouldRecordRappor) { | 165 TEST(RecordPageImpressionTest, ShouldRecordRappor) { |
| 166 rappor::TestRapporServiceImpl rappor_service; | 166 rappor::TestRapporServiceImpl rappor_service; |
| 167 | 167 |
| 168 RecordPageImpression( | 168 RecordPageImpression( |
| 169 {{NTPTileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, | 169 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, |
| 170 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, | 170 {TileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, |
| 171 {NTPTileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}, | 171 {TileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}, |
| 172 {NTPTileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}}, | 172 {TileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}}, |
| 173 &rappor_service); | 173 &rappor_service); |
| 174 | 174 |
| 175 // Thumbnail shouldn't get reported. | 175 // Thumbnail shouldn't get reported. |
| 176 EXPECT_EQ(3, rappor_service.GetReportsCount()); | 176 EXPECT_EQ(3, rappor_service.GetReportsCount()); |
| 177 | 177 |
| 178 { | 178 { |
| 179 std::string sample; | 179 std::string sample; |
| 180 rappor::RapporType type; | 180 rappor::RapporType type; |
| 181 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 181 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
| 182 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); | 182 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 199 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 199 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
| 200 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); | 200 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); |
| 201 EXPECT_EQ("site3.com", sample); | 201 EXPECT_EQ("site3.com", sample); |
| 202 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 202 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace | 206 } // namespace |
| 207 } // namespace metrics | 207 } // namespace metrics |
| 208 } // namespace ntp_tiles | 208 } // namespace ntp_tiles |
| OLD | NEW |