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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "chrome/browser/favicon/favicon_handler.h" | 6 #include "chrome/browser/favicon/favicon_handler.h" |
7 #include "chrome/browser/favicon/favicon_service_factory.h" | 7 #include "chrome/browser/favicon/favicon_service_factory.h" |
8 #include "chrome/browser/history/history_service_factory.h" | 8 #include "chrome/browser/history/history_service_factory.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 430 |
431 void UpdateFaviconURL( | 431 void UpdateFaviconURL( |
432 TestFaviconHandler* favicon_handler, | 432 TestFaviconHandler* favicon_handler, |
433 const GURL& page_url, | 433 const GURL& page_url, |
434 const std::vector<FaviconURL>& candidate_icons) { | 434 const std::vector<FaviconURL>& candidate_icons) { |
435 favicon_handler->ResetNumFaviconUpdateNotifications(); | 435 favicon_handler->ResetNumFaviconUpdateNotifications(); |
436 | 436 |
437 favicon_handler->FetchFavicon(page_url); | 437 favicon_handler->FetchFavicon(page_url); |
438 favicon_handler->history_handler()->InvokeCallback(); | 438 favicon_handler->history_handler()->InvokeCallback(); |
439 | 439 |
440 favicon_handler->OnUpdateFaviconURL(0, candidate_icons); | 440 favicon_handler->OnUpdateFaviconURL(candidate_icons); |
441 } | 441 } |
442 | 442 |
443 virtual void SetUp() { | 443 virtual void SetUp() { |
444 // The score computed by SelectFaviconFrames() is dependent on the supported | 444 // The score computed by SelectFaviconFrames() is dependent on the supported |
445 // scale factors of the platform. It is used for determining the goodness of | 445 // scale factors of the platform. It is used for determining the goodness of |
446 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 446 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
447 // Force the values of the scale factors so that the tests produce the same | 447 // Force the values of the scale factors so that the tests produce the same |
448 // results on all platforms. | 448 // results on all platforms. |
449 std::vector<ui::ScaleFactor> scale_factors; | 449 std::vector<ui::ScaleFactor> scale_factors; |
450 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 450 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // Send history response. | 491 // Send history response. |
492 history_handler->InvokeCallback(); | 492 history_handler->InvokeCallback(); |
493 // Verify FaviconHandler status | 493 // Verify FaviconHandler status |
494 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 494 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
495 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 495 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
496 | 496 |
497 // Simulates update favicon url. | 497 // Simulates update favicon url. |
498 std::vector<FaviconURL> urls; | 498 std::vector<FaviconURL> urls; |
499 urls.push_back( | 499 urls.push_back( |
500 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 500 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
501 helper.OnUpdateFaviconURL(0, urls); | 501 helper.OnUpdateFaviconURL(urls); |
502 | 502 |
503 // Verify FaviconHandler status | 503 // Verify FaviconHandler status |
504 EXPECT_EQ(1U, helper.urls().size()); | 504 EXPECT_EQ(1U, helper.urls().size()); |
505 ASSERT_TRUE(helper.current_candidate()); | 505 ASSERT_TRUE(helper.current_candidate()); |
506 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 506 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
507 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 507 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
508 | 508 |
509 // Favicon shouldn't request to download icon. | 509 // Favicon shouldn't request to download icon. |
510 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 510 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
511 } | 511 } |
(...skipping 23 matching lines...) Expand all Loading... |
535 // Send history response. | 535 // Send history response. |
536 history_handler->InvokeCallback(); | 536 history_handler->InvokeCallback(); |
537 // Verify FaviconHandler status | 537 // Verify FaviconHandler status |
538 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 538 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
539 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 539 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
540 | 540 |
541 // Simulates update favicon url. | 541 // Simulates update favicon url. |
542 std::vector<FaviconURL> urls; | 542 std::vector<FaviconURL> urls; |
543 urls.push_back( | 543 urls.push_back( |
544 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 544 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
545 helper.OnUpdateFaviconURL(0, urls); | 545 helper.OnUpdateFaviconURL(urls); |
546 | 546 |
547 // Verify FaviconHandler status | 547 // Verify FaviconHandler status |
548 EXPECT_EQ(1U, helper.urls().size()); | 548 EXPECT_EQ(1U, helper.urls().size()); |
549 ASSERT_TRUE(helper.current_candidate()); | 549 ASSERT_TRUE(helper.current_candidate()); |
550 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 550 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
551 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 551 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
552 | 552 |
553 // Favicon should request to download icon now. | 553 // Favicon should request to download icon now. |
554 DownloadHandler* download_handler = helper.download_handler(); | 554 DownloadHandler* download_handler = helper.download_handler(); |
555 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 555 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 607 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
608 | 608 |
609 // Reset the history_handler to verify whether new icon is requested from | 609 // Reset the history_handler to verify whether new icon is requested from |
610 // history. | 610 // history. |
611 helper.set_history_handler(NULL); | 611 helper.set_history_handler(NULL); |
612 | 612 |
613 // Simulates update with the different favicon url. | 613 // Simulates update with the different favicon url. |
614 std::vector<FaviconURL> urls; | 614 std::vector<FaviconURL> urls; |
615 urls.push_back( | 615 urls.push_back( |
616 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 616 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
617 helper.OnUpdateFaviconURL(0, urls); | 617 helper.OnUpdateFaviconURL(urls); |
618 | 618 |
619 // Verify FaviconHandler status. | 619 // Verify FaviconHandler status. |
620 EXPECT_EQ(1U, helper.urls().size()); | 620 EXPECT_EQ(1U, helper.urls().size()); |
621 ASSERT_TRUE(helper.current_candidate()); | 621 ASSERT_TRUE(helper.current_candidate()); |
622 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 622 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
623 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 623 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
624 | 624 |
625 // Favicon should be requested from history. | 625 // Favicon should be requested from history. |
626 history_handler = helper.history_handler(); | 626 history_handler = helper.history_handler(); |
627 ASSERT_TRUE(history_handler); | 627 ASSERT_TRUE(history_handler); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); | 697 EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); |
698 | 698 |
699 // Reset the history_handler to verify whether new icon is requested from | 699 // Reset the history_handler to verify whether new icon is requested from |
700 // history. | 700 // history. |
701 helper.set_history_handler(NULL); | 701 helper.set_history_handler(NULL); |
702 | 702 |
703 // Simulates update with matching favicon URL. | 703 // Simulates update with matching favicon URL. |
704 std::vector<FaviconURL> urls; | 704 std::vector<FaviconURL> urls; |
705 urls.push_back( | 705 urls.push_back( |
706 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 706 FaviconURL(icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
707 helper.OnUpdateFaviconURL(0, urls); | 707 helper.OnUpdateFaviconURL(urls); |
708 | 708 |
709 // A download for the favicon should be requested, and we should not do | 709 // A download for the favicon should be requested, and we should not do |
710 // another history request. | 710 // another history request. |
711 DownloadHandler* download_handler = helper.download_handler(); | 711 DownloadHandler* download_handler = helper.download_handler(); |
712 EXPECT_TRUE(helper.download_handler()->HasDownload()); | 712 EXPECT_TRUE(helper.download_handler()->HasDownload()); |
713 EXPECT_EQ(NULL, helper.history_handler()); | 713 EXPECT_EQ(NULL, helper.history_handler()); |
714 | 714 |
715 // Verify the download request. | 715 // Verify the download request. |
716 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 716 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
717 | 717 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); | 761 EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); |
762 | 762 |
763 // Reset the history_handler to verify whether new icon is requested from | 763 // Reset the history_handler to verify whether new icon is requested from |
764 // history. | 764 // history. |
765 helper.set_history_handler(NULL); | 765 helper.set_history_handler(NULL); |
766 | 766 |
767 // Simulates update with the different favicon url. | 767 // Simulates update with the different favicon url. |
768 std::vector<FaviconURL> urls; | 768 std::vector<FaviconURL> urls; |
769 urls.push_back( | 769 urls.push_back( |
770 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 770 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
771 helper.OnUpdateFaviconURL(0, urls); | 771 helper.OnUpdateFaviconURL(urls); |
772 | 772 |
773 // Verify FaviconHandler status. | 773 // Verify FaviconHandler status. |
774 EXPECT_EQ(1U, helper.urls().size()); | 774 EXPECT_EQ(1U, helper.urls().size()); |
775 ASSERT_TRUE(helper.current_candidate()); | 775 ASSERT_TRUE(helper.current_candidate()); |
776 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 776 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); |
777 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 777 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
778 | 778 |
779 // Favicon should be requested from history. | 779 // Favicon should be requested from history. |
780 history_handler = helper.history_handler(); | 780 history_handler = helper.history_handler(); |
781 ASSERT_TRUE(history_handler); | 781 ASSERT_TRUE(history_handler); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 helper.set_history_handler(NULL); | 828 helper.set_history_handler(NULL); |
829 | 829 |
830 // Simulates update with the different favicon url. | 830 // Simulates update with the different favicon url. |
831 std::vector<FaviconURL> urls; | 831 std::vector<FaviconURL> urls; |
832 urls.push_back(FaviconURL( | 832 urls.push_back(FaviconURL( |
833 icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON, std::vector<gfx::Size>())); | 833 icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON, std::vector<gfx::Size>())); |
834 urls.push_back(FaviconURL( | 834 urls.push_back(FaviconURL( |
835 new_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); | 835 new_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); |
836 urls.push_back( | 836 urls.push_back( |
837 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 837 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
838 helper.OnUpdateFaviconURL(0, urls); | 838 helper.OnUpdateFaviconURL(urls); |
839 | 839 |
840 // Verify FaviconHandler status. | 840 // Verify FaviconHandler status. |
841 EXPECT_EQ(2U, helper.urls().size()); | 841 EXPECT_EQ(2U, helper.urls().size()); |
842 ASSERT_TRUE(helper.current_candidate()); | 842 ASSERT_TRUE(helper.current_candidate()); |
843 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 843 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
844 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, | 844 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, |
845 helper.current_candidate()->icon_type); | 845 helper.current_candidate()->icon_type); |
846 | 846 |
847 // Favicon should be requested from history. | 847 // Favicon should be requested from history. |
848 history_handler = helper.history_handler(); | 848 history_handler = helper.history_handler(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 helper.set_history_handler(NULL); | 942 helper.set_history_handler(NULL); |
943 | 943 |
944 // Simulates update with the different favicon url. | 944 // Simulates update with the different favicon url. |
945 std::vector<FaviconURL> urls; | 945 std::vector<FaviconURL> urls; |
946 urls.push_back(FaviconURL( | 946 urls.push_back(FaviconURL( |
947 icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON, std::vector<gfx::Size>())); | 947 icon_url, FaviconURL::TOUCH_PRECOMPOSED_ICON, std::vector<gfx::Size>())); |
948 urls.push_back(FaviconURL( | 948 urls.push_back(FaviconURL( |
949 new_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); | 949 new_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); |
950 urls.push_back( | 950 urls.push_back( |
951 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); | 951 FaviconURL(new_icon_url, FaviconURL::FAVICON, std::vector<gfx::Size>())); |
952 helper.OnUpdateFaviconURL(0, urls); | 952 helper.OnUpdateFaviconURL(urls); |
953 | 953 |
954 // Verify FaviconHandler status. | 954 // Verify FaviconHandler status. |
955 EXPECT_EQ(2U, helper.urls().size()); | 955 EXPECT_EQ(2U, helper.urls().size()); |
956 ASSERT_TRUE(helper.current_candidate()); | 956 ASSERT_TRUE(helper.current_candidate()); |
957 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 957 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); |
958 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, | 958 ASSERT_EQ(FaviconURL::TOUCH_PRECOMPOSED_ICON, |
959 helper.current_candidate()->icon_type); | 959 helper.current_candidate()->icon_type); |
960 | 960 |
961 // Favicon should be requested from history. | 961 // Favicon should be requested from history. |
962 history_handler = helper.history_handler(); | 962 history_handler = helper.history_handler(); |
(...skipping 13 matching lines...) Expand all Loading... |
976 // Verify the download request. | 976 // Verify the download request. |
977 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 977 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
978 | 978 |
979 // Reset the history_handler to verify whether favicon is request from | 979 // Reset the history_handler to verify whether favicon is request from |
980 // history. | 980 // history. |
981 helper.set_history_handler(NULL); | 981 helper.set_history_handler(NULL); |
982 const GURL latest_icon_url("http://www.google.com/latest_favicon"); | 982 const GURL latest_icon_url("http://www.google.com/latest_favicon"); |
983 std::vector<FaviconURL> latest_urls; | 983 std::vector<FaviconURL> latest_urls; |
984 latest_urls.push_back(FaviconURL( | 984 latest_urls.push_back(FaviconURL( |
985 latest_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); | 985 latest_icon_url, FaviconURL::TOUCH_ICON, std::vector<gfx::Size>())); |
986 helper.OnUpdateFaviconURL(0, latest_urls); | 986 helper.OnUpdateFaviconURL(latest_urls); |
987 | 987 |
988 EXPECT_EQ(1U, helper.urls().size()); | 988 EXPECT_EQ(1U, helper.urls().size()); |
989 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); | 989 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); |
990 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); | 990 EXPECT_EQ(FaviconURL::TOUCH_ICON, helper.current_candidate()->icon_type); |
991 | 991 |
992 // Whether new icon is requested from history | 992 // Whether new icon is requested from history |
993 history_handler = helper.history_handler(); | 993 history_handler = helper.history_handler(); |
994 ASSERT_TRUE(history_handler); | 994 ASSERT_TRUE(history_handler); |
995 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 995 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
996 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 996 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1491 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1492 EXPECT_NE(0, download_id); | 1492 EXPECT_NE(0, download_id); |
1493 // Report download success with HTTP 200 status. | 1493 // Report download success with HTTP 200 status. |
1494 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1494 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1495 empty_icons, empty_icon_sizes); | 1495 empty_icons, empty_icon_sizes); |
1496 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1496 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1497 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1497 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1498 } | 1498 } |
1499 | 1499 |
1500 } // namespace. | 1500 } // namespace. |
OLD | NEW |