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

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

Issue 227153007: Remove dependency on Profile's IsOffTheRecord in favicon_handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FAVICON_create_core_dir
Patch Set: Review fixes. Created 6 years, 8 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 "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"
11 #include "components/favicon/content/browser/content_favicon_driver.h"
11 #include "content/public/browser/favicon_status.h" 12 #include "content/public/browser/favicon_status.h"
12 #include "content/public/browser/invalidate_type.h" 13 #include "content/public/browser/invalidate_type.h"
13 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/gfx/codec/png_codec.h" 17 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/favicon_size.h" 18 #include "ui/gfx/favicon_size.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 20
20 class TestFaviconHandler; 21 class TestFaviconHandler;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const std::vector<unsigned char> bitmap_data_; 161 const std::vector<unsigned char> bitmap_data_;
161 std::vector<chrome::FaviconBitmapResult> history_results_; 162 std::vector<chrome::FaviconBitmapResult> history_results_;
162 FaviconService::FaviconResultsCallback callback_; 163 FaviconService::FaviconResultsCallback callback_;
163 164
164 private: 165 private:
165 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); 166 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler);
166 }; 167 };
167 168
168 } // namespace 169 } // namespace
169 170
171 class TestFaviconDriver : public FaviconDriver {
172 virtual bool IsOffTheRecord() OVERRIDE { return false; }
173 };
170 174
171 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { 175 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate {
172 public: 176 public:
173 TestFaviconHandlerDelegate() { 177 TestFaviconHandlerDelegate() {
174 } 178 }
175 179
176 virtual ~TestFaviconHandlerDelegate() { 180 virtual ~TestFaviconHandlerDelegate() {
177 } 181 }
178 182
179 virtual NavigationEntry* GetActiveEntry() OVERRIDE { 183 virtual NavigationEntry* GetActiveEntry() OVERRIDE {
(...skipping 18 matching lines...) Expand all
198 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); 202 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate);
199 }; 203 };
200 204
201 // This class is used to catch the FaviconHandler's download and history 205 // This class is used to catch the FaviconHandler's download and history
202 // request, and also provide the methods to access the FaviconHandler 206 // request, and also provide the methods to access the FaviconHandler
203 // internals. 207 // internals.
204 class TestFaviconHandler : public FaviconHandler { 208 class TestFaviconHandler : public FaviconHandler {
205 public: 209 public:
206 TestFaviconHandler(const GURL& page_url, 210 TestFaviconHandler(const GURL& page_url,
207 Profile* profile, 211 Profile* profile,
212 FaviconDriver* driver,
208 FaviconHandlerDelegate* delegate, 213 FaviconHandlerDelegate* delegate,
209 Type type) 214 Type type)
210 : FaviconHandler(profile, delegate, type), 215 : FaviconHandler(profile, driver, delegate, type),
211 entry_(NavigationEntry::Create()), 216 entry_(NavigationEntry::Create()),
212 download_id_(0), 217 download_id_(0),
213 num_favicon_updates_(0) { 218 num_favicon_updates_(0) {
214 entry_->SetURL(page_url); 219 entry_->SetURL(page_url);
215 download_handler_.reset(new DownloadHandler(this)); 220 download_handler_.reset(new DownloadHandler(this));
216 } 221 }
217 222
218 virtual ~TestFaviconHandler() { 223 virtual ~TestFaviconHandler() {
219 } 224 }
220 225
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 ScopedSetSupportedScaleFactors; 435 ScopedSetSupportedScaleFactors;
431 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; 436 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;
432 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); 437 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
433 }; 438 };
434 439
435 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { 440 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
436 const GURL page_url("http://www.google.com"); 441 const GURL page_url("http://www.google.com");
437 const GURL icon_url("http://www.google.com/favicon"); 442 const GURL icon_url("http://www.google.com/favicon");
438 443
439 TestFaviconHandlerDelegate delegate; 444 TestFaviconHandlerDelegate delegate;
445 TestFaviconDriver driver;
440 Profile* profile = Profile::FromBrowserContext( 446 Profile* profile = Profile::FromBrowserContext(
441 web_contents()->GetBrowserContext()); 447 web_contents()->GetBrowserContext());
442 TestFaviconHandler helper(page_url, profile, 448 TestFaviconHandler helper(
443 &delegate, FaviconHandler::FAVICON); 449 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON);
444 450
445 helper.FetchFavicon(page_url); 451 helper.FetchFavicon(page_url);
446 HistoryRequestHandler* history_handler = helper.history_handler(); 452 HistoryRequestHandler* history_handler = helper.history_handler();
447 // Ensure the data given to history is correct. 453 // Ensure the data given to history is correct.
448 ASSERT_TRUE(history_handler); 454 ASSERT_TRUE(history_handler);
449 EXPECT_EQ(page_url, history_handler->page_url_); 455 EXPECT_EQ(page_url, history_handler->page_url_);
450 EXPECT_EQ(GURL(), history_handler->icon_url_); 456 EXPECT_EQ(GURL(), history_handler->icon_url_);
451 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); 457 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_);
452 458
453 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); 459 SetFaviconBitmapResult(icon_url, &history_handler->history_results_);
(...skipping 18 matching lines...) Expand all
472 478
473 // Favicon shouldn't request to download icon. 479 // Favicon shouldn't request to download icon.
474 EXPECT_FALSE(helper.download_handler()->HasDownload()); 480 EXPECT_FALSE(helper.download_handler()->HasDownload());
475 } 481 }
476 482
477 TEST_F(FaviconHandlerTest, DownloadFavicon) { 483 TEST_F(FaviconHandlerTest, DownloadFavicon) {
478 const GURL page_url("http://www.google.com"); 484 const GURL page_url("http://www.google.com");
479 const GURL icon_url("http://www.google.com/favicon"); 485 const GURL icon_url("http://www.google.com/favicon");
480 486
481 TestFaviconHandlerDelegate delegate; 487 TestFaviconHandlerDelegate delegate;
488 TestFaviconDriver driver;
482 Profile* profile = Profile::FromBrowserContext( 489 Profile* profile = Profile::FromBrowserContext(
483 web_contents()->GetBrowserContext()); 490 web_contents()->GetBrowserContext());
484 TestFaviconHandler helper(page_url, profile, 491 TestFaviconHandler helper(
485 &delegate, FaviconHandler::FAVICON); 492 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON);
486 493
487 helper.FetchFavicon(page_url); 494 helper.FetchFavicon(page_url);
488 HistoryRequestHandler* history_handler = helper.history_handler(); 495 HistoryRequestHandler* history_handler = helper.history_handler();
489 // Ensure the data given to history is correct. 496 // Ensure the data given to history is correct.
490 ASSERT_TRUE(history_handler); 497 ASSERT_TRUE(history_handler);
491 EXPECT_EQ(page_url, history_handler->page_url_); 498 EXPECT_EQ(page_url, history_handler->page_url_);
492 EXPECT_EQ(GURL(), history_handler->icon_url_); 499 EXPECT_EQ(GURL(), history_handler->icon_url_);
493 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); 500 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_);
494 501
495 // Set icon data expired 502 // Set icon data expired
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 EXPECT_FALSE(favicon_status.image.IsEmpty()); 548 EXPECT_FALSE(favicon_status.image.IsEmpty());
542 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); 549 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
543 } 550 }
544 551
545 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { 552 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
546 const GURL page_url("http://www.google.com"); 553 const GURL page_url("http://www.google.com");
547 const GURL icon_url("http://www.google.com/favicon"); 554 const GURL icon_url("http://www.google.com/favicon");
548 const GURL new_icon_url("http://www.google.com/new_favicon"); 555 const GURL new_icon_url("http://www.google.com/new_favicon");
549 556
550 TestFaviconHandlerDelegate delegate; 557 TestFaviconHandlerDelegate delegate;
558 TestFaviconDriver driver;
551 Profile* profile = Profile::FromBrowserContext( 559 Profile* profile = Profile::FromBrowserContext(
552 web_contents()->GetBrowserContext()); 560 web_contents()->GetBrowserContext());
553 TestFaviconHandler helper(page_url, profile, 561 TestFaviconHandler helper(
554 &delegate, FaviconHandler::FAVICON); 562 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON);
555 563
556 helper.FetchFavicon(page_url); 564 helper.FetchFavicon(page_url);
557 HistoryRequestHandler* history_handler = helper.history_handler(); 565 HistoryRequestHandler* history_handler = helper.history_handler();
558 // Ensure the data given to history is correct. 566 // Ensure the data given to history is correct.
559 ASSERT_TRUE(history_handler); 567 ASSERT_TRUE(history_handler);
560 EXPECT_EQ(page_url, history_handler->page_url_); 568 EXPECT_EQ(page_url, history_handler->page_url_);
561 EXPECT_EQ(GURL(), history_handler->icon_url_); 569 EXPECT_EQ(GURL(), history_handler->icon_url_);
562 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); 570 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_);
563 571
564 // Set valid icon data. 572 // Set valid icon data.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 EXPECT_TRUE(favicon_status.valid); 632 EXPECT_TRUE(favicon_status.valid);
625 EXPECT_FALSE(favicon_status.image.IsEmpty()); 633 EXPECT_FALSE(favicon_status.image.IsEmpty());
626 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); 634 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
627 } 635 }
628 636
629 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { 637 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
630 const GURL page_url("http://www.google.com"); 638 const GURL page_url("http://www.google.com");
631 const GURL icon_url("http://www.google.com/favicon"); 639 const GURL icon_url("http://www.google.com/favicon");
632 640
633 TestFaviconHandlerDelegate delegate; 641 TestFaviconHandlerDelegate delegate;
642 TestFaviconDriver driver;
634 Profile* profile = Profile::FromBrowserContext( 643 Profile* profile = Profile::FromBrowserContext(
635 web_contents()->GetBrowserContext()); 644 web_contents()->GetBrowserContext());
636 TestFaviconHandler helper(page_url, profile, 645 TestFaviconHandler helper(
637 &delegate, FaviconHandler::FAVICON); 646 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON);
638 647
639 helper.FetchFavicon(page_url); 648 helper.FetchFavicon(page_url);
640 HistoryRequestHandler* history_handler = helper.history_handler(); 649 HistoryRequestHandler* history_handler = helper.history_handler();
641 // Ensure the data given to history is correct. 650 // Ensure the data given to history is correct.
642 ASSERT_TRUE(history_handler); 651 ASSERT_TRUE(history_handler);
643 EXPECT_EQ(page_url, history_handler->page_url_); 652 EXPECT_EQ(page_url, history_handler->page_url_);
644 EXPECT_EQ(GURL(), history_handler->icon_url_); 653 EXPECT_EQ(GURL(), history_handler->icon_url_);
645 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); 654 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_);
646 655
647 // 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
698 EXPECT_FALSE(favicon_status.image.IsEmpty()); 707 EXPECT_FALSE(favicon_status.image.IsEmpty());
699 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); 708 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
700 } 709 }
701 710
702 TEST_F(FaviconHandlerTest, UpdateFavicon) { 711 TEST_F(FaviconHandlerTest, UpdateFavicon) {
703 const GURL page_url("http://www.google.com"); 712 const GURL page_url("http://www.google.com");
704 const GURL icon_url("http://www.google.com/favicon"); 713 const GURL icon_url("http://www.google.com/favicon");
705 const GURL new_icon_url("http://www.google.com/new_favicon"); 714 const GURL new_icon_url("http://www.google.com/new_favicon");
706 715
707 TestFaviconHandlerDelegate delegate; 716 TestFaviconHandlerDelegate delegate;
717 TestFaviconDriver driver;
708 Profile* profile = Profile::FromBrowserContext( 718 Profile* profile = Profile::FromBrowserContext(
709 web_contents()->GetBrowserContext()); 719 web_contents()->GetBrowserContext());
710 TestFaviconHandler helper(page_url, profile, 720 TestFaviconHandler helper(
711 &delegate, FaviconHandler::FAVICON); 721 page_url, profile, &driver, &delegate, FaviconHandler::FAVICON);
712 722
713 helper.FetchFavicon(page_url); 723 helper.FetchFavicon(page_url);
714 HistoryRequestHandler* history_handler = helper.history_handler(); 724 HistoryRequestHandler* history_handler = helper.history_handler();
715 // Ensure the data given to history is correct. 725 // Ensure the data given to history is correct.
716 ASSERT_TRUE(history_handler); 726 ASSERT_TRUE(history_handler);
717 EXPECT_EQ(page_url, history_handler->page_url_); 727 EXPECT_EQ(page_url, history_handler->page_url_);
718 EXPECT_EQ(GURL(), history_handler->icon_url_); 728 EXPECT_EQ(GURL(), history_handler->icon_url_);
719 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_); 729 EXPECT_EQ(chrome::FAVICON, history_handler->icon_type_);
720 730
721 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
761 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); 771 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
762 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); 772 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
763 } 773 }
764 774
765 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { 775 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
766 const GURL page_url("http://www.google.com"); 776 const GURL page_url("http://www.google.com");
767 const GURL icon_url("http://www.google.com/favicon"); 777 const GURL icon_url("http://www.google.com/favicon");
768 const GURL new_icon_url("http://www.google.com/new_favicon"); 778 const GURL new_icon_url("http://www.google.com/new_favicon");
769 779
770 TestFaviconHandlerDelegate delegate; 780 TestFaviconHandlerDelegate delegate;
781 TestFaviconDriver driver;
771 Profile* profile = Profile::FromBrowserContext( 782 Profile* profile = Profile::FromBrowserContext(
772 web_contents()->GetBrowserContext()); 783 web_contents()->GetBrowserContext());
773 TestFaviconHandler helper(page_url, profile, 784 TestFaviconHandler helper(
774 &delegate, FaviconHandler::TOUCH); 785 page_url, profile, &driver, &delegate, FaviconHandler::TOUCH);
775 786
776 helper.FetchFavicon(page_url); 787 helper.FetchFavicon(page_url);
777 HistoryRequestHandler* history_handler = helper.history_handler(); 788 HistoryRequestHandler* history_handler = helper.history_handler();
778 // Ensure the data given to history is correct. 789 // Ensure the data given to history is correct.
779 ASSERT_TRUE(history_handler); 790 ASSERT_TRUE(history_handler);
780 EXPECT_EQ(page_url, history_handler->page_url_); 791 EXPECT_EQ(page_url, history_handler->page_url_);
781 EXPECT_EQ(GURL(), history_handler->icon_url_); 792 EXPECT_EQ(GURL(), history_handler->icon_url_);
782 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, 793 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON,
783 history_handler->icon_type_); 794 history_handler->icon_type_);
784 795
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 EXPECT_LT(0U, history_handler->bitmap_data_.size()); 885 EXPECT_LT(0U, history_handler->bitmap_data_.size());
875 EXPECT_EQ(page_url, history_handler->page_url_); 886 EXPECT_EQ(page_url, history_handler->page_url_);
876 } 887 }
877 888
878 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { 889 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
879 const GURL page_url("http://www.google.com"); 890 const GURL page_url("http://www.google.com");
880 const GURL icon_url("http://www.google.com/favicon"); 891 const GURL icon_url("http://www.google.com/favicon");
881 const GURL new_icon_url("http://www.google.com/new_favicon"); 892 const GURL new_icon_url("http://www.google.com/new_favicon");
882 893
883 TestFaviconHandlerDelegate delegate; 894 TestFaviconHandlerDelegate delegate;
895 TestFaviconDriver driver;
884 Profile* profile = Profile::FromBrowserContext( 896 Profile* profile = Profile::FromBrowserContext(
885 web_contents()->GetBrowserContext()); 897 web_contents()->GetBrowserContext());
886 TestFaviconHandler helper(page_url, profile, 898 TestFaviconHandler helper(
887 &delegate, FaviconHandler::TOUCH); 899 page_url, profile, &driver, &delegate, FaviconHandler::TOUCH);
888 900
889 helper.FetchFavicon(page_url); 901 helper.FetchFavicon(page_url);
890 HistoryRequestHandler* history_handler = helper.history_handler(); 902 HistoryRequestHandler* history_handler = helper.history_handler();
891 // Ensure the data given to history is correct. 903 // Ensure the data given to history is correct.
892 ASSERT_TRUE(history_handler); 904 ASSERT_TRUE(history_handler);
893 EXPECT_EQ(page_url, history_handler->page_url_); 905 EXPECT_EQ(page_url, history_handler->page_url_);
894 EXPECT_EQ(GURL(), history_handler->icon_url_); 906 EXPECT_EQ(GURL(), history_handler->icon_url_);
895 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON, 907 EXPECT_EQ(chrome::TOUCH_PRECOMPOSED_ICON | chrome::TOUCH_ICON,
896 history_handler->icon_type_); 908 history_handler->icon_type_);
897 909
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 scale_factors.push_back(ui::SCALE_FACTOR_100P); 1030 scale_factors.push_back(ui::SCALE_FACTOR_100P);
1019 scale_factors.push_back(ui::SCALE_FACTOR_200P); 1031 scale_factors.push_back(ui::SCALE_FACTOR_200P);
1020 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); 1032 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors);
1021 1033
1022 Profile* profile = Profile::FromBrowserContext( 1034 Profile* profile = Profile::FromBrowserContext(
1023 web_contents()->GetBrowserContext()); 1035 web_contents()->GetBrowserContext());
1024 1036
1025 // 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
1026 // that the largest exact match is chosen. 1038 // that the largest exact match is chosen.
1027 TestFaviconHandlerDelegate delegate1; 1039 TestFaviconHandlerDelegate delegate1;
1028 TestFaviconHandler handler1(kPageURL, profile, 1040 TestFaviconDriver driver;
1029 &delegate1, FaviconHandler::FAVICON); 1041 TestFaviconHandler handler1(
1042 kPageURL, profile, &driver, &delegate1, FaviconHandler::FAVICON);
1030 const int kSizes1[] = { 16, 24, 32, 48, 256 }; 1043 const int kSizes1[] = { 16, 24, 32, 48, 256 };
1031 std::vector<FaviconURL> urls1(kSourceIconURLs, 1044 std::vector<FaviconURL> urls1(kSourceIconURLs,
1032 kSourceIconURLs + arraysize(kSizes1)); 1045 kSourceIconURLs + arraysize(kSizes1));
1033 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); 1046 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1);
1034 1047
1035 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); 1048 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon());
1036 EXPECT_EQ(0u, handler1.image_urls().size()); 1049 EXPECT_EQ(0u, handler1.image_urls().size());
1037 EXPECT_TRUE(favicon_status1.valid); 1050 EXPECT_TRUE(favicon_status1.valid);
1038 EXPECT_FALSE(favicon_status1.image.IsEmpty()); 1051 EXPECT_FALSE(favicon_status1.image.IsEmpty());
1039 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); 1052 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width());
1040 1053
1041 size_t expected_index = 2u; 1054 size_t expected_index = 2u;
1042 EXPECT_EQ(32, kSizes1[expected_index]); 1055 EXPECT_EQ(32, kSizes1[expected_index]);
1043 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1056 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
1044 handler1.GetEntry()->GetFavicon().url); 1057 handler1.GetEntry()->GetFavicon().url);
1045 1058
1046 // 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
1047 // 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.
1048 TestFaviconHandlerDelegate delegate2; 1061 TestFaviconHandlerDelegate delegate2;
1049 TestFaviconHandler handler2(kPageURL, profile, 1062 TestFaviconHandler handler2(
1050 &delegate2, FaviconHandler::FAVICON); 1063 kPageURL, profile, &driver, &delegate2, FaviconHandler::FAVICON);
1051 const int kSizes2[] = { 16, 24, 48, 256 }; 1064 const int kSizes2[] = { 16, 24, 48, 256 };
1052 std::vector<FaviconURL> urls2(kSourceIconURLs, 1065 std::vector<FaviconURL> urls2(kSourceIconURLs,
1053 kSourceIconURLs + arraysize(kSizes2)); 1066 kSourceIconURLs + arraysize(kSizes2));
1054 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); 1067 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2);
1055 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); 1068 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid);
1056 expected_index = 0u; 1069 expected_index = 0u;
1057 EXPECT_EQ(16, kSizes2[expected_index]); 1070 EXPECT_EQ(16, kSizes2[expected_index]);
1058 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1071 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
1059 handler2.GetEntry()->GetFavicon().url); 1072 handler2.GetEntry()->GetFavicon().url);
1060 1073
1061 // 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
1062 // a little are preferred over huge favicons. 1075 // a little are preferred over huge favicons.
1063 TestFaviconHandlerDelegate delegate3; 1076 TestFaviconHandlerDelegate delegate3;
1064 TestFaviconHandler handler3(kPageURL, profile, 1077 TestFaviconHandler handler3(
1065 &delegate3, FaviconHandler::FAVICON); 1078 kPageURL, profile, &driver, &delegate3, FaviconHandler::FAVICON);
1066 const int kSizes3[] = { 256, 48 }; 1079 const int kSizes3[] = { 256, 48 };
1067 std::vector<FaviconURL> urls3(kSourceIconURLs, 1080 std::vector<FaviconURL> urls3(kSourceIconURLs,
1068 kSourceIconURLs + arraysize(kSizes3)); 1081 kSourceIconURLs + arraysize(kSizes3));
1069 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); 1082 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3);
1070 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); 1083 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid);
1071 expected_index = 1u; 1084 expected_index = 1u;
1072 EXPECT_EQ(48, kSizes3[expected_index]); 1085 EXPECT_EQ(48, kSizes3[expected_index]);
1073 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1086 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
1074 handler3.GetEntry()->GetFavicon().url); 1087 handler3.GetEntry()->GetFavicon().url);
1075 1088
1076 TestFaviconHandlerDelegate delegate4; 1089 TestFaviconHandlerDelegate delegate4;
1077 TestFaviconHandler handler4(kPageURL, profile, 1090 TestFaviconHandler handler4(
1078 &delegate4, FaviconHandler::FAVICON); 1091 kPageURL, profile, &driver, &delegate4, FaviconHandler::FAVICON);
1079 const int kSizes4[] = { 17, 256 }; 1092 const int kSizes4[] = { 17, 256 };
1080 std::vector<FaviconURL> urls4(kSourceIconURLs, 1093 std::vector<FaviconURL> urls4(kSourceIconURLs,
1081 kSourceIconURLs + arraysize(kSizes4)); 1094 kSourceIconURLs + arraysize(kSizes4));
1082 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); 1095 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4);
1083 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); 1096 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid);
1084 expected_index = 0u; 1097 expected_index = 0u;
1085 EXPECT_EQ(17, kSizes4[expected_index]); 1098 EXPECT_EQ(17, kSizes4[expected_index]);
1086 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, 1099 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
1087 handler4.GetEntry()->GetFavicon().url); 1100 handler4.GetEntry()->GetFavicon().url);
1088 } 1101 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); 1179 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0);
1167 EXPECT_NE(0, download_id); 1180 EXPECT_NE(0, download_id);
1168 // Report download success with HTTP 200 status. 1181 // Report download success with HTTP 200 status.
1169 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, 1182 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url,
1170 empty_icons, empty_icon_sizes); 1183 empty_icons, empty_icon_sizes);
1171 // 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.
1172 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); 1185 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
1173 } 1186 }
1174 1187
1175 } // namespace. 1188 } // namespace.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698