OLD | NEW |
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 Loading... |
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 Loading... |
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(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1077 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED, |
| 1078 /*expected_count=*/1))); |
1075 } | 1079 } |
1076 | 1080 |
1077 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempt) { | 1081 TEST_F(FaviconHandlerTest, TestRecordSingleLargeIconDownloadAttempt) { |
1078 base::HistogramTester histogram_tester; | 1082 base::HistogramTester histogram_tester; |
1079 | 1083 |
1080 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_LARGEST, | 1084 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_LARGEST, |
1081 {FaviconURL(kIconURL64x64, FAVICON, kEmptySizes)}); | 1085 {FaviconURL(kIconURL64x64, FAVICON, kEmptySizes)}); |
1082 | 1086 |
1083 EXPECT_THAT( | 1087 EXPECT_THAT( |
1084 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 1088 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
1085 IsEmpty()); | 1089 IsEmpty()); |
1086 EXPECT_THAT( | 1090 EXPECT_THAT( |
1087 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), | 1091 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), |
1088 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); | 1092 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); |
1089 EXPECT_THAT( | 1093 EXPECT_THAT( |
1090 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), | 1094 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), |
1091 IsEmpty()); | 1095 IsEmpty()); |
| 1096 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1097 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED, |
| 1098 /*expected_count=*/1))); |
1092 } | 1099 } |
1093 | 1100 |
1094 TEST_F(FaviconHandlerTest, TestRecordSingleTouchIconDownloadAttempt) { | 1101 TEST_F(FaviconHandlerTest, TestRecordSingleTouchIconDownloadAttempt) { |
1095 base::HistogramTester histogram_tester; | 1102 base::HistogramTester histogram_tester; |
1096 RunHandlerWithCandidates( | 1103 RunHandlerWithCandidates( |
1097 FaviconDriverObserver::TOUCH_LARGEST, | 1104 FaviconDriverObserver::TOUCH_LARGEST, |
1098 {FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes)}); | 1105 {FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes)}); |
1099 | 1106 |
1100 EXPECT_THAT( | 1107 EXPECT_THAT( |
1101 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), | 1108 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), |
1102 IsEmpty()); | 1109 IsEmpty()); |
1103 EXPECT_THAT( | 1110 EXPECT_THAT( |
1104 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 1111 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
1105 IsEmpty()); | 1112 IsEmpty()); |
1106 EXPECT_THAT( | 1113 EXPECT_THAT( |
1107 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), | 1114 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), |
1108 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); | 1115 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); |
| 1116 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1117 ElementsAre(base::Bucket(DownloadOutcome::SUCCEEDED, |
| 1118 /*expected_count=*/1))); |
1109 } | 1119 } |
1110 | 1120 |
1111 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) { | 1121 TEST_F(FaviconHandlerTest, TestRecordDownloadAttemptsFinishedByCache) { |
1112 const GURL kIconURL1024x1024("http://www.google.com/a-404-ing-icon"); | 1122 const GURL kIconURL1024x1024("http://www.google.com/a-404-ing-icon"); |
1113 base::HistogramTester histogram_tester; | 1123 base::HistogramTester histogram_tester; |
1114 favicon_service_.fake()->Store( | 1124 favicon_service_.fake()->Store( |
1115 GURL("http://so.de"), kIconURL64x64, | 1125 GURL("http://so.de"), kIconURL64x64, |
1116 CreateRawBitmapResult(kIconURL64x64, FAVICON, /*expired=*/false, 64)); | 1126 CreateRawBitmapResult(kIconURL64x64, FAVICON, /*expired=*/false, 64)); |
1117 | 1127 |
1118 RunHandlerWithCandidates( | 1128 RunHandlerWithCandidates( |
1119 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1129 FaviconDriverObserver::NON_TOUCH_LARGEST, |
1120 {FaviconURL(kIconURL1024x1024, FAVICON, {gfx::Size(1024, 1024)}), | 1130 {FaviconURL(kIconURL1024x1024, FAVICON, {gfx::Size(1024, 1024)}), |
1121 FaviconURL(kIconURL12x12, FAVICON, {gfx::Size(12, 12)}), | 1131 FaviconURL(kIconURL12x12, FAVICON, {gfx::Size(12, 12)}), |
1122 FaviconURL(kIconURL64x64, FAVICON, {gfx::Size(64, 64)})}); | 1132 FaviconURL(kIconURL64x64, FAVICON, {gfx::Size(64, 64)})}); |
1123 | 1133 |
1124 // Should try only the first (receive 404) and get second icon from cache. | 1134 // Should try only the first (receive 404) and get second icon from cache. |
1125 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024x1024)); | 1135 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1024x1024)); |
1126 | 1136 |
1127 EXPECT_THAT( | 1137 EXPECT_THAT( |
1128 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), | 1138 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), |
1129 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); | 1139 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); |
1130 EXPECT_THAT( | 1140 EXPECT_THAT( |
1131 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 1141 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
1132 IsEmpty()); | 1142 IsEmpty()); |
1133 EXPECT_THAT( | 1143 EXPECT_THAT( |
1134 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), | 1144 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.TouchIcons"), |
1135 IsEmpty()); | 1145 IsEmpty()); |
1136 } | 1146 } |
1137 | 1147 |
| 1148 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) { |
| 1149 base::HistogramTester histogram_tester; |
| 1150 const GURL k404IconURL("http://www.google.com/404.png"); |
| 1151 |
| 1152 delegate_.fake_downloader().AddError(k404IconURL, 404); |
| 1153 |
| 1154 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL)); |
| 1155 |
| 1156 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1157 |
| 1158 EXPECT_THAT( |
| 1159 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1160 ElementsAre(base::Bucket(DownloadOutcome::FAILED, /*expected_count=*/1))); |
| 1161 } |
| 1162 |
| 1163 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) { |
| 1164 base::HistogramTester histogram_tester; |
| 1165 const GURL k404IconURL("http://www.google.com/404.png"); |
| 1166 |
| 1167 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL)) |
| 1168 .WillByDefault(Return(true)); |
| 1169 |
| 1170 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1171 |
| 1172 EXPECT_THAT(histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1173 ElementsAre(base::Bucket(DownloadOutcome::SKIPPED, |
| 1174 /*expected_count=*/1))); |
| 1175 } |
| 1176 |
1138 } // namespace | 1177 } // namespace |
1139 } // namespace favicon | 1178 } // namespace favicon |
OLD | NEW |