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

Side by Side Diff: components/favicon/core/favicon_handler_unittest.cc

Issue 2808063002: Add DownloadStatus metric to FaviconHandler (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/favicon/core/favicon_handler.h" 5 #include "components/favicon/core/favicon_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 24 matching lines...) Expand all
35 using favicon_base::TOUCH_ICON; 35 using favicon_base::TOUCH_ICON;
36 using favicon_base::TOUCH_PRECOMPOSED_ICON; 36 using favicon_base::TOUCH_PRECOMPOSED_ICON;
37 using testing::Assign; 37 using testing::Assign;
38 using testing::ElementsAre; 38 using testing::ElementsAre;
39 using testing::InSequence; 39 using testing::InSequence;
40 using testing::Invoke; 40 using testing::Invoke;
41 using testing::IsEmpty; 41 using testing::IsEmpty;
42 using testing::Return; 42 using testing::Return;
43 using testing::_; 43 using testing::_;
44 44
45 using DownloadOutcome = FaviconHandler::DownloadOutcome;
45 using IntVector = std::vector<int>; 46 using IntVector = std::vector<int>;
46 using URLVector = std::vector<GURL>; 47 using URLVector = std::vector<GURL>;
47 using BitmapVector = std::vector<SkBitmap>; 48 using BitmapVector = std::vector<SkBitmap>;
48 using SizeVector = std::vector<gfx::Size>; 49 using SizeVector = std::vector<gfx::Size>;
49 50
50 MATCHER_P2(ImageSizeIs, width, height, "") { 51 MATCHER_P2(ImageSizeIs, width, height, "") {
51 *result_listener << "where size is " << arg.Width() << "x" << arg.Height(); 52 *result_listener << "where size is " << arg.Width() << "x" << arg.Height();
52 return arg.Size() == gfx::Size(width, height); 53 return arg.Size() == gfx::Size(width, height);
53 } 54 }
54 55
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 1066
1066 EXPECT_THAT( 1067 EXPECT_THAT(
1067 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), 1068 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"),
1068 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1069 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1069 EXPECT_THAT( 1070 EXPECT_THAT(
1070 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), 1071 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"),
1071 IsEmpty()); 1072 IsEmpty());
1072 EXPECT_THAT( 1073 EXPECT_THAT(
1073 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), 1074 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"),
1074 IsEmpty()); 1075 IsEmpty());
1076 EXPECT_THAT(
1077 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1078 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SUCCEEDED),
1079 /*expected_count=*/1)));
1075 } 1080 }
1076 1081
1077 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempt) { 1082 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempt) {
1078 base::HistogramTester histogram_tester; 1083 base::HistogramTester histogram_tester;
1079 1084
1080 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_LARGEST, 1085 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_LARGEST,
1081 {FaviconURL(kIconURL64x64, FAVICON, kEmptySizes)}); 1086 {FaviconURL(kIconURL64x64, FAVICON, kEmptySizes)});
1082 1087
1083 EXPECT_THAT( 1088 EXPECT_THAT(
1084 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), 1089 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"),
1085 IsEmpty()); 1090 IsEmpty());
1086 EXPECT_THAT( 1091 EXPECT_THAT(
1087 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), 1092 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"),
1088 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1093 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1089 EXPECT_THAT( 1094 EXPECT_THAT(
1090 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), 1095 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"),
1091 IsEmpty()); 1096 IsEmpty());
1097 EXPECT_THAT(
1098 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1099 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SUCCEEDED),
1100 /*expected_count=*/1)));
1092 } 1101 }
1093 1102
1094 TEST_F(FaviconHandlerTest, TestRecordSingleTouchIconDownloadAttempt) { 1103 TEST_F(FaviconHandlerTest, TestRecordSingleTouchIconDownloadAttempt) {
1095 base::HistogramTester histogram_tester; 1104 base::HistogramTester histogram_tester;
1096 RunHandlerWithCandidates( 1105 RunHandlerWithCandidates(
1097 FaviconDriverObserver::TOUCH_LARGEST, 1106 FaviconDriverObserver::TOUCH_LARGEST,
1098 {FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes)}); 1107 {FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes)});
1099 1108
1100 EXPECT_THAT( 1109 EXPECT_THAT(
1101 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), 1110 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"),
1102 IsEmpty()); 1111 IsEmpty());
1103 EXPECT_THAT( 1112 EXPECT_THAT(
1104 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), 1113 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"),
1105 IsEmpty()); 1114 IsEmpty());
1106 EXPECT_THAT( 1115 EXPECT_THAT(
1107 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), 1116 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"),
1108 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1117 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1118 EXPECT_THAT(
1119 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1120 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SUCCEEDED),
1121 /*expected_count=*/1)));
1109 } 1122 }
1110 1123
1111 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) { 1124 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) {
1112 const GURL kIconURL1024x1024("http://www.google.com/a-404-ing-icon"); 1125 const GURL kIconURL1024x1024("http://www.google.com/a-404-ing-icon");
1113 base::HistogramTester histogram_tester; 1126 base::HistogramTester histogram_tester;
1114 favicon_service_.fake()->Store( 1127 favicon_service_.fake()->Store(
1115 GURL("http://so.de"), kIconURL64x64, 1128 GURL("http://so.de"), kIconURL64x64,
1116 CreateRawBitmapResult(kIconURL64x64, FAVICON, /*expired=*/false, 64)); 1129 CreateRawBitmapResult(kIconURL64x64, FAVICON, /*expired=*/false, 64));
1117 1130
1118 RunHandlerWithCandidates( 1131 RunHandlerWithCandidates(
(...skipping 22 matching lines...) Expand all
1141 GURL("http://www.google.com/ps"), kIconURL16x16, 1154 GURL("http://www.google.com/ps"), kIconURL16x16,
1142 CreateRawBitmapResult(kIconURL16x16, FAVICON, /*expired=*/true)); 1155 CreateRawBitmapResult(kIconURL16x16, FAVICON, /*expired=*/true));
1143 1156
1144 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); 1157 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16});
1145 1158
1146 EXPECT_THAT( 1159 EXPECT_THAT(
1147 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), 1160 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"),
1148 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1161 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1149 } 1162 }
1150 1163
1164 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) {
1165 base::HistogramTester histogram_tester;
1166 const GURL k404IconURL("http://www.google.com/404.png");
1167
1168 delegate_.fake_downloader().AddError(k404IconURL, 404);
1169
1170 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL));
1171
1172 RunHandlerWithSimpleFaviconCandidates({k404IconURL});
1173
1174 EXPECT_THAT(
1175 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1176 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::FAILED),
1177 /*expected_count=*/1)));
1178 }
1179
1180 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) {
1181 base::HistogramTester histogram_tester;
1182 const GURL k404IconURL("http://www.google.com/404.png");
1183
1184 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL))
1185 .WillByDefault(Return(true));
1186
1187 RunHandlerWithSimpleFaviconCandidates({k404IconURL});
1188
1189 EXPECT_THAT(
1190 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1191 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED),
1192 /*expected_count=*/1)));
1193 }
1194
1151 } // namespace 1195 } // namespace
1152 } // namespace favicon 1196 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698