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

Side by Side Diff: chrome/browser/favicon/favicon_handler_unittest.cc

Issue 987113005: Refactor favicon to use C++11 loop and fix style violation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@favicon_client
Patch Set: Rebase Created 5 years, 9 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
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 "chrome/browser/favicon/favicon_handler.h" 5 #include "chrome/browser/favicon/favicon_handler.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/favicon/chrome_favicon_client.h" 8 #include "chrome/browser/favicon/chrome_favicon_client.h"
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h"
10 #include "chrome/browser/favicon/favicon_service.h" 10 #include "chrome/browser/favicon/favicon_service.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 // This class is used to save the download request for verifying with test case. 75 // This class is used to save the download request for verifying with test case.
76 // It also will be used to invoke the onDidDownload callback. 76 // It also will be used to invoke the onDidDownload callback.
77 class DownloadHandler { 77 class DownloadHandler {
78 public: 78 public:
79 explicit DownloadHandler(TestFaviconHandler* favicon_helper) 79 explicit DownloadHandler(TestFaviconHandler* favicon_helper)
80 : favicon_helper_(favicon_helper), 80 : favicon_helper_(favicon_helper),
81 failed_(false) { 81 failed_(false) {
82 } 82 }
83 83
84 virtual ~DownloadHandler() { 84 ~DownloadHandler() {}
85 }
86 85
87 void Reset() { 86 void Reset() {
88 download_.reset(NULL); 87 download_.reset();
89 failed_ = false; 88 failed_ = false;
90 } 89 }
91 90
92 void AddDownload( 91 void AddDownload(
93 int download_id, 92 int download_id,
94 const GURL& image_url, 93 const GURL& image_url,
95 const std::vector<int>& image_sizes, 94 const std::vector<int>& image_sizes,
96 int max_image_size) { 95 int max_image_size) {
97 download_.reset(new Download( 96 download_.reset(new Download(
98 download_id, image_url, image_sizes, max_image_size, false)); 97 download_id, image_url, image_sizes, max_image_size, false));
99 } 98 }
100 99
101 void InvokeCallback(); 100 void InvokeCallback();
102 101
103 void set_failed(bool failed) { failed_ = failed; } 102 void set_failed(bool failed) { failed_ = failed; }
104 103
105 bool HasDownload() const { return download_.get() != NULL; } 104 bool HasDownload() const { return download_.get(); }
106 const GURL& GetImageUrl() const { return download_->image_url; } 105 const GURL& GetImageUrl() const { return download_->image_url; }
107 void SetImageSizes(const std::vector<int>& sizes) { 106 void SetImageSizes(const std::vector<int>& sizes) {
108 download_->image_sizes = sizes; } 107 download_->image_sizes = sizes; }
109 108
110 private: 109 private:
111 struct Download { 110 struct Download {
112 Download(int id, 111 Download(int id,
113 GURL url, 112 GURL url,
114 const std::vector<int>& sizes, 113 const std::vector<int>& sizes,
115 int max_size, 114 int max_size,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int icon_type, 150 int icon_type,
152 const std::vector<unsigned char>& bitmap_data, 151 const std::vector<unsigned char>& bitmap_data,
153 const gfx::Size& size) 152 const gfx::Size& size)
154 : page_url_(page_url), 153 : page_url_(page_url),
155 icon_url_(icon_url), 154 icon_url_(icon_url),
156 icon_type_(icon_type), 155 icon_type_(icon_type),
157 bitmap_data_(bitmap_data), 156 bitmap_data_(bitmap_data),
158 size_(size) { 157 size_(size) {
159 } 158 }
160 159
161 virtual ~HistoryRequestHandler() {} 160 ~HistoryRequestHandler() {}
162 void InvokeCallback(); 161 void InvokeCallback();
163 162
164 const GURL page_url_; 163 const GURL page_url_;
165 const GURL icon_url_; 164 const GURL icon_url_;
166 const int icon_type_; 165 const int icon_type_;
167 const std::vector<unsigned char> bitmap_data_; 166 const std::vector<unsigned char> bitmap_data_;
168 const gfx::Size size_; 167 const gfx::Size size_;
169 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; 168 std::vector<favicon_base::FaviconRawBitmapResult> history_results_;
170 favicon_base::FaviconResultsCallback callback_; 169 favicon_base::FaviconResultsCallback callback_;
171 170
172 private: 171 private:
173 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); 172 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler);
174 }; 173 };
175 174
176 } // namespace 175 } // namespace
177 176
178 class TestFaviconClient : public FaviconClient { 177 class TestFaviconClient : public FaviconClient {
179 public: 178 public:
180 ~TestFaviconClient() override{}; 179 ~TestFaviconClient() override {}
181 180
182 bool IsBookmarked(const GURL& url) override { return false; } 181 bool IsBookmarked(const GURL& url) override { return false; }
183 }; 182 };
184 183
185 class TestFaviconDriver : public FaviconDriver { 184 class TestFaviconDriver : public FaviconDriver {
186 public: 185 public:
187 TestFaviconDriver() 186 TestFaviconDriver()
188 : favicon_validity_(false), 187 : favicon_validity_(false),
189 num_active_favicon_(0), 188 num_active_favicon_(0),
190 num_favicon_available_(0), 189 num_favicon_available_(0),
191 update_active_favicon_(false) {} 190 update_active_favicon_(false) {}
192 191
193 virtual ~TestFaviconDriver() { 192 ~TestFaviconDriver() override {}
194 }
195 193
196 bool IsOffTheRecord() override { return false; } 194 bool IsOffTheRecord() override { return false; }
197 195
198 const gfx::Image GetActiveFaviconImage() override { return image_; } 196 const gfx::Image GetActiveFaviconImage() override { return image_; }
199 197
200 const GURL GetActiveFaviconURL() override { return favicon_url_; } 198 const GURL GetActiveFaviconURL() override { return favicon_url_; }
201 199
202 bool GetActiveFaviconValidity() override { return favicon_validity_; } 200 bool GetActiveFaviconValidity() override { return favicon_validity_; }
203 201
204 const GURL GetActiveURL() override { return url_; } 202 const GURL GetActiveURL() override { return url_; }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 scale_factors.push_back(ui::SCALE_FACTOR_100P); 469 scale_factors.push_back(ui::SCALE_FACTOR_100P);
472 scoped_set_supported_scale_factors_.reset( 470 scoped_set_supported_scale_factors_.reset(
473 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); 471 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
474 472
475 ChromeRenderViewHostTestHarness::SetUp(); 473 ChromeRenderViewHostTestHarness::SetUp();
476 } 474 }
477 475
478 void TearDown() override { 476 void TearDown() override {
479 Profile* profile = Profile::FromBrowserContext( 477 Profile* profile = Profile::FromBrowserContext(
480 web_contents()->GetBrowserContext()); 478 web_contents()->GetBrowserContext());
481 FaviconServiceFactory::GetInstance()->SetTestingFactory( 479 FaviconServiceFactory::GetInstance()->SetTestingFactory(profile, nullptr);
482 profile, NULL);
483 ChromeRenderViewHostTestHarness::TearDown(); 480 ChromeRenderViewHostTestHarness::TearDown();
484 } 481 }
485 482
486 private: 483 private:
487 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> 484 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors>
488 ScopedSetSupportedScaleFactors; 485 ScopedSetSupportedScaleFactors;
489 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; 486 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
490 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
491 }; 488 };
492 489
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); 569 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type);
573 570
574 // Favicon should request to download icon now. 571 // Favicon should request to download icon now.
575 DownloadHandler* download_handler = helper.download_handler(); 572 DownloadHandler* download_handler = helper.download_handler();
576 EXPECT_TRUE(helper.download_handler()->HasDownload()); 573 EXPECT_TRUE(helper.download_handler()->HasDownload());
577 574
578 // Verify the download request. 575 // Verify the download request.
579 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 576 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
580 577
581 // Reset the history_handler to verify whether favicon is set. 578 // Reset the history_handler to verify whether favicon is set.
582 helper.set_history_handler(NULL); 579 helper.set_history_handler(nullptr);
583 580
584 // Smulates download done. 581 // Smulates download done.
585 download_handler->InvokeCallback(); 582 download_handler->InvokeCallback();
586 583
587 // New icon should be saved to history backend and navigation entry. 584 // New icon should be saved to history backend and navigation entry.
588 history_handler = helper.history_handler(); 585 history_handler = helper.history_handler();
589 ASSERT_TRUE(history_handler); 586 ASSERT_TRUE(history_handler);
590 EXPECT_EQ(icon_url, history_handler->icon_url_); 587 EXPECT_EQ(icon_url, history_handler->icon_url_);
591 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 588 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
592 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 589 EXPECT_LT(0U, history_handler->bitmap_data_.size());
(...skipping 28 matching lines...) Expand all
621 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); 618 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_);
622 619
623 // Send history response. 620 // Send history response.
624 history_handler->InvokeCallback(); 621 history_handler->InvokeCallback();
625 // Verify FaviconHandler status. 622 // Verify FaviconHandler status.
626 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 623 EXPECT_TRUE(driver.GetActiveFaviconValidity());
627 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 624 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
628 625
629 // Reset the history_handler to verify whether new icon is requested from 626 // Reset the history_handler to verify whether new icon is requested from
630 // history. 627 // history.
631 helper.set_history_handler(NULL); 628 helper.set_history_handler(nullptr);
632 629
633 // Simulates update with the different favicon url. 630 // Simulates update with the different favicon url.
634 std::vector<FaviconURL> urls; 631 std::vector<FaviconURL> urls;
635 urls.push_back(FaviconURL( 632 urls.push_back(FaviconURL(
636 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 633 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
637 helper.OnUpdateFaviconURL(urls); 634 helper.OnUpdateFaviconURL(urls);
638 635
639 // Verify FaviconHandler status. 636 // Verify FaviconHandler status.
640 EXPECT_EQ(1U, helper.urls().size()); 637 EXPECT_EQ(1U, helper.urls().size());
641 ASSERT_TRUE(helper.current_candidate()); 638 ASSERT_TRUE(helper.current_candidate());
(...skipping 12 matching lines...) Expand all
654 history_handler->InvokeCallback(); 651 history_handler->InvokeCallback();
655 652
656 // Favicon should request to download icon now. 653 // Favicon should request to download icon now.
657 DownloadHandler* download_handler = helper.download_handler(); 654 DownloadHandler* download_handler = helper.download_handler();
658 EXPECT_TRUE(helper.download_handler()->HasDownload()); 655 EXPECT_TRUE(helper.download_handler()->HasDownload());
659 656
660 // Verify the download request. 657 // Verify the download request.
661 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); 658 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl());
662 659
663 // Reset the history_handler to verify whether favicon is set. 660 // Reset the history_handler to verify whether favicon is set.
664 helper.set_history_handler(NULL); 661 helper.set_history_handler(nullptr);
665 662
666 // Smulates download done. 663 // Smulates download done.
667 download_handler->InvokeCallback(); 664 download_handler->InvokeCallback();
668 665
669 // New icon should be saved to history backend and navigation entry. 666 // New icon should be saved to history backend and navigation entry.
670 history_handler = helper.history_handler(); 667 history_handler = helper.history_handler();
671 ASSERT_TRUE(history_handler); 668 ASSERT_TRUE(history_handler);
672 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 669 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
673 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); 670 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_);
674 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 671 EXPECT_LT(0U, history_handler->bitmap_data_.size());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 history_handler->history_results_.push_back(bitmap_result); 707 history_handler->history_results_.push_back(bitmap_result);
711 708
712 // Send history response. 709 // Send history response.
713 history_handler->InvokeCallback(); 710 history_handler->InvokeCallback();
714 // The NavigationEntry should not be set yet as the history data is invalid. 711 // The NavigationEntry should not be set yet as the history data is invalid.
715 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 712 EXPECT_FALSE(driver.GetActiveFaviconValidity());
716 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 713 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
717 714
718 // Reset the history_handler to verify whether new icon is requested from 715 // Reset the history_handler to verify whether new icon is requested from
719 // history. 716 // history.
720 helper.set_history_handler(NULL); 717 helper.set_history_handler(nullptr);
721 718
722 // Simulates update with matching favicon URL. 719 // Simulates update with matching favicon URL.
723 std::vector<FaviconURL> urls; 720 std::vector<FaviconURL> urls;
724 urls.push_back( 721 urls.push_back(
725 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 722 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
726 helper.OnUpdateFaviconURL(urls); 723 helper.OnUpdateFaviconURL(urls);
727 724
728 // A download for the favicon should be requested, and we should not do 725 // A download for the favicon should be requested, and we should not do
729 // another history request. 726 // another history request.
730 DownloadHandler* download_handler = helper.download_handler(); 727 DownloadHandler* download_handler = helper.download_handler();
731 EXPECT_TRUE(helper.download_handler()->HasDownload()); 728 EXPECT_TRUE(helper.download_handler()->HasDownload());
732 EXPECT_EQ(NULL, helper.history_handler()); 729 EXPECT_EQ(nullptr, helper.history_handler());
733 730
734 // Verify the download request. 731 // Verify the download request.
735 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 732 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
736 733
737 // Simulates download done. 734 // Simulates download done.
738 download_handler->InvokeCallback(); 735 download_handler->InvokeCallback();
739 736
740 // New icon should be saved to history backend and navigation entry. 737 // New icon should be saved to history backend and navigation entry.
741 history_handler = helper.history_handler(); 738 history_handler = helper.history_handler();
742 ASSERT_TRUE(history_handler); 739 ASSERT_TRUE(history_handler);
(...skipping 30 matching lines...) Expand all
773 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); 770 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_);
774 771
775 // Send history response. 772 // Send history response.
776 history_handler->InvokeCallback(); 773 history_handler->InvokeCallback();
777 // Verify FaviconHandler status. 774 // Verify FaviconHandler status.
778 EXPECT_TRUE(driver.GetActiveFaviconValidity()); 775 EXPECT_TRUE(driver.GetActiveFaviconValidity());
779 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL()); 776 EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
780 777
781 // Reset the history_handler to verify whether new icon is requested from 778 // Reset the history_handler to verify whether new icon is requested from
782 // history. 779 // history.
783 helper.set_history_handler(NULL); 780 helper.set_history_handler(nullptr);
784 781
785 // Simulates update with the different favicon url. 782 // Simulates update with the different favicon url.
786 std::vector<FaviconURL> urls; 783 std::vector<FaviconURL> urls;
787 urls.push_back(FaviconURL( 784 urls.push_back(FaviconURL(
788 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 785 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
789 helper.OnUpdateFaviconURL(urls); 786 helper.OnUpdateFaviconURL(urls);
790 787
791 // Verify FaviconHandler status. 788 // Verify FaviconHandler status.
792 EXPECT_EQ(1U, helper.urls().size()); 789 EXPECT_EQ(1U, helper.urls().size());
793 ASSERT_TRUE(helper.current_candidate()); 790 ASSERT_TRUE(helper.current_candidate());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 // Icon not found. 833 // Icon not found.
837 history_handler->history_results_.clear(); 834 history_handler->history_results_.clear();
838 // Send history response. 835 // Send history response.
839 history_handler->InvokeCallback(); 836 history_handler->InvokeCallback();
840 // Verify FaviconHandler status. 837 // Verify FaviconHandler status.
841 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 838 EXPECT_FALSE(driver.GetActiveFaviconValidity());
842 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 839 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
843 840
844 // Reset the history_handler to verify whether new icon is requested from 841 // Reset the history_handler to verify whether new icon is requested from
845 // history. 842 // history.
846 helper.set_history_handler(NULL); 843 helper.set_history_handler(nullptr);
847 844
848 // Simulates update with the different favicon url. 845 // Simulates update with the different favicon url.
849 std::vector<FaviconURL> urls; 846 std::vector<FaviconURL> urls;
850 urls.push_back(FaviconURL(icon_url, 847 urls.push_back(FaviconURL(icon_url,
851 favicon_base::TOUCH_PRECOMPOSED_ICON, 848 favicon_base::TOUCH_PRECOMPOSED_ICON,
852 std::vector<gfx::Size>())); 849 std::vector<gfx::Size>()));
853 urls.push_back(FaviconURL( 850 urls.push_back(FaviconURL(
854 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 851 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
855 urls.push_back(FaviconURL( 852 urls.push_back(FaviconURL(
856 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 853 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
(...skipping 19 matching lines...) Expand all
876 873
877 // Should request download favicon. 874 // Should request download favicon.
878 DownloadHandler* download_handler = helper.download_handler(); 875 DownloadHandler* download_handler = helper.download_handler();
879 EXPECT_TRUE(helper.download_handler()->HasDownload()); 876 EXPECT_TRUE(helper.download_handler()->HasDownload());
880 877
881 // Verify the download request. 878 // Verify the download request.
882 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 879 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
883 880
884 // Reset the history_handler to verify whether favicon is request from 881 // Reset the history_handler to verify whether favicon is request from
885 // history. 882 // history.
886 helper.set_history_handler(NULL); 883 helper.set_history_handler(nullptr);
887 // Smulates download failed. 884 // Smulates download failed.
888 download_handler->set_failed(true); 885 download_handler->set_failed(true);
889 download_handler->InvokeCallback(); 886 download_handler->InvokeCallback();
890 887
891 // Left 1 url. 888 // Left 1 url.
892 EXPECT_EQ(1U, helper.urls().size()); 889 EXPECT_EQ(1U, helper.urls().size());
893 ASSERT_TRUE(helper.current_candidate()); 890 ASSERT_TRUE(helper.current_candidate());
894 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); 891 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url);
895 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); 892 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type);
896 893
(...skipping 11 matching lines...) Expand all
908 SetFaviconRawBitmapResult(new_icon_url, 905 SetFaviconRawBitmapResult(new_icon_url,
909 favicon_base::TOUCH_ICON, 906 favicon_base::TOUCH_ICON,
910 true /* expired */, 907 true /* expired */,
911 &history_handler->history_results_); 908 &history_handler->history_results_);
912 history_handler->InvokeCallback(); 909 history_handler->InvokeCallback();
913 910
914 // Verify the download request. 911 // Verify the download request.
915 EXPECT_TRUE(helper.download_handler()->HasDownload()); 912 EXPECT_TRUE(helper.download_handler()->HasDownload());
916 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); 913 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl());
917 914
918 helper.set_history_handler(NULL); 915 helper.set_history_handler(nullptr);
919 916
920 // Simulates icon being downloaded. 917 // Simulates icon being downloaded.
921 download_handler->InvokeCallback(); 918 download_handler->InvokeCallback();
922 919
923 // New icon should be saved to history backend. 920 // New icon should be saved to history backend.
924 history_handler = helper.history_handler(); 921 history_handler = helper.history_handler();
925 ASSERT_TRUE(history_handler); 922 ASSERT_TRUE(history_handler);
926 EXPECT_EQ(new_icon_url, history_handler->icon_url_); 923 EXPECT_EQ(new_icon_url, history_handler->icon_url_);
927 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); 924 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_);
928 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 925 EXPECT_LT(0U, history_handler->bitmap_data_.size());
(...skipping 22 matching lines...) Expand all
951 // Icon not found. 948 // Icon not found.
952 history_handler->history_results_.clear(); 949 history_handler->history_results_.clear();
953 // Send history response. 950 // Send history response.
954 history_handler->InvokeCallback(); 951 history_handler->InvokeCallback();
955 // Verify FaviconHandler status. 952 // Verify FaviconHandler status.
956 EXPECT_FALSE(driver.GetActiveFaviconValidity()); 953 EXPECT_FALSE(driver.GetActiveFaviconValidity());
957 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL()); 954 EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
958 955
959 // Reset the history_handler to verify whether new icon is requested from 956 // Reset the history_handler to verify whether new icon is requested from
960 // history. 957 // history.
961 helper.set_history_handler(NULL); 958 helper.set_history_handler(nullptr);
962 959
963 // Simulates update with the different favicon url. 960 // Simulates update with the different favicon url.
964 std::vector<FaviconURL> urls; 961 std::vector<FaviconURL> urls;
965 urls.push_back(FaviconURL(icon_url, 962 urls.push_back(FaviconURL(icon_url,
966 favicon_base::TOUCH_PRECOMPOSED_ICON, 963 favicon_base::TOUCH_PRECOMPOSED_ICON,
967 std::vector<gfx::Size>())); 964 std::vector<gfx::Size>()));
968 urls.push_back(FaviconURL( 965 urls.push_back(FaviconURL(
969 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 966 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
970 urls.push_back(FaviconURL( 967 urls.push_back(FaviconURL(
971 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); 968 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>()));
(...skipping 19 matching lines...) Expand all
991 988
992 // Should request download favicon. 989 // Should request download favicon.
993 DownloadHandler* download_handler = helper.download_handler(); 990 DownloadHandler* download_handler = helper.download_handler();
994 EXPECT_TRUE(helper.download_handler()->HasDownload()); 991 EXPECT_TRUE(helper.download_handler()->HasDownload());
995 992
996 // Verify the download request. 993 // Verify the download request.
997 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); 994 EXPECT_EQ(icon_url, download_handler->GetImageUrl());
998 995
999 // Reset the history_handler to verify whether favicon is request from 996 // Reset the history_handler to verify whether favicon is request from
1000 // history. 997 // history.
1001 helper.set_history_handler(NULL); 998 helper.set_history_handler(nullptr);
1002 const GURL latest_icon_url("http://www.google.com/latest_favicon"); 999 const GURL latest_icon_url("http://www.google.com/latest_favicon");
1003 std::vector<FaviconURL> latest_urls; 1000 std::vector<FaviconURL> latest_urls;
1004 latest_urls.push_back(FaviconURL( 1001 latest_urls.push_back(FaviconURL(
1005 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); 1002 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>()));
1006 helper.OnUpdateFaviconURL(latest_urls); 1003 helper.OnUpdateFaviconURL(latest_urls);
1007 1004
1008 EXPECT_EQ(1U, helper.urls().size()); 1005 EXPECT_EQ(1U, helper.urls().size());
1009 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); 1006 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url);
1010 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); 1007 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type);
1011 1008
1012 // Whether new icon is requested from history 1009 // Whether new icon is requested from history
1013 history_handler = helper.history_handler(); 1010 history_handler = helper.history_handler();
1014 ASSERT_TRUE(history_handler); 1011 ASSERT_TRUE(history_handler);
1015 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); 1012 EXPECT_EQ(latest_icon_url, history_handler->icon_url_);
1016 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); 1013 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_);
1017 EXPECT_EQ(page_url, history_handler->page_url_); 1014 EXPECT_EQ(page_url, history_handler->page_url_);
1018 1015
1019 // Reset the history_handler to verify whether favicon is request from 1016 // Reset the history_handler to verify whether favicon is request from
1020 // history. 1017 // history.
1021 // Save the callback for late use. 1018 // Save the callback for late use.
1022 favicon_base::FaviconResultsCallback callback = history_handler->callback_; 1019 favicon_base::FaviconResultsCallback callback = history_handler->callback_;
1023 helper.set_history_handler(NULL); 1020 helper.set_history_handler(nullptr);
1024 1021
1025 // Simulates download succeed. 1022 // Simulates download succeed.
1026 download_handler->InvokeCallback(); 1023 download_handler->InvokeCallback();
1027 // The downloaded icon should be thrown away as there is favicon update. 1024 // The downloaded icon should be thrown away as there is favicon update.
1028 EXPECT_FALSE(helper.history_handler()); 1025 EXPECT_FALSE(helper.history_handler());
1029 1026
1030 download_handler->Reset(); 1027 download_handler->Reset();
1031 1028
1032 // Simulates getting the icon from history. 1029 // Simulates getting the icon from history.
1033 scoped_ptr<HistoryRequestHandler> handler; 1030 scoped_ptr<HistoryRequestHandler> handler;
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 EXPECT_EQ(new_favicon_url, driver1.available_icon_url()); 1644 EXPECT_EQ(new_favicon_url, driver1.available_icon_url());
1648 EXPECT_FALSE(driver1.update_active_favicon()); 1645 EXPECT_FALSE(driver1.update_active_favicon());
1649 EXPECT_EQ(3u, driver1.num_favicon_available()); 1646 EXPECT_EQ(3u, driver1.num_favicon_available());
1650 } 1647 }
1651 1648
1652 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse, 1649 INSTANTIATE_TEST_CASE_P(FaviconHandlerTestActiveFaviconValidityTrueOrFalse,
1653 FaviconHandlerActiveFaviconValidityParamTest, 1650 FaviconHandlerActiveFaviconValidityParamTest,
1654 ::testing::Bool()); 1651 ::testing::Bool());
1655 1652
1656 } // namespace. 1653 } // namespace.
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_handler.cc ('k') | components/favicon/core/browser/favicon_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698