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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const std::vector<unsigned char> bitmap_data_; | 160 const std::vector<unsigned char> bitmap_data_; |
161 std::vector<chrome::FaviconBitmapResult> history_results_; | 161 std::vector<chrome::FaviconBitmapResult> history_results_; |
162 FaviconService::FaviconResultsCallback callback_; | 162 FaviconService::FaviconResultsCallback callback_; |
163 | 163 |
164 private: | 164 private: |
165 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 165 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
166 }; | 166 }; |
167 | 167 |
168 } // namespace | 168 } // namespace |
169 | 169 |
| 170 class TestFaviconClient : public FaviconClient { |
| 171 public: |
| 172 virtual FaviconService* GetFaviconService() OVERRIDE { |
| 173 // Just give none NULL value, so overridden methods can be hit. |
| 174 return (FaviconService*)(1); |
| 175 } |
| 176 }; |
170 | 177 |
171 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { | 178 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { |
172 public: | 179 public: |
173 TestFaviconHandlerDelegate() { | 180 TestFaviconHandlerDelegate() { |
174 } | 181 } |
175 | 182 |
176 virtual ~TestFaviconHandlerDelegate() { | 183 virtual ~TestFaviconHandlerDelegate() { |
177 } | 184 } |
178 | 185 |
179 virtual bool IsOffTheRecord() OVERRIDE { return false; } | 186 virtual bool IsOffTheRecord() OVERRIDE { return false; } |
(...skipping 20 matching lines...) Expand all Loading... |
200 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); | 207 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); |
201 }; | 208 }; |
202 | 209 |
203 // This class is used to catch the FaviconHandler's download and history | 210 // This class is used to catch the FaviconHandler's download and history |
204 // request, and also provide the methods to access the FaviconHandler | 211 // request, and also provide the methods to access the FaviconHandler |
205 // internals. | 212 // internals. |
206 class TestFaviconHandler : public FaviconHandler { | 213 class TestFaviconHandler : public FaviconHandler { |
207 public: | 214 public: |
208 TestFaviconHandler(const GURL& page_url, | 215 TestFaviconHandler(const GURL& page_url, |
209 Profile* profile, | 216 Profile* profile, |
| 217 FaviconClient* client, |
210 FaviconHandlerDelegate* delegate, | 218 FaviconHandlerDelegate* delegate, |
211 Type type) | 219 Type type) |
212 : FaviconHandler(profile, delegate, type), | 220 : FaviconHandler(profile, client, delegate, type), |
213 entry_(NavigationEntry::Create()), | 221 entry_(NavigationEntry::Create()), |
214 download_id_(0), | 222 download_id_(0), |
215 num_favicon_updates_(0) { | 223 num_favicon_updates_(0) { |
216 entry_->SetURL(page_url); | 224 entry_->SetURL(page_url); |
217 download_handler_.reset(new DownloadHandler(this)); | 225 download_handler_.reset(new DownloadHandler(this)); |
218 } | 226 } |
219 | 227 |
220 virtual ~TestFaviconHandler() { | 228 virtual ~TestFaviconHandler() { |
221 } | 229 } |
222 | 230 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 const GURL& icon_url, | 303 const GURL& icon_url, |
296 chrome::IconType icon_type, | 304 chrome::IconType icon_type, |
297 const gfx::Image& image) OVERRIDE { | 305 const gfx::Image& image) OVERRIDE { |
298 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 306 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
299 std::vector<unsigned char> bitmap_data(bytes->front(), | 307 std::vector<unsigned char> bitmap_data(bytes->front(), |
300 bytes->front() + bytes->size()); | 308 bytes->front() + bytes->size()); |
301 history_handler_.reset(new HistoryRequestHandler( | 309 history_handler_.reset(new HistoryRequestHandler( |
302 page_url, icon_url, icon_type, bitmap_data)); | 310 page_url, icon_url, icon_type, bitmap_data)); |
303 } | 311 } |
304 | 312 |
305 virtual FaviconService* GetFaviconService() OVERRIDE { | |
306 // Just give none NULL value, so overridden methods can be hit. | |
307 return (FaviconService*)(1); | |
308 } | |
309 | |
310 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { | 313 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { |
311 return true; | 314 return true; |
312 } | 315 } |
313 | 316 |
314 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { | 317 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { |
315 ++num_favicon_updates_; | 318 ++num_favicon_updates_; |
316 } | 319 } |
317 | 320 |
318 GURL page_url_; | 321 GURL page_url_; |
319 | 322 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 ScopedSetSupportedScaleFactors; | 435 ScopedSetSupportedScaleFactors; |
433 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 436 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
434 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 437 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
435 }; | 438 }; |
436 | 439 |
437 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 440 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
438 const GURL page_url("http://www.google.com"); | 441 const GURL page_url("http://www.google.com"); |
439 const GURL icon_url("http://www.google.com/favicon"); | 442 const GURL icon_url("http://www.google.com/favicon"); |
440 | 443 |
441 TestFaviconHandlerDelegate delegate; | 444 TestFaviconHandlerDelegate delegate; |
| 445 TestFaviconClient client; |
442 Profile* profile = Profile::FromBrowserContext( | 446 Profile* profile = Profile::FromBrowserContext( |
443 web_contents()->GetBrowserContext()); | 447 web_contents()->GetBrowserContext()); |
444 TestFaviconHandler helper(page_url, profile, | 448 TestFaviconHandler helper( |
445 &delegate, FaviconHandler::FAVICON); | 449 page_url, profile, &client, &delegate, FaviconHandler::FAVICON); |
446 | 450 |
447 helper.FetchFavicon(page_url); | 451 helper.FetchFavicon(page_url); |
448 HistoryRequestHandler* history_handler = helper.history_handler(); | 452 HistoryRequestHandler* history_handler = helper.history_handler(); |
449 // Ensure the data given to history is correct. | 453 // Ensure the data given to history is correct. |
450 ASSERT_TRUE(history_handler); | 454 ASSERT_TRUE(history_handler); |
451 EXPECT_EQ(page_url, history_handler->page_url_); | 455 EXPECT_EQ(page_url, history_handler->page_url_); |
452 EXPECT_EQ(GURL(), history_handler->icon_url_); | 456 EXPECT_EQ(GURL(), history_handler->icon_url_); |
453 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 457 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
454 | 458 |
455 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 459 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
(...skipping 18 matching lines...) Expand all Loading... |
474 | 478 |
475 // Favicon shouldn't request to download icon. | 479 // Favicon shouldn't request to download icon. |
476 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 480 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
477 } | 481 } |
478 | 482 |
479 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 483 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
480 const GURL page_url("http://www.google.com"); | 484 const GURL page_url("http://www.google.com"); |
481 const GURL icon_url("http://www.google.com/favicon"); | 485 const GURL icon_url("http://www.google.com/favicon"); |
482 | 486 |
483 TestFaviconHandlerDelegate delegate; | 487 TestFaviconHandlerDelegate delegate; |
| 488 TestFaviconClient client; |
484 Profile* profile = Profile::FromBrowserContext( | 489 Profile* profile = Profile::FromBrowserContext( |
485 web_contents()->GetBrowserContext()); | 490 web_contents()->GetBrowserContext()); |
486 TestFaviconHandler helper(page_url, profile, | 491 TestFaviconHandler helper( |
487 &delegate, FaviconHandler::FAVICON); | 492 page_url, profile, &client, &delegate, FaviconHandler::FAVICON); |
488 | 493 |
489 helper.FetchFavicon(page_url); | 494 helper.FetchFavicon(page_url); |
490 HistoryRequestHandler* history_handler = helper.history_handler(); | 495 HistoryRequestHandler* history_handler = helper.history_handler(); |
491 // Ensure the data given to history is correct. | 496 // Ensure the data given to history is correct. |
492 ASSERT_TRUE(history_handler); | 497 ASSERT_TRUE(history_handler); |
493 EXPECT_EQ(page_url, history_handler->page_url_); | 498 EXPECT_EQ(page_url, history_handler->page_url_); |
494 EXPECT_EQ(GURL(), history_handler->icon_url_); | 499 EXPECT_EQ(GURL(), history_handler->icon_url_); |
495 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 500 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
496 | 501 |
497 // Set icon data expired | 502 // Set icon data expired |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 548 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
544 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 549 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
545 } | 550 } |
546 | 551 |
547 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 552 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
548 const GURL page_url("http://www.google.com"); | 553 const GURL page_url("http://www.google.com"); |
549 const GURL icon_url("http://www.google.com/favicon"); | 554 const GURL icon_url("http://www.google.com/favicon"); |
550 const GURL new_icon_url("http://www.google.com/new_favicon"); | 555 const GURL new_icon_url("http://www.google.com/new_favicon"); |
551 | 556 |
552 TestFaviconHandlerDelegate delegate; | 557 TestFaviconHandlerDelegate delegate; |
| 558 TestFaviconClient client; |
553 Profile* profile = Profile::FromBrowserContext( | 559 Profile* profile = Profile::FromBrowserContext( |
554 web_contents()->GetBrowserContext()); | 560 web_contents()->GetBrowserContext()); |
555 TestFaviconHandler helper(page_url, profile, | 561 TestFaviconHandler helper( |
556 &delegate, FaviconHandler::FAVICON); | 562 page_url, profile, &client, &delegate, FaviconHandler::FAVICON); |
557 | 563 |
558 helper.FetchFavicon(page_url); | 564 helper.FetchFavicon(page_url); |
559 HistoryRequestHandler* history_handler = helper.history_handler(); | 565 HistoryRequestHandler* history_handler = helper.history_handler(); |
560 // Ensure the data given to history is correct. | 566 // Ensure the data given to history is correct. |
561 ASSERT_TRUE(history_handler); | 567 ASSERT_TRUE(history_handler); |
562 EXPECT_EQ(page_url, history_handler->page_url_); | 568 EXPECT_EQ(page_url, history_handler->page_url_); |
563 EXPECT_EQ(GURL(), history_handler->icon_url_); | 569 EXPECT_EQ(GURL(), history_handler->icon_url_); |
564 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 570 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
565 | 571 |
566 // Set valid icon data. | 572 // Set valid icon data. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 EXPECT_TRUE(favicon_status.valid); | 632 EXPECT_TRUE(favicon_status.valid); |
627 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 633 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
628 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 634 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
629 } | 635 } |
630 | 636 |
631 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 637 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
632 const GURL page_url("http://www.google.com"); | 638 const GURL page_url("http://www.google.com"); |
633 const GURL icon_url("http://www.google.com/favicon"); | 639 const GURL icon_url("http://www.google.com/favicon"); |
634 | 640 |
635 TestFaviconHandlerDelegate delegate; | 641 TestFaviconHandlerDelegate delegate; |
| 642 TestFaviconClient client; |
636 Profile* profile = Profile::FromBrowserContext( | 643 Profile* profile = Profile::FromBrowserContext( |
637 web_contents()->GetBrowserContext()); | 644 web_contents()->GetBrowserContext()); |
638 TestFaviconHandler helper(page_url, profile, | 645 TestFaviconHandler helper( |
639 &delegate, FaviconHandler::FAVICON); | 646 page_url, profile, &client, &delegate, FaviconHandler::FAVICON); |
640 | 647 |
641 helper.FetchFavicon(page_url); | 648 helper.FetchFavicon(page_url); |
642 HistoryRequestHandler* history_handler = helper.history_handler(); | 649 HistoryRequestHandler* history_handler = helper.history_handler(); |
643 // Ensure the data given to history is correct. | 650 // Ensure the data given to history is correct. |
644 ASSERT_TRUE(history_handler); | 651 ASSERT_TRUE(history_handler); |
645 EXPECT_EQ(page_url, history_handler->page_url_); | 652 EXPECT_EQ(page_url, history_handler->page_url_); |
646 EXPECT_EQ(GURL(), history_handler->icon_url_); | 653 EXPECT_EQ(GURL(), history_handler->icon_url_); |
647 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 654 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
648 | 655 |
649 // Set non empty but invalid data. | 656 // Set non empty but invalid data. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 707 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
701 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 708 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
702 } | 709 } |
703 | 710 |
704 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 711 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
705 const GURL page_url("http://www.google.com"); | 712 const GURL page_url("http://www.google.com"); |
706 const GURL icon_url("http://www.google.com/favicon"); | 713 const GURL icon_url("http://www.google.com/favicon"); |
707 const GURL new_icon_url("http://www.google.com/new_favicon"); | 714 const GURL new_icon_url("http://www.google.com/new_favicon"); |
708 | 715 |
709 TestFaviconHandlerDelegate delegate; | 716 TestFaviconHandlerDelegate delegate; |
| 717 TestFaviconClient client; |
710 Profile* profile = Profile::FromBrowserContext( | 718 Profile* profile = Profile::FromBrowserContext( |
711 web_contents()->GetBrowserContext()); | 719 web_contents()->GetBrowserContext()); |
712 TestFaviconHandler helper(page_url, profile, | 720 TestFaviconHandler helper( |
713 &delegate, FaviconHandler::FAVICON); | 721 page_url, profile, &client, &delegate, FaviconHandler::FAVICON); |
714 | 722 |
715 helper.FetchFavicon(page_url); | 723 helper.FetchFavicon(page_url); |
716 HistoryRequestHandler* history_handler = helper.history_handler(); | 724 HistoryRequestHandler* history_handler = helper.history_handler(); |
717 // Ensure the data given to history is correct. | 725 // Ensure the data given to history is correct. |
718 ASSERT_TRUE(history_handler); | 726 ASSERT_TRUE(history_handler); |
719 EXPECT_EQ(page_url, history_handler->page_url_); | 727 EXPECT_EQ(page_url, history_handler->page_url_); |
720 EXPECT_EQ(GURL(), history_handler->icon_url_); | 728 EXPECT_EQ(GURL(), history_handler->icon_url_); |
721 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 729 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
722 | 730 |
723 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 731 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 771 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
764 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 772 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
765 } | 773 } |
766 | 774 |
767 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 775 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
768 const GURL page_url("http://www.google.com"); | 776 const GURL page_url("http://www.google.com"); |
769 const GURL icon_url("http://www.google.com/favicon"); | 777 const GURL icon_url("http://www.google.com/favicon"); |
770 const GURL new_icon_url("http://www.google.com/new_favicon"); | 778 const GURL new_icon_url("http://www.google.com/new_favicon"); |
771 | 779 |
772 TestFaviconHandlerDelegate delegate; | 780 TestFaviconHandlerDelegate delegate; |
| 781 TestFaviconClient client; |
773 Profile* profile = Profile::FromBrowserContext( | 782 Profile* profile = Profile::FromBrowserContext( |
774 web_contents()->GetBrowserContext()); | 783 web_contents()->GetBrowserContext()); |
775 TestFaviconHandler helper(page_url, profile, | 784 TestFaviconHandler helper( |
776 &delegate, FaviconHandler::TOUCH); | 785 page_url, profile, &client, &delegate, FaviconHandler::TOUCH); |
777 | 786 |
778 helper.FetchFavicon(page_url); | 787 helper.FetchFavicon(page_url); |
779 HistoryRequestHandler* history_handler = helper.history_handler(); | 788 HistoryRequestHandler* history_handler = helper.history_handler(); |
780 // Ensure the data given to history is correct. | 789 // Ensure the data given to history is correct. |
781 ASSERT_TRUE(history_handler); | 790 ASSERT_TRUE(history_handler); |
782 EXPECT_EQ(page_url, history_handler->page_url_); | 791 EXPECT_EQ(page_url, history_handler->page_url_); |
783 EXPECT_EQ(GURL(), history_handler->icon_url_); | 792 EXPECT_EQ(GURL(), history_handler->icon_url_); |
784 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, | 793 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, |
785 history_handler->icon_type_); | 794 history_handler->icon_type_); |
786 | 795 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 885 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
877 EXPECT_EQ(page_url, history_handler->page_url_); | 886 EXPECT_EQ(page_url, history_handler->page_url_); |
878 } | 887 } |
879 | 888 |
880 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 889 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
881 const GURL page_url("http://www.google.com"); | 890 const GURL page_url("http://www.google.com"); |
882 const GURL icon_url("http://www.google.com/favicon"); | 891 const GURL icon_url("http://www.google.com/favicon"); |
883 const GURL new_icon_url("http://www.google.com/new_favicon"); | 892 const GURL new_icon_url("http://www.google.com/new_favicon"); |
884 | 893 |
885 TestFaviconHandlerDelegate delegate; | 894 TestFaviconHandlerDelegate delegate; |
| 895 TestFaviconClient client; |
886 Profile* profile = Profile::FromBrowserContext( | 896 Profile* profile = Profile::FromBrowserContext( |
887 web_contents()->GetBrowserContext()); | 897 web_contents()->GetBrowserContext()); |
888 TestFaviconHandler helper(page_url, profile, | 898 TestFaviconHandler helper( |
889 &delegate, FaviconHandler::TOUCH); | 899 page_url, profile, &client, &delegate, FaviconHandler::TOUCH); |
890 | 900 |
891 helper.FetchFavicon(page_url); | 901 helper.FetchFavicon(page_url); |
892 HistoryRequestHandler* history_handler = helper.history_handler(); | 902 HistoryRequestHandler* history_handler = helper.history_handler(); |
893 // Ensure the data given to history is correct. | 903 // Ensure the data given to history is correct. |
894 ASSERT_TRUE(history_handler); | 904 ASSERT_TRUE(history_handler); |
895 EXPECT_EQ(page_url, history_handler->page_url_); | 905 EXPECT_EQ(page_url, history_handler->page_url_); |
896 EXPECT_EQ(GURL(), history_handler->icon_url_); | 906 EXPECT_EQ(GURL(), history_handler->icon_url_); |
897 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, | 907 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, |
898 history_handler->icon_type_); | 908 history_handler->icon_type_); |
899 | 909 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1030 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
1021 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1031 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
1022 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1032 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
1023 | 1033 |
1024 Profile* profile = Profile::FromBrowserContext( | 1034 Profile* profile = Profile::FromBrowserContext( |
1025 web_contents()->GetBrowserContext()); | 1035 web_contents()->GetBrowserContext()); |
1026 | 1036 |
1027 // 1) Test that if there are several single resolution favicons to choose from | 1037 // 1) Test that if there are several single resolution favicons to choose from |
1028 // that the largest exact match is chosen. | 1038 // that the largest exact match is chosen. |
1029 TestFaviconHandlerDelegate delegate1; | 1039 TestFaviconHandlerDelegate delegate1; |
1030 TestFaviconHandler handler1(kPageURL, profile, | 1040 TestFaviconClient client; |
1031 &delegate1, FaviconHandler::FAVICON); | 1041 TestFaviconHandler handler1( |
| 1042 kPageURL, profile, &client, &delegate1, FaviconHandler::FAVICON); |
1032 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1043 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1033 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1044 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1034 kSourceIconURLs + arraysize(kSizes1)); | 1045 kSourceIconURLs + arraysize(kSizes1)); |
1035 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); | 1046 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); |
1036 | 1047 |
1037 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); | 1048 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); |
1038 EXPECT_EQ(0u, handler1.image_urls().size()); | 1049 EXPECT_EQ(0u, handler1.image_urls().size()); |
1039 EXPECT_TRUE(favicon_status1.valid); | 1050 EXPECT_TRUE(favicon_status1.valid); |
1040 EXPECT_FALSE(favicon_status1.image.IsEmpty()); | 1051 EXPECT_FALSE(favicon_status1.image.IsEmpty()); |
1041 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); | 1052 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); |
1042 | 1053 |
1043 size_t expected_index = 2u; | 1054 size_t expected_index = 2u; |
1044 EXPECT_EQ(32, kSizes1[expected_index]); | 1055 EXPECT_EQ(32, kSizes1[expected_index]); |
1045 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1056 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1046 handler1.GetEntry()->GetFavicon().url); | 1057 handler1.GetEntry()->GetFavicon().url); |
1047 | 1058 |
1048 // 2) Test that if there are several single resolution favicons to choose | 1059 // 2) Test that if there are several single resolution favicons to choose |
1049 // from, the exact match is preferred even if it results in upsampling. | 1060 // from, the exact match is preferred even if it results in upsampling. |
1050 TestFaviconHandlerDelegate delegate2; | 1061 TestFaviconHandlerDelegate delegate2; |
1051 TestFaviconHandler handler2(kPageURL, profile, | 1062 TestFaviconHandler handler2( |
1052 &delegate2, FaviconHandler::FAVICON); | 1063 kPageURL, profile, &client, &delegate2, FaviconHandler::FAVICON); |
1053 const int kSizes2[] = { 16, 24, 48, 256 }; | 1064 const int kSizes2[] = { 16, 24, 48, 256 }; |
1054 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1065 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1055 kSourceIconURLs + arraysize(kSizes2)); | 1066 kSourceIconURLs + arraysize(kSizes2)); |
1056 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); | 1067 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); |
1057 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); | 1068 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); |
1058 expected_index = 0u; | 1069 expected_index = 0u; |
1059 EXPECT_EQ(16, kSizes2[expected_index]); | 1070 EXPECT_EQ(16, kSizes2[expected_index]); |
1060 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1071 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1061 handler2.GetEntry()->GetFavicon().url); | 1072 handler2.GetEntry()->GetFavicon().url); |
1062 | 1073 |
1063 // 3) Test that favicons which need to be upsampled a little or downsampled | 1074 // 3) Test that favicons which need to be upsampled a little or downsampled |
1064 // a little are preferred over huge favicons. | 1075 // a little are preferred over huge favicons. |
1065 TestFaviconHandlerDelegate delegate3; | 1076 TestFaviconHandlerDelegate delegate3; |
1066 TestFaviconHandler handler3(kPageURL, profile, | 1077 TestFaviconHandler handler3( |
1067 &delegate3, FaviconHandler::FAVICON); | 1078 kPageURL, profile, &client, &delegate3, FaviconHandler::FAVICON); |
1068 const int kSizes3[] = { 256, 48 }; | 1079 const int kSizes3[] = { 256, 48 }; |
1069 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1080 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1070 kSourceIconURLs + arraysize(kSizes3)); | 1081 kSourceIconURLs + arraysize(kSizes3)); |
1071 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); | 1082 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); |
1072 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); | 1083 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); |
1073 expected_index = 1u; | 1084 expected_index = 1u; |
1074 EXPECT_EQ(48, kSizes3[expected_index]); | 1085 EXPECT_EQ(48, kSizes3[expected_index]); |
1075 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1086 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1076 handler3.GetEntry()->GetFavicon().url); | 1087 handler3.GetEntry()->GetFavicon().url); |
1077 | 1088 |
1078 TestFaviconHandlerDelegate delegate4; | 1089 TestFaviconHandlerDelegate delegate4; |
1079 TestFaviconHandler handler4(kPageURL, profile, | 1090 TestFaviconHandler handler4( |
1080 &delegate4, FaviconHandler::FAVICON); | 1091 kPageURL, profile, &client, &delegate4, FaviconHandler::FAVICON); |
1081 const int kSizes4[] = { 17, 256 }; | 1092 const int kSizes4[] = { 17, 256 }; |
1082 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1093 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1083 kSourceIconURLs + arraysize(kSizes4)); | 1094 kSourceIconURLs + arraysize(kSizes4)); |
1084 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); | 1095 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); |
1085 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); | 1096 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); |
1086 expected_index = 0u; | 1097 expected_index = 0u; |
1087 EXPECT_EQ(17, kSizes4[expected_index]); | 1098 EXPECT_EQ(17, kSizes4[expected_index]); |
1088 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1099 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1089 handler4.GetEntry()->GetFavicon().url); | 1100 handler4.GetEntry()->GetFavicon().url); |
1090 } | 1101 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1179 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1169 EXPECT_NE(0, download_id); | 1180 EXPECT_NE(0, download_id); |
1170 // Report download success with HTTP 200 status. | 1181 // Report download success with HTTP 200 status. |
1171 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1182 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1172 empty_icons, empty_icon_sizes); | 1183 empty_icons, empty_icon_sizes); |
1173 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1184 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1174 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1185 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1175 } | 1186 } |
1176 | 1187 |
1177 } // namespace. | 1188 } // namespace. |
OLD | NEW |