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 "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/favicon/chrome_favicon_client.h" | 8 #include "chrome/browser/favicon/chrome_favicon_client.h" |
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 FaviconService* GetFaviconService() override { | 182 FaviconService* GetFaviconService() override { |
183 // Just give none NULL value, so overridden methods can be hit. | 183 // Just give none NULL value, so overridden methods can be hit. |
184 return (FaviconService*)(1); | 184 return (FaviconService*)(1); |
185 } | 185 } |
186 | 186 |
187 bool IsBookmarked(const GURL& url) override { return false; } | 187 bool IsBookmarked(const GURL& url) override { return false; } |
188 }; | 188 }; |
189 | 189 |
190 class TestFaviconDriver : public FaviconDriver { | 190 class TestFaviconDriver : public FaviconDriver { |
191 public: | 191 public: |
192 TestFaviconDriver() : favicon_validity_(false) {} | 192 TestFaviconDriver() |
| 193 : favicon_validity_(false), |
| 194 num_favicon_available_(0), |
| 195 update_active_favicon_(false) {} |
193 | 196 |
194 virtual ~TestFaviconDriver() { | 197 virtual ~TestFaviconDriver() { |
195 } | 198 } |
196 | 199 |
197 bool IsOffTheRecord() override { return false; } | 200 bool IsOffTheRecord() override { return false; } |
198 | 201 |
199 const gfx::Image GetActiveFaviconImage() override { return image_; } | 202 const gfx::Image GetActiveFaviconImage() override { return image_; } |
200 | 203 |
201 const GURL GetActiveFaviconURL() override { return favicon_url_; } | 204 const GURL GetActiveFaviconURL() override { return favicon_url_; } |
202 | 205 |
203 bool GetActiveFaviconValidity() override { return favicon_validity_; } | 206 bool GetActiveFaviconValidity() override { return favicon_validity_; } |
204 | 207 |
205 const GURL GetActiveURL() override { return url_; } | 208 const GURL GetActiveURL() override { return url_; } |
206 | 209 |
207 void SetActiveFaviconImage(gfx::Image image) override { image_ = image; } | 210 void SetActiveFaviconImage(gfx::Image image) { image_ = image; } |
208 | 211 |
209 void SetActiveFaviconURL(GURL favicon_url) override { | 212 void SetActiveFaviconURL(GURL favicon_url) { favicon_url_ = favicon_url; } |
210 favicon_url_ = favicon_url; | |
211 } | |
212 | 213 |
213 void SetActiveFaviconValidity(bool favicon_validity) override { | 214 void SetActiveFaviconValidity(bool favicon_validity) { |
214 favicon_validity_ = favicon_validity; | 215 favicon_validity_ = favicon_validity; |
215 } | 216 } |
216 | 217 |
217 int StartDownload(const GURL& url, int max_bitmap_size) override { | 218 int StartDownload(const GURL& url, int max_bitmap_size) override { |
218 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | 219 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " |
219 << "should never be called in tests."; | 220 << "should never be called in tests."; |
220 return -1; | 221 return -1; |
221 } | 222 } |
222 | 223 |
223 void NotifyFaviconUpdated(bool icon_url_changed) override { | 224 void OnFaviconAvailable(const gfx::Image& image, |
224 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " | 225 const GURL& icon_url, |
225 << "should never be called in tests."; | 226 bool update_active_favicon) override { |
| 227 available_image_ = image; |
| 228 available_icon_url_ = icon_url; |
| 229 update_active_favicon_ = update_active_favicon; |
| 230 if (!update_active_favicon) |
| 231 return; |
| 232 |
| 233 ++num_favicon_available_; |
| 234 SetActiveFaviconURL(icon_url); |
| 235 SetActiveFaviconValidity(true); |
| 236 SetActiveFaviconImage(image); |
226 } | 237 } |
227 | 238 |
| 239 size_t num_favicon_available() const { return num_favicon_available_; } |
| 240 |
| 241 void ResetNumFaviconAvailable() { num_favicon_available_ = 0; } |
| 242 |
228 void SetActiveURL(GURL url) { url_ = url; } | 243 void SetActiveURL(GURL url) { url_ = url; } |
229 | 244 |
| 245 const gfx::Image available_favicon() { return available_image_; } |
| 246 |
| 247 const GURL available_icon_url() { return available_icon_url_; } |
| 248 |
| 249 bool update_active_favicon() { return update_active_favicon_; } |
| 250 |
230 private: | 251 private: |
231 GURL favicon_url_; | 252 GURL favicon_url_; |
232 GURL url_; | 253 GURL url_; |
233 gfx::Image image_; | 254 gfx::Image image_; |
234 bool favicon_validity_; | 255 bool favicon_validity_; |
| 256 |
| 257 // The number of times that NotifyFaviconAvailable() has been called. |
| 258 size_t num_favicon_available_; |
| 259 gfx::Image available_image_; |
| 260 GURL available_icon_url_; |
| 261 bool update_active_favicon_; |
| 262 |
235 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); | 263 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); |
236 }; | 264 }; |
237 | 265 |
238 // This class is used to catch the FaviconHandler's download and history | 266 // This class is used to catch the FaviconHandler's download and history |
239 // request, and also provide the methods to access the FaviconHandler | 267 // request, and also provide the methods to access the FaviconHandler |
240 // internals. | 268 // internals. |
241 class TestFaviconHandler : public FaviconHandler { | 269 class TestFaviconHandler : public FaviconHandler { |
242 public: | 270 public: |
243 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 271 static int GetMaximalIconSize(favicon_base::IconType icon_type) { |
244 return FaviconHandler::GetMaximalIconSize(icon_type); | 272 return FaviconHandler::GetMaximalIconSize(icon_type); |
245 } | 273 } |
246 | 274 |
247 TestFaviconHandler(const GURL& page_url, | 275 TestFaviconHandler(const GURL& page_url, |
248 FaviconClient* client, | 276 FaviconClient* client, |
249 TestFaviconDriver* driver, | 277 TestFaviconDriver* driver, |
250 Type type, | 278 Type type, |
251 bool download_largest_icon) | 279 bool download_largest_icon) |
252 : FaviconHandler(client, driver, type, download_largest_icon), | 280 : FaviconHandler(client, driver, type, download_largest_icon), |
253 download_id_(0), | 281 download_id_(0) { |
254 num_favicon_updates_(0) { | |
255 driver->SetActiveURL(page_url); | 282 driver->SetActiveURL(page_url); |
256 download_handler_.reset(new DownloadHandler(this)); | 283 download_handler_.reset(new DownloadHandler(this)); |
257 } | 284 } |
258 | 285 |
259 ~TestFaviconHandler() override {} | 286 ~TestFaviconHandler() override {} |
260 | 287 |
261 HistoryRequestHandler* history_handler() { | 288 HistoryRequestHandler* history_handler() { |
262 return history_handler_.get(); | 289 return history_handler_.get(); |
263 } | 290 } |
264 | 291 |
265 // This method will take the ownership of the given handler. | 292 // This method will take the ownership of the given handler. |
266 void set_history_handler(HistoryRequestHandler* handler) { | 293 void set_history_handler(HistoryRequestHandler* handler) { |
267 history_handler_.reset(handler); | 294 history_handler_.reset(handler); |
268 } | 295 } |
269 | 296 |
270 DownloadHandler* download_handler() { | 297 DownloadHandler* download_handler() { |
271 return download_handler_.get(); | 298 return download_handler_.get(); |
272 } | 299 } |
273 | 300 |
274 size_t num_favicon_update_notifications() const { | |
275 return num_favicon_updates_; | |
276 } | |
277 | |
278 void ResetNumFaviconUpdateNotifications() { | |
279 num_favicon_updates_ = 0; | |
280 } | |
281 | |
282 // Methods to access favicon internals. | 301 // Methods to access favicon internals. |
283 const std::vector<FaviconURL>& urls() { | 302 const std::vector<FaviconURL>& urls() { |
284 return image_urls_; | 303 return image_urls_; |
285 } | 304 } |
286 | 305 |
287 FaviconURL* current_candidate() { | 306 FaviconURL* current_candidate() { |
288 return FaviconHandler::current_candidate(); | 307 return FaviconHandler::current_candidate(); |
289 } | 308 } |
290 | 309 |
291 const FaviconCandidate& best_favicon_candidate() { | 310 const FaviconCandidate& best_favicon_candidate() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 const gfx::Image& image) override { | 355 const gfx::Image& image) override { |
337 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 356 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
338 std::vector<unsigned char> bitmap_data(bytes->front(), | 357 std::vector<unsigned char> bitmap_data(bytes->front(), |
339 bytes->front() + bytes->size()); | 358 bytes->front() + bytes->size()); |
340 history_handler_.reset(new HistoryRequestHandler( | 359 history_handler_.reset(new HistoryRequestHandler( |
341 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 360 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
342 } | 361 } |
343 | 362 |
344 bool ShouldSaveFavicon(const GURL& url) override { return true; } | 363 bool ShouldSaveFavicon(const GURL& url) override { return true; } |
345 | 364 |
346 void NotifyFaviconUpdated(bool icon_url_changed) override { | |
347 ++num_favicon_updates_; | |
348 } | |
349 | |
350 GURL page_url_; | 365 GURL page_url_; |
351 | 366 |
352 private: | 367 private: |
353 | 368 |
354 // The unique id of a download request. It will be returned to a | 369 // The unique id of a download request. It will be returned to a |
355 // FaviconHandler. | 370 // FaviconHandler. |
356 int download_id_; | 371 int download_id_; |
357 | 372 |
358 scoped_ptr<DownloadHandler> download_handler_; | 373 scoped_ptr<DownloadHandler> download_handler_; |
359 scoped_ptr<HistoryRequestHandler> history_handler_; | 374 scoped_ptr<HistoryRequestHandler> history_handler_; |
360 | 375 |
361 // The number of times that NotifyFaviconUpdated() has been called. | |
362 size_t num_favicon_updates_; | |
363 | |
364 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 376 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
365 }; | 377 }; |
366 | 378 |
367 namespace { | 379 namespace { |
368 | 380 |
369 void HistoryRequestHandler::InvokeCallback() { | 381 void HistoryRequestHandler::InvokeCallback() { |
370 if (!callback_.is_null()) { | 382 if (!callback_.is_null()) { |
371 callback_.Run(history_results_); | 383 callback_.Run(history_results_); |
372 } | 384 } |
373 } | 385 } |
(...skipping 29 matching lines...) Expand all Loading... |
403 | 415 |
404 ~FaviconHandlerTest() override {} | 416 ~FaviconHandlerTest() override {} |
405 | 417 |
406 // Simulates requesting a favicon for |page_url| given: | 418 // Simulates requesting a favicon for |page_url| given: |
407 // - We have not previously cached anything in history for |page_url| or for | 419 // - We have not previously cached anything in history for |page_url| or for |
408 // any of |candidates|. | 420 // any of |candidates|. |
409 // - The page provides favicons at |candidate_icons|. | 421 // - The page provides favicons at |candidate_icons|. |
410 // - The favicons at |candidate_icons| have edge pixel sizes of | 422 // - The favicons at |candidate_icons| have edge pixel sizes of |
411 // |candidate_icon_sizes|. | 423 // |candidate_icon_sizes|. |
412 void DownloadTillDoneIgnoringHistory( | 424 void DownloadTillDoneIgnoringHistory( |
| 425 TestFaviconDriver* favicon_driver, |
413 TestFaviconHandler* favicon_handler, | 426 TestFaviconHandler* favicon_handler, |
414 const GURL& page_url, | 427 const GURL& page_url, |
415 const std::vector<FaviconURL>& candidate_icons, | 428 const std::vector<FaviconURL>& candidate_icons, |
416 const int* candidate_icon_sizes) { | 429 const int* candidate_icon_sizes) { |
417 UpdateFaviconURL(favicon_handler, page_url, candidate_icons); | 430 UpdateFaviconURL( |
| 431 favicon_driver, favicon_handler, page_url, candidate_icons); |
418 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 432 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
419 | 433 |
420 DownloadHandler* download_handler = favicon_handler->download_handler(); | 434 DownloadHandler* download_handler = favicon_handler->download_handler(); |
421 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 435 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
422 favicon_handler->history_handler()->history_results_.clear(); | 436 favicon_handler->history_handler()->history_results_.clear(); |
423 favicon_handler->history_handler()->InvokeCallback(); | 437 favicon_handler->history_handler()->InvokeCallback(); |
424 ASSERT_TRUE(download_handler->HasDownload()); | 438 ASSERT_TRUE(download_handler->HasDownload()); |
425 EXPECT_EQ(download_handler->GetImageUrl(), | 439 EXPECT_EQ(download_handler->GetImageUrl(), |
426 candidate_icons[i].icon_url); | 440 candidate_icons[i].icon_url); |
427 std::vector<int> sizes; | 441 std::vector<int> sizes; |
428 sizes.push_back(candidate_icon_sizes[i]); | 442 sizes.push_back(candidate_icon_sizes[i]); |
429 download_handler->SetImageSizes(sizes); | 443 download_handler->SetImageSizes(sizes); |
430 download_handler->InvokeCallback(); | 444 download_handler->InvokeCallback(); |
431 | 445 |
432 if (favicon_handler->num_favicon_update_notifications()) | 446 if (favicon_driver->num_favicon_available()) |
433 return; | 447 return; |
434 } | 448 } |
435 } | 449 } |
436 | 450 |
437 void UpdateFaviconURL( | 451 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, |
438 TestFaviconHandler* favicon_handler, | 452 TestFaviconHandler* favicon_handler, |
439 const GURL& page_url, | 453 const GURL& page_url, |
440 const std::vector<FaviconURL>& candidate_icons) { | 454 const std::vector<FaviconURL>& candidate_icons) { |
441 favicon_handler->ResetNumFaviconUpdateNotifications(); | 455 favicon_driver->ResetNumFaviconAvailable(); |
442 | 456 |
443 favicon_handler->FetchFavicon(page_url); | 457 favicon_handler->FetchFavicon(page_url); |
444 favicon_handler->history_handler()->InvokeCallback(); | 458 favicon_handler->history_handler()->InvokeCallback(); |
445 | 459 |
446 favicon_handler->OnUpdateFaviconURL(candidate_icons); | 460 favicon_handler->OnUpdateFaviconURL(candidate_icons); |
447 } | 461 } |
448 | 462 |
449 void SetUp() override { | 463 void SetUp() override { |
450 // The score computed by SelectFaviconFrames() is dependent on the supported | 464 // The score computed by SelectFaviconFrames() is dependent on the supported |
451 // scale factors of the platform. It is used for determining the goodness of | 465 // scale factors of the platform. It is used for determining the goodness of |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 // 1) Test that if there are several single resolution favicons to choose from | 1077 // 1) Test that if there are several single resolution favicons to choose from |
1064 // that the largest exact match is chosen. | 1078 // that the largest exact match is chosen. |
1065 TestFaviconDriver driver1; | 1079 TestFaviconDriver driver1; |
1066 TestFaviconClient client; | 1080 TestFaviconClient client; |
1067 TestFaviconHandler handler1( | 1081 TestFaviconHandler handler1( |
1068 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); | 1082 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); |
1069 | 1083 |
1070 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1084 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1071 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1085 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1072 kSourceIconURLs + arraysize(kSizes1)); | 1086 kSourceIconURLs + arraysize(kSizes1)); |
1073 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); | 1087 DownloadTillDoneIgnoringHistory( |
| 1088 &driver1, &handler1, kPageURL, urls1, kSizes1); |
1074 | 1089 |
1075 EXPECT_EQ(0u, handler1.image_urls().size()); | 1090 EXPECT_EQ(0u, handler1.image_urls().size()); |
1076 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); | 1091 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); |
1077 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); | 1092 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); |
1078 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); | 1093 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); |
1079 | 1094 |
1080 size_t expected_index = 2u; | 1095 size_t expected_index = 2u; |
1081 EXPECT_EQ(32, kSizes1[expected_index]); | 1096 EXPECT_EQ(32, kSizes1[expected_index]); |
1082 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1097 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1083 driver1.GetActiveFaviconURL()); | 1098 driver1.GetActiveFaviconURL()); |
1084 | 1099 |
1085 // 2) Test that if there are several single resolution favicons to choose | 1100 // 2) Test that if there are several single resolution favicons to choose |
1086 // from, the exact match is preferred even if it results in upsampling. | 1101 // from, the exact match is preferred even if it results in upsampling. |
1087 TestFaviconDriver driver2; | 1102 TestFaviconDriver driver2; |
1088 TestFaviconHandler handler2( | 1103 TestFaviconHandler handler2( |
1089 kPageURL, &client, &driver2, FaviconHandler::FAVICON, false); | 1104 kPageURL, &client, &driver2, FaviconHandler::FAVICON, false); |
1090 | 1105 |
1091 const int kSizes2[] = { 16, 24, 48, 256 }; | 1106 const int kSizes2[] = { 16, 24, 48, 256 }; |
1092 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1107 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1093 kSourceIconURLs + arraysize(kSizes2)); | 1108 kSourceIconURLs + arraysize(kSizes2)); |
1094 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); | 1109 DownloadTillDoneIgnoringHistory( |
| 1110 &driver2, &handler2, kPageURL, urls2, kSizes2); |
1095 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); | 1111 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); |
1096 expected_index = 0u; | 1112 expected_index = 0u; |
1097 EXPECT_EQ(16, kSizes2[expected_index]); | 1113 EXPECT_EQ(16, kSizes2[expected_index]); |
1098 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1114 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1099 driver2.GetActiveFaviconURL()); | 1115 driver2.GetActiveFaviconURL()); |
1100 | 1116 |
1101 // 3) Test that favicons which need to be upsampled a little or downsampled | 1117 // 3) Test that favicons which need to be upsampled a little or downsampled |
1102 // a little are preferred over huge favicons. | 1118 // a little are preferred over huge favicons. |
1103 TestFaviconDriver driver3; | 1119 TestFaviconDriver driver3; |
1104 TestFaviconHandler handler3( | 1120 TestFaviconHandler handler3( |
1105 kPageURL, &client, &driver3, FaviconHandler::FAVICON, false); | 1121 kPageURL, &client, &driver3, FaviconHandler::FAVICON, false); |
1106 | 1122 |
1107 const int kSizes3[] = { 256, 48 }; | 1123 const int kSizes3[] = { 256, 48 }; |
1108 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1124 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1109 kSourceIconURLs + arraysize(kSizes3)); | 1125 kSourceIconURLs + arraysize(kSizes3)); |
1110 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); | 1126 DownloadTillDoneIgnoringHistory( |
| 1127 &driver3, &handler3, kPageURL, urls3, kSizes3); |
1111 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); | 1128 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); |
1112 expected_index = 1u; | 1129 expected_index = 1u; |
1113 EXPECT_EQ(48, kSizes3[expected_index]); | 1130 EXPECT_EQ(48, kSizes3[expected_index]); |
1114 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1131 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1115 driver3.GetActiveFaviconURL()); | 1132 driver3.GetActiveFaviconURL()); |
1116 | 1133 |
1117 TestFaviconDriver driver4; | 1134 TestFaviconDriver driver4; |
1118 TestFaviconHandler handler4( | 1135 TestFaviconHandler handler4( |
1119 kPageURL, &client, &driver4, FaviconHandler::FAVICON, false); | 1136 kPageURL, &client, &driver4, FaviconHandler::FAVICON, false); |
1120 | 1137 |
1121 const int kSizes4[] = { 17, 256 }; | 1138 const int kSizes4[] = { 17, 256 }; |
1122 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1139 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1123 kSourceIconURLs + arraysize(kSizes4)); | 1140 kSourceIconURLs + arraysize(kSizes4)); |
1124 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); | 1141 DownloadTillDoneIgnoringHistory( |
| 1142 &driver4, &handler4, kPageURL, urls4, kSizes4); |
1125 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); | 1143 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); |
1126 expected_index = 0u; | 1144 expected_index = 0u; |
1127 EXPECT_EQ(17, kSizes4[expected_index]); | 1145 EXPECT_EQ(17, kSizes4[expected_index]); |
1128 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1146 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1129 driver4.GetActiveFaviconURL()); | 1147 driver4.GetActiveFaviconURL()); |
1130 } | 1148 } |
1131 | 1149 |
1132 #endif | 1150 #endif |
1133 | 1151 |
1134 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1152 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
(...skipping 20 matching lines...) Expand all Loading... |
1155 FaviconURL(GURL("http://www.google.com/e"), | 1173 FaviconURL(GURL("http://www.google.com/e"), |
1156 favicon_base::FAVICON, | 1174 favicon_base::FAVICON, |
1157 std::vector<gfx::Size>())}; | 1175 std::vector<gfx::Size>())}; |
1158 | 1176 |
1159 TestFaviconClient client; | 1177 TestFaviconClient client; |
1160 TestFaviconDriver driver1; | 1178 TestFaviconDriver driver1; |
1161 TestFaviconHandler handler1( | 1179 TestFaviconHandler handler1( |
1162 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1180 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1163 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1181 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1164 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1182 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1165 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1183 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1166 | 1184 |
1167 struct ExpectedResult { | 1185 struct ExpectedResult { |
1168 // The favicon's index in kSourceIconURLs. | 1186 // The favicon's index in kSourceIconURLs. |
1169 size_t favicon_index; | 1187 size_t favicon_index; |
1170 // Width of largest bitmap. | 1188 // Width of largest bitmap. |
1171 int width; | 1189 int width; |
1172 } results[] = { | 1190 } results[] = { |
1173 // First is icon1, though its size larger than maximal. | 1191 // First is icon1, though its size larger than maximal. |
1174 {0, 1024}, | 1192 {0, 1024}, |
1175 // Second is icon2 | 1193 // Second is icon2 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 FaviconURL(GURL("http://www.google.com/e"), | 1237 FaviconURL(GURL("http://www.google.com/e"), |
1220 favicon_base::FAVICON, | 1238 favicon_base::FAVICON, |
1221 std::vector<gfx::Size>())}; | 1239 std::vector<gfx::Size>())}; |
1222 | 1240 |
1223 TestFaviconClient client; | 1241 TestFaviconClient client; |
1224 TestFaviconDriver driver1; | 1242 TestFaviconDriver driver1; |
1225 TestFaviconHandler handler1( | 1243 TestFaviconHandler handler1( |
1226 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1244 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1227 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1245 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1228 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1246 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1229 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1247 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1230 | 1248 |
1231 // Simulate the download failed, to check whether the icons were requested | 1249 // Simulate the download failed, to check whether the icons were requested |
1232 // to download according their size. | 1250 // to download according their size. |
1233 struct ExpectedResult { | 1251 struct ExpectedResult { |
1234 // The size of image_urls_. | 1252 // The size of image_urls_. |
1235 size_t image_urls_size; | 1253 size_t image_urls_size; |
1236 // The favicon's index in kSourceIconURLs. | 1254 // The favicon's index in kSourceIconURLs. |
1237 size_t favicon_index; | 1255 size_t favicon_index; |
1238 // Width of largest bitmap. | 1256 // Width of largest bitmap. |
1239 int width; | 1257 int width; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1303 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
1286 FaviconURL( | 1304 FaviconURL( |
1287 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1305 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
1288 | 1306 |
1289 TestFaviconClient client; | 1307 TestFaviconClient client; |
1290 TestFaviconDriver driver1; | 1308 TestFaviconDriver driver1; |
1291 TestFaviconHandler handler1( | 1309 TestFaviconHandler handler1( |
1292 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1310 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1293 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1311 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1294 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1312 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1295 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1313 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1296 | 1314 |
1297 ASSERT_EQ(2u, handler1.urls().size()); | 1315 ASSERT_EQ(2u, handler1.urls().size()); |
1298 | 1316 |
1299 // Index of largest favicon in kSourceIconURLs. | 1317 // Index of largest favicon in kSourceIconURLs. |
1300 size_t i = 1; | 1318 size_t i = 1; |
1301 // The largest bitmap's index in Favicon . | 1319 // The largest bitmap's index in Favicon . |
1302 int b = 1; | 1320 int b = 1; |
1303 | 1321 |
1304 // Verify the icon_bitmaps_ was initialized correctly. | 1322 // Verify the icon_bitmaps_ was initialized correctly. |
1305 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1323 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
(...skipping 17 matching lines...) Expand all Loading... |
1323 j != kSourceIconURLs[i].icon_sizes.end(); ++j) | 1341 j != kSourceIconURLs[i].icon_sizes.end(); ++j) |
1324 sizes.push_back(j->width()); | 1342 sizes.push_back(j->width()); |
1325 | 1343 |
1326 handler1.download_handler()->SetImageSizes(sizes); | 1344 handler1.download_handler()->SetImageSizes(sizes); |
1327 handler1.download_handler()->InvokeCallback(); | 1345 handler1.download_handler()->InvokeCallback(); |
1328 | 1346 |
1329 // Verify the largest bitmap has been saved into history. | 1347 // Verify the largest bitmap has been saved into history. |
1330 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1348 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1331 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1349 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1332 handler1.history_handler()->size_); | 1350 handler1.history_handler()->size_); |
| 1351 // Verify NotifyFaviconAvailable(). |
| 1352 EXPECT_FALSE(driver1.update_active_favicon()); |
| 1353 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.available_icon_url()); |
| 1354 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
| 1355 driver1.available_favicon().Size()); |
1333 } | 1356 } |
1334 | 1357 |
1335 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1358 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
1336 const GURL kPageURL("http://www.google.com"); | 1359 const GURL kPageURL("http://www.google.com"); |
1337 const int kMaximalSize = | 1360 const int kMaximalSize = |
1338 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1361 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
1339 | 1362 |
1340 std::vector<gfx::Size> icon1; | 1363 std::vector<gfx::Size> icon1; |
1341 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1364 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
1342 | 1365 |
1343 std::vector<gfx::Size> icon2; | 1366 std::vector<gfx::Size> icon2; |
1344 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1367 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
1345 | 1368 |
1346 const FaviconURL kSourceIconURLs[] = { | 1369 const FaviconURL kSourceIconURLs[] = { |
1347 FaviconURL( | 1370 FaviconURL( |
1348 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1371 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1349 FaviconURL( | 1372 FaviconURL( |
1350 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1373 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
1351 | 1374 |
1352 TestFaviconClient client; | 1375 TestFaviconClient client; |
1353 TestFaviconDriver driver1; | 1376 TestFaviconDriver driver1; |
1354 TestFaviconHandler handler1( | 1377 TestFaviconHandler handler1( |
1355 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1378 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1356 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1379 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1357 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1380 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1358 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1381 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1359 | 1382 |
1360 ASSERT_EQ(2u, handler1.urls().size()); | 1383 ASSERT_EQ(2u, handler1.urls().size()); |
1361 | 1384 |
1362 // Index of largest favicon in kSourceIconURLs. | 1385 // Index of largest favicon in kSourceIconURLs. |
1363 size_t i = 1; | 1386 size_t i = 1; |
1364 // The largest bitmap's index in Favicon . | 1387 // The largest bitmap's index in Favicon . |
1365 int b = 0; | 1388 int b = 0; |
1366 | 1389 |
1367 // Verify the icon_bitmaps_ was initialized correctly. | 1390 // Verify the icon_bitmaps_ was initialized correctly. |
1368 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1391 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 FaviconURL(GURL("http://www.google.com/d"), | 1433 FaviconURL(GURL("http://www.google.com/d"), |
1411 favicon_base::FAVICON, | 1434 favicon_base::FAVICON, |
1412 std::vector<gfx::Size>())}; | 1435 std::vector<gfx::Size>())}; |
1413 | 1436 |
1414 TestFaviconClient client; | 1437 TestFaviconClient client; |
1415 TestFaviconDriver driver1; | 1438 TestFaviconDriver driver1; |
1416 TestFaviconHandler handler1( | 1439 TestFaviconHandler handler1( |
1417 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1440 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1418 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1441 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1419 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1442 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1420 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1443 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1421 ASSERT_EQ(3u, handler1.urls().size()); | 1444 ASSERT_EQ(3u, handler1.urls().size()); |
1422 | 1445 |
1423 // Simulate no favicon from history. | 1446 // Simulate no favicon from history. |
1424 handler1.history_handler()->history_results_.clear(); | 1447 handler1.history_handler()->history_results_.clear(); |
1425 handler1.history_handler()->InvokeCallback(); | 1448 handler1.history_handler()->InvokeCallback(); |
1426 | 1449 |
1427 // Verify the first icon was request to download | 1450 // Verify the first icon was request to download |
1428 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1451 ASSERT_TRUE(handler1.download_handler()->HasDownload()); |
1429 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1452 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1430 handler1.download_handler()->GetImageUrl()); | 1453 handler1.download_handler()->GetImageUrl()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1564 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1542 EXPECT_NE(0, download_id); | 1565 EXPECT_NE(0, download_id); |
1543 // Report download success with HTTP 200 status. | 1566 // Report download success with HTTP 200 status. |
1544 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1567 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1545 empty_icons, empty_icon_sizes); | 1568 empty_icons, empty_icon_sizes); |
1546 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1569 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1547 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1570 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1548 } | 1571 } |
1549 | 1572 |
1550 } // namespace. | 1573 } // namespace. |
OLD | NEW |