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<set> | 7 #include<set> |
8 #include<vector> | 8 #include<vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 private: | 180 private: |
181 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 181 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
182 }; | 182 }; |
183 | 183 |
184 } // namespace | 184 } // namespace |
185 | 185 |
186 class TestFaviconDriver : public FaviconDriver { | 186 class TestFaviconDriver : public FaviconDriver { |
187 public: | 187 public: |
188 TestFaviconDriver() | 188 TestFaviconDriver() |
189 : favicon_validity_(false), | 189 : num_notifications_(0u) {} |
190 num_active_favicon_(0), | |
191 num_favicon_available_(0), | |
192 update_active_favicon_(false) {} | |
193 | 190 |
194 ~TestFaviconDriver() override {} | 191 ~TestFaviconDriver() override {} |
195 | 192 |
196 // FaviconDriver implementation. | 193 // FaviconDriver implementation. |
197 void FetchFavicon(const GURL& url) override { | 194 void FetchFavicon(const GURL& url) override { |
198 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() " | 195 ADD_FAILURE() << "TestFaviconDriver::FetchFavicon() " |
199 << "should never be called in tests."; | 196 << "should never be called in tests."; |
200 } | 197 } |
201 | 198 |
202 gfx::Image GetFavicon() const override { | 199 gfx::Image GetFavicon() const override { |
(...skipping 17 matching lines...) Expand all Loading... |
220 int StartDownload(const GURL& url, int max_bitmap_size) override { | 217 int StartDownload(const GURL& url, int max_bitmap_size) override { |
221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | 218 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " |
222 << "should never be called in tests."; | 219 << "should never be called in tests."; |
223 return -1; | 220 return -1; |
224 } | 221 } |
225 | 222 |
226 bool IsOffTheRecord() override { return false; } | 223 bool IsOffTheRecord() override { return false; } |
227 | 224 |
228 bool IsBookmarked(const GURL& url) override { return false; } | 225 bool IsBookmarked(const GURL& url) override { return false; } |
229 | 226 |
230 GURL GetActiveURL() override { return url_; } | 227 GURL GetActiveURL() override { |
231 | 228 ADD_FAILURE() << "TestFaviconDriver::GetActiveURL() " |
232 bool GetActiveFaviconValidity() { return favicon_validity_; } | 229 << "should never be called in tests."; |
233 | 230 return GURL(); |
234 void SetActiveFaviconValidity(bool favicon_validity) override { | |
235 favicon_validity_ = favicon_validity; | |
236 } | 231 } |
237 | 232 |
238 GURL GetActiveFaviconURL() override { return favicon_url_; } | 233 void OnFaviconUpdated( |
239 | 234 const GURL& page_url, |
240 void SetActiveFaviconURL(const GURL& favicon_url) override { | 235 FaviconDriverObserver::NotificationIconType notification_icon_type, |
241 favicon_url_ = favicon_url; | 236 const GURL& icon_url, |
242 } | 237 bool icon_url_changed, |
243 | 238 const gfx::Image& image) override { |
244 gfx::Image GetActiveFaviconImage() { return image_; } | 239 ++num_notifications_; |
245 | 240 icon_url_ = icon_url; |
246 void SetActiveFaviconImage(const gfx::Image& image) override { | |
247 image_ = image; | 241 image_ = image; |
248 } | 242 } |
249 | 243 |
250 void OnFaviconAvailable(const GURL& page_url, | 244 const GURL& icon_url() const { return icon_url_; } |
251 const GURL& icon_url, | |
252 const gfx::Image& image, | |
253 bool update_active_favicon) override { | |
254 ++num_favicon_available_; | |
255 available_image_ = image; | |
256 available_icon_url_ = icon_url; | |
257 update_active_favicon_ = update_active_favicon; | |
258 if (!update_active_favicon) | |
259 return; | |
260 | 245 |
261 ++num_active_favicon_; | 246 const gfx::Image& image() const { return image_; } |
262 SetActiveFaviconURL(icon_url); | |
263 SetActiveFaviconValidity(true); | |
264 SetActiveFaviconImage(image); | |
265 } | |
266 | 247 |
267 size_t num_active_favicon() const { return num_active_favicon_; } | 248 size_t num_notifications() const { return num_notifications_; } |
268 size_t num_favicon_available() const { return num_favicon_available_; } | 249 void ResetNumNotifications() { num_notifications_ = 0; } |
269 void ResetNumActiveFavicon() { num_active_favicon_ = 0; } | |
270 void ResetNumFaviconAvailable() { num_favicon_available_ = 0; } | |
271 | |
272 void SetActiveURL(GURL url) { url_ = url; } | |
273 | |
274 const gfx::Image& available_favicon() { return available_image_; } | |
275 | |
276 const GURL& available_icon_url() { return available_icon_url_; } | |
277 | |
278 bool update_active_favicon() { return update_active_favicon_; } | |
279 | 250 |
280 private: | 251 private: |
281 GURL favicon_url_; | 252 GURL icon_url_; |
282 GURL url_; | |
283 gfx::Image image_; | 253 gfx::Image image_; |
284 bool favicon_validity_; | 254 size_t num_notifications_; |
285 | |
286 // The number of times that NotifyFaviconAvailable() has been called with | |
287 // |is_active_favicon| is true. | |
288 size_t num_active_favicon_; | |
289 // The number of times that NotifyFaviconAvailable() has been called. | |
290 size_t num_favicon_available_; | |
291 gfx::Image available_image_; | |
292 GURL available_icon_url_; | |
293 bool update_active_favicon_; | |
294 | 255 |
295 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); | 256 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); |
296 }; | 257 }; |
297 | 258 |
298 // This class is used to catch the FaviconHandler's download and history | 259 // This class is used to catch the FaviconHandler's download and history |
299 // request, and also provide the methods to access the FaviconHandler | 260 // request, and also provide the methods to access the FaviconHandler |
300 // internals. | 261 // internals. |
301 class TestFaviconHandler : public FaviconHandler { | 262 class TestFaviconHandler : public FaviconHandler { |
302 public: | 263 public: |
303 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 264 static int GetMaximalIconSize(favicon_base::IconType icon_type) { |
304 return FaviconHandler::GetMaximalIconSize(icon_type); | 265 return FaviconHandler::GetMaximalIconSize(icon_type); |
305 } | 266 } |
306 | 267 |
307 TestFaviconHandler(const GURL& page_url, | 268 TestFaviconHandler(TestFaviconDriver* driver, |
308 TestFaviconDriver* driver, | 269 FaviconDriverObserver::NotificationIconType handler_type) |
309 Type type) | 270 : FaviconHandler(nullptr, driver, handler_type), |
310 : FaviconHandler(nullptr, driver, type), | |
311 download_id_(0) { | 271 download_id_(0) { |
312 driver->SetActiveURL(page_url); | |
313 download_handler_.reset(new DownloadHandler(this)); | 272 download_handler_.reset(new DownloadHandler(this)); |
314 } | 273 } |
315 | 274 |
316 ~TestFaviconHandler() override {} | 275 ~TestFaviconHandler() override {} |
317 | 276 |
318 HistoryRequestHandler* history_handler() { | 277 HistoryRequestHandler* history_handler() { |
319 return history_handler_.get(); | 278 return history_handler_.get(); |
320 } | 279 } |
321 | 280 |
322 // This method will take the ownership of the given handler. | 281 // This method will take the ownership of the given handler. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 // any of |candidates|. | 421 // any of |candidates|. |
463 // - The page provides favicons at |candidate_icons|. | 422 // - The page provides favicons at |candidate_icons|. |
464 // - The favicons at |candidate_icons| have edge pixel sizes of | 423 // - The favicons at |candidate_icons| have edge pixel sizes of |
465 // |candidate_icon_sizes|. | 424 // |candidate_icon_sizes|. |
466 void DownloadTillDoneIgnoringHistory( | 425 void DownloadTillDoneIgnoringHistory( |
467 TestFaviconDriver* favicon_driver, | 426 TestFaviconDriver* favicon_driver, |
468 TestFaviconHandler* favicon_handler, | 427 TestFaviconHandler* favicon_handler, |
469 const GURL& page_url, | 428 const GURL& page_url, |
470 const std::vector<FaviconURL>& candidate_icons, | 429 const std::vector<FaviconURL>& candidate_icons, |
471 const int* candidate_icon_sizes) { | 430 const int* candidate_icon_sizes) { |
| 431 size_t old_num_notifications = favicon_driver->num_notifications(); |
| 432 |
472 UpdateFaviconURL( | 433 UpdateFaviconURL( |
473 favicon_driver, favicon_handler, page_url, candidate_icons); | 434 favicon_driver, favicon_handler, page_url, candidate_icons); |
474 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 435 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
475 | 436 |
476 DownloadHandler* download_handler = favicon_handler->download_handler(); | 437 DownloadHandler* download_handler = favicon_handler->download_handler(); |
477 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 438 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
478 favicon_handler->history_handler()->history_results_.clear(); | 439 favicon_handler->history_handler()->history_results_.clear(); |
479 favicon_handler->history_handler()->InvokeCallback(); | 440 favicon_handler->history_handler()->InvokeCallback(); |
480 ASSERT_TRUE(download_handler->HasDownload()); | 441 ASSERT_TRUE(download_handler->HasDownload()); |
481 EXPECT_EQ(download_handler->GetImageUrl(), | 442 EXPECT_EQ(download_handler->GetImageUrl(), |
482 candidate_icons[i].icon_url); | 443 candidate_icons[i].icon_url); |
483 std::vector<int> sizes; | 444 std::vector<int> sizes; |
484 sizes.push_back(candidate_icon_sizes[i]); | 445 sizes.push_back(candidate_icon_sizes[i]); |
485 download_handler->SetImageSizes(sizes); | 446 download_handler->SetImageSizes(sizes); |
486 download_handler->InvokeCallback(); | 447 download_handler->InvokeCallback(); |
487 | 448 |
488 download_handler->Reset(); | 449 download_handler->Reset(); |
489 | 450 |
490 if (favicon_driver->num_active_favicon()) | 451 if (favicon_driver->num_notifications() > old_num_notifications) |
491 return; | 452 return; |
492 } | 453 } |
493 } | 454 } |
494 | 455 |
495 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, | 456 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, |
496 TestFaviconHandler* favicon_handler, | 457 TestFaviconHandler* favicon_handler, |
497 const GURL& page_url, | 458 const GURL& page_url, |
498 const std::vector<FaviconURL>& candidate_icons) { | 459 const std::vector<FaviconURL>& candidate_icons) { |
499 favicon_driver->ResetNumActiveFavicon(); | 460 favicon_driver->ResetNumNotifications(); |
500 | 461 |
501 favicon_handler->FetchFavicon(page_url); | 462 favicon_handler->FetchFavicon(page_url); |
502 favicon_handler->history_handler()->InvokeCallback(); | 463 favicon_handler->history_handler()->InvokeCallback(); |
503 | 464 |
504 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); | 465 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); |
505 } | 466 } |
506 | 467 |
507 void SetUp() override { | 468 void SetUp() override { |
508 // The score computed by SelectFaviconFrames() is dependent on the supported | 469 // The score computed by SelectFaviconFrames() is dependent on the supported |
509 // scale factors of the platform. It is used for determining the goodness of | 470 // scale factors of the platform. It is used for determining the goodness of |
(...skipping 11 matching lines...) Expand all Loading... |
521 scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 482 scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
522 scoped_set_supported_scale_factors_; | 483 scoped_set_supported_scale_factors_; |
523 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 484 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
524 }; | 485 }; |
525 | 486 |
526 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 487 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
527 const GURL page_url("http://www.google.com"); | 488 const GURL page_url("http://www.google.com"); |
528 const GURL icon_url("http://www.google.com/favicon"); | 489 const GURL icon_url("http://www.google.com/favicon"); |
529 | 490 |
530 TestFaviconDriver driver; | 491 TestFaviconDriver driver; |
531 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 492 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
532 | 493 |
533 helper.FetchFavicon(page_url); | 494 helper.FetchFavicon(page_url); |
534 HistoryRequestHandler* history_handler = helper.history_handler(); | 495 HistoryRequestHandler* history_handler = helper.history_handler(); |
535 // Ensure the data given to history is correct. | 496 // Ensure the data given to history is correct. |
536 ASSERT_TRUE(history_handler); | 497 ASSERT_TRUE(history_handler); |
537 EXPECT_EQ(page_url, history_handler->page_url_); | 498 EXPECT_EQ(page_url, history_handler->page_url_); |
538 EXPECT_EQ(GURL(), history_handler->icon_url_); | 499 EXPECT_EQ(GURL(), history_handler->icon_url_); |
539 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 500 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
540 | 501 |
541 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 502 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
542 | 503 |
543 // Send history response. | 504 // Send history response. |
544 history_handler->InvokeCallback(); | 505 history_handler->InvokeCallback(); |
545 // Verify FaviconHandler status | 506 // Verify FaviconHandler status |
546 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 507 EXPECT_EQ(1u, driver.num_notifications()); |
547 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 508 EXPECT_EQ(icon_url, driver.icon_url()); |
548 | 509 |
549 // Simulates update favicon url. | 510 // Simulates update favicon url. |
550 std::vector<FaviconURL> urls; | 511 std::vector<FaviconURL> urls; |
551 urls.push_back( | 512 urls.push_back( |
552 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 513 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
553 helper.OnUpdateFaviconURL(page_url, urls); | 514 helper.OnUpdateFaviconURL(page_url, urls); |
554 | 515 |
555 // Verify FaviconHandler status | 516 // Verify FaviconHandler status |
556 EXPECT_EQ(1u, helper.image_urls().size()); | 517 EXPECT_EQ(1u, helper.image_urls().size()); |
557 ASSERT_TRUE(helper.current_candidate()); | 518 ASSERT_TRUE(helper.current_candidate()); |
558 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 519 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
559 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 520 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); |
560 | 521 |
561 // Favicon shouldn't request to download icon. | 522 // Favicon shouldn't request to download icon. |
562 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 523 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
563 } | 524 } |
564 | 525 |
565 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 526 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
566 const GURL page_url("http://www.google.com"); | 527 const GURL page_url("http://www.google.com"); |
567 const GURL icon_url("http://www.google.com/favicon"); | 528 const GURL icon_url("http://www.google.com/favicon"); |
568 | 529 |
569 TestFaviconDriver driver; | 530 TestFaviconDriver driver; |
570 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 531 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
571 | 532 |
572 helper.FetchFavicon(page_url); | 533 helper.FetchFavicon(page_url); |
573 HistoryRequestHandler* history_handler = helper.history_handler(); | 534 HistoryRequestHandler* history_handler = helper.history_handler(); |
574 // Ensure the data given to history is correct. | 535 // Ensure the data given to history is correct. |
575 ASSERT_TRUE(history_handler); | 536 ASSERT_TRUE(history_handler); |
576 EXPECT_EQ(page_url, history_handler->page_url_); | 537 EXPECT_EQ(page_url, history_handler->page_url_); |
577 EXPECT_EQ(GURL(), history_handler->icon_url_); | 538 EXPECT_EQ(GURL(), history_handler->icon_url_); |
578 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 539 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
579 | 540 |
580 // Set icon data expired | 541 // Set icon data expired |
581 SetFaviconRawBitmapResult(icon_url, | 542 SetFaviconRawBitmapResult(icon_url, |
582 favicon_base::FAVICON, | 543 favicon_base::FAVICON, |
583 true /* expired */, | 544 true /* expired */, |
584 &history_handler->history_results_); | 545 &history_handler->history_results_); |
585 // Send history response. | 546 // Send history response. |
586 history_handler->InvokeCallback(); | 547 history_handler->InvokeCallback(); |
587 // Verify FaviconHandler status | 548 // Verify FaviconHandler status |
588 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 549 EXPECT_EQ(1u, driver.num_notifications()); |
589 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 550 EXPECT_EQ(icon_url, driver.icon_url()); |
590 | 551 |
591 // Simulates update favicon url. | 552 // Simulates update favicon url. |
592 std::vector<FaviconURL> urls; | 553 std::vector<FaviconURL> urls; |
593 urls.push_back( | 554 urls.push_back( |
594 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 555 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
595 helper.OnUpdateFaviconURL(page_url, urls); | 556 helper.OnUpdateFaviconURL(page_url, urls); |
596 | 557 |
597 // Verify FaviconHandler status | 558 // Verify FaviconHandler status |
598 EXPECT_EQ(1u, helper.image_urls().size()); | 559 EXPECT_EQ(1u, helper.image_urls().size()); |
599 ASSERT_TRUE(helper.current_candidate()); | 560 ASSERT_TRUE(helper.current_candidate()); |
(...skipping 15 matching lines...) Expand all Loading... |
615 | 576 |
616 // New icon should be saved to history backend and navigation entry. | 577 // New icon should be saved to history backend and navigation entry. |
617 history_handler = helper.history_handler(); | 578 history_handler = helper.history_handler(); |
618 ASSERT_TRUE(history_handler); | 579 ASSERT_TRUE(history_handler); |
619 EXPECT_EQ(icon_url, history_handler->icon_url_); | 580 EXPECT_EQ(icon_url, history_handler->icon_url_); |
620 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 581 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
621 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 582 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
622 EXPECT_EQ(page_url, history_handler->page_url_); | 583 EXPECT_EQ(page_url, history_handler->page_url_); |
623 | 584 |
624 // Verify NavigationEntry. | 585 // Verify NavigationEntry. |
625 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 586 EXPECT_EQ(2u, driver.num_notifications()); |
626 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 587 EXPECT_EQ(icon_url, driver.icon_url()); |
627 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); | 588 EXPECT_FALSE(driver.image().IsEmpty()); |
628 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); | 589 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
629 } | 590 } |
630 | 591 |
631 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 592 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
632 const GURL page_url("http://www.google.com"); | 593 const GURL page_url("http://www.google.com"); |
633 const GURL icon_url("http://www.google.com/favicon"); | 594 const GURL icon_url("http://www.google.com/favicon"); |
634 const GURL new_icon_url("http://www.google.com/new_favicon"); | 595 const GURL new_icon_url("http://www.google.com/new_favicon"); |
635 | 596 |
636 TestFaviconDriver driver; | 597 TestFaviconDriver driver; |
637 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 598 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
638 | 599 |
639 helper.FetchFavicon(page_url); | 600 helper.FetchFavicon(page_url); |
640 HistoryRequestHandler* history_handler = helper.history_handler(); | 601 HistoryRequestHandler* history_handler = helper.history_handler(); |
641 // Ensure the data given to history is correct. | 602 // Ensure the data given to history is correct. |
642 ASSERT_TRUE(history_handler); | 603 ASSERT_TRUE(history_handler); |
643 EXPECT_EQ(page_url, history_handler->page_url_); | 604 EXPECT_EQ(page_url, history_handler->page_url_); |
644 EXPECT_EQ(GURL(), history_handler->icon_url_); | 605 EXPECT_EQ(GURL(), history_handler->icon_url_); |
645 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 606 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
646 | 607 |
647 // Set valid icon data. | 608 // Set valid icon data. |
648 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 609 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
649 | 610 |
650 // Send history response. | 611 // Send history response. |
651 history_handler->InvokeCallback(); | 612 history_handler->InvokeCallback(); |
652 // Verify FaviconHandler status. | 613 // Verify FaviconHandler status. |
653 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 614 EXPECT_EQ(1u, driver.num_notifications()); |
654 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 615 EXPECT_EQ(icon_url, driver.icon_url()); |
655 | 616 |
656 // Reset the history_handler to verify whether new icon is requested from | 617 // Reset the history_handler to verify whether new icon is requested from |
657 // history. | 618 // history. |
658 helper.set_history_handler(nullptr); | 619 helper.set_history_handler(nullptr); |
659 | 620 |
660 // Simulates update with the different favicon url. | 621 // Simulates update with the different favicon url. |
661 std::vector<FaviconURL> urls; | 622 std::vector<FaviconURL> urls; |
662 urls.push_back(FaviconURL( | 623 urls.push_back(FaviconURL( |
663 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 624 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
664 helper.OnUpdateFaviconURL(page_url, urls); | 625 helper.OnUpdateFaviconURL(page_url, urls); |
(...skipping 30 matching lines...) Expand all Loading... |
695 | 656 |
696 // New icon should be saved to history backend and navigation entry. | 657 // New icon should be saved to history backend and navigation entry. |
697 history_handler = helper.history_handler(); | 658 history_handler = helper.history_handler(); |
698 ASSERT_TRUE(history_handler); | 659 ASSERT_TRUE(history_handler); |
699 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 660 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
700 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 661 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
701 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 662 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
702 EXPECT_EQ(page_url, history_handler->page_url_); | 663 EXPECT_EQ(page_url, history_handler->page_url_); |
703 | 664 |
704 // Verify NavigationEntry. | 665 // Verify NavigationEntry. |
705 EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); | 666 EXPECT_EQ(2u, driver.num_notifications()); |
706 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 667 EXPECT_EQ(new_icon_url, driver.icon_url()); |
707 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); | 668 EXPECT_FALSE(driver.image().IsEmpty()); |
708 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); | 669 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
709 } | 670 } |
710 | 671 |
711 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 672 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
712 const GURL page_url("http://www.google.com"); | 673 const GURL page_url("http://www.google.com"); |
713 const GURL icon_url("http://www.google.com/favicon"); | 674 const GURL icon_url("http://www.google.com/favicon"); |
714 | 675 |
715 TestFaviconDriver driver; | 676 TestFaviconDriver driver; |
716 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 677 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
717 | 678 |
718 helper.FetchFavicon(page_url); | 679 helper.FetchFavicon(page_url); |
719 HistoryRequestHandler* history_handler = helper.history_handler(); | 680 HistoryRequestHandler* history_handler = helper.history_handler(); |
720 // Ensure the data given to history is correct. | 681 // Ensure the data given to history is correct. |
721 ASSERT_TRUE(history_handler); | 682 ASSERT_TRUE(history_handler); |
722 EXPECT_EQ(page_url, history_handler->page_url_); | 683 EXPECT_EQ(page_url, history_handler->page_url_); |
723 EXPECT_EQ(GURL(), history_handler->icon_url_); | 684 EXPECT_EQ(GURL(), history_handler->icon_url_); |
724 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 685 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
725 | 686 |
726 // Set non empty but invalid data. | 687 // Set non empty but invalid data. |
727 favicon_base::FaviconRawBitmapResult bitmap_result; | 688 favicon_base::FaviconRawBitmapResult bitmap_result; |
728 bitmap_result.expired = false; | 689 bitmap_result.expired = false; |
729 // Empty bitmap data is invalid. | 690 // Empty bitmap data is invalid. |
730 bitmap_result.bitmap_data = new base::RefCountedBytes(); | 691 bitmap_result.bitmap_data = new base::RefCountedBytes(); |
731 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 692 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
732 bitmap_result.icon_type = favicon_base::FAVICON; | 693 bitmap_result.icon_type = favicon_base::FAVICON; |
733 bitmap_result.icon_url = icon_url; | 694 bitmap_result.icon_url = icon_url; |
734 history_handler->history_results_.clear(); | 695 history_handler->history_results_.clear(); |
735 history_handler->history_results_.push_back(bitmap_result); | 696 history_handler->history_results_.push_back(bitmap_result); |
736 | 697 |
737 // Send history response. | 698 // Send history response. |
738 history_handler->InvokeCallback(); | 699 history_handler->InvokeCallback(); |
739 // The NavigationEntry should not be set yet as the history data is invalid. | 700 // The NavigationEntry should not be set yet as the history data is invalid. |
740 EXPECT_FALSE(driver.GetActiveFaviconValidity()); | 701 EXPECT_EQ(0u, driver.num_notifications()); |
741 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); | 702 EXPECT_EQ(GURL(), driver.icon_url()); |
742 | 703 |
743 // Reset the history_handler to verify whether new icon is requested from | 704 // Reset the history_handler to verify whether new icon is requested from |
744 // history. | 705 // history. |
745 helper.set_history_handler(nullptr); | 706 helper.set_history_handler(nullptr); |
746 | 707 |
747 // Simulates update with matching favicon URL. | 708 // Simulates update with matching favicon URL. |
748 std::vector<FaviconURL> urls; | 709 std::vector<FaviconURL> urls; |
749 urls.push_back( | 710 urls.push_back( |
750 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 711 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
751 helper.OnUpdateFaviconURL(page_url, urls); | 712 helper.OnUpdateFaviconURL(page_url, urls); |
(...skipping 12 matching lines...) Expand all Loading... |
764 | 725 |
765 // New icon should be saved to history backend and navigation entry. | 726 // New icon should be saved to history backend and navigation entry. |
766 history_handler = helper.history_handler(); | 727 history_handler = helper.history_handler(); |
767 ASSERT_TRUE(history_handler); | 728 ASSERT_TRUE(history_handler); |
768 EXPECT_EQ(icon_url, history_handler->icon_url_); | 729 EXPECT_EQ(icon_url, history_handler->icon_url_); |
769 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 730 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
770 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 731 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
771 EXPECT_EQ(page_url, history_handler->page_url_); | 732 EXPECT_EQ(page_url, history_handler->page_url_); |
772 | 733 |
773 // Verify NavigationEntry. | 734 // Verify NavigationEntry. |
774 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 735 EXPECT_EQ(1u, driver.num_notifications()); |
775 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 736 EXPECT_EQ(icon_url, driver.icon_url()); |
776 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); | 737 EXPECT_FALSE(driver.image().IsEmpty()); |
777 EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width()); | 738 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
778 } | 739 } |
779 | 740 |
780 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 741 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
781 const GURL page_url("http://www.google.com"); | 742 const GURL page_url("http://www.google.com"); |
782 const GURL icon_url("http://www.google.com/favicon"); | 743 const GURL icon_url("http://www.google.com/favicon"); |
783 const GURL new_icon_url("http://www.google.com/new_favicon"); | 744 const GURL new_icon_url("http://www.google.com/new_favicon"); |
784 | 745 |
785 TestFaviconDriver driver; | 746 TestFaviconDriver driver; |
786 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 747 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
787 | 748 |
788 helper.FetchFavicon(page_url); | 749 helper.FetchFavicon(page_url); |
789 HistoryRequestHandler* history_handler = helper.history_handler(); | 750 HistoryRequestHandler* history_handler = helper.history_handler(); |
790 // Ensure the data given to history is correct. | 751 // Ensure the data given to history is correct. |
791 ASSERT_TRUE(history_handler); | 752 ASSERT_TRUE(history_handler); |
792 EXPECT_EQ(page_url, history_handler->page_url_); | 753 EXPECT_EQ(page_url, history_handler->page_url_); |
793 EXPECT_EQ(GURL(), history_handler->icon_url_); | 754 EXPECT_EQ(GURL(), history_handler->icon_url_); |
794 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 755 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
795 | 756 |
796 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 757 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
797 | 758 |
798 // Send history response. | 759 // Send history response. |
799 history_handler->InvokeCallback(); | 760 history_handler->InvokeCallback(); |
800 // Verify FaviconHandler status. | 761 // Verify FaviconHandler status. |
801 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 762 EXPECT_EQ(1u, driver.num_notifications()); |
802 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); | 763 EXPECT_EQ(icon_url, driver.icon_url()); |
803 | 764 |
804 // Reset the history_handler to verify whether new icon is requested from | 765 // Reset the history_handler to verify whether new icon is requested from |
805 // history. | 766 // history. |
806 helper.set_history_handler(nullptr); | 767 helper.set_history_handler(nullptr); |
807 | 768 |
808 // Simulates update with the different favicon url. | 769 // Simulates update with the different favicon url. |
809 std::vector<FaviconURL> urls; | 770 std::vector<FaviconURL> urls; |
810 urls.push_back(FaviconURL( | 771 urls.push_back(FaviconURL( |
811 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 772 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); |
812 helper.OnUpdateFaviconURL(page_url, urls); | 773 helper.OnUpdateFaviconURL(page_url, urls); |
(...skipping 12 matching lines...) Expand all Loading... |
825 EXPECT_EQ(page_url, history_handler->page_url_); | 786 EXPECT_EQ(page_url, history_handler->page_url_); |
826 | 787 |
827 // Simulate find icon. | 788 // Simulate find icon. |
828 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); | 789 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); |
829 history_handler->InvokeCallback(); | 790 history_handler->InvokeCallback(); |
830 | 791 |
831 // Shouldn't request download favicon | 792 // Shouldn't request download favicon |
832 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 793 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
833 | 794 |
834 // Verify the favicon status. | 795 // Verify the favicon status. |
835 EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL()); | 796 EXPECT_EQ(2u, driver.num_notifications()); |
836 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 797 EXPECT_EQ(new_icon_url, driver.icon_url()); |
837 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); | 798 EXPECT_FALSE(driver.image().IsEmpty()); |
838 } | 799 } |
839 | 800 |
840 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 801 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
841 const GURL page_url("http://www.google.com"); | 802 const GURL page_url("http://www.google.com"); |
842 const GURL icon_url("http://www.google.com/favicon"); | 803 const GURL icon_url("http://www.google.com/favicon"); |
843 const GURL new_icon_url("http://www.google.com/new_favicon"); | 804 const GURL new_icon_url("http://www.google.com/new_favicon"); |
844 | 805 |
845 TestFaviconDriver driver; | 806 TestFaviconDriver driver; |
846 TestFaviconHandler helper(page_url, &driver, FaviconHandler::LARGEST_TOUCH); | 807 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); |
847 std::set<GURL> fail_downloads; | 808 std::set<GURL> fail_downloads; |
848 fail_downloads.insert(icon_url); | 809 fail_downloads.insert(icon_url); |
849 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); | 810 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); |
850 | 811 |
851 helper.FetchFavicon(page_url); | 812 helper.FetchFavicon(page_url); |
852 HistoryRequestHandler* history_handler = helper.history_handler(); | 813 HistoryRequestHandler* history_handler = helper.history_handler(); |
853 // Ensure the data given to history is correct. | 814 // Ensure the data given to history is correct. |
854 ASSERT_TRUE(history_handler); | 815 ASSERT_TRUE(history_handler); |
855 EXPECT_EQ(page_url, history_handler->page_url_); | 816 EXPECT_EQ(page_url, history_handler->page_url_); |
856 EXPECT_EQ(GURL(), history_handler->icon_url_); | 817 EXPECT_EQ(GURL(), history_handler->icon_url_); |
857 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 818 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
858 history_handler->icon_type_); | 819 history_handler->icon_type_); |
859 | 820 |
860 // Icon not found. | 821 // Icon not found. |
861 history_handler->history_results_.clear(); | 822 history_handler->history_results_.clear(); |
862 // Send history response. | 823 // Send history response. |
863 history_handler->InvokeCallback(); | 824 history_handler->InvokeCallback(); |
864 // Verify FaviconHandler status. | 825 // Verify FaviconHandler status. |
865 EXPECT_FALSE(driver.GetActiveFaviconValidity()); | 826 EXPECT_EQ(0u, driver.num_notifications()); |
866 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); | 827 EXPECT_EQ(GURL(), driver.icon_url()); |
867 | 828 |
868 // Reset the history_handler to verify whether new icon is requested from | 829 // Reset the history_handler to verify whether new icon is requested from |
869 // history. | 830 // history. |
870 helper.set_history_handler(nullptr); | 831 helper.set_history_handler(nullptr); |
871 | 832 |
872 // Simulates update with the different favicon url. | 833 // Simulates update with the different favicon url. |
873 std::vector<FaviconURL> urls; | 834 std::vector<FaviconURL> urls; |
874 urls.push_back(FaviconURL(icon_url, | 835 urls.push_back(FaviconURL(icon_url, |
875 favicon_base::TOUCH_PRECOMPOSED_ICON, | 836 favicon_base::TOUCH_PRECOMPOSED_ICON, |
876 std::vector<gfx::Size>())); | 837 std::vector<gfx::Size>())); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 912 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
952 EXPECT_EQ(page_url, history_handler->page_url_); | 913 EXPECT_EQ(page_url, history_handler->page_url_); |
953 } | 914 } |
954 | 915 |
955 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 916 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
956 const GURL page_url("http://www.google.com"); | 917 const GURL page_url("http://www.google.com"); |
957 const GURL icon_url("http://www.google.com/favicon"); | 918 const GURL icon_url("http://www.google.com/favicon"); |
958 const GURL new_icon_url("http://www.google.com/new_favicon"); | 919 const GURL new_icon_url("http://www.google.com/new_favicon"); |
959 | 920 |
960 TestFaviconDriver driver; | 921 TestFaviconDriver driver; |
961 TestFaviconHandler helper(page_url, &driver, FaviconHandler::LARGEST_TOUCH); | 922 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); |
962 | 923 |
963 helper.FetchFavicon(page_url); | 924 helper.FetchFavicon(page_url); |
964 HistoryRequestHandler* history_handler = helper.history_handler(); | 925 HistoryRequestHandler* history_handler = helper.history_handler(); |
965 // Ensure the data given to history is correct. | 926 // Ensure the data given to history is correct. |
966 ASSERT_TRUE(history_handler); | 927 ASSERT_TRUE(history_handler); |
967 EXPECT_EQ(page_url, history_handler->page_url_); | 928 EXPECT_EQ(page_url, history_handler->page_url_); |
968 EXPECT_EQ(GURL(), history_handler->icon_url_); | 929 EXPECT_EQ(GURL(), history_handler->icon_url_); |
969 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 930 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
970 history_handler->icon_type_); | 931 history_handler->icon_type_); |
971 | 932 |
972 // Icon not found. | 933 // Icon not found. |
973 history_handler->history_results_.clear(); | 934 history_handler->history_results_.clear(); |
974 // Send history response. | 935 // Send history response. |
975 history_handler->InvokeCallback(); | 936 history_handler->InvokeCallback(); |
976 // Verify FaviconHandler status. | 937 // Verify FaviconHandler status. |
977 EXPECT_FALSE(driver.GetActiveFaviconValidity()); | 938 EXPECT_EQ(0u, driver.num_notifications()); |
978 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); | 939 EXPECT_EQ(GURL(), driver.icon_url()); |
979 | 940 |
980 // Reset the history_handler to verify whether new icon is requested from | 941 // Reset the history_handler to verify whether new icon is requested from |
981 // history. | 942 // history. |
982 helper.set_history_handler(nullptr); | 943 helper.set_history_handler(nullptr); |
983 | 944 |
984 // Simulates update with the different favicon url. | 945 // Simulates update with the different favicon url. |
985 std::vector<FaviconURL> urls; | 946 std::vector<FaviconURL> urls; |
986 urls.push_back(FaviconURL(icon_url, | 947 urls.push_back(FaviconURL(icon_url, |
987 favicon_base::TOUCH_PRECOMPOSED_ICON, | 948 favicon_base::TOUCH_PRECOMPOSED_ICON, |
988 std::vector<gfx::Size>())); | 949 std::vector<gfx::Size>())); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 const GURL icon_url2("http://www.google.com/favicon2"); | 1034 const GURL icon_url2("http://www.google.com/favicon2"); |
1074 std::vector<FaviconURL> favicon_urls; | 1035 std::vector<FaviconURL> favicon_urls; |
1075 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 1036 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
1076 favicon_base::FAVICON, | 1037 favicon_base::FAVICON, |
1077 std::vector<gfx::Size>())); | 1038 std::vector<gfx::Size>())); |
1078 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 1039 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
1079 favicon_base::FAVICON, | 1040 favicon_base::FAVICON, |
1080 std::vector<gfx::Size>())); | 1041 std::vector<gfx::Size>())); |
1081 | 1042 |
1082 TestFaviconDriver driver; | 1043 TestFaviconDriver driver; |
1083 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON); | 1044 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
1084 | 1045 |
1085 // Initiate a request for favicon data for |page_url|. History does not know | 1046 // Initiate a request for favicon data for |page_url|. History does not know |
1086 // about the page URL or the icon URLs. | 1047 // about the page URL or the icon URLs. |
1087 helper.FetchFavicon(page_url); | 1048 helper.FetchFavicon(page_url); |
1088 helper.history_handler()->InvokeCallback(); | 1049 helper.history_handler()->InvokeCallback(); |
1089 helper.set_history_handler(nullptr); | 1050 helper.set_history_handler(nullptr); |
1090 | 1051 |
1091 // Got icon URLs. | 1052 // Got icon URLs. |
1092 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1053 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
1093 | 1054 |
(...skipping 25 matching lines...) Expand all Loading... |
1119 } | 1080 } |
1120 | 1081 |
1121 // Fixes crbug.com/544560 | 1082 // Fixes crbug.com/544560 |
1122 TEST_F(FaviconHandlerTest, | 1083 TEST_F(FaviconHandlerTest, |
1123 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 1084 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
1124 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 1085 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
1125 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; | 1086 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; |
1126 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; | 1087 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; |
1127 | 1088 |
1128 TestFaviconDriver driver; | 1089 TestFaviconDriver driver; |
1129 TestFaviconHandler helper(kPageURL, &driver, FaviconHandler::FAVICON); | 1090 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
1130 | 1091 |
1131 // Initial state: | 1092 // Initial state: |
1132 // - The database does not know about |kPageURL|. | 1093 // - The database does not know about |kPageURL|. |
1133 // - The page uses |kIconURL1| and |kIconURL2|. | 1094 // - The page uses |kIconURL1| and |kIconURL2|. |
1134 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 1095 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
1135 // are expired in the database. | 1096 // are expired in the database. |
1136 helper.FetchFavicon(kPageURL); | 1097 helper.FetchFavicon(kPageURL); |
1137 ASSERT_TRUE(helper.history_handler()); | 1098 ASSERT_TRUE(helper.history_handler()); |
1138 helper.history_handler()->InvokeCallback(); | 1099 helper.history_handler()->InvokeCallback(); |
1139 { | 1100 { |
1140 std::vector<FaviconURL> icon_urls; | 1101 std::vector<FaviconURL> icon_urls; |
1141 icon_urls.push_back( | 1102 icon_urls.push_back( |
1142 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1103 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); |
1143 icon_urls.push_back( | 1104 icon_urls.push_back( |
1144 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); | 1105 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); |
1145 helper.OnUpdateFaviconURL(kPageURL, icon_urls); | 1106 helper.OnUpdateFaviconURL(kPageURL, icon_urls); |
1146 } | 1107 } |
1147 | 1108 |
1148 // FaviconHandler should request from history and download |kIconURL1| and | 1109 // FaviconHandler should request from history and download |kIconURL1| and |
1149 // |kIconURL2|. |kIconURL1| is the better match. A | 1110 // |kIconURL2|. |kIconURL1| is the better match. A |
1150 // FaviconDriver::OnFaviconAvailable() notification should be sent for | 1111 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1151 // |kIconURL1|. | 1112 // |kIconURL1|. |
1152 | 1113 ASSERT_EQ(0u, driver.num_notifications()); |
1153 // Clear the favicon validity so that we can use it to detect whether | |
1154 // OnFaviconAvailable() is invoked. | |
1155 driver.SetActiveFaviconValidity(false); | |
1156 | |
1157 ASSERT_TRUE(helper.history_handler()); | 1114 ASSERT_TRUE(helper.history_handler()); |
1158 SetFaviconRawBitmapResult(kIconURL1, | 1115 SetFaviconRawBitmapResult(kIconURL1, |
1159 favicon_base::FAVICON, | 1116 favicon_base::FAVICON, |
1160 true /* expired */, | 1117 true /* expired */, |
1161 &helper.history_handler()->history_results_); | 1118 &helper.history_handler()->history_results_); |
1162 helper.history_handler()->InvokeCallback(); | 1119 helper.history_handler()->InvokeCallback(); |
1163 helper.set_history_handler(nullptr); | 1120 helper.set_history_handler(nullptr); |
1164 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1121 ASSERT_TRUE(helper.download_handler()->HasDownload()); |
1165 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); | 1122 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); |
1166 helper.download_handler()->InvokeCallback(); | 1123 helper.download_handler()->InvokeCallback(); |
1167 helper.download_handler()->Reset(); | 1124 helper.download_handler()->Reset(); |
1168 | 1125 |
1169 ASSERT_TRUE(helper.history_handler()); | 1126 ASSERT_TRUE(helper.history_handler()); |
1170 helper.history_handler()->InvokeCallback(); | 1127 helper.history_handler()->InvokeCallback(); |
1171 SetFaviconRawBitmapResult(kIconURL2, | 1128 SetFaviconRawBitmapResult(kIconURL2, |
1172 favicon_base::FAVICON, | 1129 favicon_base::FAVICON, |
1173 true /* expired */, | 1130 true /* expired */, |
1174 &helper.history_handler()->history_results_); | 1131 &helper.history_handler()->history_results_); |
1175 helper.history_handler()->InvokeCallback(); | 1132 helper.history_handler()->InvokeCallback(); |
1176 helper.set_history_handler(nullptr); | 1133 helper.set_history_handler(nullptr); |
1177 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1134 ASSERT_TRUE(helper.download_handler()->HasDownload()); |
1178 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 1135 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
1179 helper.download_handler()->InvokeCallback(); | 1136 helper.download_handler()->InvokeCallback(); |
1180 helper.download_handler()->Reset(); | 1137 helper.download_handler()->Reset(); |
1181 | 1138 |
1182 ASSERT_TRUE(driver.GetActiveFaviconValidity()); | 1139 ASSERT_LT(0u, driver.num_notifications()); |
1183 ASSERT_EQ(kIconURL1, driver.GetActiveFaviconURL()); | 1140 ASSERT_EQ(kIconURL1, driver.icon_url()); |
1184 | 1141 |
1185 // Clear the history handler because SetHistoryFavicons() sets it. | 1142 // Clear the history handler because SetHistoryFavicons() sets it. |
1186 helper.set_history_handler(nullptr); | 1143 helper.set_history_handler(nullptr); |
1187 | 1144 |
1188 // Simulate the page changing it's icon URL to just |kIconURL2| via | 1145 // Simulate the page changing it's icon URL to just |kIconURL2| via |
1189 // Javascript. | 1146 // Javascript. |
1190 helper.OnUpdateFaviconURL( | 1147 helper.OnUpdateFaviconURL( |
1191 kPageURL, | 1148 kPageURL, |
1192 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, | 1149 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, |
1193 std::vector<gfx::Size>()))); | 1150 std::vector<gfx::Size>()))); |
1194 | 1151 |
1195 // FaviconHandler should request from history and download |kIconURL2|. A | 1152 // FaviconHandler should request from history and download |kIconURL2|. A |
1196 // FaviconDriver::OnFaviconAvailable() notification should be sent for | 1153 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1197 // |kIconURL2|. | 1154 // |kIconURL2|. |
1198 driver.SetActiveFaviconValidity(false); | 1155 driver.ResetNumNotifications(); |
1199 | |
1200 ASSERT_TRUE(helper.history_handler()); | 1156 ASSERT_TRUE(helper.history_handler()); |
1201 SetFaviconRawBitmapResult(kIconURL2, | 1157 SetFaviconRawBitmapResult(kIconURL2, |
1202 favicon_base::FAVICON, | 1158 favicon_base::FAVICON, |
1203 true /* expired */, | 1159 true /* expired */, |
1204 &helper.history_handler()->history_results_); | 1160 &helper.history_handler()->history_results_); |
1205 helper.history_handler()->InvokeCallback(); | 1161 helper.history_handler()->InvokeCallback(); |
1206 helper.set_history_handler(nullptr); | 1162 helper.set_history_handler(nullptr); |
1207 ASSERT_TRUE(helper.download_handler()->HasDownload()); | 1163 ASSERT_TRUE(helper.download_handler()->HasDownload()); |
1208 helper.download_handler()->InvokeCallback(); | 1164 helper.download_handler()->InvokeCallback(); |
1209 helper.download_handler()->Reset(); | 1165 helper.download_handler()->Reset(); |
1210 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 1166 ASSERT_LT(0u, driver.num_notifications()); |
1211 EXPECT_EQ(kIconURL2, driver.GetActiveFaviconURL()); | 1167 EXPECT_EQ(kIconURL2, driver.icon_url()); |
1212 } | 1168 } |
1213 | 1169 |
1214 // Test the favicon which is selected when the web page provides several | 1170 // Test the favicon which is selected when the web page provides several |
1215 // favicons and none of the favicons are cached in history. | 1171 // favicons and none of the favicons are cached in history. |
1216 // The goal of this test is to be more of an integration test than | 1172 // The goal of this test is to be more of an integration test than |
1217 // SelectFaviconFramesTest.*. | 1173 // SelectFaviconFramesTest.*. |
1218 TEST_F(FaviconHandlerTest, MultipleFavicons) { | 1174 TEST_F(FaviconHandlerTest, MultipleFavicons) { |
1219 const GURL kPageURL("http://www.google.com"); | 1175 const GURL kPageURL("http://www.google.com"); |
1220 const FaviconURL kSourceIconURLs[] = { | 1176 const FaviconURL kSourceIconURLs[] = { |
1221 FaviconURL(GURL("http://www.google.com/a"), | 1177 FaviconURL(GURL("http://www.google.com/a"), |
(...skipping 15 matching lines...) Expand all Loading... |
1237 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1193 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
1238 // SelectFaviconFrames(). | 1194 // SelectFaviconFrames(). |
1239 std::vector<ui::ScaleFactor> scale_factors; | 1195 std::vector<ui::ScaleFactor> scale_factors; |
1240 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1196 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
1241 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1197 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
1242 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1198 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
1243 | 1199 |
1244 // 1) Test that if there are several single resolution favicons to choose from | 1200 // 1) Test that if there are several single resolution favicons to choose from |
1245 // that the largest exact match is chosen. | 1201 // that the largest exact match is chosen. |
1246 TestFaviconDriver driver1; | 1202 TestFaviconDriver driver1; |
1247 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON); | 1203 TestFaviconHandler handler1(&driver1, |
| 1204 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1248 | 1205 |
1249 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1206 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1250 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1207 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1251 kSourceIconURLs + arraysize(kSizes1)); | 1208 kSourceIconURLs + arraysize(kSizes1)); |
1252 DownloadTillDoneIgnoringHistory( | 1209 DownloadTillDoneIgnoringHistory( |
1253 &driver1, &handler1, kPageURL, urls1, kSizes1); | 1210 &driver1, &handler1, kPageURL, urls1, kSizes1); |
1254 | 1211 |
1255 EXPECT_EQ(nullptr, handler1.current_candidate()); | 1212 EXPECT_EQ(nullptr, handler1.current_candidate()); |
1256 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); | 1213 EXPECT_EQ(1u, driver1.num_notifications()); |
1257 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); | 1214 EXPECT_FALSE(driver1.image().IsEmpty()); |
1258 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); | 1215 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); |
1259 | 1216 |
1260 size_t expected_index = 2u; | 1217 size_t expected_index = 2u; |
1261 EXPECT_EQ(32, kSizes1[expected_index]); | 1218 EXPECT_EQ(32, kSizes1[expected_index]); |
1262 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1219 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); |
1263 driver1.GetActiveFaviconURL()); | |
1264 | 1220 |
1265 // 2) Test that if there are several single resolution favicons to choose | 1221 // 2) Test that if there are several single resolution favicons to choose |
1266 // from, the exact match is preferred even if it results in upsampling. | 1222 // from, the exact match is preferred even if it results in upsampling. |
1267 TestFaviconDriver driver2; | 1223 TestFaviconDriver driver2; |
1268 TestFaviconHandler handler2(kPageURL, &driver2, FaviconHandler::FAVICON); | 1224 TestFaviconHandler handler2(&driver2, |
| 1225 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1269 | 1226 |
1270 const int kSizes2[] = { 16, 24, 48, 256 }; | 1227 const int kSizes2[] = { 16, 24, 48, 256 }; |
1271 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1228 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1272 kSourceIconURLs + arraysize(kSizes2)); | 1229 kSourceIconURLs + arraysize(kSizes2)); |
1273 DownloadTillDoneIgnoringHistory( | 1230 DownloadTillDoneIgnoringHistory( |
1274 &driver2, &handler2, kPageURL, urls2, kSizes2); | 1231 &driver2, &handler2, kPageURL, urls2, kSizes2); |
1275 EXPECT_TRUE(driver2.GetActiveFaviconValidity()); | 1232 EXPECT_EQ(1u, driver2.num_notifications()); |
1276 expected_index = 0u; | 1233 expected_index = 0u; |
1277 EXPECT_EQ(16, kSizes2[expected_index]); | 1234 EXPECT_EQ(16, kSizes2[expected_index]); |
1278 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1235 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); |
1279 driver2.GetActiveFaviconURL()); | |
1280 | 1236 |
1281 // 3) Test that favicons which need to be upsampled a little or downsampled | 1237 // 3) Test that favicons which need to be upsampled a little or downsampled |
1282 // a little are preferred over huge favicons. | 1238 // a little are preferred over huge favicons. |
1283 TestFaviconDriver driver3; | 1239 TestFaviconDriver driver3; |
1284 TestFaviconHandler handler3(kPageURL, &driver3, FaviconHandler::FAVICON); | 1240 TestFaviconHandler handler3(&driver3, |
| 1241 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1285 | 1242 |
1286 const int kSizes3[] = { 256, 48 }; | 1243 const int kSizes3[] = { 256, 48 }; |
1287 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1244 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1288 kSourceIconURLs + arraysize(kSizes3)); | 1245 kSourceIconURLs + arraysize(kSizes3)); |
1289 DownloadTillDoneIgnoringHistory( | 1246 DownloadTillDoneIgnoringHistory( |
1290 &driver3, &handler3, kPageURL, urls3, kSizes3); | 1247 &driver3, &handler3, kPageURL, urls3, kSizes3); |
1291 EXPECT_TRUE(driver3.GetActiveFaviconValidity()); | 1248 EXPECT_EQ(1u, driver3.num_notifications()); |
1292 expected_index = 1u; | 1249 expected_index = 1u; |
1293 EXPECT_EQ(48, kSizes3[expected_index]); | 1250 EXPECT_EQ(48, kSizes3[expected_index]); |
1294 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1251 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); |
1295 driver3.GetActiveFaviconURL()); | |
1296 | 1252 |
1297 TestFaviconDriver driver4; | 1253 TestFaviconDriver driver4; |
1298 TestFaviconHandler handler4(kPageURL, &driver4, FaviconHandler::FAVICON); | 1254 TestFaviconHandler handler4(&driver4, |
| 1255 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1299 | 1256 |
1300 const int kSizes4[] = { 17, 256 }; | 1257 const int kSizes4[] = { 17, 256 }; |
1301 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1258 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1302 kSourceIconURLs + arraysize(kSizes4)); | 1259 kSourceIconURLs + arraysize(kSizes4)); |
1303 DownloadTillDoneIgnoringHistory( | 1260 DownloadTillDoneIgnoringHistory( |
1304 &driver4, &handler4, kPageURL, urls4, kSizes4); | 1261 &driver4, &handler4, kPageURL, urls4, kSizes4); |
1305 EXPECT_TRUE(driver4.GetActiveFaviconValidity()); | 1262 EXPECT_EQ(1u, driver4.num_notifications()); |
1306 expected_index = 0u; | 1263 expected_index = 0u; |
1307 EXPECT_EQ(17, kSizes4[expected_index]); | 1264 EXPECT_EQ(17, kSizes4[expected_index]); |
1308 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1265 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver4.icon_url()); |
1309 driver4.GetActiveFaviconURL()); | |
1310 } | 1266 } |
1311 | 1267 |
1312 // Test that the best favicon is selected when: | 1268 // Test that the best favicon is selected when: |
1313 // - The page provides several favicons. | 1269 // - The page provides several favicons. |
1314 // - Downloading one of the page's icon URLs previously returned a 404. | 1270 // - Downloading one of the page's icon URLs previously returned a 404. |
1315 // - None of the favicons are cached in the Favicons database. | 1271 // - None of the favicons are cached in the Favicons database. |
1316 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 1272 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
1317 const GURL kPageURL("http://www.google.com"); | 1273 const GURL kPageURL("http://www.google.com"); |
1318 const GURL k404IconURL("http://www.google.com/404.png"); | 1274 const GURL k404IconURL("http://www.google.com/404.png"); |
1319 const FaviconURL k404FaviconURL( | 1275 const FaviconURL k404FaviconURL( |
1320 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); | 1276 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); |
1321 const FaviconURL kFaviconURLs[] = { | 1277 const FaviconURL kFaviconURLs[] = { |
1322 FaviconURL(GURL("http://www.google.com/a"), | 1278 FaviconURL(GURL("http://www.google.com/a"), |
1323 favicon_base::FAVICON, | 1279 favicon_base::FAVICON, |
1324 std::vector<gfx::Size>()), | 1280 std::vector<gfx::Size>()), |
1325 k404FaviconURL, | 1281 k404FaviconURL, |
1326 FaviconURL(GURL("http://www.google.com/c"), | 1282 FaviconURL(GURL("http://www.google.com/c"), |
1327 favicon_base::FAVICON, | 1283 favicon_base::FAVICON, |
1328 std::vector<gfx::Size>()), | 1284 std::vector<gfx::Size>()), |
1329 }; | 1285 }; |
1330 | 1286 |
1331 TestFaviconDriver driver; | 1287 TestFaviconDriver driver; |
1332 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); | 1288 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
1333 DownloadHandler* download_handler = handler.download_handler(); | 1289 DownloadHandler* download_handler = handler.download_handler(); |
1334 | 1290 |
1335 std::set<GURL> k404URLs; | 1291 std::set<GURL> k404URLs; |
1336 k404URLs.insert(k404IconURL); | 1292 k404URLs.insert(k404IconURL); |
1337 download_handler->FailDownloadForIconURLs(k404URLs); | 1293 download_handler->FailDownloadForIconURLs(k404URLs); |
1338 | 1294 |
1339 // Make the initial download for |k404IconURL| fail. | 1295 // Make the initial download for |k404IconURL| fail. |
1340 const int kSizes1[] = { 0 }; | 1296 const int kSizes1[] = { 0 }; |
1341 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 1297 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
1342 DownloadTillDoneIgnoringHistory( | 1298 DownloadTillDoneIgnoringHistory( |
1343 &driver, &handler, kPageURL, urls1, kSizes1); | 1299 &driver, &handler, kPageURL, urls1, kSizes1); |
1344 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); | 1300 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); |
1345 | 1301 |
1346 // Do a fetch now that the initial download for |k404IconURL| has failed. The | 1302 // Do a fetch now that the initial download for |k404IconURL| has failed. The |
1347 // behavior is different because OnDidDownloadFavicon() is invoked | 1303 // behavior is different because OnDidDownloadFavicon() is invoked |
1348 // synchronously from DownloadFavicon(). | 1304 // synchronously from DownloadFavicon(). |
1349 const int kSizes2[] = { 10, 0, 16 }; | 1305 const int kSizes2[] = { 10, 0, 16 }; |
1350 std::vector<FaviconURL> urls2(kFaviconURLs, | 1306 std::vector<FaviconURL> urls2(kFaviconURLs, |
1351 kFaviconURLs + arraysize(kFaviconURLs)); | 1307 kFaviconURLs + arraysize(kFaviconURLs)); |
1352 DownloadTillDoneIgnoringHistory( | 1308 DownloadTillDoneIgnoringHistory( |
1353 &driver, &handler, kPageURL, urls2, kSizes2); | 1309 &driver, &handler, kPageURL, urls2, kSizes2); |
1354 | 1310 |
1355 EXPECT_EQ(nullptr, handler.current_candidate()); | 1311 EXPECT_EQ(nullptr, handler.current_candidate()); |
1356 EXPECT_TRUE(driver.GetActiveFaviconValidity()); | 1312 EXPECT_EQ(1u, driver.num_notifications()); |
1357 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); | 1313 EXPECT_FALSE(driver.image().IsEmpty()); |
1358 int expected_index = 2u; | 1314 int expected_index = 2u; |
1359 EXPECT_EQ(16, kSizes2[expected_index]); | 1315 EXPECT_EQ(16, kSizes2[expected_index]); |
1360 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, | 1316 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, driver.icon_url()); |
1361 driver.GetActiveFaviconURL()); | |
1362 } | 1317 } |
1363 | 1318 |
1364 // Test that no favicon is selected when: | 1319 // Test that no favicon is selected when: |
1365 // - The page provides several favicons. | 1320 // - The page provides several favicons. |
1366 // - Downloading the page's icons has previously returned a 404. | 1321 // - Downloading the page's icons has previously returned a 404. |
1367 // - None of the favicons are cached in the Favicons database. | 1322 // - None of the favicons are cached in the Favicons database. |
1368 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { | 1323 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { |
1369 const GURL kPageURL("http://www.google.com"); | 1324 const GURL kPageURL("http://www.google.com"); |
1370 const GURL k404IconURL1("http://www.google.com/4041.png"); | 1325 const GURL k404IconURL1("http://www.google.com/4041.png"); |
1371 const GURL k404IconURL2("http://www.google.com/4042.png"); | 1326 const GURL k404IconURL2("http://www.google.com/4042.png"); |
1372 const FaviconURL kFaviconURLs[] = { | 1327 const FaviconURL kFaviconURLs[] = { |
1373 FaviconURL(k404IconURL1, | 1328 FaviconURL(k404IconURL1, |
1374 favicon_base::FAVICON, | 1329 favicon_base::FAVICON, |
1375 std::vector<gfx::Size>()), | 1330 std::vector<gfx::Size>()), |
1376 FaviconURL(k404IconURL2, | 1331 FaviconURL(k404IconURL2, |
1377 favicon_base::FAVICON, | 1332 favicon_base::FAVICON, |
1378 std::vector<gfx::Size>()), | 1333 std::vector<gfx::Size>()), |
1379 }; | 1334 }; |
1380 | 1335 |
1381 TestFaviconDriver driver; | 1336 TestFaviconDriver driver; |
1382 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); | 1337 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
1383 DownloadHandler* download_handler = handler.download_handler(); | 1338 DownloadHandler* download_handler = handler.download_handler(); |
1384 | 1339 |
1385 std::set<GURL> k404URLs; | 1340 std::set<GURL> k404URLs; |
1386 k404URLs.insert(k404IconURL1); | 1341 k404URLs.insert(k404IconURL1); |
1387 k404URLs.insert(k404IconURL2); | 1342 k404URLs.insert(k404IconURL2); |
1388 download_handler->FailDownloadForIconURLs(k404URLs); | 1343 download_handler->FailDownloadForIconURLs(k404URLs); |
1389 | 1344 |
1390 // Make the initial downloads for |kFaviconURLs| fail. | 1345 // Make the initial downloads for |kFaviconURLs| fail. |
1391 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1346 for (const FaviconURL& favicon_url : kFaviconURLs) { |
1392 const int kSizes[] = { 0 }; | 1347 const int kSizes[] = { 0 }; |
1393 std::vector<FaviconURL> urls(1u, favicon_url); | 1348 std::vector<FaviconURL> urls(1u, favicon_url); |
1394 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1349 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); |
1395 } | 1350 } |
1396 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); | 1351 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); |
1397 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); | 1352 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); |
1398 | 1353 |
1399 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. | 1354 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. |
1400 // The behavior is different because OnDidDownloadFavicon() is invoked | 1355 // The behavior is different because OnDidDownloadFavicon() is invoked |
1401 // synchronously from DownloadFavicon(). | 1356 // synchronously from DownloadFavicon(). |
1402 const int kSizes[] = { 0, 0 }; | 1357 const int kSizes[] = { 0, 0 }; |
1403 std::vector<FaviconURL> urls(kFaviconURLs, | 1358 std::vector<FaviconURL> urls(kFaviconURLs, |
1404 kFaviconURLs + arraysize(kFaviconURLs)); | 1359 kFaviconURLs + arraysize(kFaviconURLs)); |
1405 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); | 1360 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); |
1406 | 1361 |
1407 EXPECT_EQ(nullptr, handler.current_candidate()); | 1362 EXPECT_EQ(nullptr, handler.current_candidate()); |
1408 EXPECT_FALSE(driver.GetActiveFaviconValidity()); | 1363 EXPECT_EQ(0u, driver.num_notifications()); |
1409 EXPECT_TRUE(driver.GetActiveFaviconImage().IsEmpty()); | 1364 EXPECT_TRUE(driver.image().IsEmpty()); |
1410 } | 1365 } |
1411 | 1366 |
1412 // Test that no favicon is selected when the page's only icon uses an invalid | 1367 // Test that no favicon is selected when the page's only icon uses an invalid |
1413 // URL syntax. | 1368 // URL syntax. |
1414 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1369 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
1415 const GURL kPageURL("http://www.google.com"); | 1370 const GURL kPageURL("http://www.google.com"); |
1416 const GURL kInvalidFormatURL("invalid"); | 1371 const GURL kInvalidFormatURL("invalid"); |
1417 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1372 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
1418 | 1373 |
1419 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1374 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, |
1420 std::vector<gfx::Size>()); | 1375 std::vector<gfx::Size>()); |
1421 | 1376 |
1422 TestFaviconDriver driver; | 1377 TestFaviconDriver driver; |
1423 TestFaviconHandler handler(kPageURL, &driver, FaviconHandler::FAVICON); | 1378 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
1424 UpdateFaviconURL(&driver, &handler, kPageURL, | 1379 UpdateFaviconURL(&driver, &handler, kPageURL, |
1425 std::vector<FaviconURL>(1u, favicon_url)); | 1380 std::vector<FaviconURL>(1u, favicon_url)); |
1426 EXPECT_EQ(0u, handler.image_urls().size()); | 1381 EXPECT_EQ(0u, handler.image_urls().size()); |
1427 } | 1382 } |
1428 | 1383 |
1429 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1384 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
1430 const GURL kPageURL("http://www.google.com"); | 1385 const GURL kPageURL("http://www.google.com"); |
1431 std::vector<gfx::Size> icon1; | 1386 std::vector<gfx::Size> icon1; |
1432 icon1.push_back(gfx::Size(1024, 1024)); | 1387 icon1.push_back(gfx::Size(1024, 1024)); |
1433 icon1.push_back(gfx::Size(512, 512)); | 1388 icon1.push_back(gfx::Size(512, 512)); |
(...skipping 11 matching lines...) Expand all Loading... |
1445 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1400 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
1446 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1401 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1447 FaviconURL(GURL("http://www.google.com/d"), | 1402 FaviconURL(GURL("http://www.google.com/d"), |
1448 favicon_base::FAVICON, | 1403 favicon_base::FAVICON, |
1449 std::vector<gfx::Size>()), | 1404 std::vector<gfx::Size>()), |
1450 FaviconURL(GURL("http://www.google.com/e"), | 1405 FaviconURL(GURL("http://www.google.com/e"), |
1451 favicon_base::FAVICON, | 1406 favicon_base::FAVICON, |
1452 std::vector<gfx::Size>())}; | 1407 std::vector<gfx::Size>())}; |
1453 | 1408 |
1454 TestFaviconDriver driver1; | 1409 TestFaviconDriver driver1; |
1455 TestFaviconHandler handler1(kPageURL, &driver1, | 1410 TestFaviconHandler handler1(&driver1, |
1456 FaviconHandler::LARGEST_FAVICON); | 1411 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1457 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1412 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1458 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1413 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1459 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1414 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1460 | 1415 |
1461 struct ExpectedResult { | 1416 struct ExpectedResult { |
1462 // The favicon's index in kSourceIconURLs. | 1417 // The favicon's index in kSourceIconURLs. |
1463 size_t favicon_index; | 1418 size_t favicon_index; |
1464 // Width of largest bitmap. | 1419 // Width of largest bitmap. |
1465 int width; | 1420 int width; |
1466 } results[] = { | 1421 } results[] = { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 FaviconURL( | 1463 FaviconURL( |
1509 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1464 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1510 FaviconURL(GURL("http://www.google.com/d"), | 1465 FaviconURL(GURL("http://www.google.com/d"), |
1511 favicon_base::FAVICON, | 1466 favicon_base::FAVICON, |
1512 std::vector<gfx::Size>()), | 1467 std::vector<gfx::Size>()), |
1513 FaviconURL(GURL("http://www.google.com/e"), | 1468 FaviconURL(GURL("http://www.google.com/e"), |
1514 favicon_base::FAVICON, | 1469 favicon_base::FAVICON, |
1515 std::vector<gfx::Size>())}; | 1470 std::vector<gfx::Size>())}; |
1516 | 1471 |
1517 TestFaviconDriver driver1; | 1472 TestFaviconDriver driver1; |
1518 TestFaviconHandler handler1(kPageURL, &driver1, | 1473 TestFaviconHandler handler1(&driver1, |
1519 FaviconHandler::LARGEST_FAVICON); | 1474 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1520 | 1475 |
1521 std::set<GURL> fail_icon_urls; | 1476 std::set<GURL> fail_icon_urls; |
1522 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1477 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
1523 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1478 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
1524 } | 1479 } |
1525 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1480 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
1526 | 1481 |
1527 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1482 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1528 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1483 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1529 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1484 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 two_icons.push_back(gfx::Size(14, 14)); | 1531 two_icons.push_back(gfx::Size(14, 14)); |
1577 two_icons.push_back(gfx::Size(16, 16)); | 1532 two_icons.push_back(gfx::Size(16, 16)); |
1578 | 1533 |
1579 const FaviconURL kSourceIconURLs[] = { | 1534 const FaviconURL kSourceIconURLs[] = { |
1580 FaviconURL( | 1535 FaviconURL( |
1581 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1536 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
1582 FaviconURL( | 1537 FaviconURL( |
1583 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1538 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
1584 | 1539 |
1585 TestFaviconDriver driver1; | 1540 TestFaviconDriver driver1; |
1586 TestFaviconHandler handler1(kPageURL, &driver1, | 1541 TestFaviconHandler handler1(&driver1, |
1587 FaviconHandler::LARGEST_FAVICON); | 1542 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1588 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1543 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1589 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1544 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1590 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1545 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1591 | 1546 |
1592 ASSERT_EQ(2u, handler1.image_urls().size()); | 1547 ASSERT_EQ(2u, handler1.image_urls().size()); |
1593 | 1548 |
1594 // Index of largest favicon in kSourceIconURLs. | 1549 // Index of largest favicon in kSourceIconURLs. |
1595 size_t i = 1; | 1550 size_t i = 1; |
1596 // The largest bitmap's index in Favicon . | 1551 // The largest bitmap's index in Favicon . |
1597 int b = 1; | 1552 int b = 1; |
(...skipping 21 matching lines...) Expand all Loading... |
1619 sizes.push_back(j->width()); | 1574 sizes.push_back(j->width()); |
1620 | 1575 |
1621 handler1.download_handler()->SetImageSizes(sizes); | 1576 handler1.download_handler()->SetImageSizes(sizes); |
1622 handler1.download_handler()->InvokeCallback(); | 1577 handler1.download_handler()->InvokeCallback(); |
1623 | 1578 |
1624 // Verify the largest bitmap has been saved into history. | 1579 // Verify the largest bitmap has been saved into history. |
1625 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1580 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1626 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1581 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1627 handler1.history_handler()->size_); | 1582 handler1.history_handler()->size_); |
1628 // Verify NotifyFaviconAvailable(). | 1583 // Verify NotifyFaviconAvailable(). |
1629 EXPECT_FALSE(driver1.update_active_favicon()); | 1584 EXPECT_EQ(1u, driver1.num_notifications()); |
1630 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.available_icon_url()); | 1585 EXPECT_EQ(kSourceIconURLs[i].icon_url, driver1.icon_url()); |
1631 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1586 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], driver1.image().Size()); |
1632 driver1.available_favicon().Size()); | |
1633 } | 1587 } |
1634 | 1588 |
1635 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1589 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
1636 const GURL kPageURL("http://www.google.com"); | 1590 const GURL kPageURL("http://www.google.com"); |
1637 const int kMaximalSize = | 1591 const int kMaximalSize = |
1638 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1592 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
1639 | 1593 |
1640 std::vector<gfx::Size> icon1; | 1594 std::vector<gfx::Size> icon1; |
1641 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1595 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
1642 | 1596 |
1643 std::vector<gfx::Size> icon2; | 1597 std::vector<gfx::Size> icon2; |
1644 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1598 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
1645 | 1599 |
1646 const FaviconURL kSourceIconURLs[] = { | 1600 const FaviconURL kSourceIconURLs[] = { |
1647 FaviconURL( | 1601 FaviconURL( |
1648 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1602 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1649 FaviconURL( | 1603 FaviconURL( |
1650 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1604 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
1651 | 1605 |
1652 TestFaviconDriver driver1; | 1606 TestFaviconDriver driver1; |
1653 TestFaviconHandler handler1(kPageURL, &driver1, | 1607 TestFaviconHandler handler1(&driver1, |
1654 FaviconHandler::LARGEST_FAVICON); | 1608 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1655 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1609 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1656 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1610 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1657 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1611 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1658 | 1612 |
1659 ASSERT_EQ(2u, handler1.image_urls().size()); | 1613 ASSERT_EQ(2u, handler1.image_urls().size()); |
1660 | 1614 |
1661 // Index of largest favicon in kSourceIconURLs. | 1615 // Index of largest favicon in kSourceIconURLs. |
1662 size_t i = 1; | 1616 size_t i = 1; |
1663 // The largest bitmap's index in Favicon . | 1617 // The largest bitmap's index in Favicon . |
1664 int b = 0; | 1618 int b = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 const int actual_size2 = 12; | 1658 const int actual_size2 = 12; |
1705 | 1659 |
1706 const FaviconURL kSourceIconURLs[] = { | 1660 const FaviconURL kSourceIconURLs[] = { |
1707 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1661 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1708 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1662 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
1709 FaviconURL(GURL("http://www.google.com/d"), | 1663 FaviconURL(GURL("http://www.google.com/d"), |
1710 favicon_base::FAVICON, | 1664 favicon_base::FAVICON, |
1711 std::vector<gfx::Size>())}; | 1665 std::vector<gfx::Size>())}; |
1712 | 1666 |
1713 TestFaviconDriver driver1; | 1667 TestFaviconDriver driver1; |
1714 TestFaviconHandler handler1(kPageURL, &driver1, | 1668 TestFaviconHandler handler1(&driver1, |
1715 FaviconHandler::LARGEST_FAVICON); | 1669 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1716 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1670 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1717 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1671 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1718 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1672 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
1719 ASSERT_EQ(3u, handler1.image_urls().size()); | 1673 ASSERT_EQ(3u, handler1.image_urls().size()); |
1720 | 1674 |
1721 // Simulate no favicon from history. | 1675 // Simulate no favicon from history. |
1722 handler1.history_handler()->history_results_.clear(); | 1676 handler1.history_handler()->history_results_.clear(); |
1723 handler1.history_handler()->InvokeCallback(); | 1677 handler1.history_handler()->InvokeCallback(); |
1724 | 1678 |
1725 // Verify the first icon was request to download | 1679 // Verify the first icon was request to download |
(...skipping 29 matching lines...) Expand all Loading... |
1755 handler1.download_handler()->SetImageSizes(sizes); | 1709 handler1.download_handler()->SetImageSizes(sizes); |
1756 handler1.download_handler()->InvokeCallback(); | 1710 handler1.download_handler()->InvokeCallback(); |
1757 handler1.download_handler()->Reset(); | 1711 handler1.download_handler()->Reset(); |
1758 | 1712 |
1759 // Verify icon2 has been saved into history. | 1713 // Verify icon2 has been saved into history. |
1760 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1714 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
1761 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1715 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
1762 handler1.history_handler()->size_); | 1716 handler1.history_handler()->size_); |
1763 } | 1717 } |
1764 | 1718 |
1765 class FaviconHandlerActiveFaviconValidityParamTest : | |
1766 public FaviconHandlerTest, | |
1767 public ::testing::WithParamInterface<bool> { | |
1768 public: | |
1769 FaviconHandlerActiveFaviconValidityParamTest() {} | |
1770 | |
1771 ~FaviconHandlerActiveFaviconValidityParamTest() override {} | |
1772 | |
1773 bool GetActiveFaviconValiditySetting() { | |
1774 return GetParam(); | |
1775 } | |
1776 | |
1777 private: | |
1778 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerActiveFaviconValidityParamTest); | |
1779 }; | |
1780 | |
1781 TEST_P(FaviconHandlerActiveFaviconValidityParamTest, | |
1782 TestDownloadLargestIconDoesNotImpactActiveFaviconValidity) { | |
1783 const GURL page_url("http://www.google.com"); | |
1784 | |
1785 std::vector<gfx::Size> one_icon; | |
1786 one_icon.push_back(gfx::Size(15, 15)); | |
1787 | |
1788 const GURL old_favicon_url("http://www.google.com/old"); | |
1789 const GURL new_favicon_url("http://www.google.com/b"); | |
1790 const FaviconURL source_icon_urls[] = { | |
1791 FaviconURL(new_favicon_url, favicon_base::FAVICON, one_icon)}; | |
1792 TestFaviconDriver driver1; | |
1793 TestFaviconHandler handler1(page_url, &driver1, | |
1794 FaviconHandler::LARGEST_FAVICON); | |
1795 std::vector<FaviconURL> urls1(source_icon_urls, | |
1796 source_icon_urls + arraysize(source_icon_urls)); | |
1797 UpdateFaviconURL(&driver1, &handler1, page_url, urls1); | |
1798 | |
1799 HistoryRequestHandler* history_handler = handler1.history_handler(); | |
1800 | |
1801 // Simulate the active favicon is updated, this shouldn't happen in real | |
1802 // use case, but we want to verify the behavior below is not impacted by | |
1803 // accident. | |
1804 driver1.SetActiveFaviconValidity(GetActiveFaviconValiditySetting()); | |
1805 // Simulate the get favicon from history, but favicon URL didn't match. | |
1806 SetFaviconRawBitmapResult(old_favicon_url, | |
1807 &history_handler->history_results_); | |
1808 history_handler->InvokeCallback(); | |
1809 // Since we downloaded largest icon, and don't want to set active favicon | |
1810 // NotifyFaviconAvaliable() should be called with is_active_favicon as false. | |
1811 EXPECT_EQ(old_favicon_url, driver1.available_icon_url()); | |
1812 EXPECT_FALSE(driver1.update_active_favicon()); | |
1813 EXPECT_EQ(1u, driver1.num_favicon_available()); | |
1814 | |
1815 // We are trying to get favicon from history again. | |
1816 history_handler = handler1.history_handler(); | |
1817 EXPECT_EQ(new_favicon_url, history_handler->icon_url_); | |
1818 // Simulate the get expired favicon from history. | |
1819 history_handler->history_results_.clear(); | |
1820 SetFaviconRawBitmapResult(new_favicon_url, favicon_base::FAVICON, true, | |
1821 &history_handler->history_results_); | |
1822 history_handler->InvokeCallback(); | |
1823 // Since we downloaded largest icon, and don't want to set active favicon | |
1824 // NotifyFaviconAvaliable() should be called with is_active_favicon as false. | |
1825 EXPECT_EQ(new_favicon_url, driver1.available_icon_url()); | |
1826 EXPECT_FALSE(driver1.update_active_favicon()); | |
1827 EXPECT_EQ(2u, driver1.num_favicon_available()); | |
1828 | |
1829 // We are trying to download favicon. | |
1830 DownloadHandler* download_handler = handler1.download_handler(); | |
1831 EXPECT_TRUE(download_handler->HasDownload()); | |
1832 EXPECT_EQ(new_favicon_url, download_handler->GetImageUrl()); | |
1833 // Simulate the download succeed. | |
1834 download_handler->InvokeCallback(); | |
1835 // Since we downloaded largest icon, and don't want to set active favicon | |
1836 // NotifyFaviconAvaliable() should be called with is_active_favicon as false. | |
1837 EXPECT_EQ(new_favicon_url, driver1.available_icon_url()); | |
1838 EXPECT_FALSE(driver1.update_active_favicon()); | |
1839 EXPECT_EQ(3u, driver1.num_favicon_available()); | |
1840 } | |
1841 | |
1842 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse, | |
1843 FaviconHandlerActiveFaviconValidityParamTest, | |
1844 ::testing::Bool()); | |
1845 | |
1846 } // namespace | 1719 } // namespace |
1847 } // namespace favicon | 1720 } // namespace favicon |
OLD | NEW |