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> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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({{TileSource::TOP_SITES, THUMBNAIL, GURL()}, | 93 RecordPageImpression({{TileSource::TOP_SITES, THUMBNAIL_FAILED, GURL()}, |
94 {TileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, | 94 {TileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, |
95 {TileSource::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"), |
106 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | 106 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
107 EXPECT_THAT( | 107 EXPECT_THAT( |
108 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"), | 108 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"), |
109 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); | 109 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); |
110 EXPECT_THAT(histogram_tester.GetAllSamples( | 110 EXPECT_THAT(histogram_tester.GetAllSamples( |
111 "NewTabPage.SuggestionsImpression.popular"), | 111 "NewTabPage.SuggestionsImpression.popular"), |
112 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1))); | 112 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1))); |
113 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), IsEmpty()); | 113 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), |
114 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/2), | |
115 base::Bucket(/*min=*/THUMBNAIL_FAILED, /*count=*/1))); | |
114 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), | 116 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), |
115 IsEmpty()); | 117 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/1))); |
116 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), | 118 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), |
117 IsEmpty()); | 119 ElementsAre(base::Bucket(/*min=*/THUMBNAIL_FAILED, /*count=*/1))); |
118 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), | 120 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), |
119 IsEmpty()); | 121 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/1))); |
120 EXPECT_THAT(histogram_tester.GetAllSamples( | 122 EXPECT_THAT(histogram_tester.GetAllSamples( |
121 "NewTabPage.SuggestionsImpression.IconsReal"), | 123 "NewTabPage.SuggestionsImpression.IconsReal"), |
122 IsEmpty()); | 124 IsEmpty()); |
123 EXPECT_THAT(histogram_tester.GetAllSamples( | 125 EXPECT_THAT(histogram_tester.GetAllSamples( |
124 "NewTabPage.SuggestionsImpression.IconsColor"), | 126 "NewTabPage.SuggestionsImpression.IconsColor"), |
125 IsEmpty()); | 127 IsEmpty()); |
126 EXPECT_THAT(histogram_tester.GetAllSamples( | 128 EXPECT_THAT(histogram_tester.GetAllSamples( |
127 "NewTabPage.SuggestionsImpression.IconsGray"), | 129 "NewTabPage.SuggestionsImpression.IconsGray"), |
128 IsEmpty()); | 130 IsEmpty()); |
129 } | 131 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 IsEmpty()); | 164 IsEmpty()); |
163 } | 165 } |
164 | 166 |
165 TEST(RecordPageImpressionTest, ShouldRecordRappor) { | 167 TEST(RecordPageImpressionTest, ShouldRecordRappor) { |
166 rappor::TestRapporServiceImpl rappor_service; | 168 rappor::TestRapporServiceImpl rappor_service; |
167 | 169 |
168 RecordPageImpression( | 170 RecordPageImpression( |
169 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, | 171 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, |
170 {TileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, | 172 {TileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, |
171 {TileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}, | 173 {TileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}, |
172 {TileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}}, | 174 {TileSource::TOP_SITES, UNKNOWN_TILE_TYPE, GURL("http://www.s4.com/")}}, |
sfiera
2017/04/06 08:53:28
Can this be its own test, instead of hiding it in
Marc Treib
2017/04/06 09:16:44
Sure, done. I've also updated/expanded the tests a
| |
173 &rappor_service); | 175 &rappor_service); |
174 | 176 |
175 // Thumbnail shouldn't get reported. | 177 // Unknown tile type shouldn't get reported. |
176 EXPECT_EQ(3, rappor_service.GetReportsCount()); | 178 EXPECT_EQ(3, rappor_service.GetReportsCount()); |
177 | 179 |
178 { | 180 { |
179 std::string sample; | 181 std::string sample; |
180 rappor::RapporType type; | 182 rappor::RapporType type; |
181 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 183 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
182 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); | 184 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); |
183 EXPECT_EQ("site1.com", sample); | 185 EXPECT_EQ("site1.com", sample); |
184 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 186 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
185 } | 187 } |
(...skipping 13 matching lines...) Expand all Loading... | |
199 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 201 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
200 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); | 202 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); |
201 EXPECT_EQ("site3.com", sample); | 203 EXPECT_EQ("site3.com", sample); |
202 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 204 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
203 } | 205 } |
204 } | 206 } |
205 | 207 |
206 } // namespace | 208 } // namespace |
207 } // namespace metrics | 209 } // namespace metrics |
208 } // namespace ntp_tiles | 210 } // namespace ntp_tiles |
OLD | NEW |