| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 virtual ~TestFaviconClient() {}; | 182 virtual ~TestFaviconClient() {}; |
| 183 | 183 |
| 184 virtual FaviconService* GetFaviconService() OVERRIDE { | 184 virtual FaviconService* GetFaviconService() OVERRIDE { |
| 185 // Just give none NULL value, so overridden methods can be hit. | 185 // Just give none NULL value, so overridden methods can be hit. |
| 186 return (FaviconService*)(1); | 186 return (FaviconService*)(1); |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual bool IsBookmarked(const GURL& url) OVERRIDE { return false; } | 189 virtual bool IsBookmarked(const GURL& url) OVERRIDE { return false; } |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { | 192 class TestFaviconDriver : public FaviconDriver { |
| 193 public: | 193 public: |
| 194 TestFaviconHandlerDelegate() { | 194 TestFaviconDriver() { |
| 195 } | 195 } |
| 196 | 196 |
| 197 virtual ~TestFaviconHandlerDelegate() { | 197 virtual ~TestFaviconDriver() { |
| 198 } | 198 } |
| 199 | 199 |
| 200 virtual bool IsOffTheRecord() OVERRIDE { return false; } | 200 virtual bool IsOffTheRecord() OVERRIDE { return false; } |
| 201 | 201 |
| 202 virtual NavigationEntry* GetActiveEntry() OVERRIDE { | 202 virtual NavigationEntry* GetActiveEntry() OVERRIDE { |
| 203 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " | 203 ADD_FAILURE() << "TestFaviconDriver::GetActiveEntry() " |
| 204 << "should never be called in tests."; | 204 << "should never be called in tests."; |
| 205 return NULL; | 205 return NULL; |
| 206 } | 206 } |
| 207 | 207 |
| 208 virtual int StartDownload(const GURL& url, | 208 virtual int StartDownload(const GURL& url, |
| 209 int max_bitmap_size) OVERRIDE { | 209 int max_bitmap_size) OVERRIDE { |
| 210 ADD_FAILURE() << "TestFaviconHandlerDelegate::StartDownload() " | 210 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " |
| 211 << "should never be called in tests."; | 211 << "should never be called in tests."; |
| 212 return -1; | 212 return -1; |
| 213 } | 213 } |
| 214 | 214 |
| 215 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { | 215 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { |
| 216 ADD_FAILURE() << "TestFaviconHandlerDelegate::NotifyFaviconUpdated() " | 216 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " |
| 217 << "should never be called in tests."; | 217 << "should never be called in tests."; |
| 218 } | 218 } |
| 219 | 219 |
| 220 private: | 220 private: |
| 221 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandlerDelegate); | 221 DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 // This class is used to catch the FaviconHandler's download and history | 224 // This class is used to catch the FaviconHandler's download and history |
| 225 // request, and also provide the methods to access the FaviconHandler | 225 // request, and also provide the methods to access the FaviconHandler |
| 226 // internals. | 226 // internals. |
| 227 class TestFaviconHandler : public FaviconHandler { | 227 class TestFaviconHandler : public FaviconHandler { |
| 228 public: | 228 public: |
| 229 TestFaviconHandler(const GURL& page_url, | 229 TestFaviconHandler(const GURL& page_url, |
| 230 FaviconClient* client, | 230 FaviconClient* client, |
| 231 FaviconHandlerDelegate* delegate, | 231 FaviconDriver* driver, |
| 232 Type type, | 232 Type type, |
| 233 bool download_largest_icon) | 233 bool download_largest_icon) |
| 234 : FaviconHandler(client, delegate, type, | 234 : FaviconHandler(client, driver, type, |
| 235 download_largest_icon), | 235 download_largest_icon), |
| 236 entry_(NavigationEntry::Create()), | 236 entry_(NavigationEntry::Create()), |
| 237 download_id_(0), | 237 download_id_(0), |
| 238 num_favicon_updates_(0) { | 238 num_favicon_updates_(0) { |
| 239 entry_->SetURL(page_url); | 239 entry_->SetURL(page_url); |
| 240 download_handler_.reset(new DownloadHandler(this)); | 240 download_handler_.reset(new DownloadHandler(this)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 virtual ~TestFaviconHandler() { | 243 virtual ~TestFaviconHandler() { |
| 244 } | 244 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 466 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 467 ScopedSetSupportedScaleFactors; | 467 ScopedSetSupportedScaleFactors; |
| 468 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 468 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
| 469 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 469 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
| 470 }; | 470 }; |
| 471 | 471 |
| 472 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 472 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 473 const GURL page_url("http://www.google.com"); | 473 const GURL page_url("http://www.google.com"); |
| 474 const GURL icon_url("http://www.google.com/favicon"); | 474 const GURL icon_url("http://www.google.com/favicon"); |
| 475 | 475 |
| 476 TestFaviconHandlerDelegate delegate; | 476 TestFaviconDriver driver; |
| 477 TestFaviconClient client; | 477 TestFaviconClient client; |
| 478 TestFaviconHandler helper( | 478 TestFaviconHandler helper( |
| 479 page_url, &client, &delegate, FaviconHandler::FAVICON, false); | 479 page_url, &client, &driver, FaviconHandler::FAVICON, false); |
| 480 | 480 |
| 481 helper.FetchFavicon(page_url); | 481 helper.FetchFavicon(page_url); |
| 482 HistoryRequestHandler* history_handler = helper.history_handler(); | 482 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 483 // Ensure the data given to history is correct. | 483 // Ensure the data given to history is correct. |
| 484 ASSERT_TRUE(history_handler); | 484 ASSERT_TRUE(history_handler); |
| 485 EXPECT_EQ(page_url, history_handler->page_url_); | 485 EXPECT_EQ(page_url, history_handler->page_url_); |
| 486 EXPECT_EQ(GURL(), history_handler->icon_url_); | 486 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 487 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 487 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 488 | 488 |
| 489 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 489 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 507 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); | 507 ASSERT_EQ(FaviconURL::FAVICON, helper.current_candidate()->icon_type); |
| 508 | 508 |
| 509 // Favicon shouldn't request to download icon. | 509 // Favicon shouldn't request to download icon. |
| 510 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 510 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 513 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
| 514 const GURL page_url("http://www.google.com"); | 514 const GURL page_url("http://www.google.com"); |
| 515 const GURL icon_url("http://www.google.com/favicon"); | 515 const GURL icon_url("http://www.google.com/favicon"); |
| 516 | 516 |
| 517 TestFaviconHandlerDelegate delegate; | 517 TestFaviconDriver driver; |
| 518 TestFaviconClient client; | 518 TestFaviconClient client; |
| 519 TestFaviconHandler helper( | 519 TestFaviconHandler helper( |
| 520 page_url, &client, &delegate, FaviconHandler::FAVICON, false); | 520 page_url, &client, &driver, FaviconHandler::FAVICON, false); |
| 521 | 521 |
| 522 helper.FetchFavicon(page_url); | 522 helper.FetchFavicon(page_url); |
| 523 HistoryRequestHandler* history_handler = helper.history_handler(); | 523 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 524 // Ensure the data given to history is correct. | 524 // Ensure the data given to history is correct. |
| 525 ASSERT_TRUE(history_handler); | 525 ASSERT_TRUE(history_handler); |
| 526 EXPECT_EQ(page_url, history_handler->page_url_); | 526 EXPECT_EQ(page_url, history_handler->page_url_); |
| 527 EXPECT_EQ(GURL(), history_handler->icon_url_); | 527 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 528 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 528 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 529 | 529 |
| 530 // Set icon data expired | 530 // Set icon data expired |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 EXPECT_TRUE(favicon_status.valid); | 577 EXPECT_TRUE(favicon_status.valid); |
| 578 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 578 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
| 579 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 579 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
| 580 } | 580 } |
| 581 | 581 |
| 582 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 582 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 583 const GURL page_url("http://www.google.com"); | 583 const GURL page_url("http://www.google.com"); |
| 584 const GURL icon_url("http://www.google.com/favicon"); | 584 const GURL icon_url("http://www.google.com/favicon"); |
| 585 const GURL new_icon_url("http://www.google.com/new_favicon"); | 585 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 586 | 586 |
| 587 TestFaviconHandlerDelegate delegate; | 587 TestFaviconDriver driver; |
| 588 TestFaviconClient client; | 588 TestFaviconClient client; |
| 589 TestFaviconHandler helper( | 589 TestFaviconHandler helper( |
| 590 page_url, &client, &delegate, FaviconHandler::FAVICON, false); | 590 page_url, &client, &driver, FaviconHandler::FAVICON, false); |
| 591 | 591 |
| 592 helper.FetchFavicon(page_url); | 592 helper.FetchFavicon(page_url); |
| 593 HistoryRequestHandler* history_handler = helper.history_handler(); | 593 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 594 // Ensure the data given to history is correct. | 594 // Ensure the data given to history is correct. |
| 595 ASSERT_TRUE(history_handler); | 595 ASSERT_TRUE(history_handler); |
| 596 EXPECT_EQ(page_url, history_handler->page_url_); | 596 EXPECT_EQ(page_url, history_handler->page_url_); |
| 597 EXPECT_EQ(GURL(), history_handler->icon_url_); | 597 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 598 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 598 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 599 | 599 |
| 600 // Set valid icon data. | 600 // Set valid icon data. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 EXPECT_EQ(new_icon_url, favicon_status.url); | 659 EXPECT_EQ(new_icon_url, favicon_status.url); |
| 660 EXPECT_TRUE(favicon_status.valid); | 660 EXPECT_TRUE(favicon_status.valid); |
| 661 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 661 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
| 662 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 662 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
| 663 } | 663 } |
| 664 | 664 |
| 665 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 665 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
| 666 const GURL page_url("http://www.google.com"); | 666 const GURL page_url("http://www.google.com"); |
| 667 const GURL icon_url("http://www.google.com/favicon"); | 667 const GURL icon_url("http://www.google.com/favicon"); |
| 668 | 668 |
| 669 TestFaviconHandlerDelegate delegate; | 669 TestFaviconDriver driver; |
| 670 TestFaviconClient client; | 670 TestFaviconClient client; |
| 671 TestFaviconHandler helper( | 671 TestFaviconHandler helper( |
| 672 page_url, &client, &delegate, FaviconHandler::FAVICON, false); | 672 page_url, &client, &driver, FaviconHandler::FAVICON, false); |
| 673 | 673 |
| 674 helper.FetchFavicon(page_url); | 674 helper.FetchFavicon(page_url); |
| 675 HistoryRequestHandler* history_handler = helper.history_handler(); | 675 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 676 // Ensure the data given to history is correct. | 676 // Ensure the data given to history is correct. |
| 677 ASSERT_TRUE(history_handler); | 677 ASSERT_TRUE(history_handler); |
| 678 EXPECT_EQ(page_url, history_handler->page_url_); | 678 EXPECT_EQ(page_url, history_handler->page_url_); |
| 679 EXPECT_EQ(GURL(), history_handler->icon_url_); | 679 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 680 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 680 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 681 | 681 |
| 682 // Set non empty but invalid data. | 682 // Set non empty but invalid data. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 EXPECT_TRUE(favicon_status.valid); | 732 EXPECT_TRUE(favicon_status.valid); |
| 733 EXPECT_FALSE(favicon_status.image.IsEmpty()); | 733 EXPECT_FALSE(favicon_status.image.IsEmpty()); |
| 734 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); | 734 EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width()); |
| 735 } | 735 } |
| 736 | 736 |
| 737 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 737 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 738 const GURL page_url("http://www.google.com"); | 738 const GURL page_url("http://www.google.com"); |
| 739 const GURL icon_url("http://www.google.com/favicon"); | 739 const GURL icon_url("http://www.google.com/favicon"); |
| 740 const GURL new_icon_url("http://www.google.com/new_favicon"); | 740 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 741 | 741 |
| 742 TestFaviconHandlerDelegate delegate; | 742 TestFaviconDriver driver; |
| 743 TestFaviconClient client; | 743 TestFaviconClient client; |
| 744 TestFaviconHandler helper( | 744 TestFaviconHandler helper( |
| 745 page_url, &client, &delegate, FaviconHandler::FAVICON, false); | 745 page_url, &client, &driver, FaviconHandler::FAVICON, false); |
| 746 | 746 |
| 747 helper.FetchFavicon(page_url); | 747 helper.FetchFavicon(page_url); |
| 748 HistoryRequestHandler* history_handler = helper.history_handler(); | 748 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 749 // Ensure the data given to history is correct. | 749 // Ensure the data given to history is correct. |
| 750 ASSERT_TRUE(history_handler); | 750 ASSERT_TRUE(history_handler); |
| 751 EXPECT_EQ(page_url, history_handler->page_url_); | 751 EXPECT_EQ(page_url, history_handler->page_url_); |
| 752 EXPECT_EQ(GURL(), history_handler->icon_url_); | 752 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 753 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 753 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 754 | 754 |
| 755 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); | 755 SetFaviconBitmapResult(icon_url, &history_handler->history_results_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); | 794 EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); |
| 795 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); | 795 EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); |
| 796 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); | 796 EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); |
| 797 } | 797 } |
| 798 | 798 |
| 799 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 799 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 800 const GURL page_url("http://www.google.com"); | 800 const GURL page_url("http://www.google.com"); |
| 801 const GURL icon_url("http://www.google.com/favicon"); | 801 const GURL icon_url("http://www.google.com/favicon"); |
| 802 const GURL new_icon_url("http://www.google.com/new_favicon"); | 802 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 803 | 803 |
| 804 TestFaviconHandlerDelegate delegate; | 804 TestFaviconDriver driver; |
| 805 TestFaviconClient client; | 805 TestFaviconClient client; |
| 806 TestFaviconHandler helper( | 806 TestFaviconHandler helper( |
| 807 page_url, &client, &delegate, FaviconHandler::TOUCH, false); | 807 page_url, &client, &driver, FaviconHandler::TOUCH, false); |
| 808 | 808 |
| 809 helper.FetchFavicon(page_url); | 809 helper.FetchFavicon(page_url); |
| 810 HistoryRequestHandler* history_handler = helper.history_handler(); | 810 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 811 // Ensure the data given to history is correct. | 811 // Ensure the data given to history is correct. |
| 812 ASSERT_TRUE(history_handler); | 812 ASSERT_TRUE(history_handler); |
| 813 EXPECT_EQ(page_url, history_handler->page_url_); | 813 EXPECT_EQ(page_url, history_handler->page_url_); |
| 814 EXPECT_EQ(GURL(), history_handler->icon_url_); | 814 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 815 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 815 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 816 history_handler->icon_type_); | 816 history_handler->icon_type_); |
| 817 | 817 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); | 908 EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_); |
| 909 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 909 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 910 EXPECT_EQ(page_url, history_handler->page_url_); | 910 EXPECT_EQ(page_url, history_handler->page_url_); |
| 911 } | 911 } |
| 912 | 912 |
| 913 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 913 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 914 const GURL page_url("http://www.google.com"); | 914 const GURL page_url("http://www.google.com"); |
| 915 const GURL icon_url("http://www.google.com/favicon"); | 915 const GURL icon_url("http://www.google.com/favicon"); |
| 916 const GURL new_icon_url("http://www.google.com/new_favicon"); | 916 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 917 | 917 |
| 918 TestFaviconHandlerDelegate delegate; | 918 TestFaviconDriver driver; |
| 919 TestFaviconClient client; | 919 TestFaviconClient client; |
| 920 TestFaviconHandler helper( | 920 TestFaviconHandler helper( |
| 921 page_url, &client, &delegate, FaviconHandler::TOUCH, false); | 921 page_url, &client, &driver, FaviconHandler::TOUCH, false); |
| 922 | 922 |
| 923 helper.FetchFavicon(page_url); | 923 helper.FetchFavicon(page_url); |
| 924 HistoryRequestHandler* history_handler = helper.history_handler(); | 924 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 925 // Ensure the data given to history is correct. | 925 // Ensure the data given to history is correct. |
| 926 ASSERT_TRUE(history_handler); | 926 ASSERT_TRUE(history_handler); |
| 927 EXPECT_EQ(page_url, history_handler->page_url_); | 927 EXPECT_EQ(page_url, history_handler->page_url_); |
| 928 EXPECT_EQ(GURL(), history_handler->icon_url_); | 928 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 929 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 929 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 930 history_handler->icon_type_); | 930 history_handler->icon_type_); |
| 931 | 931 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 | 1050 |
| 1051 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1051 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
| 1052 // SelectFaviconFrames(). | 1052 // SelectFaviconFrames(). |
| 1053 std::vector<ui::ScaleFactor> scale_factors; | 1053 std::vector<ui::ScaleFactor> scale_factors; |
| 1054 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1054 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1055 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1055 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1056 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1056 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
| 1057 | 1057 |
| 1058 // 1) Test that if there are several single resolution favicons to choose from | 1058 // 1) Test that if there are several single resolution favicons to choose from |
| 1059 // that the largest exact match is chosen. | 1059 // that the largest exact match is chosen. |
| 1060 TestFaviconHandlerDelegate delegate1; | 1060 TestFaviconDriver driver1; |
| 1061 TestFaviconClient client; | 1061 TestFaviconClient client; |
| 1062 TestFaviconHandler handler1( | 1062 TestFaviconHandler handler1( |
| 1063 kPageURL, &client, &delegate1, FaviconHandler::FAVICON, false); | 1063 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); |
| 1064 | 1064 |
| 1065 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1065 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
| 1066 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1066 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1067 kSourceIconURLs + arraysize(kSizes1)); | 1067 kSourceIconURLs + arraysize(kSizes1)); |
| 1068 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); | 1068 DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); |
| 1069 | 1069 |
| 1070 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); | 1070 content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon()); |
| 1071 EXPECT_EQ(0u, handler1.image_urls().size()); | 1071 EXPECT_EQ(0u, handler1.image_urls().size()); |
| 1072 EXPECT_TRUE(favicon_status1.valid); | 1072 EXPECT_TRUE(favicon_status1.valid); |
| 1073 EXPECT_FALSE(favicon_status1.image.IsEmpty()); | 1073 EXPECT_FALSE(favicon_status1.image.IsEmpty()); |
| 1074 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); | 1074 EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); |
| 1075 | 1075 |
| 1076 size_t expected_index = 2u; | 1076 size_t expected_index = 2u; |
| 1077 EXPECT_EQ(32, kSizes1[expected_index]); | 1077 EXPECT_EQ(32, kSizes1[expected_index]); |
| 1078 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1078 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
| 1079 handler1.GetEntry()->GetFavicon().url); | 1079 handler1.GetEntry()->GetFavicon().url); |
| 1080 | 1080 |
| 1081 // 2) Test that if there are several single resolution favicons to choose | 1081 // 2) Test that if there are several single resolution favicons to choose |
| 1082 // from, the exact match is preferred even if it results in upsampling. | 1082 // from, the exact match is preferred even if it results in upsampling. |
| 1083 TestFaviconHandlerDelegate delegate2; | 1083 TestFaviconDriver driver2; |
| 1084 TestFaviconHandler handler2( | 1084 TestFaviconHandler handler2( |
| 1085 kPageURL, &client, &delegate2, FaviconHandler::FAVICON, false); | 1085 kPageURL, &client, &driver2, FaviconHandler::FAVICON, false); |
| 1086 | 1086 |
| 1087 const int kSizes2[] = { 16, 24, 48, 256 }; | 1087 const int kSizes2[] = { 16, 24, 48, 256 }; |
| 1088 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1088 std::vector<FaviconURL> urls2(kSourceIconURLs, |
| 1089 kSourceIconURLs + arraysize(kSizes2)); | 1089 kSourceIconURLs + arraysize(kSizes2)); |
| 1090 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); | 1090 DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); |
| 1091 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); | 1091 EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); |
| 1092 expected_index = 0u; | 1092 expected_index = 0u; |
| 1093 EXPECT_EQ(16, kSizes2[expected_index]); | 1093 EXPECT_EQ(16, kSizes2[expected_index]); |
| 1094 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1094 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
| 1095 handler2.GetEntry()->GetFavicon().url); | 1095 handler2.GetEntry()->GetFavicon().url); |
| 1096 | 1096 |
| 1097 // 3) Test that favicons which need to be upsampled a little or downsampled | 1097 // 3) Test that favicons which need to be upsampled a little or downsampled |
| 1098 // a little are preferred over huge favicons. | 1098 // a little are preferred over huge favicons. |
| 1099 TestFaviconHandlerDelegate delegate3; | 1099 TestFaviconDriver driver3; |
| 1100 TestFaviconHandler handler3( | 1100 TestFaviconHandler handler3( |
| 1101 kPageURL, &client, &delegate3, FaviconHandler::FAVICON, false); | 1101 kPageURL, &client, &driver3, FaviconHandler::FAVICON, false); |
| 1102 | 1102 |
| 1103 const int kSizes3[] = { 256, 48 }; | 1103 const int kSizes3[] = { 256, 48 }; |
| 1104 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1104 std::vector<FaviconURL> urls3(kSourceIconURLs, |
| 1105 kSourceIconURLs + arraysize(kSizes3)); | 1105 kSourceIconURLs + arraysize(kSizes3)); |
| 1106 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); | 1106 DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); |
| 1107 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); | 1107 EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); |
| 1108 expected_index = 1u; | 1108 expected_index = 1u; |
| 1109 EXPECT_EQ(48, kSizes3[expected_index]); | 1109 EXPECT_EQ(48, kSizes3[expected_index]); |
| 1110 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1110 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
| 1111 handler3.GetEntry()->GetFavicon().url); | 1111 handler3.GetEntry()->GetFavicon().url); |
| 1112 | 1112 |
| 1113 TestFaviconHandlerDelegate delegate4; | 1113 TestFaviconDriver driver4; |
| 1114 TestFaviconHandler handler4( | 1114 TestFaviconHandler handler4( |
| 1115 kPageURL, &client, &delegate4, FaviconHandler::FAVICON, false); | 1115 kPageURL, &client, &driver4, FaviconHandler::FAVICON, false); |
| 1116 | 1116 |
| 1117 const int kSizes4[] = { 17, 256 }; | 1117 const int kSizes4[] = { 17, 256 }; |
| 1118 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1118 std::vector<FaviconURL> urls4(kSourceIconURLs, |
| 1119 kSourceIconURLs + arraysize(kSizes4)); | 1119 kSourceIconURLs + arraysize(kSizes4)); |
| 1120 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); | 1120 DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); |
| 1121 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); | 1121 EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); |
| 1122 expected_index = 0u; | 1122 expected_index = 0u; |
| 1123 EXPECT_EQ(17, kSizes4[expected_index]); | 1123 EXPECT_EQ(17, kSizes4[expected_index]); |
| 1124 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, | 1124 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, |
| 1125 handler4.GetEntry()->GetFavicon().url); | 1125 handler4.GetEntry()->GetFavicon().url); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1152 FaviconURL::FAVICON, | 1152 FaviconURL::FAVICON, |
| 1153 icon3), | 1153 icon3), |
| 1154 FaviconURL(GURL("http://www.google.com/d"), | 1154 FaviconURL(GURL("http://www.google.com/d"), |
| 1155 FaviconURL::FAVICON, | 1155 FaviconURL::FAVICON, |
| 1156 std::vector<gfx::Size>()), | 1156 std::vector<gfx::Size>()), |
| 1157 FaviconURL(GURL("http://www.google.com/e"), | 1157 FaviconURL(GURL("http://www.google.com/e"), |
| 1158 FaviconURL::FAVICON, | 1158 FaviconURL::FAVICON, |
| 1159 std::vector<gfx::Size>())}; | 1159 std::vector<gfx::Size>())}; |
| 1160 | 1160 |
| 1161 TestFaviconClient client; | 1161 TestFaviconClient client; |
| 1162 TestFaviconHandlerDelegate delegate1; | 1162 TestFaviconDriver driver1; |
| 1163 TestFaviconHandler handler1( | 1163 TestFaviconHandler handler1( |
| 1164 kPageURL, &client, &delegate1, FaviconHandler::FAVICON, true); | 1164 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
| 1165 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1165 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1166 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1166 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1167 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1167 UpdateFaviconURL(&handler1, kPageURL, urls1); |
| 1168 | 1168 |
| 1169 struct ExpectedResult { | 1169 struct ExpectedResult { |
| 1170 // The favicon's index in kSourceIconURLs. | 1170 // The favicon's index in kSourceIconURLs. |
| 1171 size_t favicon_index; | 1171 size_t favicon_index; |
| 1172 // Width of largest bitmap. | 1172 // Width of largest bitmap. |
| 1173 int width; | 1173 int width; |
| 1174 } results[] = { | 1174 } results[] = { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 FaviconURL::FAVICON, | 1217 FaviconURL::FAVICON, |
| 1218 two_icons), | 1218 two_icons), |
| 1219 FaviconURL(GURL("http://www.google.com/d"), | 1219 FaviconURL(GURL("http://www.google.com/d"), |
| 1220 FaviconURL::FAVICON, | 1220 FaviconURL::FAVICON, |
| 1221 std::vector<gfx::Size>()), | 1221 std::vector<gfx::Size>()), |
| 1222 FaviconURL(GURL("http://www.google.com/e"), | 1222 FaviconURL(GURL("http://www.google.com/e"), |
| 1223 FaviconURL::FAVICON, | 1223 FaviconURL::FAVICON, |
| 1224 std::vector<gfx::Size>())}; | 1224 std::vector<gfx::Size>())}; |
| 1225 | 1225 |
| 1226 TestFaviconClient client; | 1226 TestFaviconClient client; |
| 1227 TestFaviconHandlerDelegate delegate1; | 1227 TestFaviconDriver driver1; |
| 1228 TestFaviconHandler handler1( | 1228 TestFaviconHandler handler1( |
| 1229 kPageURL, &client, &delegate1, FaviconHandler::FAVICON, true); | 1229 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
| 1230 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1230 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1231 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1231 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1232 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1232 UpdateFaviconURL(&handler1, kPageURL, urls1); |
| 1233 | 1233 |
| 1234 // Simulate the download failed, to check whether the icons were requested | 1234 // Simulate the download failed, to check whether the icons were requested |
| 1235 // to download according their size. | 1235 // to download according their size. |
| 1236 struct ExpectedResult { | 1236 struct ExpectedResult { |
| 1237 // The size of image_urls_. | 1237 // The size of image_urls_. |
| 1238 size_t image_urls_size; | 1238 size_t image_urls_size; |
| 1239 // The favicon's index in kSourceIconURLs. | 1239 // The favicon's index in kSourceIconURLs. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 | 1289 |
| 1290 const FaviconURL kSourceIconURLs[] = { | 1290 const FaviconURL kSourceIconURLs[] = { |
| 1291 FaviconURL(GURL("http://www.google.com/b"), | 1291 FaviconURL(GURL("http://www.google.com/b"), |
| 1292 FaviconURL::FAVICON, | 1292 FaviconURL::FAVICON, |
| 1293 one_icon), | 1293 one_icon), |
| 1294 FaviconURL(GURL("http://www.google.com/c"), | 1294 FaviconURL(GURL("http://www.google.com/c"), |
| 1295 FaviconURL::FAVICON, | 1295 FaviconURL::FAVICON, |
| 1296 two_icons)}; | 1296 two_icons)}; |
| 1297 | 1297 |
| 1298 TestFaviconClient client; | 1298 TestFaviconClient client; |
| 1299 TestFaviconHandlerDelegate delegate1; | 1299 TestFaviconDriver driver1; |
| 1300 TestFaviconHandler handler1( | 1300 TestFaviconHandler handler1( |
| 1301 kPageURL, &client, &delegate1, FaviconHandler::FAVICON, true); | 1301 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
| 1302 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1302 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1303 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1303 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1304 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1304 UpdateFaviconURL(&handler1, kPageURL, urls1); |
| 1305 | 1305 |
| 1306 ASSERT_EQ(2u, handler1.urls().size()); | 1306 ASSERT_EQ(2u, handler1.urls().size()); |
| 1307 | 1307 |
| 1308 // Index of largest favicon in kSourceIconURLs. | 1308 // Index of largest favicon in kSourceIconURLs. |
| 1309 size_t i = 1; | 1309 size_t i = 1; |
| 1310 // The largest bitmap's index in Favicon . | 1310 // The largest bitmap's index in Favicon . |
| 1311 int b = 1; | 1311 int b = 1; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 FaviconURL::FAVICON, | 1357 FaviconURL::FAVICON, |
| 1358 icon1), | 1358 icon1), |
| 1359 FaviconURL(GURL("http://www.google.com/c"), | 1359 FaviconURL(GURL("http://www.google.com/c"), |
| 1360 FaviconURL::FAVICON, | 1360 FaviconURL::FAVICON, |
| 1361 icon2), | 1361 icon2), |
| 1362 FaviconURL(GURL("http://www.google.com/d"), | 1362 FaviconURL(GURL("http://www.google.com/d"), |
| 1363 FaviconURL::FAVICON, | 1363 FaviconURL::FAVICON, |
| 1364 std::vector<gfx::Size>())}; | 1364 std::vector<gfx::Size>())}; |
| 1365 | 1365 |
| 1366 TestFaviconClient client; | 1366 TestFaviconClient client; |
| 1367 TestFaviconHandlerDelegate delegate1; | 1367 TestFaviconDriver driver1; |
| 1368 TestFaviconHandler handler1( | 1368 TestFaviconHandler handler1( |
| 1369 kPageURL, &client, &delegate1, FaviconHandler::FAVICON, true); | 1369 kPageURL, &client, &driver1, FaviconHandler::FAVICON, true); |
| 1370 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1370 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1371 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1371 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1372 UpdateFaviconURL(&handler1, kPageURL, urls1); | 1372 UpdateFaviconURL(&handler1, kPageURL, urls1); |
| 1373 ASSERT_EQ(3u, handler1.urls().size()); | 1373 ASSERT_EQ(3u, handler1.urls().size()); |
| 1374 | 1374 |
| 1375 // Simulate no favicon from history. | 1375 // Simulate no favicon from history. |
| 1376 handler1.history_handler()->history_results_.clear(); | 1376 handler1.history_handler()->history_results_.clear(); |
| 1377 handler1.history_handler()->InvokeCallback(); | 1377 handler1.history_handler()->InvokeCallback(); |
| 1378 | 1378 |
| 1379 // Verify the first icon was request to download | 1379 // Verify the first icon was request to download |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1491 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
| 1492 EXPECT_NE(0, download_id); | 1492 EXPECT_NE(0, download_id); |
| 1493 // Report download success with HTTP 200 status. | 1493 // Report download success with HTTP 200 status. |
| 1494 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1494 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
| 1495 empty_icons, empty_icon_sizes); | 1495 empty_icons, empty_icon_sizes); |
| 1496 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1496 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
| 1497 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1497 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
| 1498 } | 1498 } |
| 1499 | 1499 |
| 1500 } // namespace. | 1500 } // namespace. |
| OLD | NEW |