| 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 testing::StrictMock<MockFaviconService> favicon_service_; |
| 488 |
| 489 private: |
| 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 490 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
| 488 }; | 491 }; |
| 489 | 492 |
| 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 493 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 491 const GURL page_url("http://www.google.com"); | 494 const GURL page_url("http://www.google.com"); |
| 492 const GURL icon_url("http://www.google.com/favicon"); | 495 const GURL icon_url("http://www.google.com/favicon"); |
| 493 | 496 |
| 494 TestFaviconDriver driver; | 497 TestFaviconDriver driver; |
| 495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 498 TestFaviconHandler helper(&favicon_service_, &driver, |
| 499 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 496 | 500 |
| 497 helper.FetchFavicon(page_url); | 501 helper.FetchFavicon(page_url); |
| 498 HistoryRequestHandler* history_handler = helper.history_handler(); | 502 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 499 // Ensure the data given to history is correct. | 503 // Ensure the data given to history is correct. |
| 500 ASSERT_TRUE(history_handler); | 504 ASSERT_TRUE(history_handler); |
| 501 EXPECT_EQ(page_url, history_handler->page_url_); | 505 EXPECT_EQ(page_url, history_handler->page_url_); |
| 502 EXPECT_EQ(GURL(), history_handler->icon_url_); | 506 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 503 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 507 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 504 | 508 |
| 505 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 509 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 524 | 528 |
| 525 // Favicon shouldn't request to download icon. | 529 // Favicon shouldn't request to download icon. |
| 526 EXPECT_FALSE(helper.download_handler()->HasDownload()); | 530 EXPECT_FALSE(helper.download_handler()->HasDownload()); |
| 527 } | 531 } |
| 528 | 532 |
| 529 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 533 TEST_F(FaviconHandlerTest, DownloadFavicon) { |
| 530 const GURL page_url("http://www.google.com"); | 534 const GURL page_url("http://www.google.com"); |
| 531 const GURL icon_url("http://www.google.com/favicon"); | 535 const GURL icon_url("http://www.google.com/favicon"); |
| 532 | 536 |
| 533 TestFaviconDriver driver; | 537 TestFaviconDriver driver; |
| 534 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 538 TestFaviconHandler helper(&favicon_service_, &driver, |
| 539 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 535 | 540 |
| 536 helper.FetchFavicon(page_url); | 541 helper.FetchFavicon(page_url); |
| 537 HistoryRequestHandler* history_handler = helper.history_handler(); | 542 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 538 // Ensure the data given to history is correct. | 543 // Ensure the data given to history is correct. |
| 539 ASSERT_TRUE(history_handler); | 544 ASSERT_TRUE(history_handler); |
| 540 EXPECT_EQ(page_url, history_handler->page_url_); | 545 EXPECT_EQ(page_url, history_handler->page_url_); |
| 541 EXPECT_EQ(GURL(), history_handler->icon_url_); | 546 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 542 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 547 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 543 | 548 |
| 544 // Set icon data expired | 549 // Set icon data expired |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 EXPECT_FALSE(driver.image().IsEmpty()); | 596 EXPECT_FALSE(driver.image().IsEmpty()); |
| 592 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 597 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 593 } | 598 } |
| 594 | 599 |
| 595 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 600 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 596 const GURL page_url("http://www.google.com"); | 601 const GURL page_url("http://www.google.com"); |
| 597 const GURL icon_url("http://www.google.com/favicon"); | 602 const GURL icon_url("http://www.google.com/favicon"); |
| 598 const GURL new_icon_url("http://www.google.com/new_favicon"); | 603 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 599 | 604 |
| 600 TestFaviconDriver driver; | 605 TestFaviconDriver driver; |
| 601 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 606 TestFaviconHandler helper(&favicon_service_, &driver, |
| 607 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 602 | 608 |
| 603 helper.FetchFavicon(page_url); | 609 helper.FetchFavicon(page_url); |
| 604 HistoryRequestHandler* history_handler = helper.history_handler(); | 610 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 605 // Ensure the data given to history is correct. | 611 // Ensure the data given to history is correct. |
| 606 ASSERT_TRUE(history_handler); | 612 ASSERT_TRUE(history_handler); |
| 607 EXPECT_EQ(page_url, history_handler->page_url_); | 613 EXPECT_EQ(page_url, history_handler->page_url_); |
| 608 EXPECT_EQ(GURL(), history_handler->icon_url_); | 614 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 609 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 615 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 610 | 616 |
| 611 // Set valid icon data. | 617 // 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()); | 676 EXPECT_EQ(new_icon_url, driver.icon_url()); |
| 671 EXPECT_FALSE(driver.image().IsEmpty()); | 677 EXPECT_FALSE(driver.image().IsEmpty()); |
| 672 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 678 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 673 } | 679 } |
| 674 | 680 |
| 675 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 681 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
| 676 const GURL page_url("http://www.google.com"); | 682 const GURL page_url("http://www.google.com"); |
| 677 const GURL icon_url("http://www.google.com/favicon"); | 683 const GURL icon_url("http://www.google.com/favicon"); |
| 678 | 684 |
| 679 TestFaviconDriver driver; | 685 TestFaviconDriver driver; |
| 680 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 686 TestFaviconHandler helper(&favicon_service_, &driver, |
| 687 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 681 | 688 |
| 682 helper.FetchFavicon(page_url); | 689 helper.FetchFavicon(page_url); |
| 683 HistoryRequestHandler* history_handler = helper.history_handler(); | 690 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 684 // Ensure the data given to history is correct. | 691 // Ensure the data given to history is correct. |
| 685 ASSERT_TRUE(history_handler); | 692 ASSERT_TRUE(history_handler); |
| 686 EXPECT_EQ(page_url, history_handler->page_url_); | 693 EXPECT_EQ(page_url, history_handler->page_url_); |
| 687 EXPECT_EQ(GURL(), history_handler->icon_url_); | 694 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 688 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 695 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 689 | 696 |
| 690 // Set non empty but invalid data. | 697 // 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()); | 747 EXPECT_FALSE(driver.image().IsEmpty()); |
| 741 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); | 748 EXPECT_EQ(gfx::kFaviconSize, driver.image().Width()); |
| 742 } | 749 } |
| 743 | 750 |
| 744 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 751 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 745 const GURL page_url("http://www.google.com"); | 752 const GURL page_url("http://www.google.com"); |
| 746 const GURL icon_url("http://www.google.com/favicon"); | 753 const GURL icon_url("http://www.google.com/favicon"); |
| 747 const GURL new_icon_url("http://www.google.com/new_favicon"); | 754 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 748 | 755 |
| 749 TestFaviconDriver driver; | 756 TestFaviconDriver driver; |
| 750 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 757 TestFaviconHandler helper(&favicon_service_, &driver, |
| 758 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 751 | 759 |
| 752 helper.FetchFavicon(page_url); | 760 helper.FetchFavicon(page_url); |
| 753 HistoryRequestHandler* history_handler = helper.history_handler(); | 761 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 754 // Ensure the data given to history is correct. | 762 // Ensure the data given to history is correct. |
| 755 ASSERT_TRUE(history_handler); | 763 ASSERT_TRUE(history_handler); |
| 756 EXPECT_EQ(page_url, history_handler->page_url_); | 764 EXPECT_EQ(page_url, history_handler->page_url_); |
| 757 EXPECT_EQ(GURL(), history_handler->icon_url_); | 765 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 758 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 766 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
| 759 | 767 |
| 760 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 768 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()); | 808 EXPECT_EQ(new_icon_url, driver.icon_url()); |
| 801 EXPECT_FALSE(driver.image().IsEmpty()); | 809 EXPECT_FALSE(driver.image().IsEmpty()); |
| 802 } | 810 } |
| 803 | 811 |
| 804 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 812 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 805 const GURL page_url("http://www.google.com"); | 813 const GURL page_url("http://www.google.com"); |
| 806 const GURL icon_url("http://www.google.com/favicon"); | 814 const GURL icon_url("http://www.google.com/favicon"); |
| 807 const GURL new_icon_url("http://www.google.com/new_favicon"); | 815 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 808 | 816 |
| 809 TestFaviconDriver driver; | 817 TestFaviconDriver driver; |
| 810 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 818 TestFaviconHandler helper(&favicon_service_, &driver, |
| 819 FaviconDriverObserver::TOUCH_LARGEST); |
| 811 std::set<GURL> fail_downloads; | 820 std::set<GURL> fail_downloads; |
| 812 fail_downloads.insert(icon_url); | 821 fail_downloads.insert(icon_url); |
| 813 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); | 822 helper.download_handler()->FailDownloadForIconURLs(fail_downloads); |
| 814 | 823 |
| 815 helper.FetchFavicon(page_url); | 824 helper.FetchFavicon(page_url); |
| 816 HistoryRequestHandler* history_handler = helper.history_handler(); | 825 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 817 // Ensure the data given to history is correct. | 826 // Ensure the data given to history is correct. |
| 818 ASSERT_TRUE(history_handler); | 827 ASSERT_TRUE(history_handler); |
| 819 EXPECT_EQ(page_url, history_handler->page_url_); | 828 EXPECT_EQ(page_url, history_handler->page_url_); |
| 820 EXPECT_EQ(GURL(), history_handler->icon_url_); | 829 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()); | 924 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
| 916 EXPECT_EQ(page_url, history_handler->page_url_); | 925 EXPECT_EQ(page_url, history_handler->page_url_); |
| 917 } | 926 } |
| 918 | 927 |
| 919 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 928 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 920 const GURL page_url("http://www.google.com"); | 929 const GURL page_url("http://www.google.com"); |
| 921 const GURL icon_url("http://www.google.com/favicon"); | 930 const GURL icon_url("http://www.google.com/favicon"); |
| 922 const GURL new_icon_url("http://www.google.com/new_favicon"); | 931 const GURL new_icon_url("http://www.google.com/new_favicon"); |
| 923 | 932 |
| 924 TestFaviconDriver driver; | 933 TestFaviconDriver driver; |
| 925 TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST); | 934 TestFaviconHandler helper(&favicon_service_, &driver, |
| 935 FaviconDriverObserver::TOUCH_LARGEST); |
| 926 | 936 |
| 927 helper.FetchFavicon(page_url); | 937 helper.FetchFavicon(page_url); |
| 928 HistoryRequestHandler* history_handler = helper.history_handler(); | 938 HistoryRequestHandler* history_handler = helper.history_handler(); |
| 929 // Ensure the data given to history is correct. | 939 // Ensure the data given to history is correct. |
| 930 ASSERT_TRUE(history_handler); | 940 ASSERT_TRUE(history_handler); |
| 931 EXPECT_EQ(page_url, history_handler->page_url_); | 941 EXPECT_EQ(page_url, history_handler->page_url_); |
| 932 EXPECT_EQ(GURL(), history_handler->icon_url_); | 942 EXPECT_EQ(GURL(), history_handler->icon_url_); |
| 933 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 943 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
| 934 history_handler->icon_type_); | 944 history_handler->icon_type_); |
| 935 | 945 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 const GURL icon_url2("http://www.google.com/favicon2"); | 1047 const GURL icon_url2("http://www.google.com/favicon2"); |
| 1038 std::vector<FaviconURL> favicon_urls; | 1048 std::vector<FaviconURL> favicon_urls; |
| 1039 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 1049 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
| 1040 favicon_base::FAVICON, | 1050 favicon_base::FAVICON, |
| 1041 std::vector<gfx::Size>())); | 1051 std::vector<gfx::Size>())); |
| 1042 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 1052 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
| 1043 favicon_base::FAVICON, | 1053 favicon_base::FAVICON, |
| 1044 std::vector<gfx::Size>())); | 1054 std::vector<gfx::Size>())); |
| 1045 | 1055 |
| 1046 TestFaviconDriver driver; | 1056 TestFaviconDriver driver; |
| 1047 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1057 TestFaviconHandler helper(&favicon_service_, &driver, |
| 1058 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1048 | 1059 |
| 1049 // Initiate a request for favicon data for |page_url|. History does not know | 1060 // Initiate a request for favicon data for |page_url|. History does not know |
| 1050 // about the page URL or the icon URLs. | 1061 // about the page URL or the icon URLs. |
| 1051 helper.FetchFavicon(page_url); | 1062 helper.FetchFavicon(page_url); |
| 1052 helper.history_handler()->InvokeCallback(); | 1063 helper.history_handler()->InvokeCallback(); |
| 1053 helper.set_history_handler(nullptr); | 1064 helper.set_history_handler(nullptr); |
| 1054 | 1065 |
| 1055 // Got icon URLs. | 1066 // Got icon URLs. |
| 1056 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 1067 helper.OnUpdateFaviconURL(page_url, favicon_urls); |
| 1057 | 1068 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1083 } | 1094 } |
| 1084 | 1095 |
| 1085 // Fixes crbug.com/544560 | 1096 // Fixes crbug.com/544560 |
| 1086 TEST_F(FaviconHandlerTest, | 1097 TEST_F(FaviconHandlerTest, |
| 1087 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 1098 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
| 1088 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 1099 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
| 1089 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png")
; | 1100 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")
; | 1101 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png")
; |
| 1091 | 1102 |
| 1092 TestFaviconDriver driver; | 1103 TestFaviconDriver driver; |
| 1093 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1104 TestFaviconHandler helper(&favicon_service_, &driver, |
| 1105 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1094 | 1106 |
| 1095 // Initial state: | 1107 // Initial state: |
| 1096 // - The database does not know about |kPageURL|. | 1108 // - The database does not know about |kPageURL|. |
| 1097 // - The page uses |kIconURL1| and |kIconURL2|. | 1109 // - The page uses |kIconURL1| and |kIconURL2|. |
| 1098 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 1110 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
| 1099 // are expired in the database. | 1111 // are expired in the database. |
| 1100 helper.FetchFavicon(kPageURL); | 1112 helper.FetchFavicon(kPageURL); |
| 1101 ASSERT_TRUE(helper.history_handler()); | 1113 ASSERT_TRUE(helper.history_handler()); |
| 1102 helper.history_handler()->InvokeCallback(); | 1114 helper.history_handler()->InvokeCallback(); |
| 1103 { | 1115 { |
| (...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 | 1208 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
| 1197 // SelectFaviconFrames(). | 1209 // SelectFaviconFrames(). |
| 1198 std::vector<ui::ScaleFactor> scale_factors; | 1210 std::vector<ui::ScaleFactor> scale_factors; |
| 1199 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1211 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1200 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1212 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1201 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1213 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
| 1202 | 1214 |
| 1203 // 1) Test that if there are several single resolution favicons to choose from | 1215 // 1) Test that if there are several single resolution favicons to choose from |
| 1204 // that the largest exact match is chosen. | 1216 // that the largest exact match is chosen. |
| 1205 TestFaviconDriver driver1; | 1217 TestFaviconDriver driver1; |
| 1206 TestFaviconHandler handler1(&driver1, | 1218 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1207 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1219 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1208 | 1220 |
| 1209 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1221 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
| 1210 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1222 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1211 kSourceIconURLs + arraysize(kSizes1)); | 1223 kSourceIconURLs + arraysize(kSizes1)); |
| 1212 DownloadTillDoneIgnoringHistory( | 1224 DownloadTillDoneIgnoringHistory( |
| 1213 &driver1, &handler1, kPageURL, urls1, kSizes1); | 1225 &driver1, &handler1, kPageURL, urls1, kSizes1); |
| 1214 | 1226 |
| 1215 EXPECT_EQ(nullptr, handler1.current_candidate()); | 1227 EXPECT_EQ(nullptr, handler1.current_candidate()); |
| 1216 EXPECT_EQ(1u, driver1.num_notifications()); | 1228 EXPECT_EQ(1u, driver1.num_notifications()); |
| 1217 EXPECT_FALSE(driver1.image().IsEmpty()); | 1229 EXPECT_FALSE(driver1.image().IsEmpty()); |
| 1218 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); | 1230 EXPECT_EQ(gfx::kFaviconSize, driver1.image().Width()); |
| 1219 | 1231 |
| 1220 size_t expected_index = 2u; | 1232 size_t expected_index = 2u; |
| 1221 EXPECT_EQ(32, kSizes1[expected_index]); | 1233 EXPECT_EQ(32, kSizes1[expected_index]); |
| 1222 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); | 1234 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver1.icon_url()); |
| 1223 | 1235 |
| 1224 // 2) Test that if there are several single resolution favicons to choose | 1236 // 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. | 1237 // from, the exact match is preferred even if it results in upsampling. |
| 1226 TestFaviconDriver driver2; | 1238 TestFaviconDriver driver2; |
| 1227 TestFaviconHandler handler2(&driver2, | 1239 TestFaviconHandler handler2(&favicon_service_, &driver2, |
| 1228 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1240 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1229 | 1241 |
| 1230 const int kSizes2[] = { 16, 24, 48, 256 }; | 1242 const int kSizes2[] = { 16, 24, 48, 256 }; |
| 1231 std::vector<FaviconURL> urls2(kSourceIconURLs, | 1243 std::vector<FaviconURL> urls2(kSourceIconURLs, |
| 1232 kSourceIconURLs + arraysize(kSizes2)); | 1244 kSourceIconURLs + arraysize(kSizes2)); |
| 1233 DownloadTillDoneIgnoringHistory( | 1245 DownloadTillDoneIgnoringHistory( |
| 1234 &driver2, &handler2, kPageURL, urls2, kSizes2); | 1246 &driver2, &handler2, kPageURL, urls2, kSizes2); |
| 1235 EXPECT_EQ(1u, driver2.num_notifications()); | 1247 EXPECT_EQ(1u, driver2.num_notifications()); |
| 1236 expected_index = 0u; | 1248 expected_index = 0u; |
| 1237 EXPECT_EQ(16, kSizes2[expected_index]); | 1249 EXPECT_EQ(16, kSizes2[expected_index]); |
| 1238 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); | 1250 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver2.icon_url()); |
| 1239 | 1251 |
| 1240 // 3) Test that favicons which need to be upsampled a little or downsampled | 1252 // 3) Test that favicons which need to be upsampled a little or downsampled |
| 1241 // a little are preferred over huge favicons. | 1253 // a little are preferred over huge favicons. |
| 1242 TestFaviconDriver driver3; | 1254 TestFaviconDriver driver3; |
| 1243 TestFaviconHandler handler3(&driver3, | 1255 TestFaviconHandler handler3(&favicon_service_, &driver3, |
| 1244 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1256 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1245 | 1257 |
| 1246 const int kSizes3[] = { 256, 48 }; | 1258 const int kSizes3[] = { 256, 48 }; |
| 1247 std::vector<FaviconURL> urls3(kSourceIconURLs, | 1259 std::vector<FaviconURL> urls3(kSourceIconURLs, |
| 1248 kSourceIconURLs + arraysize(kSizes3)); | 1260 kSourceIconURLs + arraysize(kSizes3)); |
| 1249 DownloadTillDoneIgnoringHistory( | 1261 DownloadTillDoneIgnoringHistory( |
| 1250 &driver3, &handler3, kPageURL, urls3, kSizes3); | 1262 &driver3, &handler3, kPageURL, urls3, kSizes3); |
| 1251 EXPECT_EQ(1u, driver3.num_notifications()); | 1263 EXPECT_EQ(1u, driver3.num_notifications()); |
| 1252 expected_index = 1u; | 1264 expected_index = 1u; |
| 1253 EXPECT_EQ(48, kSizes3[expected_index]); | 1265 EXPECT_EQ(48, kSizes3[expected_index]); |
| 1254 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); | 1266 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url()); |
| 1255 | 1267 |
| 1256 TestFaviconDriver driver4; | 1268 TestFaviconDriver driver4; |
| 1257 TestFaviconHandler handler4(&driver4, | 1269 TestFaviconHandler handler4(&favicon_service_, &driver4, |
| 1258 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1270 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1259 | 1271 |
| 1260 const int kSizes4[] = { 17, 256 }; | 1272 const int kSizes4[] = { 17, 256 }; |
| 1261 std::vector<FaviconURL> urls4(kSourceIconURLs, | 1273 std::vector<FaviconURL> urls4(kSourceIconURLs, |
| 1262 kSourceIconURLs + arraysize(kSizes4)); | 1274 kSourceIconURLs + arraysize(kSizes4)); |
| 1263 DownloadTillDoneIgnoringHistory( | 1275 DownloadTillDoneIgnoringHistory( |
| 1264 &driver4, &handler4, kPageURL, urls4, kSizes4); | 1276 &driver4, &handler4, kPageURL, urls4, kSizes4); |
| 1265 EXPECT_EQ(1u, driver4.num_notifications()); | 1277 EXPECT_EQ(1u, driver4.num_notifications()); |
| 1266 expected_index = 0u; | 1278 expected_index = 0u; |
| 1267 EXPECT_EQ(17, kSizes4[expected_index]); | 1279 EXPECT_EQ(17, kSizes4[expected_index]); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1281 FaviconURL(GURL("http://www.google.com/a"), | 1293 FaviconURL(GURL("http://www.google.com/a"), |
| 1282 favicon_base::FAVICON, | 1294 favicon_base::FAVICON, |
| 1283 std::vector<gfx::Size>()), | 1295 std::vector<gfx::Size>()), |
| 1284 k404FaviconURL, | 1296 k404FaviconURL, |
| 1285 FaviconURL(GURL("http://www.google.com/c"), | 1297 FaviconURL(GURL("http://www.google.com/c"), |
| 1286 favicon_base::FAVICON, | 1298 favicon_base::FAVICON, |
| 1287 std::vector<gfx::Size>()), | 1299 std::vector<gfx::Size>()), |
| 1288 }; | 1300 }; |
| 1289 | 1301 |
| 1290 TestFaviconDriver driver; | 1302 TestFaviconDriver driver; |
| 1291 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1303 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1304 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1292 DownloadHandler* download_handler = handler.download_handler(); | 1305 DownloadHandler* download_handler = handler.download_handler(); |
| 1293 | 1306 |
| 1294 std::set<GURL> k404URLs; | 1307 std::set<GURL> k404URLs; |
| 1295 k404URLs.insert(k404IconURL); | 1308 k404URLs.insert(k404IconURL); |
| 1296 download_handler->FailDownloadForIconURLs(k404URLs); | 1309 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1297 | 1310 |
| 1298 // Make the initial download for |k404IconURL| fail. | 1311 // Make the initial download for |k404IconURL| fail. |
| 1299 const int kSizes1[] = { 0 }; | 1312 const int kSizes1[] = { 0 }; |
| 1300 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 1313 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
| 1301 DownloadTillDoneIgnoringHistory( | 1314 DownloadTillDoneIgnoringHistory( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1330 const FaviconURL kFaviconURLs[] = { | 1343 const FaviconURL kFaviconURLs[] = { |
| 1331 FaviconURL(k404IconURL1, | 1344 FaviconURL(k404IconURL1, |
| 1332 favicon_base::FAVICON, | 1345 favicon_base::FAVICON, |
| 1333 std::vector<gfx::Size>()), | 1346 std::vector<gfx::Size>()), |
| 1334 FaviconURL(k404IconURL2, | 1347 FaviconURL(k404IconURL2, |
| 1335 favicon_base::FAVICON, | 1348 favicon_base::FAVICON, |
| 1336 std::vector<gfx::Size>()), | 1349 std::vector<gfx::Size>()), |
| 1337 }; | 1350 }; |
| 1338 | 1351 |
| 1339 TestFaviconDriver driver; | 1352 TestFaviconDriver driver; |
| 1340 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1353 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1354 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1341 DownloadHandler* download_handler = handler.download_handler(); | 1355 DownloadHandler* download_handler = handler.download_handler(); |
| 1342 | 1356 |
| 1343 std::set<GURL> k404URLs; | 1357 std::set<GURL> k404URLs; |
| 1344 k404URLs.insert(k404IconURL1); | 1358 k404URLs.insert(k404IconURL1); |
| 1345 k404URLs.insert(k404IconURL2); | 1359 k404URLs.insert(k404IconURL2); |
| 1346 download_handler->FailDownloadForIconURLs(k404URLs); | 1360 download_handler->FailDownloadForIconURLs(k404URLs); |
| 1347 | 1361 |
| 1348 // Make the initial downloads for |kFaviconURLs| fail. | 1362 // Make the initial downloads for |kFaviconURLs| fail. |
| 1349 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1363 for (const FaviconURL& favicon_url : kFaviconURLs) { |
| 1350 const int kSizes[] = { 0 }; | 1364 const int kSizes[] = { 0 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1371 // URL syntax. | 1385 // URL syntax. |
| 1372 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1386 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
| 1373 const GURL kPageURL("http://www.google.com"); | 1387 const GURL kPageURL("http://www.google.com"); |
| 1374 const GURL kInvalidFormatURL("invalid"); | 1388 const GURL kInvalidFormatURL("invalid"); |
| 1375 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1389 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
| 1376 | 1390 |
| 1377 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1391 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, |
| 1378 std::vector<gfx::Size>()); | 1392 std::vector<gfx::Size>()); |
| 1379 | 1393 |
| 1380 TestFaviconDriver driver; | 1394 TestFaviconDriver driver; |
| 1381 TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 1395 TestFaviconHandler handler(&favicon_service_, &driver, |
| 1396 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 1382 UpdateFaviconURL(&driver, &handler, kPageURL, | 1397 UpdateFaviconURL(&driver, &handler, kPageURL, |
| 1383 std::vector<FaviconURL>(1u, favicon_url)); | 1398 std::vector<FaviconURL>(1u, favicon_url)); |
| 1384 EXPECT_EQ(0u, handler.image_urls().size()); | 1399 EXPECT_EQ(0u, handler.image_urls().size()); |
| 1385 } | 1400 } |
| 1386 | 1401 |
| 1387 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1402 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
| 1388 const GURL kPageURL("http://www.google.com"); | 1403 const GURL kPageURL("http://www.google.com"); |
| 1389 std::vector<gfx::Size> icon1; | 1404 std::vector<gfx::Size> icon1; |
| 1390 icon1.push_back(gfx::Size(1024, 1024)); | 1405 icon1.push_back(gfx::Size(1024, 1024)); |
| 1391 icon1.push_back(gfx::Size(512, 512)); | 1406 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), | 1418 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
| 1404 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1419 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1405 FaviconURL(GURL("http://www.google.com/d"), | 1420 FaviconURL(GURL("http://www.google.com/d"), |
| 1406 favicon_base::FAVICON, | 1421 favicon_base::FAVICON, |
| 1407 std::vector<gfx::Size>()), | 1422 std::vector<gfx::Size>()), |
| 1408 FaviconURL(GURL("http://www.google.com/e"), | 1423 FaviconURL(GURL("http://www.google.com/e"), |
| 1409 favicon_base::FAVICON, | 1424 favicon_base::FAVICON, |
| 1410 std::vector<gfx::Size>())}; | 1425 std::vector<gfx::Size>())}; |
| 1411 | 1426 |
| 1412 TestFaviconDriver driver1; | 1427 TestFaviconDriver driver1; |
| 1413 TestFaviconHandler handler1(&driver1, | 1428 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1414 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1429 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1415 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1430 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1416 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1431 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1417 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1432 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1418 | 1433 |
| 1419 struct ExpectedResult { | 1434 struct ExpectedResult { |
| 1420 // The favicon's index in kSourceIconURLs. | 1435 // The favicon's index in kSourceIconURLs. |
| 1421 size_t favicon_index; | 1436 size_t favicon_index; |
| 1422 // Width of largest bitmap. | 1437 // Width of largest bitmap. |
| 1423 int width; | 1438 int width; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 FaviconURL( | 1481 FaviconURL( |
| 1467 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1482 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
| 1468 FaviconURL(GURL("http://www.google.com/d"), | 1483 FaviconURL(GURL("http://www.google.com/d"), |
| 1469 favicon_base::FAVICON, | 1484 favicon_base::FAVICON, |
| 1470 std::vector<gfx::Size>()), | 1485 std::vector<gfx::Size>()), |
| 1471 FaviconURL(GURL("http://www.google.com/e"), | 1486 FaviconURL(GURL("http://www.google.com/e"), |
| 1472 favicon_base::FAVICON, | 1487 favicon_base::FAVICON, |
| 1473 std::vector<gfx::Size>())}; | 1488 std::vector<gfx::Size>())}; |
| 1474 | 1489 |
| 1475 TestFaviconDriver driver1; | 1490 TestFaviconDriver driver1; |
| 1476 TestFaviconHandler handler1(&driver1, | 1491 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1477 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1492 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1478 | 1493 |
| 1479 std::set<GURL> fail_icon_urls; | 1494 std::set<GURL> fail_icon_urls; |
| 1480 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1495 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
| 1481 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1496 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
| 1482 } | 1497 } |
| 1483 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1498 handler1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
| 1484 | 1499 |
| 1485 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1500 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1486 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1501 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)); | 1549 two_icons.push_back(gfx::Size(14, 14)); |
| 1535 two_icons.push_back(gfx::Size(16, 16)); | 1550 two_icons.push_back(gfx::Size(16, 16)); |
| 1536 | 1551 |
| 1537 const FaviconURL kSourceIconURLs[] = { | 1552 const FaviconURL kSourceIconURLs[] = { |
| 1538 FaviconURL( | 1553 FaviconURL( |
| 1539 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1554 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
| 1540 FaviconURL( | 1555 FaviconURL( |
| 1541 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1556 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
| 1542 | 1557 |
| 1543 TestFaviconDriver driver1; | 1558 TestFaviconDriver driver1; |
| 1544 TestFaviconHandler handler1(&driver1, | 1559 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1545 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1560 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1546 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1561 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1547 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1562 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1548 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1563 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1549 | 1564 |
| 1550 ASSERT_EQ(2u, handler1.image_urls().size()); | 1565 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1551 | 1566 |
| 1552 // Index of largest favicon in kSourceIconURLs. | 1567 // Index of largest favicon in kSourceIconURLs. |
| 1553 size_t i = 1; | 1568 size_t i = 1; |
| 1554 // The largest bitmap's index in Favicon . | 1569 // 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; | 1615 std::vector<gfx::Size> icon2; |
| 1601 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1616 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
| 1602 | 1617 |
| 1603 const FaviconURL kSourceIconURLs[] = { | 1618 const FaviconURL kSourceIconURLs[] = { |
| 1604 FaviconURL( | 1619 FaviconURL( |
| 1605 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1620 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1606 FaviconURL( | 1621 FaviconURL( |
| 1607 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1622 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
| 1608 | 1623 |
| 1609 TestFaviconDriver driver1; | 1624 TestFaviconDriver driver1; |
| 1610 TestFaviconHandler handler1(&driver1, | 1625 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1611 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1626 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1612 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1627 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1613 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1628 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1614 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1629 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1615 | 1630 |
| 1616 ASSERT_EQ(2u, handler1.image_urls().size()); | 1631 ASSERT_EQ(2u, handler1.image_urls().size()); |
| 1617 | 1632 |
| 1618 // Index of largest favicon in kSourceIconURLs. | 1633 // Index of largest favicon in kSourceIconURLs. |
| 1619 size_t i = 1; | 1634 size_t i = 1; |
| 1620 // The largest bitmap's index in Favicon . | 1635 // 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; | 1676 const int actual_size2 = 12; |
| 1662 | 1677 |
| 1663 const FaviconURL kSourceIconURLs[] = { | 1678 const FaviconURL kSourceIconURLs[] = { |
| 1664 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1679 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
| 1665 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1680 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
| 1666 FaviconURL(GURL("http://www.google.com/d"), | 1681 FaviconURL(GURL("http://www.google.com/d"), |
| 1667 favicon_base::FAVICON, | 1682 favicon_base::FAVICON, |
| 1668 std::vector<gfx::Size>())}; | 1683 std::vector<gfx::Size>())}; |
| 1669 | 1684 |
| 1670 TestFaviconDriver driver1; | 1685 TestFaviconDriver driver1; |
| 1671 TestFaviconHandler handler1(&driver1, | 1686 TestFaviconHandler handler1(&favicon_service_, &driver1, |
| 1672 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1687 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1673 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1688 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| 1674 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1689 kSourceIconURLs + arraysize(kSourceIconURLs)); |
| 1675 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); | 1690 UpdateFaviconURL(&driver1, &handler1, kPageURL, urls1); |
| 1676 ASSERT_EQ(3u, handler1.image_urls().size()); | 1691 ASSERT_EQ(3u, handler1.image_urls().size()); |
| 1677 | 1692 |
| 1678 // Simulate no favicon from history. | 1693 // Simulate no favicon from history. |
| 1679 handler1.history_handler()->history_results_.clear(); | 1694 handler1.history_handler()->history_results_.clear(); |
| 1680 handler1.history_handler()->InvokeCallback(); | 1695 handler1.history_handler()->InvokeCallback(); |
| 1681 | 1696 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 handler1.download_handler()->Reset(); | 1729 handler1.download_handler()->Reset(); |
| 1715 | 1730 |
| 1716 // Verify icon2 has been saved into history. | 1731 // Verify icon2 has been saved into history. |
| 1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1732 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
| 1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1733 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
| 1719 handler1.history_handler()->size_); | 1734 handler1.history_handler()->size_); |
| 1720 } | 1735 } |
| 1721 | 1736 |
| 1722 } // namespace | 1737 } // namespace |
| 1723 } // namespace favicon | 1738 } // namespace favicon |
| OLD | NEW |