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 30 matching lines...) Expand all Loading... |
404 virtual ~FaviconHandlerTest() { | 416 virtual ~FaviconHandlerTest() { |
405 } | 417 } |
406 | 418 |
407 // Simulates requesting a favicon for |page_url| given: | 419 // Simulates requesting a favicon for |page_url| given: |
408 // - We have not previously cached anything in history for |page_url| or for | 420 // - We have not previously cached anything in history for |page_url| or for |
409 // any of |candidates|. | 421 // any of |candidates|. |
410 // - The page provides favicons at |candidate_icons|. | 422 // - The page provides favicons at |candidate_icons|. |
411 // - The favicons at |candidate_icons| have edge pixel sizes of | 423 // - The favicons at |candidate_icons| have edge pixel sizes of |
412 // |candidate_icon_sizes|. | 424 // |candidate_icon_sizes|. |
413 void DownloadTillDoneIgnoringHistory( | 425 void DownloadTillDoneIgnoringHistory( |
| 426 TestFaviconDriver* favicon_driver, |
414 TestFaviconHandler* favicon_handler, | 427 TestFaviconHandler* favicon_handler, |
415 const GURL& page_url, | 428 const GURL& page_url, |
416 const std::vector<FaviconURL>& candidate_icons, | 429 const std::vector<FaviconURL>& candidate_icons, |
417 const int* candidate_icon_sizes) { | 430 const int* candidate_icon_sizes) { |
418 UpdateFaviconURL(favicon_handler, page_url, candidate_icons); | 431 UpdateFaviconURL( |
| 432 favicon_driver, favicon_handler, page_url, candidate_icons); |
419 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 433 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
420 | 434 |
421 DownloadHandler* download_handler = favicon_handler->download_handler(); | 435 DownloadHandler* download_handler = favicon_handler->download_handler(); |
422 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 436 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
423 favicon_handler->history_handler()->history_results_.clear(); | 437 favicon_handler->history_handler()->history_results_.clear(); |
424 favicon_handler->history_handler()->InvokeCallback(); | 438 favicon_handler->history_handler()->InvokeCallback(); |
425 ASSERT_TRUE(download_handler->HasDownload()); | 439 ASSERT_TRUE(download_handler->HasDownload()); |
426 EXPECT_EQ(download_handler->GetImageUrl(), | 440 EXPECT_EQ(download_handler->GetImageUrl(), |
427 candidate_icons[i].icon_url); | 441 candidate_icons[i].icon_url); |
428 std::vector<int> sizes; | 442 std::vector<int> sizes; |
429 sizes.push_back(candidate_icon_sizes[i]); | 443 sizes.push_back(candidate_icon_sizes[i]); |
430 download_handler->SetImageSizes(sizes); | 444 download_handler->SetImageSizes(sizes); |
431 download_handler->InvokeCallback(); | 445 download_handler->InvokeCallback(); |
432 | 446 |
433 if (favicon_handler->num_favicon_update_notifications()) | 447 if (favicon_driver->num_favicon_available()) |
434 return; | 448 return; |
435 } | 449 } |
436 } | 450 } |
437 | 451 |
438 void UpdateFaviconURL( | 452 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, |
439 TestFaviconHandler* favicon_handler, | 453 TestFaviconHandler* favicon_handler, |
440 const GURL& page_url, | 454 const GURL& page_url, |
441 const std::vector<FaviconURL>& candidate_icons) { | 455 const std::vector<FaviconURL>& candidate_icons) { |
442 favicon_handler->ResetNumFaviconUpdateNotifications(); | 456 favicon_driver->ResetNumFaviconAvailable(); |
443 | 457 |
444 favicon_handler->FetchFavicon(page_url); | 458 favicon_handler->FetchFavicon(page_url); |
445 favicon_handler->history_handler()->InvokeCallback(); | 459 favicon_handler->history_handler()->InvokeCallback(); |
446 | 460 |
447 favicon_handler->OnUpdateFaviconURL(candidate_icons); | 461 favicon_handler->OnUpdateFaviconURL(candidate_icons); |
448 } | 462 } |
449 | 463 |
450 virtual void SetUp() { | 464 virtual void SetUp() { |
451 // The score computed by SelectFaviconFrames() is dependent on the supported | 465 // The score computed by SelectFaviconFrames() is dependent on the supported |
452 // scale factors of the platform. It is used for determining the goodness of | 466 // 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... |
1064 // 1) Test that if there are several single resolution favicons to choose from | 1078 // 1) Test that if there are several single resolution favicons to choose from |
1065 // that the largest exact match is chosen. | 1079 // that the largest exact match is chosen. |
1066 TestFaviconDriver driver1; | 1080 TestFaviconDriver driver1; |
1067 TestFaviconClient client; | 1081 TestFaviconClient client; |
1068 TestFaviconHandler handler1( | 1082 TestFaviconHandler handler1( |
1069 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); | 1083 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); |
1070 | 1084 |
1071 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1085 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1072 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1086 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1073 kSourceIconURLs + arraysize(kSizes1)); | 1087 kSourceIconURLs + arraysize(kSizes1)); |
1074 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); | 1088 DownloadTillDoneIgnoringHistory( |
| 1089 &driver1, &handler1, kPageURL, urls1, kSizes1); |
1075 | 1090 |
1076 EXPECT_EQ(0u, handler1.image_urls().size()); | 1091 EXPECT_EQ(0u, handler1.image_urls().size()); |
1077 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); | 1092 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); |
1078 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); | 1093 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); |
1079 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); | 1094 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); |
1080 | 1095 |
1081 size_t expected_index = 2u; | 1096 size_t expected_index = 2u; |
1082 EXPECT_EQ(32, kSizes1[expected_index]); | 1097 EXPECT_EQ(32, kSizes1[expected_index]); |
1083 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1098 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1084 driver1.GetActiveFaviconURL()); | 1099 driver1.GetActiveFaviconURL()); |
1085 | 1100 |
1086 // 2) Test that if there are several single resolution favicons to choose | 1101 // 2) Test that if there are several single resolution favicons to choose |
1087 // from, the exact match is preferred even if it results in upsampling. | 1102 // from, the exact match is preferred even if it results in upsampling. |
1088 TestFaviconDriver driver2; | 1103 TestFaviconDriver driver2; |
1089 TestFaviconHandler handler2( | 1104 TestFaviconHandler handler2( |
1090 kPageURL, &client, &driver2, FaviconHandler::FAVICON, false); | 1105 kPageURL, &client, &driver2, FaviconHandler::FAVICON, false); |
1091 | 1106 |
1092 const int kSizes2[] = { 16, 24, 48, 256 }; | 1107 const int kSizes2[] = { 16, 24, 48, 256 }; |
1093 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1108 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1094 kSourceIconURLs + arraysize(kSizes2)); | 1109 kSourceIconURLs + arraysize(kSizes2)); |
1095 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); | 1110 DownloadTillDoneIgnoringHistory( |
| 1111 &driver2, &handler2, kPageURL, urls2, kSizes2); |
1096 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); | 1112 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); |
1097 expected_index = 0u; | 1113 expected_index = 0u; |
1098 EXPECT_EQ(16, kSizes2[expected_index]); | 1114 EXPECT_EQ(16, kSizes2[expected_index]); |
1099 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1115 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1100 driver2.GetActiveFaviconURL()); | 1116 driver2.GetActiveFaviconURL()); |
1101 | 1117 |
1102 // 3) Test that favicons which need to be upsampled a little or downsampled | 1118 // 3) Test that favicons which need to be upsampled a little or downsampled |
1103 // a little are preferred over huge favicons. | 1119 // a little are preferred over huge favicons. |
1104 TestFaviconDriver driver3; | 1120 TestFaviconDriver driver3; |
1105 TestFaviconHandler handler3( | 1121 TestFaviconHandler handler3( |
1106 kPageURL, &client, &driver3, FaviconHandler::FAVICON, false); | 1122 kPageURL, &client, &driver3, FaviconHandler::FAVICON, false); |
1107 | 1123 |
1108 const int kSizes3[] = { 256, 48 }; | 1124 const int kSizes3[] = { 256, 48 }; |
1109 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1125 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1110 kSourceIconURLs + arraysize(kSizes3)); | 1126 kSourceIconURLs + arraysize(kSizes3)); |
1111 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); | 1127 DownloadTillDoneIgnoringHistory( |
| 1128 &driver3, &handler3, kPageURL, urls3, kSizes3); |
1112 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); | 1129 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); |
1113 expected_index = 1u; | 1130 expected_index = 1u; |
1114 EXPECT_EQ(48, kSizes3[expected_index]); | 1131 EXPECT_EQ(48, kSizes3[expected_index]); |
1115 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1132 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1116 driver3.GetActiveFaviconURL()); | 1133 driver3.GetActiveFaviconURL()); |
1117 | 1134 |
1118 TestFaviconDriver driver4; | 1135 TestFaviconDriver driver4; |
1119 TestFaviconHandler handler4( | 1136 TestFaviconHandler handler4( |
1120 kPageURL, &client, &driver4, FaviconHandler::FAVICON, false); | 1137 kPageURL, &client, &driver4, FaviconHandler::FAVICON, false); |
1121 | 1138 |
1122 const int kSizes4[] = { 17, 256 }; | 1139 const int kSizes4[] = { 17, 256 }; |
1123 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1140 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1124 kSourceIconURLs + arraysize(kSizes4)); | 1141 kSourceIconURLs + arraysize(kSizes4)); |
1125 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); | 1142 DownloadTillDoneIgnoringHistory( |
| 1143 &driver4, &handler4, kPageURL, urls4, kSizes4); |
1126 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); | 1144 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); |
1127 expected_index = 0u; | 1145 expected_index = 0u; |
1128 EXPECT_EQ(17, kSizes4[expected_index]); | 1146 EXPECT_EQ(17, kSizes4[expected_index]); |
1129 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1147 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1130 driver4.GetActiveFaviconURL()); | 1148 driver4.GetActiveFaviconURL()); |
1131 } | 1149 } |
1132 | 1150 |
1133 #endif | 1151 #endif |
1134 | 1152 |
1135 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1153 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
(...skipping 20 matching lines...) Expand all Loading... |
1156 FaviconURL(GURL("http://www.google.com/e"), | 1174 FaviconURL(GURL("http://www.google.com/e"), |
1157 favicon_base::FAVICON, | 1175 favicon_base::FAVICON, |
1158 std::vector<gfx::Size>())}; | 1176 std::vector<gfx::Size>())}; |
1159 | 1177 |
1160 TestFaviconClient client; | 1178 TestFaviconClient client; |
1161 TestFaviconDriver driver1; | 1179 TestFaviconDriver driver1; |
1162 TestFaviconHandler handler1( | 1180 TestFaviconHandler handler1( |
1163 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1181 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1164 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1182 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1165 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1183 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1166 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1184 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1167 | 1185 |
1168 struct ExpectedResult { | 1186 struct ExpectedResult { |
1169 // The favicon's index in kSourceIconURLs. | 1187 // The favicon's index in kSourceIconURLs. |
1170 size_t favicon_index; | 1188 size_t favicon_index; |
1171 // Width of largest bitmap. | 1189 // Width of largest bitmap. |
1172 int width; | 1190 int width; |
1173 } results[] = { | 1191 } results[] = { |
1174 // First is icon1, though its size larger than maximal. | 1192 // First is icon1, though its size larger than maximal. |
1175 {0, 1024}, | 1193 {0, 1024}, |
1176 // Second is icon2 | 1194 // Second is icon2 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 FaviconURL(GURL("http://www.google.com/e"), | 1238 FaviconURL(GURL("http://www.google.com/e"), |
1221 favicon_base::FAVICON, | 1239 favicon_base::FAVICON, |
1222 std::vector<gfx::Size>())}; | 1240 std::vector<gfx::Size>())}; |
1223 | 1241 |
1224 TestFaviconClient client; | 1242 TestFaviconClient client; |
1225 TestFaviconDriver driver1; | 1243 TestFaviconDriver driver1; |
1226 TestFaviconHandler handler1( | 1244 TestFaviconHandler handler1( |
1227 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1245 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1228 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1246 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1229 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1247 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1230 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1248 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1231 | 1249 |
1232 // Simulate the download failed, to check whether the icons were requested | 1250 // Simulate the download failed, to check whether the icons were requested |
1233 // to download according their size. | 1251 // to download according their size. |
1234 struct ExpectedResult { | 1252 struct ExpectedResult { |
1235 // The size of image_urls_. | 1253 // The size of image_urls_. |
1236 size_t image_urls_size; | 1254 size_t image_urls_size; |
1237 // The favicon's index in kSourceIconURLs. | 1255 // The favicon's index in kSourceIconURLs. |
1238 size_t favicon_index; | 1256 size_t favicon_index; |
1239 // Width of largest bitmap. | 1257 // Width of largest bitmap. |
1240 int width; | 1258 int width; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1304 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
1287 FaviconURL( | 1305 FaviconURL( |
1288 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1306 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
1289 | 1307 |
1290 TestFaviconClient client; | 1308 TestFaviconClient client; |
1291 TestFaviconDriver driver1; | 1309 TestFaviconDriver driver1; |
1292 TestFaviconHandler handler1( | 1310 TestFaviconHandler handler1( |
1293 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1311 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1294 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1312 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1295 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1313 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1296 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1314 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1297 | 1315 |
1298 ASSERT_EQ(2u, handler1.urls().size()); | 1316 ASSERT_EQ(2u, handler1.urls().size()); |
1299 | 1317 |
1300 // Index of largest favicon in kSourceIconURLs. | 1318 // Index of largest favicon in kSourceIconURLs. |
1301 size_t i = 1; | 1319 size_t i = 1; |
1302 // The largest bitmap's index in Favicon . | 1320 // The largest bitmap's index in Favicon . |
1303 int b = 1; | 1321 int b = 1; |
1304 | 1322 |
1305 // Verify the icon_bitmaps_ was initialized correctly. | 1323 // Verify the icon_bitmaps_ was initialized correctly. |
1306 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1324 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
(...skipping 17 matching lines...) Expand all Loading... |
1324 j != kSourceIconURLs[i].icon_sizes.end(); ++j) | 1342 j != kSourceIconURLs[i].icon_sizes.end(); ++j) |
1325 sizes.push_back(j->width()); | 1343 sizes.push_back(j->width()); |
1326 | 1344 |
1327 handler1.download_handler()->SetImageSizes(sizes); | 1345 handler1.download_handler()->SetImageSizes(sizes); |
1328 handler1.download_handler()->InvokeCallback(); | 1346 handler1.download_handler()->InvokeCallback(); |
1329 | 1347 |
1330 // Verify the largest bitmap has been saved into history. | 1348 // Verify the largest bitmap has been saved into history. |
1331 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1349 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1332 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1350 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1333 handler1.history_handler()->size_); | 1351 handler1.history_handler()->size_); |
| 1352 // Verify NotifyFaviconAvailable(). |
| 1353 EXPECT_FALSE(driver1.update_active_favicon()); |
| 1354 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.available_icon_url()); |
| 1355 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
| 1356 driver1.available_favicon().Size()); |
1334 } | 1357 } |
1335 | 1358 |
1336 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1359 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
1337 const GURL kPageURL("http://www.google.com"); | 1360 const GURL kPageURL("http://www.google.com"); |
1338 const int kMaximalSize = | 1361 const int kMaximalSize = |
1339 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1362 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
1340 | 1363 |
1341 std::vector<gfx::Size> icon1; | 1364 std::vector<gfx::Size> icon1; |
1342 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1365 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
1343 | 1366 |
1344 std::vector<gfx::Size> icon2; | 1367 std::vector<gfx::Size> icon2; |
1345 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1368 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
1346 | 1369 |
1347 const FaviconURL kSourceIconURLs[] = { | 1370 const FaviconURL kSourceIconURLs[] = { |
1348 FaviconURL( | 1371 FaviconURL( |
1349 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1372 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1350 FaviconURL( | 1373 FaviconURL( |
1351 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1374 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
1352 | 1375 |
1353 TestFaviconClient client; | 1376 TestFaviconClient client; |
1354 TestFaviconDriver driver1; | 1377 TestFaviconDriver driver1; |
1355 TestFaviconHandler handler1( | 1378 TestFaviconHandler handler1( |
1356 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1379 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1357 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1380 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1358 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1381 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1359 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1382 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1360 | 1383 |
1361 ASSERT_EQ(2u, handler1.urls().size()); | 1384 ASSERT_EQ(2u, handler1.urls().size()); |
1362 | 1385 |
1363 // Index of largest favicon in kSourceIconURLs. | 1386 // Index of largest favicon in kSourceIconURLs. |
1364 size_t i = 1; | 1387 size_t i = 1; |
1365 // The largest bitmap's index in Favicon . | 1388 // The largest bitmap's index in Favicon . |
1366 int b = 0; | 1389 int b = 0; |
1367 | 1390 |
1368 // Verify the icon_bitmaps_ was initialized correctly. | 1391 // Verify the icon_bitmaps_ was initialized correctly. |
1369 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1392 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 FaviconURL(GURL("http://www.google.com/d"), | 1434 FaviconURL(GURL("http://www.google.com/d"), |
1412 favicon_base::FAVICON, | 1435 favicon_base::FAVICON, |
1413 std::vector<gfx::Size>())}; | 1436 std::vector<gfx::Size>())}; |
1414 | 1437 |
1415 TestFaviconClient client; | 1438 TestFaviconClient client; |
1416 TestFaviconDriver driver1; | 1439 TestFaviconDriver driver1; |
1417 TestFaviconHandler handler1( | 1440 TestFaviconHandler handler1( |
1418 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); | 1441 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
1419 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1442 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1420 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1443 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1421 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1444 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1422 ASSERT_EQ(3u, handler1.urls().size()); | 1445 ASSERT_EQ(3u, handler1.urls().size()); |
1423 | 1446 |
1424 // Simulate no favicon from history. | 1447 // Simulate no favicon from history. |
1425 handler1.history_handler()->history_results_.clear(); | 1448 handler1.history_handler()->history_results_.clear(); |
1426 handler1.history_handler()->InvokeCallback(); | 1449 handler1.history_handler()->InvokeCallback(); |
1427 | 1450 |
1428 // Verify the first icon was request to download | 1451 // Verify the first icon was request to download |
1429 ASSERT_TRUE(handler1.download_handler()->HasDownload()); | 1452 ASSERT_TRUE(handler1.download_handler()->HasDownload()); |
1430 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1453 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1431 handler1.download_handler()->GetImageUrl()); | 1454 handler1.download_handler()->GetImageUrl()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1565 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1543 EXPECT_NE(0, download_id); | 1566 EXPECT_NE(0, download_id); |
1544 // Report download success with HTTP 200 status. | 1567 // Report download success with HTTP 200 status. |
1545 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1568 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1546 empty_icons, empty_icon_sizes); | 1569 empty_icons, empty_icon_sizes); |
1547 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1570 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1548 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1571 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1549 } | 1572 } |
1550 | 1573 |
1551 } // namespace. | 1574 } // namespace. |
OLD | NEW |