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

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

Issue 1295733002: Ignore duplicate FaviconHandler::OnUpdateFaviconURL() calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page_changed_under_us
Patch Set: Created 5 years, 2 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') | no next file » | 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 // This method will take the ownership of the given handler. 323 // This method will take the ownership of the given handler.
324 void set_history_handler(HistoryRequestHandler* handler) { 324 void set_history_handler(HistoryRequestHandler* handler) {
325 history_handler_.reset(handler); 325 history_handler_.reset(handler);
326 } 326 }
327 327
328 DownloadHandler* download_handler() { 328 DownloadHandler* download_handler() {
329 return download_handler_.get(); 329 return download_handler_.get();
330 } 330 }
331 331
332 // Methods to access favicon internals.
333 const std::vector<FaviconURL>& urls() {
334 return image_urls_;
335 }
336
337 FaviconURL* current_candidate() { 332 FaviconURL* current_candidate() {
338 return FaviconHandler::current_candidate(); 333 return FaviconHandler::current_candidate();
339 } 334 }
340 335
336 size_t current_candidate_index() const {
337 return current_candidate_index_;
338 }
339
341 const FaviconCandidate& best_favicon_candidate() { 340 const FaviconCandidate& best_favicon_candidate() {
342 return best_favicon_candidate_; 341 return best_favicon_candidate_;
343 } 342 }
344 343
345 protected: 344 protected:
346 void UpdateFaviconMappingAndFetch( 345 void UpdateFaviconMappingAndFetch(
347 const GURL& page_url, 346 const GURL& page_url,
348 const GURL& icon_url, 347 const GURL& icon_url,
349 favicon_base::IconType icon_type, 348 favicon_base::IconType icon_type,
350 const favicon_base::FaviconResultsCallback& callback, 349 const favicon_base::FaviconResultsCallback& callback,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 547 EXPECT_TRUE(driver.GetActiveFaviconValidity());
549 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 548 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
550 549
551 // Simulates update favicon url. 550 // Simulates update favicon url.
552 std::vector<FaviconURL> urls; 551 std::vector<FaviconURL> urls;
553 urls.push_back( 552 urls.push_back(
554 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 553 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
555 helper.OnUpdateFaviconURL(page_url, urls); 554 helper.OnUpdateFaviconURL(page_url, urls);
556 555
557 // Verify FaviconHandler status 556 // Verify FaviconHandler status
558 EXPECT_EQ(1U, helper.urls().size()); 557 EXPECT_EQ(1u, helper.image_urls().size());
559 ASSERT_TRUE(helper.current_candidate()); 558 ASSERT_TRUE(helper.current_candidate());
560 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 559 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
561 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 560 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
562 561
563 // Favicon shouldn't request to download icon. 562 // Favicon shouldn't request to download icon.
564 EXPECT_FALSE(helper.download_handler()->HasDownload()); 563 EXPECT_FALSE(helper.download_handler()->HasDownload());
565 } 564 }
566 565
567 TEST_F(FaviconHandlerTest, DownloadFavicon) { 566 TEST_F(FaviconHandlerTest, DownloadFavicon) {
568 const GURL page_url("http://www.google.com"); 567 const GURL page_url("http://www.google.com");
(...skipping 21 matching lines...) Expand all
590 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 589 EXPECT_TRUE(driver.GetActiveFaviconValidity());
591 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 590 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
592 591
593 // Simulates update favicon url. 592 // Simulates update favicon url.
594 std::vector<FaviconURL> urls; 593 std::vector<FaviconURL> urls;
595 urls.push_back( 594 urls.push_back(
596 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 595 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
597 helper.OnUpdateFaviconURL(page_url, urls); 596 helper.OnUpdateFaviconURL(page_url, urls);
598 597
599 // Verify FaviconHandler status 598 // Verify FaviconHandler status
600 EXPECT_EQ(1U, helper.urls().size()); 599 EXPECT_EQ(1u, helper.image_urls().size());
601 ASSERT_TRUE(helper.current_candidate()); 600 ASSERT_TRUE(helper.current_candidate());
602 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 601 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
603 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 602 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
604 603
605 // Favicon should request to download icon now. 604 // Favicon should request to download icon now.
606 DownloadHandler* download_handler = helper.download_handler(); 605 DownloadHandler* download_handler = helper.download_handler();
607 EXPECT_TRUE(helper.download_handler()->HasDownload()); 606 EXPECT_TRUE(helper.download_handler()->HasDownload());
608 607
609 // Verify the download request. 608 // Verify the download request.
610 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 609 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 // history. 658 // history.
660 helper.set_history_handler(nullptr); 659 helper.set_history_handler(nullptr);
661 660
662 // Simulates update with the different favicon url. 661 // Simulates update with the different favicon url.
663 std::vector<FaviconURL> urls; 662 std::vector<FaviconURL> urls;
664 urls.push_back(FaviconURL( 663 urls.push_back(FaviconURL(
665 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 664 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
666 helper.OnUpdateFaviconURL(page_url, urls); 665 helper.OnUpdateFaviconURL(page_url, urls);
667 666
668 // Verify FaviconHandler status. 667 // Verify FaviconHandler status.
669 EXPECT_EQ(1U, helper.urls().size()); 668 EXPECT_EQ(1u, helper.image_urls().size());
670 ASSERT_TRUE(helper.current_candidate()); 669 ASSERT_TRUE(helper.current_candidate());
671 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 670 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
672 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 671 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
673 672
674 // Favicon should be requested from history. 673 // Favicon should be requested from history.
675 history_handler = helper.history_handler(); 674 history_handler = helper.history_handler();
676 ASSERT_TRUE(history_handler); 675 ASSERT_TRUE(history_handler);
677 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 676 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
678 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 677 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
679 EXPECT_EQ(page_url, history_handler->page_url_); 678 EXPECT_EQ(page_url, history_handler->page_url_);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 // history. 806 // history.
808 helper.set_history_handler(nullptr); 807 helper.set_history_handler(nullptr);
809 808
810 // Simulates update with the different favicon url. 809 // Simulates update with the different favicon url.
811 std::vector<FaviconURL> urls; 810 std::vector<FaviconURL> urls;
812 urls.push_back(FaviconURL( 811 urls.push_back(FaviconURL(
813 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 812 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
814 helper.OnUpdateFaviconURL(page_url, urls); 813 helper.OnUpdateFaviconURL(page_url, urls);
815 814
816 // Verify FaviconHandler status. 815 // Verify FaviconHandler status.
817 EXPECT_EQ(1U, helper.urls().size()); 816 EXPECT_EQ(1u, helper.image_urls().size());
818 ASSERT_TRUE(helper.current_candidate()); 817 ASSERT_TRUE(helper.current_candidate());
819 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); 818 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url);
820 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 819 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
821 820
822 // Favicon should be requested from history. 821 // Favicon should be requested from history.
823 history_handler = helper.history_handler(); 822 history_handler = helper.history_handler();
824 ASSERT_TRUE(history_handler); 823 ASSERT_TRUE(history_handler);
825 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 824 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
826 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 825 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
827 EXPECT_EQ(page_url, history_handler->page_url_); 826 EXPECT_EQ(page_url, history_handler->page_url_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 urls.push_back(FaviconURL(icon_url, 875 urls.push_back(FaviconURL(icon_url,
877 favicon_base::TOUCH_PRECOMPOSED_ICON, 876 favicon_base::TOUCH_PRECOMPOSED_ICON,
878 std::vector<gfx::Size>())); 877 std::vector<gfx::Size>()));
879 urls.push_back(FaviconURL( 878 urls.push_back(FaviconURL(
880 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 879 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
881 urls.push_back(FaviconURL( 880 urls.push_back(FaviconURL(
882 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 881 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
883 helper.OnUpdateFaviconURL(page_url, urls); 882 helper.OnUpdateFaviconURL(page_url, urls);
884 883
885 // Verify FaviconHandler status. 884 // Verify FaviconHandler status.
886 EXPECT_EQ(2U, helper.urls().size()); 885 EXPECT_EQ(2u, helper.image_urls().size());
886 EXPECT_EQ(0u, helper.current_candidate_index());
887 ASSERT_TRUE(helper.current_candidate()); 887 ASSERT_TRUE(helper.current_candidate());
888 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 888 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
889 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, 889 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON,
890 helper.current_candidate()->icon_type); 890 helper.current_candidate()->icon_type);
891 891
892 // Favicon should be requested from history. 892 // Favicon should be requested from history.
893 history_handler = helper.history_handler(); 893 history_handler = helper.history_handler();
894 ASSERT_TRUE(history_handler); 894 ASSERT_TRUE(history_handler);
895 EXPECT_EQ(icon_url, history_handler->icon_url_); 895 EXPECT_EQ(icon_url, history_handler->icon_url_);
896 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); 896 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_);
897 EXPECT_EQ(page_url, history_handler->page_url_); 897 EXPECT_EQ(page_url, history_handler->page_url_);
898 898
899 // Simulate not find icon. 899 // Simulate not find icon.
900 history_handler->history_results_.clear(); 900 history_handler->history_results_.clear();
901 history_handler->InvokeCallback(); 901 history_handler->InvokeCallback();
902 902
903 // Should request download favicon. 903 // Should request download favicon.
904 DownloadHandler* download_handler = helper.download_handler(); 904 DownloadHandler* download_handler = helper.download_handler();
905 EXPECT_TRUE(helper.download_handler()->HasDownload()); 905 EXPECT_TRUE(helper.download_handler()->HasDownload());
906 906
907 // Verify the download request. 907 // Verify the download request.
908 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 908 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
909 909
910 // Reset the history_handler to verify whether favicon is request from 910 // Reset the history_handler to verify whether favicon is request from
911 // history. 911 // history.
912 helper.set_history_handler(nullptr); 912 helper.set_history_handler(nullptr);
913 download_handler->InvokeCallback(); 913 download_handler->InvokeCallback();
914 914
915 // Left 1 url. 915 // Left 1 url.
916 EXPECT_EQ(1U, helper.urls().size()); 916 EXPECT_EQ(1u, helper.current_candidate_index());
917 ASSERT_TRUE(helper.current_candidate()); 917 ASSERT_TRUE(helper.current_candidate());
918 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); 918 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url);
919 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); 919 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type);
920 920
921 // Favicon should be requested from history. 921 // Favicon should be requested from history.
922 history_handler = helper.history_handler(); 922 history_handler = helper.history_handler();
923 ASSERT_TRUE(history_handler); 923 ASSERT_TRUE(history_handler);
924 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 924 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
925 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); 925 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_);
926 EXPECT_EQ(page_url, history_handler->page_url_); 926 EXPECT_EQ(page_url, history_handler->page_url_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 urls.push_back(FaviconURL(icon_url, 987 urls.push_back(FaviconURL(icon_url,
988 favicon_base::TOUCH_PRECOMPOSED_ICON, 988 favicon_base::TOUCH_PRECOMPOSED_ICON,
989 std::vector<gfx::Size>())); 989 std::vector<gfx::Size>()));
990 urls.push_back(FaviconURL( 990 urls.push_back(FaviconURL(
991 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 991 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
992 urls.push_back(FaviconURL( 992 urls.push_back(FaviconURL(
993 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 993 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
994 helper.OnUpdateFaviconURL(page_url, urls); 994 helper.OnUpdateFaviconURL(page_url, urls);
995 995
996 // Verify FaviconHandler status. 996 // Verify FaviconHandler status.
997 EXPECT_EQ(2U, helper.urls().size()); 997 EXPECT_EQ(2u, helper.image_urls().size());
998 ASSERT_TRUE(helper.current_candidate()); 998 ASSERT_EQ(0u, helper.current_candidate_index());
999 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); 999 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url);
1000 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, 1000 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON,
1001 helper.current_candidate()->icon_type); 1001 helper.current_candidate()->icon_type);
1002 1002
1003 // Favicon should be requested from history. 1003 // Favicon should be requested from history.
1004 history_handler = helper.history_handler(); 1004 history_handler = helper.history_handler();
1005 ASSERT_TRUE(history_handler); 1005 ASSERT_TRUE(history_handler);
1006 EXPECT_EQ(icon_url, history_handler->icon_url_); 1006 EXPECT_EQ(icon_url, history_handler->icon_url_);
1007 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); 1007 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_);
1008 EXPECT_EQ(page_url, history_handler->page_url_); 1008 EXPECT_EQ(page_url, history_handler->page_url_);
(...skipping 11 matching lines...) Expand all
1020 1020
1021 // Reset the history_handler to verify whether favicon is request from 1021 // Reset the history_handler to verify whether favicon is request from
1022 // history. 1022 // history.
1023 helper.set_history_handler(nullptr); 1023 helper.set_history_handler(nullptr);
1024 const GURL latest_icon_url("http://www.google.com/latest_favicon"); 1024 const GURL latest_icon_url("http://www.google.com/latest_favicon");
1025 std::vector<FaviconURL> latest_urls; 1025 std::vector<FaviconURL> latest_urls;
1026 latest_urls.push_back(FaviconURL( 1026 latest_urls.push_back(FaviconURL(
1027 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 1027 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
1028 helper.OnUpdateFaviconURL(page_url, latest_urls); 1028 helper.OnUpdateFaviconURL(page_url, latest_urls);
1029 1029
1030 EXPECT_EQ(1U, helper.urls().size()); 1030 EXPECT_EQ(1u, helper.image_urls().size());
1031 EXPECT_EQ(0u, helper.current_candidate_index());
1031 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); 1032 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url);
1032 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); 1033 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type);
1033 1034
1034 // Whether new icon is requested from history 1035 // Whether new icon is requested from history
1035 history_handler = helper.history_handler(); 1036 history_handler = helper.history_handler();
1036 ASSERT_TRUE(history_handler); 1037 ASSERT_TRUE(history_handler);
1037 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); 1038 EXPECT_EQ(latest_icon_url, history_handler->icon_url_);
1038 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); 1039 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_);
1039 EXPECT_EQ(page_url, history_handler->page_url_); 1040 EXPECT_EQ(page_url, history_handler->page_url_);
1040 1041
(...skipping 17 matching lines...) Expand all
1058 SetFaviconRawBitmapResult(latest_icon_url, 1059 SetFaviconRawBitmapResult(latest_icon_url,
1059 favicon_base::TOUCH_ICON, 1060 favicon_base::TOUCH_ICON,
1060 false /* expired */, 1061 false /* expired */,
1061 &handler->history_results_); 1062 &handler->history_results_);
1062 handler->InvokeCallback(); 1063 handler->InvokeCallback();
1063 1064
1064 // No download request. 1065 // No download request.
1065 EXPECT_FALSE(download_handler->HasDownload()); 1066 EXPECT_FALSE(download_handler->HasDownload());
1066 } 1067 }
1067 1068
1069 // Test that sending an icon URL update identical to the previous icon URL
1070 // update is a no-op.
1071 TEST_F(FaviconHandlerTest, UpdateSameIconURLs) {
1072 const GURL page_url("http://www.google.com");
1073 const GURL icon_url1("http://www.google.com/favicon1");
1074 const GURL icon_url2("http://www.google.com/favicon2");
1075 std::vector<FaviconURL> favicon_urls;
1076 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"),
1077 favicon_base::FAVICON,
1078 std::vector<gfx::Size>()));
1079 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"),
1080 favicon_base::FAVICON,
1081 std::vector<gfx::Size>()));
1082
1083 TestFaviconDriver driver;
1084 TestFaviconHandler helper(page_url, &driver, FaviconHandler::FAVICON, false);
1085
1086 // Initiate a request for favicon data for |page_url|. History does not know
1087 // about the page URL or the icon URLs.
1088 helper.FetchFavicon(page_url);
1089 helper.history_handler()->InvokeCallback();
1090 helper.set_history_handler(nullptr);
1091
1092 // Got icon URLs.
1093 helper.OnUpdateFaviconURL(page_url, favicon_urls);
1094
1095 // There should be an ongoing history request for |icon_url1|.
1096 ASSERT_EQ(2u, helper.image_urls().size());
1097 ASSERT_EQ(0u, helper.current_candidate_index());
1098 HistoryRequestHandler* history_handler = helper.history_handler();
1099 ASSERT_TRUE(history_handler);
1100
1101 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect.
1102 helper.OnUpdateFaviconURL(page_url, favicon_urls);
1103 EXPECT_EQ(history_handler, helper.history_handler());
1104
1105 // Complete history request for |icon_url1| and do download.
1106 helper.history_handler()->InvokeCallback();
1107 helper.set_history_handler(nullptr);
1108 helper.download_handler()->SetImageSizes(std::vector<int>(1u, 10));
1109 helper.download_handler()->InvokeCallback();
1110 helper.download_handler()->Reset();
1111
1112 // There should now be an ongoing history request for |icon_url2|.
1113 ASSERT_EQ(1u, helper.current_candidate_index());
1114 history_handler = helper.history_handler();
1115 ASSERT_TRUE(history_handler);
1116
1117 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect.
1118 helper.OnUpdateFaviconURL(page_url, favicon_urls);
1119 EXPECT_EQ(history_handler, helper.history_handler());
1120 }
1121
1068 // Test the favicon which is selected when the web page provides several 1122 // Test the favicon which is selected when the web page provides several
1069 // favicons and none of the favicons are cached in history. 1123 // favicons and none of the favicons are cached in history.
1070 // The goal of this test is to be more of an integration test than 1124 // The goal of this test is to be more of an integration test than
1071 // SelectFaviconFramesTest.*. 1125 // SelectFaviconFramesTest.*.
1072 TEST_F(FaviconHandlerTest, MultipleFavicons) { 1126 TEST_F(FaviconHandlerTest, MultipleFavicons) {
1073 const GURL kPageURL("http://www.google.com"); 1127 const GURL kPageURL("http://www.google.com");
1074 const FaviconURL kSourceIconURLs[] = { 1128 const FaviconURL kSourceIconURLs[] = {
1075 FaviconURL(GURL("http://www.google.com/a"), 1129 FaviconURL(GURL("http://www.google.com/a"),
1076 favicon_base::FAVICON, 1130 favicon_base::FAVICON,
1077 std::vector<gfx::Size>()), 1131 std::vector<gfx::Size>()),
(...skipping 22 matching lines...) Expand all
1100 TestFaviconDriver driver1; 1154 TestFaviconDriver driver1;
1101 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON, 1155 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON,
1102 false); 1156 false);
1103 1157
1104 const int kSizes1[] = { 16, 24, 32, 48, 256 }; 1158 const int kSizes1[] = { 16, 24, 32, 48, 256 };
1105 std::vector<FaviconURL> urls1(kSourceIconURLs, 1159 std::vector<FaviconURL> urls1(kSourceIconURLs,
1106 kSourceIconURLs + arraysize(kSizes1)); 1160 kSourceIconURLs + arraysize(kSizes1));
1107 DownloadTillDoneIgnoringHistory( 1161 DownloadTillDoneIgnoringHistory(
1108 &driver1, &handler1, kPageURL, urls1, kSizes1); 1162 &driver1, &handler1, kPageURL, urls1, kSizes1);
1109 1163
1110 EXPECT_EQ(0u, handler1.image_urls().size()); 1164 EXPECT_EQ(nullptr, handler1.current_candidate());
1111 EXPECT_TRUE(driver1.GetActiveFaviconValidity()); 1165 EXPECT_TRUE(driver1.GetActiveFaviconValidity());
1112 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty()); 1166 EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty());
1113 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width()); 1167 EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width());
1114 1168
1115 size_t expected_index = 2u; 1169 size_t expected_index = 2u;
1116 EXPECT_EQ(32, kSizes1[expected_index]); 1170 EXPECT_EQ(32, kSizes1[expected_index]);
1117 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1171 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
1118 driver1.GetActiveFaviconURL()); 1172 driver1.GetActiveFaviconURL());
1119 1173
1120 // 2) Test that if there are several single resolution favicons to choose 1174 // 2) Test that if there are several single resolution favicons to choose
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1257
1204 // Do a fetch now that the initial download for |k404IconURL| has failed. The 1258 // Do a fetch now that the initial download for |k404IconURL| has failed. The
1205 // behavior is different because OnDidDownloadFavicon() is invoked 1259 // behavior is different because OnDidDownloadFavicon() is invoked
1206 // synchronously from DownloadFavicon(). 1260 // synchronously from DownloadFavicon().
1207 const int kSizes2[] = { 10, 0, 16 }; 1261 const int kSizes2[] = { 10, 0, 16 };
1208 std::vector<FaviconURL> urls2(kFaviconURLs, 1262 std::vector<FaviconURL> urls2(kFaviconURLs,
1209 kFaviconURLs + arraysize(kFaviconURLs)); 1263 kFaviconURLs + arraysize(kFaviconURLs));
1210 DownloadTillDoneIgnoringHistory( 1264 DownloadTillDoneIgnoringHistory(
1211 &driver, &handler, kPageURL, urls2, kSizes2); 1265 &driver, &handler, kPageURL, urls2, kSizes2);
1212 1266
1213 EXPECT_EQ(0u, handler.image_urls().size()); 1267 EXPECT_EQ(nullptr, handler.current_candidate());
1214 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 1268 EXPECT_TRUE(driver.GetActiveFaviconValidity());
1215 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty()); 1269 EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty());
1216 int expected_index = 2u; 1270 int expected_index = 2u;
1217 EXPECT_EQ(16, kSizes2[expected_index]); 1271 EXPECT_EQ(16, kSizes2[expected_index]);
1218 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, 1272 EXPECT_EQ(kFaviconURLs[expected_index].icon_url,
1219 driver.GetActiveFaviconURL()); 1273 driver.GetActiveFaviconURL());
1220 } 1274 }
1221 1275
1222 // Test that no favicon is selected when: 1276 // Test that no favicon is selected when:
1223 // - The page provides several favicons. 1277 // - The page provides several favicons.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); 1309 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2));
1256 1310
1257 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. 1311 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed.
1258 // The behavior is different because OnDidDownloadFavicon() is invoked 1312 // The behavior is different because OnDidDownloadFavicon() is invoked
1259 // synchronously from DownloadFavicon(). 1313 // synchronously from DownloadFavicon().
1260 const int kSizes[] = { 0, 0 }; 1314 const int kSizes[] = { 0, 0 };
1261 std::vector<FaviconURL> urls(kFaviconURLs, 1315 std::vector<FaviconURL> urls(kFaviconURLs,
1262 kFaviconURLs + arraysize(kFaviconURLs)); 1316 kFaviconURLs + arraysize(kFaviconURLs));
1263 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes); 1317 DownloadTillDoneIgnoringHistory(&driver, &handler, kPageURL, urls, kSizes);
1264 1318
1265 EXPECT_EQ(0u, handler.image_urls().size()); 1319 EXPECT_EQ(nullptr, handler.current_candidate());
1266 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 1320 EXPECT_FALSE(driver.GetActiveFaviconValidity());
1267 EXPECT_TRUE(driver.GetActiveFaviconImage().IsEmpty()); 1321 EXPECT_TRUE(driver.GetActiveFaviconImage().IsEmpty());
1268 } 1322 }
1269 1323
1270 // Test that no favicon is selected when the page's only icon uses an invalid 1324 // Test that no favicon is selected when the page's only icon uses an invalid
1271 // URL syntax. 1325 // URL syntax.
1272 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { 1326 TEST_F(FaviconHandlerTest, FaviconInvalidURL) {
1273 const GURL kPageURL("http://www.google.com"); 1327 const GURL kPageURL("http://www.google.com");
1274 const GURL kInvalidFormatURL("invalid"); 1328 const GURL kInvalidFormatURL("invalid");
1275 ASSERT_TRUE(kInvalidFormatURL.is_empty()); 1329 ASSERT_TRUE(kInvalidFormatURL.is_empty());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 } 1436 }
1383 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); 1437 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls);
1384 1438
1385 std::vector<FaviconURL> urls1(kSourceIconURLs, 1439 std::vector<FaviconURL> urls1(kSourceIconURLs,
1386 kSourceIconURLs + arraysize(kSourceIconURLs)); 1440 kSourceIconURLs + arraysize(kSourceIconURLs));
1387 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1441 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1388 1442
1389 // Simulate the download failed, to check whether the icons were requested 1443 // Simulate the download failed, to check whether the icons were requested
1390 // to download according their size. 1444 // to download according their size.
1391 struct ExpectedResult { 1445 struct ExpectedResult {
1392 // The size of image_urls_.
1393 size_t image_urls_size;
1394 // The favicon's index in kSourceIconURLs. 1446 // The favicon's index in kSourceIconURLs.
1395 size_t favicon_index; 1447 size_t favicon_index;
1396 // Width of largest bitmap. 1448 // Width of largest bitmap.
1397 int width; 1449 int width;
1398 } results[] = { 1450 } results[] = {
1399 {5, 0, 1024}, 1451 {0, 1024},
1400 {4, 2, 512}, 1452 {2, 512},
1401 {3, 1, 15}, 1453 {1, 15},
1402 // The rest of bitmaps come in order. 1454 // The rest of bitmaps come in order.
1403 {2, 3, -1}, 1455 {3, -1},
1404 {1, 4, -1}, 1456 {4, -1},
1405 }; 1457 };
1406 1458
1407 for (int i = 0; i < 5; ++i) { 1459 for (int i = 0; i < 5; ++i) {
1408 ASSERT_EQ(results[i].image_urls_size, handler1.image_urls().size());
1409 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, 1460 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url,
1410 handler1.current_candidate()->icon_url); 1461 handler1.current_candidate()->icon_url);
1411 if (results[i].width != -1) { 1462 if (results[i].width != -1) {
1412 EXPECT_EQ(results[i].width, handler1.current_candidate()-> 1463 EXPECT_EQ(results[i].width, handler1.current_candidate()->
1413 icon_sizes[0].width()); 1464 icon_sizes[0].width());
1414 } 1465 }
1415 1466
1416 // Simulate no favicon from history. 1467 // Simulate no favicon from history.
1417 handler1.history_handler()->history_results_.clear(); 1468 handler1.history_handler()->history_results_.clear();
1418 handler1.history_handler()->InvokeCallback(); 1469 handler1.history_handler()->InvokeCallback();
(...skipping 24 matching lines...) Expand all
1443 FaviconURL( 1494 FaviconURL(
1444 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; 1495 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)};
1445 1496
1446 TestFaviconDriver driver1; 1497 TestFaviconDriver driver1;
1447 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON, 1498 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON,
1448 true); 1499 true);
1449 std::vector<FaviconURL> urls1(kSourceIconURLs, 1500 std::vector<FaviconURL> urls1(kSourceIconURLs,
1450 kSourceIconURLs + arraysize(kSourceIconURLs)); 1501 kSourceIconURLs + arraysize(kSourceIconURLs));
1451 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1502 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1452 1503
1453 ASSERT_EQ(2u, handler1.urls().size()); 1504 ASSERT_EQ(2u, handler1.image_urls().size());
1454 1505
1455 // Index of largest favicon in kSourceIconURLs. 1506 // Index of largest favicon in kSourceIconURLs.
1456 size_t i = 1; 1507 size_t i = 1;
1457 // The largest bitmap's index in Favicon . 1508 // The largest bitmap's index in Favicon .
1458 int b = 1; 1509 int b = 1;
1459 1510
1460 // Verify the icon_bitmaps_ was initialized correctly. 1511 // Verify the icon_bitmaps_ was initialized correctly.
1461 EXPECT_EQ(kSourceIconURLs[i].icon_url, 1512 EXPECT_EQ(kSourceIconURLs[i].icon_url,
1462 handler1.current_candidate()->icon_url); 1513 handler1.current_candidate()->icon_url);
1463 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], 1514 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b],
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 FaviconURL( 1561 FaviconURL(
1511 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; 1562 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)};
1512 1563
1513 TestFaviconDriver driver1; 1564 TestFaviconDriver driver1;
1514 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON, 1565 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON,
1515 true); 1566 true);
1516 std::vector<FaviconURL> urls1(kSourceIconURLs, 1567 std::vector<FaviconURL> urls1(kSourceIconURLs,
1517 kSourceIconURLs + arraysize(kSourceIconURLs)); 1568 kSourceIconURLs + arraysize(kSourceIconURLs));
1518 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1569 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1519 1570
1520 ASSERT_EQ(2u, handler1.urls().size()); 1571 ASSERT_EQ(2u, handler1.image_urls().size());
1521 1572
1522 // Index of largest favicon in kSourceIconURLs. 1573 // Index of largest favicon in kSourceIconURLs.
1523 size_t i = 1; 1574 size_t i = 1;
1524 // The largest bitmap's index in Favicon . 1575 // The largest bitmap's index in Favicon .
1525 int b = 0; 1576 int b = 0;
1526 1577
1527 // Verify the icon_bitmaps_ was initialized correctly. 1578 // Verify the icon_bitmaps_ was initialized correctly.
1528 EXPECT_EQ(kSourceIconURLs[i].icon_url, 1579 EXPECT_EQ(kSourceIconURLs[i].icon_url,
1529 handler1.current_candidate()->icon_url); 1580 handler1.current_candidate()->icon_url);
1530 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], 1581 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b],
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 FaviconURL(GURL("http://www.google.com/d"), 1621 FaviconURL(GURL("http://www.google.com/d"),
1571 favicon_base::FAVICON, 1622 favicon_base::FAVICON,
1572 std::vector<gfx::Size>())}; 1623 std::vector<gfx::Size>())};
1573 1624
1574 TestFaviconDriver driver1; 1625 TestFaviconDriver driver1;
1575 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON, 1626 TestFaviconHandler handler1(kPageURL, &driver1, FaviconHandler::FAVICON,
1576 true); 1627 true);
1577 std::vector<FaviconURL> urls1(kSourceIconURLs, 1628 std::vector<FaviconURL> urls1(kSourceIconURLs,
1578 kSourceIconURLs + arraysize(kSourceIconURLs)); 1629 kSourceIconURLs + arraysize(kSourceIconURLs));
1579 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); 1630 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1);
1580 ASSERT_EQ(3u, handler1.urls().size()); 1631 ASSERT_EQ(3u, handler1.image_urls().size());
1581 1632
1582 // Simulate no favicon from history. 1633 // Simulate no favicon from history.
1583 handler1.history_handler()->history_results_.clear(); 1634 handler1.history_handler()->history_results_.clear();
1584 handler1.history_handler()->InvokeCallback(); 1635 handler1.history_handler()->InvokeCallback();
1585 1636
1586 // Verify the first icon was request to download 1637 // Verify the first icon was request to download
1587 ASSERT_TRUE(handler1.download_handler()->HasDownload()); 1638 ASSERT_TRUE(handler1.download_handler()->HasDownload());
1588 EXPECT_EQ(kSourceIconURLs[0].icon_url, 1639 EXPECT_EQ(kSourceIconURLs[0].icon_url,
1589 handler1.download_handler()->GetImageUrl()); 1640 handler1.download_handler()->GetImageUrl());
1590 1641
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 EXPECT_FALSE(driver1.update_active_favicon()); 1750 EXPECT_FALSE(driver1.update_active_favicon());
1700 EXPECT_EQ(3u, driver1.num_favicon_available()); 1751 EXPECT_EQ(3u, driver1.num_favicon_available());
1701 } 1752 }
1702 1753
1703 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse, 1754 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse,
1704 FaviconHandlerActiveFaviconValidityParamTest, 1755 FaviconHandlerActiveFaviconValidityParamTest,
1705 ::testing::Bool()); 1756 ::testing::Bool());
1706 1757
1707 } // namespace 1758 } // namespace
1708 } // namespace favicon 1759 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698