| 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "components/favicon/core/favicon_driver.h" | 14 #include "components/favicon/core/favicon_driver.h" |
| 15 #include "components/favicon/core/test/mock_favicon_service.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/layout.h" | 19 #include "ui/base/layout.h" |
| 18 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
| 19 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
| 20 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 21 | 23 |
| 22 namespace favicon { | 24 namespace favicon { |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 263 |
| 262 // This class is used to catch the FaviconHandler's download and history | 264 // This class is used to catch the FaviconHandler's download and history |
| 263 // request, and also provide the methods to access the FaviconHandler | 265 // request, and also provide the methods to access the FaviconHandler |
| 264 // internals. | 266 // internals. |
| 265 class TestFaviconHandler : public FaviconHandler { | 267 class TestFaviconHandler : public FaviconHandler { |
| 266 public: | 268 public: |
| 267 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 269 static int GetMaximalIconSize(favicon_base::IconType icon_type) { |
| 268 return FaviconHandler::GetMaximalIconSize(icon_type); | 270 return FaviconHandler::GetMaximalIconSize(icon_type); |
| 269 } | 271 } |
| 270 | 272 |
| 271 TestFaviconHandler(TestFaviconDriver* driver, | 273 TestFaviconHandler(FaviconService* service, |
| 274 TestFaviconDriver* driver, |
| 272 FaviconDriverObserver::NotificationIconType handler_type) | 275 FaviconDriverObserver::NotificationIconType handler_type) |
| 273 : FaviconHandler(nullptr, driver, handler_type), | 276 : FaviconHandler(service, driver, handler_type), download_id_(0) { |
| 274 download_id_(0) { | |
| 275 download_handler_.reset(new DownloadHandler(this)); | 277 download_handler_.reset(new DownloadHandler(this)); |
| 276 } | 278 } |
| 277 | 279 |
| 278 ~TestFaviconHandler() override {} | 280 ~TestFaviconHandler() override {} |
| 279 | 281 |
| 280 HistoryRequestHandler* history_handler() { | 282 HistoryRequestHandler* history_handler() { |
| 281 return history_handler_.get(); | 283 return history_handler_.get(); |
| 282 } | 284 } |
| 283 | 285 |
| 284 // This method will take the ownership of the given handler. | 286 // This method will take the ownership of the given handler. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 bytes->front() + bytes->size()); | 359 bytes->front() + bytes->size()); |
| 358 history_handler_.reset(new HistoryRequestHandler( | 360 history_handler_.reset(new HistoryRequestHandler( |
| 359 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 361 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
| 360 } | 362 } |
| 361 | 363 |
| 362 bool ShouldSaveFavicon() override { return true; } | 364 bool ShouldSaveFavicon() override { return true; } |
| 363 | 365 |
| 364 GURL page_url_; | 366 GURL page_url_; |
| 365 | 367 |
| 366 private: | 368 private: |
| 367 | |
| 368 // The unique id of a download request. It will be returned to a | 369 // The unique id of a download request. It will be returned to a |
| 369 // FaviconHandler. | 370 // FaviconHandler. |
| 370 int download_id_; | 371 int download_id_; |
| 371 | 372 |
| 372 std::unique_ptr<DownloadHandler> download_handler_; | 373 std::unique_ptr<DownloadHandler> download_handler_; |
| 373 std::unique_ptr<HistoryRequestHandler> history_handler_; | 374 std::unique_ptr<HistoryRequestHandler> history_handler_; |
| 374 | 375 |
| 375 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 376 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 376 }; | 377 }; |
| 377 | 378 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 406 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); | 407 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); |
| 407 } | 408 } |
| 408 } | 409 } |
| 409 favicon_handler_->OnDidDownloadFavicon(download_->download_id, | 410 favicon_handler_->OnDidDownloadFavicon(download_->download_id, |
| 410 download_->image_url, bitmaps, | 411 download_->image_url, bitmaps, |
| 411 original_bitmap_sizes); | 412 original_bitmap_sizes); |
| 412 callback_invoked_ = true; | 413 callback_invoked_ = true; |
| 413 } | 414 } |
| 414 | 415 |
| 415 class FaviconHandlerTest : public testing::Test { | 416 class FaviconHandlerTest : public testing::Test { |
| 416 public: | 417 protected: |
| 417 FaviconHandlerTest() { | 418 FaviconHandlerTest() { |
| 418 } | 419 } |
| 419 | 420 |
| 420 ~FaviconHandlerTest() override {} | 421 ~FaviconHandlerTest() override {} |
| 421 | 422 |
| 422 // Simulates requesting a favicon for |page_url| given: | 423 // Simulates requesting a favicon for |page_url| given: |
| 423 // - We have not previously cached anything in history for |page_url| or for | 424 // - We have not previously cached anything in history for |page_url| or for |
| 424 // any of |candidates|. | 425 // any of |candidates|. |
| 425 // - The page provides favicons at |candidate_icons|. | 426 // - The page provides favicons at |candidate_icons|. |
| 426 // - The favicons at |candidate_icons| have edge pixel sizes of | 427 // - The favicons at |candidate_icons| have edge pixel sizes of |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 475 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
| 475 // Force the values of the scale factors so that the tests produce the same | 476 // Force the values of the scale factors so that the tests produce the same |
| 476 // results on all platforms. | 477 // results on all platforms. |
| 477 std::vector<ui::ScaleFactor> scale_factors; | 478 std::vector<ui::ScaleFactor> scale_factors; |
| 478 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 479 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 479 scoped_set_supported_scale_factors_.reset( | 480 scoped_set_supported_scale_factors_.reset( |
| 480 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 481 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
| 481 testing::Test::SetUp(); | 482 testing::Test::SetUp(); |
| 482 } | 483 } |
| 483 | 484 |
| 484 private: | |
| 485 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 485 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 486 scoped_set_supported_scale_factors_; | 486 scoped_set_supported_scale_factors_; |
| 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 487 testing::StrictMock<MockFaviconService> favicon_service_; |
| 488 }; | 488 }; |
| 489 | 489 |
| 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 491 const GURL page_url("http://www.google.com"); | 491 const GURL page_url("http://www.google.com"); |
| 492 const GURL icon_url("http://www.google.com/favicon"); | 492 const GURL icon_url("http://www.google.com/favicon"); |
| 493 | 493 |
| 494 TestFaviconDriver driver; | 494 TestFaviconDriver driver; |
| 495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 495 TestFaviconHandler helper(&favicon_service_, &driver, |
| 496 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 496 | 497 |
| 497 helper.FetchFavicon(page_url); | 498 helper.FetchFavicon(page_url); |
| 498 HistoryRequestHandler* history_handler = helper.history_handler(); | 499 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 499 // Ensure the data given to history is correct. | 500 // Ensure the data given to history is correct. |
| 500 ASSERT_TRUE(history_handler); | 501 ASSERT_TRUE(history_handler); |
| 501 EXPECT_EQ(page_url, history_handler->page_url_); | 502 EXPECT_EQ(page_url, history_handler->page_url_); |
| 502 EXPECT_EQ(GURL(), history_handler->icon_url_); | 503 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 503 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 504 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 504 | 505 |
| 505 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 506 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 524 | 525 |
| 525 // Favicon shouldn't request to download icon. | 526 // Favicon shouldn't request to download icon. |
| 526 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 527 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 527 } | 528 } |
| 528 | 529 |
| 529 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 530 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
| 530 const GURL page_url("http://www.google.com"); | 531 const GURL page_url("http://www.google.com"); |
| 531 const GURL icon_url("http://www.google.com/favicon"); | 532 const GURL icon_url("http://www.google.com/favicon"); |
| 532 | 533 |
| 533 TestFaviconDriver driver; | 534 TestFaviconDriver driver; |
| 534 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 535 TestFaviconHandler helper(&favicon_service_, &driver, |
| 536 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 535 | 537 |
| 536 helper.FetchFavicon(page_url); | 538 helper.FetchFavicon(page_url); |
| 537 HistoryRequestHandler* history_handler = helper.history_handler(); | 539 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 538 // Ensure the data given to history is correct. | 540 // Ensure the data given to history is correct. |
| 539 ASSERT_TRUE(history_handler); | 541 ASSERT_TRUE(history_handler); |
| 540 EXPECT_EQ(page_url, history_handler->page_url_); | 542 EXPECT_EQ(page_url, history_handler->page_url_); |
| 541 EXPECT_EQ(GURL(), history_handler->icon_url_); | 543 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 542 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 544 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 543 | 545 |
| 544 // Set icon data expired | 546 // Set icon data expired |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 EXPECT_FALSE(driver.image().IsEmpty()); | 593 EXPECT_FALSE(driver.image().IsEmpty()); |
| 592 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 594 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 593 } | 595 } |
| 594 | 596 |
| 595 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 597 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 596 const GURL page_url("http://www.google.com"); | 598 const GURL page_url("http://www.google.com"); |
| 597 const GURL icon_url("http://www.google.com/favicon"); | 599 const GURL icon_url("http://www.google.com/favicon"); |
| 598 const GURL new_icon_url("http://www.google.com/new_favicon"); | 600 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 599 | 601 |
| 600 TestFaviconDriver driver; | 602 TestFaviconDriver driver; |
| 601 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 603 TestFaviconHandler helper(&favicon_service_, &driver, |
| 604 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 602 | 605 |
| 603 helper.FetchFavicon(page_url); | 606 helper.FetchFavicon(page_url); |
| 604 HistoryRequestHandler* history_handler = helper.history_handler(); | 607 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 605 // Ensure the data given to history is correct. | 608 // Ensure the data given to history is correct. |
| 606 ASSERT_TRUE(history_handler); | 609 ASSERT_TRUE(history_handler); |
| 607 EXPECT_EQ(page_url, history_handler->page_url_); | 610 EXPECT_EQ(page_url, history_handler->page_url_); |
| 608 EXPECT_EQ(GURL(), history_handler->icon_url_); | 611 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 609 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 612 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 610 | 613 |
| 611 // Set valid icon data. | 614 // Set valid icon data. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 EXPECT_EQ(new_icon_url, driver.icon_url()); | 673 EXPECT_EQ(new_icon_url, driver.icon_url()); |
| 671 EXPECT_FALSE(driver.image().IsEmpty()); | 674 EXPECT_FALSE(driver.image().IsEmpty()); |
| 672 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 675 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 673 } | 676 } |
| 674 | 677 |
| 675 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 678 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
| 676 const GURL page_url("http://www.google.com"); | 679 const GURL page_url("http://www.google.com"); |
| 677 const GURL icon_url("http://www.google.com/favicon"); | 680 const GURL icon_url("http://www.google.com/favicon"); |
| 678 | 681 |
| 679 TestFaviconDriver driver; | 682 TestFaviconDriver driver; |
| 680 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 683 TestFaviconHandler helper(&favicon_service_, &driver, |
| 684 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 681 | 685 |
| 682 helper.FetchFavicon(page_url); | 686 helper.FetchFavicon(page_url); |
| 683 HistoryRequestHandler* history_handler = helper.history_handler(); | 687 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 684 // Ensure the data given to history is correct. | 688 // Ensure the data given to history is correct. |
| 685 ASSERT_TRUE(history_handler); | 689 ASSERT_TRUE(history_handler); |
| 686 EXPECT_EQ(page_url, history_handler->page_url_); | 690 EXPECT_EQ(page_url, history_handler->page_url_); |
| 687 EXPECT_EQ(GURL(), history_handler->icon_url_); | 691 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 688 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 692 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 689 | 693 |
| 690 // Set non empty but invalid data. | 694 // Set non empty but invalid data. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 EXPECT_FALSE(driver.image().IsEmpty()); | 744 EXPECT_FALSE(driver.image().IsEmpty()); |
| 741 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 745 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 742 } | 746 } |
| 743 | 747 |
| 744 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 748 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 745 const GURL page_url("http://www.google.com"); | 749 const GURL page_url("http://www.google.com"); |
| 746 const GURL icon_url("http://www.google.com/favicon"); | 750 const GURL icon_url("http://www.google.com/favicon"); |
| 747 const GURL new_icon_url("http://www.google.com/new_favicon"); | 751 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 748 | 752 |
| 749 TestFaviconDriver driver; | 753 TestFaviconDriver driver; |
| 750 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 754 TestFaviconHandler helper(&favicon_service_, &driver, |
| 755 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 751 | 756 |
| 752 helper.FetchFavicon(page_url); | 757 helper.FetchFavicon(page_url); |
| 753 HistoryRequestHandler* history_handler = helper.history_handler(); | 758 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 754 // Ensure the data given to history is correct. | 759 // Ensure the data given to history is correct. |
| 755 ASSERT_TRUE(history_handler); | 760 ASSERT_TRUE(history_handler); |
| 756 EXPECT_EQ(page_url, history_handler->page_url_); | 761 EXPECT_EQ(page_url, history_handler->page_url_); |
| 757 EXPECT_EQ(GURL(), history_handler->icon_url_); | 762 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 758 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 763 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 759 | 764 |
| 760 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 765 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 EXPECT_EQ(new_icon_url, driver.icon_url()); | 805 EXPECT_EQ(new_icon_url, driver.icon_url()); |
| 801 EXPECT_FALSE(driver.image().IsEmpty()); | 806 EXPECT_FALSE(driver.image().IsEmpty()); |
| 802 } | 807 } |
| 803 | 808 |
| 804 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 809 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 805 const GURL page_url("http://www.google.com"); | 810 const GURL page_url("http://www.google.com"); |
| 806 const GURL icon_url("http://www.google.com/favicon"); | 811 const GURL icon_url("http://www.google.com/favicon"); |
| 807 const GURL new_icon_url("http://www.google.com/new_favicon"); | 812 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 808 | 813 |
| 809 TestFaviconDriver driver; | 814 TestFaviconDriver driver; |
| 810 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 815 TestFaviconHandler helper(&favicon_service_, &driver, |
| 816 FaviconDriverObserver::TOUCH_LARGEST); |
| 811 std::set<GURL> fail_downloads; | 817 std::set<GURL> fail_downloads; |
| 812 fail_downloads.insert(icon_url); | 818 fail_downloads.insert(icon_url); |
| 813 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); | 819 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); |
| 814 | 820 |
| 815 helper.FetchFavicon(page_url); | 821 helper.FetchFavicon(page_url); |
| 816 HistoryRequestHandler* history_handler = helper.history_handler(); | 822 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 817 // Ensure the data given to history is correct. | 823 // Ensure the data given to history is correct. |
| 818 ASSERT_TRUE(history_handler); | 824 ASSERT_TRUE(history_handler); |
| 819 EXPECT_EQ(page_url, history_handler->page_url_); | 825 EXPECT_EQ(page_url, history_handler->page_url_); |
| 820 EXPECT_EQ(GURL(), history_handler->icon_url_); | 826 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 921 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 916 EXPECT_EQ(page_url, history_handler->page_url_); | 922 EXPECT_EQ(page_url, history_handler->page_url_); |
| 917 } | 923 } |
| 918 | 924 |
| 919 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 925 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 920 const GURL page_url("http://www.google.com"); | 926 const GURL page_url("http://www.google.com"); |
| 921 const GURL icon_url("http://www.google.com/favicon"); | 927 const GURL icon_url("http://www.google.com/favicon"); |
| 922 const GURL new_icon_url("http://www.google.com/new_favicon"); | 928 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 923 | 929 |
| 924 TestFaviconDriver driver; | 930 TestFaviconDriver driver; |
| 925 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 931 TestFaviconHandler helper(&favicon_service_, &driver, |
| 932 FaviconDriverObserver::TOUCH_LARGEST); |
| 926 | 933 |
| 927 helper.FetchFavicon(page_url); | 934 helper.FetchFavicon(page_url); |
| 928 HistoryRequestHandler* history_handler = helper.history_handler(); | 935 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 929 // Ensure the data given to history is correct. | 936 // Ensure the data given to history is correct. |
| 930 ASSERT_TRUE(history_handler); | 937 ASSERT_TRUE(history_handler); |
| 931 EXPECT_EQ(page_url, history_handler->page_url_); | 938 EXPECT_EQ(page_url, history_handler->page_url_); |
| 932 EXPECT_EQ(GURL(), history_handler->icon_url_); | 939 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 933 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 940 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 934 history_handler->icon_type_); | 941 history_handler->icon_type_); |
| 935 | 942 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 const GURL icon_url2("http://www.google.com/favicon2"); | 1044 const GURL icon_url2("http://www.google.com/favicon2"); |
| 1038 std::vector<FaviconURL> favicon_urls; | 1045 std::vector<FaviconURL> favicon_urls; |
| 1039 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 1046 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
| 1040 favicon_base::FAVICON, | 1047 favicon_base::FAVICON, |
| 1041 std::vector<gfx::Size>())); | 1048 std::vector<gfx::Size>())); |
| 1042 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 1049 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
| 1043 favicon_base::FAVICON, | 1050 favicon_base::FAVICON, |
| 1044 std::vector<gfx::Size>())); | 1051 std::vector<gfx::Size>())); |
| 1045 | 1052 |
| 1046 TestFaviconDriver driver; | 1053 TestFaviconDriver driver; |
| 1047 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1054 TestFaviconHandler helper(&favicon_service_, &driver, |
| 1055 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1048 | 1056 |
| 1049 // Initiate a request for favicon data for |page_url|. History does not know | 1057 // Initiate a request for favicon data for |page_url|. History does not know |
| 1050 // about the page URL or the icon URLs. | 1058 // about the page URL or the icon URLs. |
| 1051 helper.FetchFavicon(page_url); | 1059 helper.FetchFavicon(page_url); |
| 1052 helper.history_handler()->InvokeCallback(); | 1060 helper.history_handler()->InvokeCallback(); |
| 1053 helper.set_history_handler(nullptr); | 1061 helper.set_history_handler(nullptr); |
| 1054 | 1062 |
| 1055 // Got icon URLs. | 1063 // Got icon URLs. |
| 1056 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1064 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
| 1057 | 1065 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1083 } | 1091 } |
| 1084 | 1092 |
| 1085 // Fixes crbug.com/544560 | 1093 // Fixes crbug.com/544560 |
| 1086 TEST_F(FaviconHandlerTest, | 1094 TEST_F(FaviconHandlerTest, |
| 1087 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 1095 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
| 1088 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 1096 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
| 1089 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; | 1097 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; |
| 1090 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; | 1098 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; |
| 1091 | 1099 |
| 1092 TestFaviconDriver driver; | 1100 TestFaviconDriver driver; |
| 1093 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1101 TestFaviconHandler helper(&favicon_service_, &driver, |
| 1102 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1094 | 1103 |
| 1095 // Initial state: | 1104 // Initial state: |
| 1096 // - The database does not know about |kPageURL|. | 1105 // - The database does not know about |kPageURL|. |
| 1097 // - The page uses |kIconURL1| and |kIconURL2|. | 1106 // - The page uses |kIconURL1| and |kIconURL2|. |
| 1098 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 1107 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
| 1099 // are expired in the database. | 1108 // are expired in the database. |
| 1100 helper.FetchFavicon(kPageURL); | 1109 helper.FetchFavicon(kPageURL); |
| 1101 ASSERT_TRUE(helper.history_handler()); | 1110 ASSERT_TRUE(helper.history_handler()); |
| 1102 helper.history_handler()->InvokeCallback(); | 1111 helper.history_handler()->InvokeCallback(); |
| 1103 { | 1112 { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1205 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
| 1197 // SelectFaviconFrames(). | 1206 // SelectFaviconFrames(). |
| 1198 std::vector<ui::ScaleFactor> scale_factors; | 1207 std::vector<ui::ScaleFactor> scale_factors; |
| 1199 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1208 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1200 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1209 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1201 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1210 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
| 1202 | 1211 |
| 1203 // 1) Test that if there are several single resolution favicons to choose from | 1212 // 1) Test that if there are several single resolution favicons to choose from |
| 1204 // that the largest exact match is chosen. | 1213 // that the largest exact match is chosen. |
| 1205 TestFaviconDriver driver1; | 1214 TestFaviconDriver driver1; |
| 1206 TestFaviconHandler handler1(&driver1, | 1215 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1207 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1216 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1208 | 1217 |
| 1209 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1218 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
| 1210 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1219 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1211 kSourceIconURLs + arraysize(kSizes1)); | 1220 kSourceIconURLs + arraysize(kSizes1)); |
| 1212 DownloadTillDoneIgnoringHistory( | 1221 DownloadTillDoneIgnoringHistory( |
| 1213 &driver1, &handler1, kPageURL, urls1, kSizes1); | 1222 &driver1, &handler1, kPageURL, urls1, kSizes1); |
| 1214 | 1223 |
| 1215 EXPECT_EQ(nullptr, handler1.current_candidate()); | 1224 EXPECT_EQ(nullptr, handler1.current_candidate()); |
| 1216 EXPECT_EQ(1u, driver1.num_notifications()); | 1225 EXPECT_EQ(1u, driver1.num_notifications()); |
| 1217 EXPECT_FALSE(driver1.image().IsEmpty()); | 1226 EXPECT_FALSE(driver1.image().IsEmpty()); |
| 1218 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); | 1227 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); |
| 1219 | 1228 |
| 1220 size_t expected_index = 2u; | 1229 size_t expected_index = 2u; |
| 1221 EXPECT_EQ(32, kSizes1[expected_index]); | 1230 EXPECT_EQ(32, kSizes1[expected_index]); |
| 1222 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); | 1231 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); |
| 1223 | 1232 |
| 1224 // 2) Test that if there are several single resolution favicons to choose | 1233 // 2) Test that if there are several single resolution favicons to choose |
| 1225 // from, the exact match is preferred even if it results in upsampling. | 1234 // from, the exact match is preferred even if it results in upsampling. |
| 1226 TestFaviconDriver driver2; | 1235 TestFaviconDriver driver2; |
| 1227 TestFaviconHandler handler2(&driver2, | 1236 TestFaviconHandler handler2(&favicon_service_, &driver2, |
| 1228 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1237 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1229 | 1238 |
| 1230 const int kSizes2[] = { 16, 24, 48, 256 }; | 1239 const int kSizes2[] = { 16, 24, 48, 256 }; |
| 1231 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1240 std::vector<FaviconURL> urls2(kSourceIconURLs, |
| 1232 kSourceIconURLs + arraysize(kSizes2)); | 1241 kSourceIconURLs + arraysize(kSizes2)); |
| 1233 DownloadTillDoneIgnoringHistory( | 1242 DownloadTillDoneIgnoringHistory( |
| 1234 &driver2, &handler2, kPageURL, urls2, kSizes2); | 1243 &driver2, &handler2, kPageURL, urls2, kSizes2); |
| 1235 EXPECT_EQ(1u, driver2.num_notifications()); | 1244 EXPECT_EQ(1u, driver2.num_notifications()); |
| 1236 expected_index = 0u; | 1245 expected_index = 0u; |
| 1237 EXPECT_EQ(16, kSizes2[expected_index]); | 1246 EXPECT_EQ(16, kSizes2[expected_index]); |
| 1238 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); | 1247 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); |
| 1239 | 1248 |
| 1240 // 3) Test that favicons which need to be upsampled a little or downsampled | 1249 // 3) Test that favicons which need to be upsampled a little or downsampled |
| 1241 // a little are preferred over huge favicons. | 1250 // a little are preferred over huge favicons. |
| 1242 TestFaviconDriver driver3; | 1251 TestFaviconDriver driver3; |
| 1243 TestFaviconHandler handler3(&driver3, | 1252 TestFaviconHandler handler3(&favicon_service_, &driver3, |
| 1244 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1253 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1245 | 1254 |
| 1246 const int kSizes3[] = { 256, 48 }; | 1255 const int kSizes3[] = { 256, 48 }; |
| 1247 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1256 std::vector<FaviconURL> urls3(kSourceIconURLs, |
| 1248 kSourceIconURLs + arraysize(kSizes3)); | 1257 kSourceIconURLs + arraysize(kSizes3)); |
| 1249 DownloadTillDoneIgnoringHistory( | 1258 DownloadTillDoneIgnoringHistory( |
| 1250 &driver3, &handler3, kPageURL, urls3, kSizes3); | 1259 &driver3, &handler3, kPageURL, urls3, kSizes3); |
| 1251 EXPECT_EQ(1u, driver3.num_notifications()); | 1260 EXPECT_EQ(1u, driver3.num_notifications()); |
| 1252 expected_index = 1u; | 1261 expected_index = 1u; |
| 1253 EXPECT_EQ(48, kSizes3[expected_index]); | 1262 EXPECT_EQ(48, kSizes3[expected_index]); |
| 1254 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); | 1263 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); |
| 1255 | 1264 |
| 1256 TestFaviconDriver driver4; | 1265 TestFaviconDriver driver4; |
| 1257 TestFaviconHandler handler4(&driver4, | 1266 TestFaviconHandler handler4(&favicon_service_, &driver4, |
| 1258 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1267 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1259 | 1268 |
| 1260 const int kSizes4[] = { 17, 256 }; | 1269 const int kSizes4[] = { 17, 256 }; |
| 1261 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1270 std::vector<FaviconURL> urls4(kSourceIconURLs, |
| 1262 kSourceIconURLs + arraysize(kSizes4)); | 1271 kSourceIconURLs + arraysize(kSizes4)); |
| 1263 DownloadTillDoneIgnoringHistory( | 1272 DownloadTillDoneIgnoringHistory( |
| 1264 &driver4, &handler4, kPageURL, urls4, kSizes4); | 1273 &driver4, &handler4, kPageURL, urls4, kSizes4); |
| 1265 EXPECT_EQ(1u, driver4.num_notifications()); | 1274 EXPECT_EQ(1u, driver4.num_notifications()); |
| 1266 expected_index = 0u; | 1275 expected_index = 0u; |
| 1267 EXPECT_EQ(17, kSizes4[expected_index]); | 1276 EXPECT_EQ(17, kSizes4[expected_index]); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1281 FaviconURL(GURL("http://www.google.com/a"), | 1290 FaviconURL(GURL("http://www.google.com/a"), |
| 1282 favicon_base::FAVICON, | 1291 favicon_base::FAVICON, |
| 1283 std::vector<gfx::Size>()), | 1292 std::vector<gfx::Size>()), |
| 1284 k404FaviconURL, | 1293 k404FaviconURL, |
| 1285 FaviconURL(GURL("http://www.google.com/c"), | 1294 FaviconURL(GURL("http://www.google.com/c"), |
| 1286 favicon_base::FAVICON, | 1295 favicon_base::FAVICON, |
| 1287 std::vector<gfx::Size>()), | 1296 std::vector<gfx::Size>()), |
| 1288 }; | 1297 }; |
| 1289 | 1298 |
| 1290 TestFaviconDriver driver; | 1299 TestFaviconDriver driver; |
| 1291 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1300 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1301 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1292 DownloadHandler* download_handler = handler.download_handler(); | 1302 DownloadHandler* download_handler = handler.download_handler(); |
| 1293 | 1303 |
| 1294 std::set<GURL> k404URLs; | 1304 std::set<GURL> k404URLs; |
| 1295 k404URLs.insert(k404IconURL); | 1305 k404URLs.insert(k404IconURL); |
| 1296 download_handler->FailDownloadForIconURLs(k404URLs); | 1306 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1297 | 1307 |
| 1298 // Make the initial download for |k404IconURL| fail. | 1308 // Make the initial download for |k404IconURL| fail. |
| 1299 const int kSizes1[] = { 0 }; | 1309 const int kSizes1[] = { 0 }; |
| 1300 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 1310 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
| 1301 DownloadTillDoneIgnoringHistory( | 1311 DownloadTillDoneIgnoringHistory( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1330 const FaviconURL kFaviconURLs[] = { | 1340 const FaviconURL kFaviconURLs[] = { |
| 1331 FaviconURL(k404IconURL1, | 1341 FaviconURL(k404IconURL1, |
| 1332 favicon_base::FAVICON, | 1342 favicon_base::FAVICON, |
| 1333 std::vector<gfx::Size>()), | 1343 std::vector<gfx::Size>()), |
| 1334 FaviconURL(k404IconURL2, | 1344 FaviconURL(k404IconURL2, |
| 1335 favicon_base::FAVICON, | 1345 favicon_base::FAVICON, |
| 1336 std::vector<gfx::Size>()), | 1346 std::vector<gfx::Size>()), |
| 1337 }; | 1347 }; |
| 1338 | 1348 |
| 1339 TestFaviconDriver driver; | 1349 TestFaviconDriver driver; |
| 1340 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1350 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1351 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1341 DownloadHandler* download_handler = handler.download_handler(); | 1352 DownloadHandler* download_handler = handler.download_handler(); |
| 1342 | 1353 |
| 1343 std::set<GURL> k404URLs; | 1354 std::set<GURL> k404URLs; |
| 1344 k404URLs.insert(k404IconURL1); | 1355 k404URLs.insert(k404IconURL1); |
| 1345 k404URLs.insert(k404IconURL2); | 1356 k404URLs.insert(k404IconURL2); |
| 1346 download_handler->FailDownloadForIconURLs(k404URLs); | 1357 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1347 | 1358 |
| 1348 // Make the initial downloads for |kFaviconURLs| fail. | 1359 // Make the initial downloads for |kFaviconURLs| fail. |
| 1349 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1360 for (const FaviconURL& favicon_url : kFaviconURLs) { |
| 1350 const int kSizes[] = { 0 }; | 1361 const int kSizes[] = { 0 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1371 // URL syntax. | 1382 // URL syntax. |
| 1372 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1383 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
| 1373 const GURL kPageURL("http://www.google.com"); | 1384 const GURL kPageURL("http://www.google.com"); |
| 1374 const GURL kInvalidFormatURL("invalid"); | 1385 const GURL kInvalidFormatURL("invalid"); |
| 1375 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1386 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
| 1376 | 1387 |
| 1377 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1388 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, |
| 1378 std::vector<gfx::Size>()); | 1389 std::vector<gfx::Size>()); |
| 1379 | 1390 |
| 1380 TestFaviconDriver driver; | 1391 TestFaviconDriver driver; |
| 1381 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1392 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1393 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1382 UpdateFaviconURL(&driver, &handler, kPageURL, | 1394 UpdateFaviconURL(&driver, &handler, kPageURL, |
| 1383 std::vector<FaviconURL>(1u, favicon_url)); | 1395 std::vector<FaviconURL>(1u, favicon_url)); |
| 1384 EXPECT_EQ(0u, handler.image_urls().size()); | 1396 EXPECT_EQ(0u, handler.image_urls().size()); |
| 1385 } | 1397 } |
| 1386 | 1398 |
| 1387 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1399 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
| 1388 const GURL kPageURL("http://www.google.com"); | 1400 const GURL kPageURL("http://www.google.com"); |
| 1389 std::vector<gfx::Size> icon1; | 1401 std::vector<gfx::Size> icon1; |
| 1390 icon1.push_back(gfx::Size(1024, 1024)); | 1402 icon1.push_back(gfx::Size(1024, 1024)); |
| 1391 icon1.push_back(gfx::Size(512, 512)); | 1403 icon1.push_back(gfx::Size(512, 512)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1403 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1415 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
| 1404 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1416 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1405 FaviconURL(GURL("http://www.google.com/d"), | 1417 FaviconURL(GURL("http://www.google.com/d"), |
| 1406 favicon_base::FAVICON, | 1418 favicon_base::FAVICON, |
| 1407 std::vector<gfx::Size>()), | 1419 std::vector<gfx::Size>()), |
| 1408 FaviconURL(GURL("http://www.google.com/e"), | 1420 FaviconURL(GURL("http://www.google.com/e"), |
| 1409 favicon_base::FAVICON, | 1421 favicon_base::FAVICON, |
| 1410 std::vector<gfx::Size>())}; | 1422 std::vector<gfx::Size>())}; |
| 1411 | 1423 |
| 1412 TestFaviconDriver driver1; | 1424 TestFaviconDriver driver1; |
| 1413 TestFaviconHandler handler1(&driver1, | 1425 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1414 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1426 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1415 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1427 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1416 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1428 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1417 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1429 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1418 | 1430 |
| 1419 struct ExpectedResult { | 1431 struct ExpectedResult { |
| 1420 // The favicon's index in kSourceIconURLs. | 1432 // The favicon's index in kSourceIconURLs. |
| 1421 size_t favicon_index; | 1433 size_t favicon_index; |
| 1422 // Width of largest bitmap. | 1434 // Width of largest bitmap. |
| 1423 int width; | 1435 int width; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 FaviconURL( | 1478 FaviconURL( |
| 1467 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1479 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1468 FaviconURL(GURL("http://www.google.com/d"), | 1480 FaviconURL(GURL("http://www.google.com/d"), |
| 1469 favicon_base::FAVICON, | 1481 favicon_base::FAVICON, |
| 1470 std::vector<gfx::Size>()), | 1482 std::vector<gfx::Size>()), |
| 1471 FaviconURL(GURL("http://www.google.com/e"), | 1483 FaviconURL(GURL("http://www.google.com/e"), |
| 1472 favicon_base::FAVICON, | 1484 favicon_base::FAVICON, |
| 1473 std::vector<gfx::Size>())}; | 1485 std::vector<gfx::Size>())}; |
| 1474 | 1486 |
| 1475 TestFaviconDriver driver1; | 1487 TestFaviconDriver driver1; |
| 1476 TestFaviconHandler handler1(&driver1, | 1488 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1477 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1489 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1478 | 1490 |
| 1479 std::set<GURL> fail_icon_urls; | 1491 std::set<GURL> fail_icon_urls; |
| 1480 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1492 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
| 1481 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1493 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
| 1482 } | 1494 } |
| 1483 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1495 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
| 1484 | 1496 |
| 1485 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1497 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1486 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1498 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 two_icons.push_back(gfx::Size(14, 14)); | 1546 two_icons.push_back(gfx::Size(14, 14)); |
| 1535 two_icons.push_back(gfx::Size(16, 16)); | 1547 two_icons.push_back(gfx::Size(16, 16)); |
| 1536 | 1548 |
| 1537 const FaviconURL kSourceIconURLs[] = { | 1549 const FaviconURL kSourceIconURLs[] = { |
| 1538 FaviconURL( | 1550 FaviconURL( |
| 1539 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1551 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
| 1540 FaviconURL( | 1552 FaviconURL( |
| 1541 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1553 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
| 1542 | 1554 |
| 1543 TestFaviconDriver driver1; | 1555 TestFaviconDriver driver1; |
| 1544 TestFaviconHandler handler1(&driver1, | 1556 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1545 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1557 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1546 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1558 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1547 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1559 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1548 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1560 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1549 | 1561 |
| 1550 ASSERT_EQ(2u, handler1.image_urls().size()); | 1562 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1551 | 1563 |
| 1552 // Index of largest favicon in kSourceIconURLs. | 1564 // Index of largest favicon in kSourceIconURLs. |
| 1553 size_t i = 1; | 1565 size_t i = 1; |
| 1554 // The largest bitmap's index in Favicon . | 1566 // The largest bitmap's index in Favicon . |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 std::vector<gfx::Size> icon2; | 1612 std::vector<gfx::Size> icon2; |
| 1601 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1613 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
| 1602 | 1614 |
| 1603 const FaviconURL kSourceIconURLs[] = { | 1615 const FaviconURL kSourceIconURLs[] = { |
| 1604 FaviconURL( | 1616 FaviconURL( |
| 1605 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1617 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1606 FaviconURL( | 1618 FaviconURL( |
| 1607 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1619 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
| 1608 | 1620 |
| 1609 TestFaviconDriver driver1; | 1621 TestFaviconDriver driver1; |
| 1610 TestFaviconHandler handler1(&driver1, | 1622 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1611 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1623 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1612 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1624 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1613 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1625 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1614 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1626 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1615 | 1627 |
| 1616 ASSERT_EQ(2u, handler1.image_urls().size()); | 1628 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1617 | 1629 |
| 1618 // Index of largest favicon in kSourceIconURLs. | 1630 // Index of largest favicon in kSourceIconURLs. |
| 1619 size_t i = 1; | 1631 size_t i = 1; |
| 1620 // The largest bitmap's index in Favicon . | 1632 // The largest bitmap's index in Favicon . |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 const int actual_size2 = 12; | 1673 const int actual_size2 = 12; |
| 1662 | 1674 |
| 1663 const FaviconURL kSourceIconURLs[] = { | 1675 const FaviconURL kSourceIconURLs[] = { |
| 1664 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1676 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1665 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1677 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
| 1666 FaviconURL(GURL("http://www.google.com/d"), | 1678 FaviconURL(GURL("http://www.google.com/d"), |
| 1667 favicon_base::FAVICON, | 1679 favicon_base::FAVICON, |
| 1668 std::vector<gfx::Size>())}; | 1680 std::vector<gfx::Size>())}; |
| 1669 | 1681 |
| 1670 TestFaviconDriver driver1; | 1682 TestFaviconDriver driver1; |
| 1671 TestFaviconHandler handler1(&driver1, | 1683 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1672 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1684 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1673 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1685 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1674 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1686 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1675 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1687 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1676 ASSERT_EQ(3u, handler1.image_urls().size()); | 1688 ASSERT_EQ(3u, handler1.image_urls().size()); |
| 1677 | 1689 |
| 1678 // Simulate no favicon from history. | 1690 // Simulate no favicon from history. |
| 1679 handler1.history_handler()->history_results_.clear(); | 1691 handler1.history_handler()->history_results_.clear(); |
| 1680 handler1.history_handler()->InvokeCallback(); | 1692 handler1.history_handler()->InvokeCallback(); |
| 1681 | 1693 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 handler1.download_handler()->Reset(); | 1726 handler1.download_handler()->Reset(); |
| 1715 | 1727 |
| 1716 // Verify icon2 has been saved into history. | 1728 // Verify icon2 has been saved into history. |
| 1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1729 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
| 1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1730 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
| 1719 handler1.history_handler()->size_); | 1731 handler1.history_handler()->size_); |
| 1720 } | 1732 } |
| 1721 | 1733 |
| 1722 } // namespace | 1734 } // namespace |
| 1723 } // namespace favicon | 1735 } // namespace favicon |
| OLD | NEW |