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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 private: | 165 private: |
166 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 166 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
167 }; | 167 }; |
168 | 168 |
169 } // namespace | 169 } // namespace |
170 | 170 |
171 class TestFaviconDriver : public FaviconDriver { | 171 class TestFaviconDriver : public FaviconDriver { |
172 virtual bool IsOffTheRecord() OVERRIDE { return false; } | 172 virtual bool IsOffTheRecord() OVERRIDE { return false; } |
173 }; | 173 }; |
174 | 174 |
| 175 class TestFaviconClient : public FaviconClient { |
| 176 public: |
| 177 virtual FaviconService* GetFaviconService() OVERRIDE { |
| 178 // Just give none NULL value, so overridden methods can be hit. |
| 179 return (FaviconService*)(1); |
| 180 } |
| 181 }; |
| 182 |
175 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { | 183 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { |
176 public: | 184 public: |
177 TestFaviconHandlerDelegate() { | 185 TestFaviconHandlerDelegate() { |
178 } | 186 } |
179 | 187 |
180 virtual ~TestFaviconHandlerDelegate() { | 188 virtual ~TestFaviconHandlerDelegate() { |
181 } | 189 } |
182 | 190 |
183 virtual NavigationEntry* GetActiveEntry() OVERRIDE { | 191 virtual NavigationEntry* GetActiveEntry() OVERRIDE { |
184 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " | 192 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " |
(...skipping 17 matching lines...) Expand all Loading... |
202 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); | 210 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); |
203 }; | 211 }; |
204 | 212 |
205 // This class is used to catch the FaviconHandler's download and history | 213 // This class is used to catch the FaviconHandler's download and history |
206 // request, and also provide the methods to access the FaviconHandler | 214 // request, and also provide the methods to access the FaviconHandler |
207 // internals. | 215 // internals. |
208 class TestFaviconHandler : public FaviconHandler { | 216 class TestFaviconHandler : public FaviconHandler { |
209 public: | 217 public: |
210 TestFaviconHandler(const GURL& page_url, | 218 TestFaviconHandler(const GURL& page_url, |
211 Profile* profile, | 219 Profile* profile, |
| 220 FaviconClient* client, |
212 FaviconDriver* driver, | 221 FaviconDriver* driver, |
213 FaviconHandlerDelegate* delegate, | 222 FaviconHandlerDelegate* delegate, |
214 Type type) | 223 Type type) |
215 : FaviconHandler(profile, driver, delegate, type), | 224 : FaviconHandler(profile, client, driver, delegate, type), |
216 entry_(NavigationEntry::Create()), | 225 entry_(NavigationEntry::Create()), |
217 download_id_(0), | 226 download_id_(0), |
218 num_favicon_updates_(0) { | 227 num_favicon_updates_(0) { |
219 entry_->SetURL(page_url); | 228 entry_->SetURL(page_url); |
220 download_handler_.reset(new DownloadHandler(this)); | 229 download_handler_.reset(new DownloadHandler(this)); |
221 } | 230 } |
222 | 231 |
223 virtual ~TestFaviconHandler() { | 232 virtual ~TestFaviconHandler() { |
224 } | 233 } |
225 | 234 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 const GURL& icon_url, | 307 const GURL& icon_url, |
299 chrome::IconType icon_type, | 308 chrome::IconType icon_type, |
300 const gfx::Image& image) OVERRIDE { | 309 const gfx::Image& image) OVERRIDE { |
301 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 310 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
302 std::vector<unsigned char> bitmap_data(bytes->front(), | 311 std::vector<unsigned char> bitmap_data(bytes->front(), |
303 bytes->front() + bytes->size()); | 312 bytes->front() + bytes->size()); |
304 history_handler_.reset(new HistoryRequestHandler( | 313 history_handler_.reset(new HistoryRequestHandler( |
305 page_url, icon_url, icon_type, bitmap_data)); | 314 page_url, icon_url, icon_type, bitmap_data)); |
306 } | 315 } |
307 | 316 |
308 virtual FaviconService* GetFaviconService() OVERRIDE { | |
309 // Just give none NULL value, so overridden methods can be hit. | |
310 return (FaviconService*)(1); | |
311 } | |
312 | |
313 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { | 317 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { |
314 return true; | 318 return true; |
315 } | 319 } |
316 | 320 |
317 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { | 321 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { |
318 ++num_favicon_updates_; | 322 ++num_favicon_updates_; |
319 } | 323 } |
320 | 324 |
321 GURL page_url_; | 325 GURL page_url_; |
322 | 326 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 ScopedSetSupportedScaleFactors; | 439 ScopedSetSupportedScaleFactors; |
436 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 440 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
437 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 441 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
438 }; | 442 }; |
439 | 443 |
440 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 444 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
441 const GURL page_url("http://www.google.com"); | 445 const GURL page_url("http://www.google.com"); |
442 const GURL icon_url("http://www.google.com/favicon"); | 446 const GURL icon_url("http://www.google.com/favicon"); |
443 | 447 |
444 TestFaviconHandlerDelegate delegate; | 448 TestFaviconHandlerDelegate delegate; |
| 449 TestFaviconClient client; |
445 TestFaviconDriver driver; | 450 TestFaviconDriver driver; |
446 Profile* profile = Profile::FromBrowserContext( | 451 Profile* profile = Profile::FromBrowserContext( |
447 web_contents()->GetBrowserContext()); | 452 web_contents()->GetBrowserContext()); |
448 TestFaviconHandler helper( | 453 TestFaviconHandler helper( |
449 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON); | 454 page_url, profile, &client, &driver, &delegate, FaviconHandler::FAVICON); |
450 | 455 |
451 helper.FetchFavicon(page_url); | 456 helper.FetchFavicon(page_url); |
452 HistoryRequestHandler* history_handler = helper.history_handler(); | 457 HistoryRequestHandler* history_handler = helper.history_handler(); |
453 // Ensure the data given to history is correct. | 458 // Ensure the data given to history is correct. |
454 ASSERT_TRUE(history_handler); | 459 ASSERT_TRUE(history_handler); |
455 EXPECT_EQ(page_url, history_handler->page_url_); | 460 EXPECT_EQ(page_url, history_handler->page_url_); |
456 EXPECT_EQ(GURL(), history_handler->icon_url_); | 461 EXPECT_EQ(GURL(), history_handler->icon_url_); |
457 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 462 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
458 | 463 |
459 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 464 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
(...skipping 18 matching lines...) Expand all Loading... |
478 | 483 |
479 // Favicon shouldn't request to download icon. | 484 // Favicon shouldn't request to download icon. |
480 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 485 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
481 } | 486 } |
482 | 487 |
483 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 488 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
484 const GURL page_url("http://www.google.com"); | 489 const GURL page_url("http://www.google.com"); |
485 const GURL icon_url("http://www.google.com/favicon"); | 490 const GURL icon_url("http://www.google.com/favicon"); |
486 | 491 |
487 TestFaviconHandlerDelegate delegate; | 492 TestFaviconHandlerDelegate delegate; |
| 493 TestFaviconClient client; |
488 TestFaviconDriver driver; | 494 TestFaviconDriver driver; |
489 Profile* profile = Profile::FromBrowserContext( | 495 Profile* profile = Profile::FromBrowserContext( |
490 web_contents()->GetBrowserContext()); | 496 web_contents()->GetBrowserContext()); |
491 TestFaviconHandler helper( | 497 TestFaviconHandler helper( |
492 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON); | 498 page_url, profile, &client, &driver, &delegate, FaviconHandler::FAVICON); |
493 | 499 |
494 helper.FetchFavicon(page_url); | 500 helper.FetchFavicon(page_url); |
495 HistoryRequestHandler* history_handler = helper.history_handler(); | 501 HistoryRequestHandler* history_handler = helper.history_handler(); |
496 // Ensure the data given to history is correct. | 502 // Ensure the data given to history is correct. |
497 ASSERT_TRUE(history_handler); | 503 ASSERT_TRUE(history_handler); |
498 EXPECT_EQ(page_url, history_handler->page_url_); | 504 EXPECT_EQ(page_url, history_handler->page_url_); |
499 EXPECT_EQ(GURL(), history_handler->icon_url_); | 505 EXPECT_EQ(GURL(), history_handler->icon_url_); |
500 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 506 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
501 | 507 |
502 // Set icon data expired | 508 // Set icon data expired |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 554 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
549 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 555 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
550 } | 556 } |
551 | 557 |
552 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 558 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
553 const GURL page_url("http://www.google.com"); | 559 const GURL page_url("http://www.google.com"); |
554 const GURL icon_url("http://www.google.com/favicon"); | 560 const GURL icon_url("http://www.google.com/favicon"); |
555 const GURL new_icon_url("http://www.google.com/new_favicon"); | 561 const GURL new_icon_url("http://www.google.com/new_favicon"); |
556 | 562 |
557 TestFaviconHandlerDelegate delegate; | 563 TestFaviconHandlerDelegate delegate; |
| 564 TestFaviconClient client; |
558 TestFaviconDriver driver; | 565 TestFaviconDriver driver; |
559 Profile* profile = Profile::FromBrowserContext( | 566 Profile* profile = Profile::FromBrowserContext( |
560 web_contents()->GetBrowserContext()); | 567 web_contents()->GetBrowserContext()); |
561 TestFaviconHandler helper( | 568 TestFaviconHandler helper( |
562 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON); | 569 page_url, profile, &client, &driver, &delegate, FaviconHandler::FAVICON); |
563 | 570 |
564 helper.FetchFavicon(page_url); | 571 helper.FetchFavicon(page_url); |
565 HistoryRequestHandler* history_handler = helper.history_handler(); | 572 HistoryRequestHandler* history_handler = helper.history_handler(); |
566 // Ensure the data given to history is correct. | 573 // Ensure the data given to history is correct. |
567 ASSERT_TRUE(history_handler); | 574 ASSERT_TRUE(history_handler); |
568 EXPECT_EQ(page_url, history_handler->page_url_); | 575 EXPECT_EQ(page_url, history_handler->page_url_); |
569 EXPECT_EQ(GURL(), history_handler->icon_url_); | 576 EXPECT_EQ(GURL(), history_handler->icon_url_); |
570 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 577 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
571 | 578 |
572 // Set valid icon data. | 579 // Set valid icon data. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 EXPECT_TRUE(favicon_status.valid); | 639 EXPECT_TRUE(favicon_status.valid); |
633 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 640 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
634 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 641 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
635 } | 642 } |
636 | 643 |
637 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 644 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
638 const GURL page_url("http://www.google.com"); | 645 const GURL page_url("http://www.google.com"); |
639 const GURL icon_url("http://www.google.com/favicon"); | 646 const GURL icon_url("http://www.google.com/favicon"); |
640 | 647 |
641 TestFaviconHandlerDelegate delegate; | 648 TestFaviconHandlerDelegate delegate; |
| 649 TestFaviconClient client; |
642 TestFaviconDriver driver; | 650 TestFaviconDriver driver; |
643 Profile* profile = Profile::FromBrowserContext( | 651 Profile* profile = Profile::FromBrowserContext( |
644 web_contents()->GetBrowserContext()); | 652 web_contents()->GetBrowserContext()); |
645 TestFaviconHandler helper( | 653 TestFaviconHandler helper( |
646 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON); | 654 page_url, profile, &client, &driver, &delegate, FaviconHandler::FAVICON); |
647 | 655 |
648 helper.FetchFavicon(page_url); | 656 helper.FetchFavicon(page_url); |
649 HistoryRequestHandler* history_handler = helper.history_handler(); | 657 HistoryRequestHandler* history_handler = helper.history_handler(); |
650 // Ensure the data given to history is correct. | 658 // Ensure the data given to history is correct. |
651 ASSERT_TRUE(history_handler); | 659 ASSERT_TRUE(history_handler); |
652 EXPECT_EQ(page_url, history_handler->page_url_); | 660 EXPECT_EQ(page_url, history_handler->page_url_); |
653 EXPECT_EQ(GURL(), history_handler->icon_url_); | 661 EXPECT_EQ(GURL(), history_handler->icon_url_); |
654 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 662 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
655 | 663 |
656 // Set non empty but invalid data. | 664 // Set non empty but invalid data. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 715 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
708 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 716 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
709 } | 717 } |
710 | 718 |
711 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 719 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
712 const GURL page_url("http://www.google.com"); | 720 const GURL page_url("http://www.google.com"); |
713 const GURL icon_url("http://www.google.com/favicon"); | 721 const GURL icon_url("http://www.google.com/favicon"); |
714 const GURL new_icon_url("http://www.google.com/new_favicon"); | 722 const GURL new_icon_url("http://www.google.com/new_favicon"); |
715 | 723 |
716 TestFaviconHandlerDelegate delegate; | 724 TestFaviconHandlerDelegate delegate; |
| 725 TestFaviconClient client; |
717 TestFaviconDriver driver; | 726 TestFaviconDriver driver; |
718 Profile* profile = Profile::FromBrowserContext( | 727 Profile* profile = Profile::FromBrowserContext( |
719 web_contents()->GetBrowserContext()); | 728 web_contents()->GetBrowserContext()); |
720 TestFaviconHandler helper( | 729 TestFaviconHandler helper( |
721 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON); | 730 page_url, profile, &client, &driver, &delegate, FaviconHandler::FAVICON); |
722 | 731 |
723 helper.FetchFavicon(page_url); | 732 helper.FetchFavicon(page_url); |
724 HistoryRequestHandler* history_handler = helper.history_handler(); | 733 HistoryRequestHandler* history_handler = helper.history_handler(); |
725 // Ensure the data given to history is correct. | 734 // Ensure the data given to history is correct. |
726 ASSERT_TRUE(history_handler); | 735 ASSERT_TRUE(history_handler); |
727 EXPECT_EQ(page_url, history_handler->page_url_); | 736 EXPECT_EQ(page_url, history_handler->page_url_); |
728 EXPECT_EQ(GURL(), history_handler->icon_url_); | 737 EXPECT_EQ(GURL(), history_handler->icon_url_); |
729 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); | 738 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); |
730 | 739 |
731 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 740 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 780 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
772 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 781 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
773 } | 782 } |
774 | 783 |
775 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 784 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
776 const GURL page_url("http://www.google.com"); | 785 const GURL page_url("http://www.google.com"); |
777 const GURL icon_url("http://www.google.com/favicon"); | 786 const GURL icon_url("http://www.google.com/favicon"); |
778 const GURL new_icon_url("http://www.google.com/new_favicon"); | 787 const GURL new_icon_url("http://www.google.com/new_favicon"); |
779 | 788 |
780 TestFaviconHandlerDelegate delegate; | 789 TestFaviconHandlerDelegate delegate; |
| 790 TestFaviconClient client; |
781 TestFaviconDriver driver; | 791 TestFaviconDriver driver; |
782 Profile* profile = Profile::FromBrowserContext( | 792 Profile* profile = Profile::FromBrowserContext( |
783 web_contents()->GetBrowserContext()); | 793 web_contents()->GetBrowserContext()); |
784 TestFaviconHandler helper( | 794 TestFaviconHandler helper( |
785 page_url, profile, &driver, &delegate, FaviconHandler::TOUCH); | 795 page_url, profile, &client, &driver, &delegate, FaviconHandler::TOUCH); |
786 | 796 |
787 helper.FetchFavicon(page_url); | 797 helper.FetchFavicon(page_url); |
788 HistoryRequestHandler* history_handler = helper.history_handler(); | 798 HistoryRequestHandler* history_handler = helper.history_handler(); |
789 // Ensure the data given to history is correct. | 799 // Ensure the data given to history is correct. |
790 ASSERT_TRUE(history_handler); | 800 ASSERT_TRUE(history_handler); |
791 EXPECT_EQ(page_url, history_handler->page_url_); | 801 EXPECT_EQ(page_url, history_handler->page_url_); |
792 EXPECT_EQ(GURL(), history_handler->icon_url_); | 802 EXPECT_EQ(GURL(), history_handler->icon_url_); |
793 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, | 803 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, |
794 history_handler->icon_type_); | 804 history_handler->icon_type_); |
795 | 805 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 895 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
886 EXPECT_EQ(page_url, history_handler->page_url_); | 896 EXPECT_EQ(page_url, history_handler->page_url_); |
887 } | 897 } |
888 | 898 |
889 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 899 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
890 const GURL page_url("http://www.google.com"); | 900 const GURL page_url("http://www.google.com"); |
891 const GURL icon_url("http://www.google.com/favicon"); | 901 const GURL icon_url("http://www.google.com/favicon"); |
892 const GURL new_icon_url("http://www.google.com/new_favicon"); | 902 const GURL new_icon_url("http://www.google.com/new_favicon"); |
893 | 903 |
894 TestFaviconHandlerDelegate delegate; | 904 TestFaviconHandlerDelegate delegate; |
| 905 TestFaviconClient client; |
895 TestFaviconDriver driver; | 906 TestFaviconDriver driver; |
896 Profile* profile = Profile::FromBrowserContext( | 907 Profile* profile = Profile::FromBrowserContext( |
897 web_contents()->GetBrowserContext()); | 908 web_contents()->GetBrowserContext()); |
898 TestFaviconHandler helper( | 909 TestFaviconHandler helper( |
899 page_url, profile, &driver, &delegate, FaviconHandler::TOUCH); | 910 page_url, profile, &client, &driver, &delegate, FaviconHandler::TOUCH); |
900 | 911 |
901 helper.FetchFavicon(page_url); | 912 helper.FetchFavicon(page_url); |
902 HistoryRequestHandler* history_handler = helper.history_handler(); | 913 HistoryRequestHandler* history_handler = helper.history_handler(); |
903 // Ensure the data given to history is correct. | 914 // Ensure the data given to history is correct. |
904 ASSERT_TRUE(history_handler); | 915 ASSERT_TRUE(history_handler); |
905 EXPECT_EQ(page_url, history_handler->page_url_); | 916 EXPECT_EQ(page_url, history_handler->page_url_); |
906 EXPECT_EQ(GURL(), history_handler->icon_url_); | 917 EXPECT_EQ(GURL(), history_handler->icon_url_); |
907 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, | 918 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, |
908 history_handler->icon_type_); | 919 history_handler->icon_type_); |
909 | 920 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1041 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
1031 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1042 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
1032 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1043 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
1033 | 1044 |
1034 Profile* profile = Profile::FromBrowserContext( | 1045 Profile* profile = Profile::FromBrowserContext( |
1035 web_contents()->GetBrowserContext()); | 1046 web_contents()->GetBrowserContext()); |
1036 | 1047 |
1037 // 1) Test that if there are several single resolution favicons to choose from | 1048 // 1) Test that if there are several single resolution favicons to choose from |
1038 // that the largest exact match is chosen. | 1049 // that the largest exact match is chosen. |
1039 TestFaviconHandlerDelegate delegate1; | 1050 TestFaviconHandlerDelegate delegate1; |
| 1051 TestFaviconClient client; |
1040 TestFaviconDriver driver; | 1052 TestFaviconDriver driver; |
1041 TestFaviconHandler handler1( | 1053 TestFaviconHandler handler1( |
1042 kPageURL, profile, &driver, &delegate1, FaviconHandler::FAVICON); | 1054 kPageURL, profile, &client, &driver, &delegate1, FaviconHandler::FAVICON); |
1043 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1055 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1044 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1056 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1045 kSourceIconURLs + arraysize(kSizes1)); | 1057 kSourceIconURLs + arraysize(kSizes1)); |
1046 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); | 1058 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); |
1047 | 1059 |
1048 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); | 1060 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); |
1049 EXPECT_EQ(0u, handler1.image_urls().size()); | 1061 EXPECT_EQ(0u, handler1.image_urls().size()); |
1050 EXPECT_TRUE(favicon_status1.valid); | 1062 EXPECT_TRUE(favicon_status1.valid); |
1051 EXPECT_FALSE(favicon_status1.image.IsEmpty()); | 1063 EXPECT_FALSE(favicon_status1.image.IsEmpty()); |
1052 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); | 1064 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); |
1053 | 1065 |
1054 size_t expected_index = 2u; | 1066 size_t expected_index = 2u; |
1055 EXPECT_EQ(32, kSizes1[expected_index]); | 1067 EXPECT_EQ(32, kSizes1[expected_index]); |
1056 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1068 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1057 handler1.GetEntry()->GetFavicon().url); | 1069 handler1.GetEntry()->GetFavicon().url); |
1058 | 1070 |
1059 // 2) Test that if there are several single resolution favicons to choose | 1071 // 2) Test that if there are several single resolution favicons to choose |
1060 // from, the exact match is preferred even if it results in upsampling. | 1072 // from, the exact match is preferred even if it results in upsampling. |
1061 TestFaviconHandlerDelegate delegate2; | 1073 TestFaviconHandlerDelegate delegate2; |
1062 TestFaviconHandler handler2( | 1074 TestFaviconHandler handler2( |
1063 kPageURL, profile, &driver, &delegate2, FaviconHandler::FAVICON); | 1075 kPageURL, profile, &client, &driver, &delegate2, FaviconHandler::FAVICON); |
1064 const int kSizes2[] = { 16, 24, 48, 256 }; | 1076 const int kSizes2[] = { 16, 24, 48, 256 }; |
1065 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1077 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1066 kSourceIconURLs + arraysize(kSizes2)); | 1078 kSourceIconURLs + arraysize(kSizes2)); |
1067 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); | 1079 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); |
1068 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); | 1080 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); |
1069 expected_index = 0u; | 1081 expected_index = 0u; |
1070 EXPECT_EQ(16, kSizes2[expected_index]); | 1082 EXPECT_EQ(16, kSizes2[expected_index]); |
1071 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1083 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1072 handler2.GetEntry()->GetFavicon().url); | 1084 handler2.GetEntry()->GetFavicon().url); |
1073 | 1085 |
1074 // 3) Test that favicons which need to be upsampled a little or downsampled | 1086 // 3) Test that favicons which need to be upsampled a little or downsampled |
1075 // a little are preferred over huge favicons. | 1087 // a little are preferred over huge favicons. |
1076 TestFaviconHandlerDelegate delegate3; | 1088 TestFaviconHandlerDelegate delegate3; |
1077 TestFaviconHandler handler3( | 1089 TestFaviconHandler handler3( |
1078 kPageURL, profile, &driver, &delegate3, FaviconHandler::FAVICON); | 1090 kPageURL, profile, &client, &driver, &delegate3, FaviconHandler::FAVICON); |
1079 const int kSizes3[] = { 256, 48 }; | 1091 const int kSizes3[] = { 256, 48 }; |
1080 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1092 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1081 kSourceIconURLs + arraysize(kSizes3)); | 1093 kSourceIconURLs + arraysize(kSizes3)); |
1082 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); | 1094 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); |
1083 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); | 1095 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); |
1084 expected_index = 1u; | 1096 expected_index = 1u; |
1085 EXPECT_EQ(48, kSizes3[expected_index]); | 1097 EXPECT_EQ(48, kSizes3[expected_index]); |
1086 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1098 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1087 handler3.GetEntry()->GetFavicon().url); | 1099 handler3.GetEntry()->GetFavicon().url); |
1088 | 1100 |
1089 TestFaviconHandlerDelegate delegate4; | 1101 TestFaviconHandlerDelegate delegate4; |
1090 TestFaviconHandler handler4( | 1102 TestFaviconHandler handler4( |
1091 kPageURL, profile, &driver, &delegate4, FaviconHandler::FAVICON); | 1103 kPageURL, profile, &client, &driver, &delegate4, FaviconHandler::FAVICON); |
1092 const int kSizes4[] = { 17, 256 }; | 1104 const int kSizes4[] = { 17, 256 }; |
1093 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1105 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1094 kSourceIconURLs + arraysize(kSizes4)); | 1106 kSourceIconURLs + arraysize(kSizes4)); |
1095 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); | 1107 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); |
1096 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); | 1108 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); |
1097 expected_index = 0u; | 1109 expected_index = 0u; |
1098 EXPECT_EQ(17, kSizes4[expected_index]); | 1110 EXPECT_EQ(17, kSizes4[expected_index]); |
1099 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1111 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
1100 handler4.GetEntry()->GetFavicon().url); | 1112 handler4.GetEntry()->GetFavicon().url); |
1101 } | 1113 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1191 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1180 EXPECT_NE(0, download_id); | 1192 EXPECT_NE(0, download_id); |
1181 // Report download success with HTTP 200 status. | 1193 // Report download success with HTTP 200 status. |
1182 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1194 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1183 empty_icons, empty_icon_sizes); | 1195 empty_icons, empty_icon_sizes); |
1184 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1196 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1185 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1197 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1186 } | 1198 } |
1187 | 1199 |
1188 } // namespace. | 1200 } // namespace. |
OLD | NEW |