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

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

Issue 1272413002: Remove useless FaviconHandler::PageChangedSinceFaviconWasRequested() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | components/favicon/ios/web_favicon_driver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/favicon/core/favicon_handler.h" 5 #include "components/favicon/core/favicon_handler.h"
6 6
7 #include<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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void SetActiveFaviconURL(const GURL& favicon_url) override { 240 void SetActiveFaviconURL(const GURL& favicon_url) override {
241 favicon_url_ = favicon_url; 241 favicon_url_ = favicon_url;
242 } 242 }
243 243
244 gfx::Image GetActiveFaviconImage() { return image_; } 244 gfx::Image GetActiveFaviconImage() { return image_; }
245 245
246 void SetActiveFaviconImage(const gfx::Image& image) override { 246 void SetActiveFaviconImage(const gfx::Image& image) override {
247 image_ = image; 247 image_ = image;
248 } 248 }
249 249
250 void OnFaviconAvailable(const gfx::Image& image, 250 void OnFaviconAvailable(const GURL& page_url,
251 const GURL& icon_url, 251 const GURL& icon_url,
252 const gfx::Image& image,
252 bool update_active_favicon) override { 253 bool update_active_favicon) override {
253 ++num_favicon_available_; 254 ++num_favicon_available_;
254 available_image_ = image; 255 available_image_ = image;
255 available_icon_url_ = icon_url; 256 available_icon_url_ = icon_url;
256 update_active_favicon_ = update_active_favicon; 257 update_active_favicon_ = update_active_favicon;
257 if (!update_active_favicon) 258 if (!update_active_favicon)
258 return; 259 return;
259 260
260 ++num_active_favicon_; 261 ++num_active_favicon_;
261 SetActiveFaviconURL(icon_url); 262 SetActiveFaviconURL(icon_url);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const GURL& icon_url, 392 const GURL& icon_url,
392 favicon_base::IconType icon_type, 393 favicon_base::IconType icon_type,
393 const gfx::Image& image) override { 394 const gfx::Image& image) override {
394 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); 395 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes();
395 std::vector<unsigned char> bitmap_data(bytes->front(), 396 std::vector<unsigned char> bitmap_data(bytes->front(),
396 bytes->front() + bytes->size()); 397 bytes->front() + bytes->size());
397 history_handler_.reset(new HistoryRequestHandler( 398 history_handler_.reset(new HistoryRequestHandler(
398 page_url, icon_url, icon_type, bitmap_data, image.Size())); 399 page_url, icon_url, icon_type, bitmap_data, image.Size()));
399 } 400 }
400 401
401 bool ShouldSaveFavicon(const GURL& url) override { return true; } 402 bool ShouldSaveFavicon() override { return true; }
402 403
403 GURL page_url_; 404 GURL page_url_;
404 405
405 private: 406 private:
406 407
407 // The unique id of a download request. It will be returned to a 408 // The unique id of a download request. It will be returned to a
408 // FaviconHandler. 409 // FaviconHandler.
409 int download_id_; 410 int download_id_;
410 411
411 scoped_ptr<DownloadHandler> download_handler_; 412 scoped_ptr<DownloadHandler> download_handler_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 496
496 void UpdateFaviconURL(TestFaviconDriver* favicon_driver, 497 void UpdateFaviconURL(TestFaviconDriver* favicon_driver,
497 TestFaviconHandler* favicon_handler, 498 TestFaviconHandler* favicon_handler,
498 const GURL& page_url, 499 const GURL& page_url,
499 const std::vector<FaviconURL>& candidate_icons) { 500 const std::vector<FaviconURL>& candidate_icons) {
500 favicon_driver->ResetNumActiveFavicon(); 501 favicon_driver->ResetNumActiveFavicon();
501 502
502 favicon_handler->FetchFavicon(page_url); 503 favicon_handler->FetchFavicon(page_url);
503 favicon_handler->history_handler()->InvokeCallback(); 504 favicon_handler->history_handler()->InvokeCallback();
504 505
505 favicon_handler->OnUpdateFaviconURL(candidate_icons); 506 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons);
506 } 507 }
507 508
508 void SetUp() override { 509 void SetUp() override {
509 // The score computed by SelectFaviconFrames() is dependent on the supported 510 // The score computed by SelectFaviconFrames() is dependent on the supported
510 // scale factors of the platform. It is used for determining the goodness of 511 // scale factors of the platform. It is used for determining the goodness of
511 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). 512 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon().
512 // Force the values of the scale factors so that the tests produce the same 513 // Force the values of the scale factors so that the tests produce the same
513 // results on all platforms. 514 // results on all platforms.
514 std::vector<ui::ScaleFactor> scale_factors; 515 std::vector<ui::ScaleFactor> scale_factors;
515 scale_factors.push_back(ui::SCALE_FACTOR_100P); 516 scale_factors.push_back(ui::SCALE_FACTOR_100P);
(...skipping 28 matching lines...) Expand all
544 // Send history response. 545 // Send history response.
545 history_handler->InvokeCallback(); 546 history_handler->InvokeCallback();
546 // Verify FaviconHandler status 547 // Verify FaviconHandler status
547 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 548 EXPECT_TRUE(driver.GetActiveFaviconValidity());
548 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 549 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
549 550
550 // Simulates update favicon url. 551 // Simulates update favicon url.
551 std::vector<FaviconURL> urls; 552 std::vector<FaviconURL> urls;
552 urls.push_back( 553 urls.push_back(
553 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 554 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
554 helper.OnUpdateFaviconURL(urls); 555 helper.OnUpdateFaviconURL(page_url, urls);
555 556
556 // Verify FaviconHandler status 557 // Verify FaviconHandler status
557 EXPECT_EQ(1U, helper.urls().size()); 558 EXPECT_EQ(1U, helper.urls().size());
558 ASSERT_TRUE(helper.current_candidate()); 559 ASSERT_TRUE(helper.current_candidate());
559 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 560 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
560 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 561 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
561 562
562 // Favicon shouldn't request to download icon. 563 // Favicon shouldn't request to download icon.
563 EXPECT_FALSE(helper.download_handler()->HasDownload()); 564 EXPECT_FALSE(helper.download_handler()->HasDownload());
564 } 565 }
(...skipping 21 matching lines...) Expand all
586 // Send history response. 587 // Send history response.
587 history_handler->InvokeCallback(); 588 history_handler->InvokeCallback();
588 // Verify FaviconHandler status 589 // Verify FaviconHandler status
589 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 590 EXPECT_TRUE(driver.GetActiveFaviconValidity());
590 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 591 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
591 592
592 // Simulates update favicon url. 593 // Simulates update favicon url.
593 std::vector<FaviconURL> urls; 594 std::vector<FaviconURL> urls;
594 urls.push_back( 595 urls.push_back(
595 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 596 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
596 helper.OnUpdateFaviconURL(urls); 597 helper.OnUpdateFaviconURL(page_url, urls);
597 598
598 // Verify FaviconHandler status 599 // Verify FaviconHandler status
599 EXPECT_EQ(1U, helper.urls().size()); 600 EXPECT_EQ(1U, helper.urls().size());
600 ASSERT_TRUE(helper.current_candidate()); 601 ASSERT_TRUE(helper.current_candidate());
601 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 602 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
602 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 603 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
603 604
604 // Favicon should request to download icon now. 605 // Favicon should request to download icon now.
605 DownloadHandler* download_handler = helper.download_handler(); 606 DownloadHandler* download_handler = helper.download_handler();
606 EXPECT_TRUE(helper.download_handler()->HasDownload()); 607 EXPECT_TRUE(helper.download_handler()->HasDownload());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 656 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
656 657
657 // Reset the history_handler to verify whether new icon is requested from 658 // Reset the history_handler to verify whether new icon is requested from
658 // history. 659 // history.
659 helper.set_history_handler(nullptr); 660 helper.set_history_handler(nullptr);
660 661
661 // Simulates update with the different favicon url. 662 // Simulates update with the different favicon url.
662 std::vector<FaviconURL> urls; 663 std::vector<FaviconURL> urls;
663 urls.push_back(FaviconURL( 664 urls.push_back(FaviconURL(
664 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 665 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
665 helper.OnUpdateFaviconURL(urls); 666 helper.OnUpdateFaviconURL(page_url, urls);
666 667
667 // Verify FaviconHandler status. 668 // Verify FaviconHandler status.
668 EXPECT_EQ(1U, helper.urls().size()); 669 EXPECT_EQ(1U, helper.urls().size());
669 ASSERT_TRUE(helper.current_candidate()); 670 ASSERT_TRUE(helper.current_candidate());
670 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 671 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
671 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 672 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
672 673
673 // Favicon should be requested from history. 674 // Favicon should be requested from history.
674 history_handler = helper.history_handler(); 675 history_handler = helper.history_handler();
675 ASSERT_TRUE(history_handler); 676 ASSERT_TRUE(history_handler);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 743 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
743 744
744 // Reset the history_handler to verify whether new icon is requested from 745 // Reset the history_handler to verify whether new icon is requested from
745 // history. 746 // history.
746 helper.set_history_handler(nullptr); 747 helper.set_history_handler(nullptr);
747 748
748 // Simulates update with matching favicon URL. 749 // Simulates update with matching favicon URL.
749 std::vector<FaviconURL> urls; 750 std::vector<FaviconURL> urls;
750 urls.push_back( 751 urls.push_back(
751 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 752 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
752 helper.OnUpdateFaviconURL(urls); 753 helper.OnUpdateFaviconURL(page_url, urls);
753 754
754 // A download for the favicon should be requested, and we should not do 755 // A download for the favicon should be requested, and we should not do
755 // another history request. 756 // another history request.
756 DownloadHandler* download_handler = helper.download_handler(); 757 DownloadHandler* download_handler = helper.download_handler();
757 EXPECT_TRUE(helper.download_handler()->HasDownload()); 758 EXPECT_TRUE(helper.download_handler()->HasDownload());
758 EXPECT_EQ(nullptr, helper.history_handler()); 759 EXPECT_EQ(nullptr, helper.history_handler());
759 760
760 // Verify the download request. 761 // Verify the download request.
761 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 762 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
762 763
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 804 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
804 805
805 // Reset the history_handler to verify whether new icon is requested from 806 // Reset the history_handler to verify whether new icon is requested from
806 // history. 807 // history.
807 helper.set_history_handler(nullptr); 808 helper.set_history_handler(nullptr);
808 809
809 // Simulates update with the different favicon url. 810 // Simulates update with the different favicon url.
810 std::vector<FaviconURL> urls; 811 std::vector<FaviconURL> urls;
811 urls.push_back(FaviconURL( 812 urls.push_back(FaviconURL(
812 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 813 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
813 helper.OnUpdateFaviconURL(urls); 814 helper.OnUpdateFaviconURL(page_url, urls);
814 815
815 // Verify FaviconHandler status. 816 // Verify FaviconHandler status.
816 EXPECT_EQ(1U, helper.urls().size()); 817 EXPECT_EQ(1U, helper.urls().size());
817 ASSERT_TRUE(helper.current_candidate()); 818 ASSERT_TRUE(helper.current_candidate());
818 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 819 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
819 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 820 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
820 821
821 // Favicon should be requested from history. 822 // Favicon should be requested from history.
822 history_handler = helper.history_handler(); 823 history_handler = helper.history_handler();
823 ASSERT_TRUE(history_handler); 824 ASSERT_TRUE(history_handler);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 873
873 // Simulates update with the different favicon url. 874 // Simulates update with the different favicon url.
874 std::vector<FaviconURL> urls; 875 std::vector<FaviconURL> urls;
875 urls.push_back(FaviconURL(icon_url, 876 urls.push_back(FaviconURL(icon_url,
876 favicon_base::TOUCH_PRECOMPOSED_ICON, 877 favicon_base::TOUCH_PRECOMPOSED_ICON,
877 std::vector<gfx::Size>())); 878 std::vector<gfx::Size>()));
878 urls.push_back(FaviconURL( 879 urls.push_back(FaviconURL(
879 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 880 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
880 urls.push_back(FaviconURL( 881 urls.push_back(FaviconURL(
881 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 882 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
882 helper.OnUpdateFaviconURL(urls); 883 helper.OnUpdateFaviconURL(page_url, urls);
883 884
884 // Verify FaviconHandler status. 885 // Verify FaviconHandler status.
885 EXPECT_EQ(2U, helper.urls().size()); 886 EXPECT_EQ(2U, helper.urls().size());
886 ASSERT_TRUE(helper.current_candidate()); 887 ASSERT_TRUE(helper.current_candidate());
887 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 888 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
888 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, 889 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON,
889 helper.current_candidate()->icon_type); 890 helper.current_candidate()->icon_type);
890 891
891 // Favicon should be requested from history. 892 // Favicon should be requested from history.
892 history_handler = helper.history_handler(); 893 history_handler = helper.history_handler();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 984
984 // Simulates update with the different favicon url. 985 // Simulates update with the different favicon url.
985 std::vector<FaviconURL> urls; 986 std::vector<FaviconURL> urls;
986 urls.push_back(FaviconURL(icon_url, 987 urls.push_back(FaviconURL(icon_url,
987 favicon_base::TOUCH_PRECOMPOSED_ICON, 988 favicon_base::TOUCH_PRECOMPOSED_ICON,
988 std::vector<gfx::Size>())); 989 std::vector<gfx::Size>()));
989 urls.push_back(FaviconURL( 990 urls.push_back(FaviconURL(
990 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 991 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
991 urls.push_back(FaviconURL( 992 urls.push_back(FaviconURL(
992 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 993 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
993 helper.OnUpdateFaviconURL(urls); 994 helper.OnUpdateFaviconURL(page_url, urls);
994 995
995 // Verify FaviconHandler status. 996 // Verify FaviconHandler status.
996 EXPECT_EQ(2U, helper.urls().size()); 997 EXPECT_EQ(2U, helper.urls().size());
997 ASSERT_TRUE(helper.current_candidate()); 998 ASSERT_TRUE(helper.current_candidate());
998 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 999 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
999 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, 1000 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON,
1000 helper.current_candidate()->icon_type); 1001 helper.current_candidate()->icon_type);
1001 1002
1002 // Favicon should be requested from history. 1003 // Favicon should be requested from history.
1003 history_handler = helper.history_handler(); 1004 history_handler = helper.history_handler();
(...skipping 13 matching lines...) Expand all
1017 // Verify the download request. 1018 // Verify the download request.
1018 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 1019 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
1019 1020
1020 // Reset the history_handler to verify whether favicon is request from 1021 // Reset the history_handler to verify whether favicon is request from
1021 // history. 1022 // history.
1022 helper.set_history_handler(nullptr); 1023 helper.set_history_handler(nullptr);
1023 const GURL latest_icon_url("http://www.google.com/latest_favicon"); 1024 const GURL latest_icon_url("http://www.google.com/latest_favicon");
1024 std::vector<FaviconURL> latest_urls; 1025 std::vector<FaviconURL> latest_urls;
1025 latest_urls.push_back(FaviconURL( 1026 latest_urls.push_back(FaviconURL(
1026 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 1027 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
1027 helper.OnUpdateFaviconURL(latest_urls); 1028 helper.OnUpdateFaviconURL(page_url, latest_urls);
1028 1029
1029 EXPECT_EQ(1U, helper.urls().size()); 1030 EXPECT_EQ(1U, helper.urls().size());
1030 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); 1031 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url);
1031 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); 1032 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type);
1032 1033
1033 // Whether new icon is requested from history 1034 // Whether new icon is requested from history
1034 history_handler = helper.history_handler(); 1035 history_handler = helper.history_handler();
1035 ASSERT_TRUE(history_handler); 1036 ASSERT_TRUE(history_handler);
1036 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); 1037 EXPECT_EQ(latest_icon_url, history_handler->icon_url_);
1037 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); 1038 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_);
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 EXPECT_FALSE(driver1.update_active_favicon()); 1699 EXPECT_FALSE(driver1.update_active_favicon());
1699 EXPECT_EQ(3u, driver1.num_favicon_available()); 1700 EXPECT_EQ(3u, driver1.num_favicon_available());
1700 } 1701 }
1701 1702
1702 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse, 1703 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse,
1703 FaviconHandlerActiveFaviconValidityParamTest, 1704 FaviconHandlerActiveFaviconValidityParamTest,
1704 ::testing::Bool()); 1705 ::testing::Bool());
1705 1706
1706 } // namespace 1707 } // namespace
1707 } // namespace favicon 1708 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | components/favicon/ios/web_favicon_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698