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

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

Issue 2808063002: Add DownloadStatus metric to FaviconHandler (Closed)
Patch Set: 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 EXPECT_THAT( 1036 EXPECT_THAT(
1036 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1037 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1037 IsEmpty()); 1038 IsEmpty());
1038 } 1039 }
1039 1040
1040 TEST_F(FaviconHandlerTest, TestRecordSingleFaviconDownloadAttempt) { 1041 TEST_F(FaviconHandlerTest, TestRecordSingleFaviconDownloadAttempt) {
1041 base::HistogramTester histogram_tester; 1042 base::HistogramTester histogram_tester;
1042 1043
1043 RunHandlerWithCandidates( 1044 RunHandlerWithCandidates(
1044 FaviconDriverObserver::NON_TOUCH_16_DIP, 1045 FaviconDriverObserver::NON_TOUCH_16_DIP,
1045 {FaviconURL(GURL("http://www.google.com/a"), FAVICON, 1046 {FaviconURL(GURL(kIconURL64x64), FAVICON,
1046 {gfx::Size(1024, 1024), gfx::Size(512, 512)})}); 1047 {gfx::Size(1024, 1024), gfx::Size(512, 512)})});
1047 1048
1048 EXPECT_THAT( 1049 EXPECT_THAT(
1049 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1050 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1050 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1051 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1051 EXPECT_THAT( 1052 EXPECT_THAT(
1052 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1053 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1053 IsEmpty()); 1054 IsEmpty());
1055 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1056 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED,
1057 /*expected_count=*/1)));
1054 } 1058 }
1055 1059
1056 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempts) { 1060 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempts) {
1057 base::HistogramTester histogram_tester; 1061 base::HistogramTester histogram_tester;
1058 1062
1059 RunHandlerWithCandidates( 1063 RunHandlerWithCandidates(
1060 FaviconDriverObserver::NON_TOUCH_LARGEST, 1064 FaviconDriverObserver::NON_TOUCH_LARGEST,
1061 {FaviconURL(GURL("http://www.google.com/a"), FAVICON, kEmptySizes)}); 1065 {FaviconURL(GURL(kIconURL16x16), FAVICON, kEmptySizes)});
1062 1066
1063 EXPECT_THAT( 1067 EXPECT_THAT(
1064 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1068 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1065 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1069 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1066 1070
1067 // TOUCH_LARGEST fills the same bucket as NON_TOUCH_LARGEST. 1071 // TOUCH_LARGEST fills the same bucket as NON_TOUCH_LARGEST.
1068 RunHandlerWithCandidates( 1072 RunHandlerWithCandidates(
1069 FaviconDriverObserver::TOUCH_LARGEST, 1073 FaviconDriverObserver::TOUCH_LARGEST,
1070 {FaviconURL(GURL("http://www.google.com/b"), TOUCH_ICON, kEmptySizes)}); 1074 {FaviconURL(GURL(kIconURL64x64), TOUCH_ICON, kEmptySizes)});
1071 1075
1072 EXPECT_THAT( 1076 EXPECT_THAT(
1073 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1077 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1074 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/2))); 1078 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/2)));
1075 EXPECT_THAT( 1079 EXPECT_THAT(
1076 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1080 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1077 IsEmpty()); 1081 IsEmpty());
1082 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1083 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED,
1084 /*expected_count=*/2)));
1078 } 1085 }
1079 1086
1080 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) { 1087 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) {
1081 // Names represent the bitmap sizes per icon. 1088 // Names represent the bitmap sizes per icon.
1082 const GURL kIconURL1024_512("http://www.google.com/a"); 1089 const GURL kIconURL1024_512("http://www.google.com/a");
1083 const GURL kIconURL15_14("http://www.google.com/b"); 1090 const GURL kIconURL15_14("http://www.google.com/b");
1084 const GURL kIconURL16_512("http://www.google.com/c"); 1091 const GURL kIconURL16_512("http://www.google.com/c");
1085 base::HistogramTester histogram_tester; 1092 base::HistogramTester histogram_tester;
1086 favicon_service_.fake()->Store( 1093 favicon_service_.fake()->Store(
1087 GURL("http://so.de"), kIconURL16_512, 1094 GURL("http://so.de"), kIconURL16_512,
(...skipping 15 matching lines...) Expand all
1103 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024_512)); 1110 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024_512));
1104 1111
1105 EXPECT_THAT( 1112 EXPECT_THAT(
1106 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"), 1113 histogram_tester.GetAllSamples("Favicons.LargeIconDownloadAttempts"),
1107 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); 1114 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1)));
1108 EXPECT_THAT( 1115 EXPECT_THAT(
1109 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"), 1116 histogram_tester.GetAllSamples("Favicons.FaviconDownloadAttempts"),
1110 IsEmpty()); 1117 IsEmpty());
1111 } 1118 }
1112 1119
1120 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadAttemptAfterFailure) {
1121 base::HistogramTester histogram_tester;
1122 const GURL k404IconURL("http://www.google.com/404.png");
1123
1124 delegate_.fake_downloader().AddError(k404IconURL, 404);
1125
1126 // When calling an URL for the first time, it should log the failure.
1127 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL));
1128
1129 RunHandlerWithCandidates(
1130 FaviconDriverObserver::NON_TOUCH_LARGEST,
1131 {FaviconURL(GURL(k404IconURL), FAVICON, kEmptySizes)});
1132
1133 EXPECT_THAT(
1134 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1135 ElementsAre(base::Bucket(DownloadOutcome::FAILED, /*expected_count=*/1)));
1136
1137 // Now, the URL is known to be failing and should be skipped.
1138
1139 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL))
1140 .WillByDefault(Return(true));
1141
1142 RunHandlerWithCandidates(
1143 FaviconDriverObserver::NON_TOUCH_LARGEST,
1144 {FaviconURL(GURL(k404IconURL), FAVICON, kEmptySizes)});
1145
1146 EXPECT_THAT(
1147 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"),
1148 ElementsAre(
1149 base::Bucket(DownloadOutcome::FAILED, /*expected_count=*/1),
1150 base::Bucket(DownloadOutcome::SKIPPED, /*expected_count=*/1)));
1151 }
1152
1113 } // namespace 1153 } // namespace
1114 } // namespace favicon 1154 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698