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

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

Issue 2808063002: Add DownloadStatus metric to FaviconHandler (Closed)
Patch Set: Rename histogram enum descriptions 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
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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 EXPECT_THAT( 1056 EXPECT_THAT(
1056 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1057 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1057 IsEmpty()); 1058 IsEmpty());
1058 } 1059 }
1059 1060
1060 TEST_F(FaviconHandlerTest, TestRecordSingleFaviconDownloadAttempt) { 1061 TEST_F(FaviconHandlerTest, TestRecordSingleFaviconDownloadAttempt) {
1061 base::HistogramTester histogram_tester; 1062 base::HistogramTester histogram_tester;
1062 1063
1063 RunHandlerWithCandidates( 1064 RunHandlerWithCandidates(
1064 FaviconDriverObserver::NON_TOUCH_16_DIP, 1065 FaviconDriverObserver::NON_TOUCH_16_DIP,
1065 {FaviconURL(GURL("http://www.google.com/a"), FAVICON, 1066 {FaviconURL(GURL(kIconURL64x64), FAVICON,
1066 {gfx::Size(1024, 1024), gfx::Size(512, 512)})}); 1067 {gfx::Size(1024, 1024), gfx::Size(512, 512)})});
1067 1068
1068 EXPECT_THAT( 1069 EXPECT_THAT(
1069 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1070 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1070 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1071 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1071 EXPECT_THAT( 1072 EXPECT_THAT(
1072 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1073 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1073 IsEmpty()); 1074 IsEmpty());
1075 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1076 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED,
1077 /*expected_count=*/1)));
1074 } 1078 }
1075 1079
1076 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempts) { 1080 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempts) {
1077 base::HistogramTester histogram_tester; 1081 base::HistogramTester histogram_tester;
1078 1082
1079 RunHandlerWithCandidates( 1083 RunHandlerWithCandidates(
1080 FaviconDriverObserver::NON_TOUCH_LARGEST, 1084 FaviconDriverObserver::NON_TOUCH_LARGEST,
1081 {FaviconURL(GURL("http://www.google.com/a"), FAVICON, kEmptySizes)}); 1085 {FaviconURL(GURL(kIconURL16x16), FAVICON, kEmptySizes)});
1082 1086
1083 EXPECT_THAT( 1087 EXPECT_THAT(
1084 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1088 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1085 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1089 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1086 1090
1087 // TOUCH_LARGEST fills the same bucket as NON_TOUCH_LARGEST. 1091 // TOUCH_LARGEST fills the same bucket as NON_TOUCH_LARGEST.
1088 RunHandlerWithCandidates( 1092 RunHandlerWithCandidates(
1089 FaviconDriverObserver::TOUCH_LARGEST, 1093 FaviconDriverObserver::TOUCH_LARGEST,
1090 {FaviconURL(GURL("http://www.google.com/b"), TOUCH_ICON, kEmptySizes)}); 1094 {FaviconURL(GURL(kIconURL64x64), TOUCH_ICON, kEmptySizes)});
1091 1095
1092 EXPECT_THAT( 1096 EXPECT_THAT(
1093 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1097 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1094 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/2))); 1098 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/2)));
1095 EXPECT_THAT( 1099 EXPECT_THAT(
1096 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1100 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1097 IsEmpty()); 1101 IsEmpty());
1102 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1103 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED,
1104 /*expected_count=*/2)));
1098 } 1105 }
1099 1106
1100 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) { 1107 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) {
1101 // Names represent the bitmap sizes per icon. 1108 // Names represent the bitmap sizes per icon.
1102 const GURL kIconURL1024_512("http://www.google.com/a"); 1109 const GURL kIconURL1024_512("http://www.google.com/a");
1103 const GURL kIconURL15_14("http://www.google.com/b"); 1110 const GURL kIconURL15_14("http://www.google.com/b");
1104 const GURL kIconURL16_512("http://www.google.com/c"); 1111 const GURL kIconURL16_512("http://www.google.com/c");
1105 base::HistogramTester histogram_tester; 1112 base::HistogramTester histogram_tester;
1106 favicon_service_.fake()->Store( 1113 favicon_service_.fake()->Store(
1107 GURL("http://so.de"), kIconURL16_512, 1114 GURL("http://so.de"), kIconURL16_512,
(...skipping 15 matching lines...) Expand all
1123 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024_512)); 1130 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024_512));
1124 1131
1125 EXPECT_THAT( 1132 EXPECT_THAT(
1126 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1133 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1127 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1134 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1128 EXPECT_THAT( 1135 EXPECT_THAT(
1129 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1136 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1130 IsEmpty()); 1137 IsEmpty());
1131 } 1138 }
1132 1139
1140 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadAttemptAfterFailure) {
pkotwicz 2017/04/10 18:30:59 Can you please split this test into two? - One tes
fhorschig 2017/04/11 12:24:53 Done.
1141 base::HistogramTester histogram_tester;
1142 const GURL k404IconURL("http://www.google.com/404.png");
1143
1144 delegate_.fake_downloader().AddError(k404IconURL, 404);
1145
1146 // When calling an URL for the first time, it should log the failure.
1147 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL));
1148
1149 RunHandlerWithCandidates(
pkotwicz 2017/04/10 18:30:59 Can you use RunHandlerWithSimpleFaviconCandidates(
fhorschig 2017/04/11 12:24:53 Done.
1150 FaviconDriverObserver::NON_TOUCH_LARGEST,
1151 {FaviconURL(GURL(k404IconURL), FAVICON, kEmptySizes)});
1152
1153 EXPECT_THAT(
1154 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1155 ElementsAre(base::Bucket(DownloadOutcome::FAILED, /*expected_count=*/1)));
1156
1157 // Now, the URL is known to be failing and should be skipped.
1158
1159 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL))
1160 .WillByDefault(Return(true));
1161
1162 RunHandlerWithCandidates(
1163 FaviconDriverObserver::NON_TOUCH_LARGEST,
1164 {FaviconURL(GURL(k404IconURL), FAVICON, kEmptySizes)});
1165
1166 EXPECT_THAT(
1167 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1168 ElementsAre(
1169 base::Bucket(DownloadOutcome::FAILED, /*expected_count=*/1),
1170 base::Bucket(DownloadOutcome::SKIPPED, /*expected_count=*/1)));
1171 }
1172
1133 } // namespace 1173 } // namespace
1134 } // namespace favicon 1174 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698