| Index: components/favicon/core/favicon_handler_unittest.cc
|
| diff --git a/components/favicon/core/favicon_handler_unittest.cc b/components/favicon/core/favicon_handler_unittest.cc
|
| index 6703473b094fc204b84b72f2c1852d47b22caed1..c5bfe0198eea22a1505f0e2475686a148dea3b3f 100644
|
| --- a/components/favicon/core/favicon_handler_unittest.cc
|
| +++ b/components/favicon/core/favicon_handler_unittest.cc
|
| @@ -12,6 +12,8 @@
|
|
|
| #include "base/macros.h"
|
| #include "components/favicon/core/favicon_driver.h"
|
| +#include "components/favicon/core/test/mock_favicon_service.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/base/layout.h"
|
| @@ -268,10 +270,10 @@ class TestFaviconHandler : public FaviconHandler {
|
| return FaviconHandler::GetMaximalIconSize(icon_type);
|
| }
|
|
|
| - TestFaviconHandler(TestFaviconDriver* driver,
|
| + TestFaviconHandler(FaviconService* service,
|
| + TestFaviconDriver* driver,
|
| FaviconDriverObserver::NotificationIconType handler_type)
|
| - : FaviconHandler(nullptr, driver, handler_type),
|
| - download_id_(0) {
|
| + : FaviconHandler(service, driver, handler_type), download_id_(0) {
|
| download_handler_.reset(new DownloadHandler(this));
|
| }
|
|
|
| @@ -364,7 +366,6 @@ class TestFaviconHandler : public FaviconHandler {
|
| GURL page_url_;
|
|
|
| private:
|
| -
|
| // The unique id of a download request. It will be returned to a
|
| // FaviconHandler.
|
| int download_id_;
|
| @@ -413,7 +414,7 @@ void DownloadHandler::InvokeCallback() {
|
| }
|
|
|
| class FaviconHandlerTest : public testing::Test {
|
| - public:
|
| + protected:
|
| FaviconHandlerTest() {
|
| }
|
|
|
| @@ -481,9 +482,11 @@ class FaviconHandlerTest : public testing::Test {
|
| testing::Test::SetUp();
|
| }
|
|
|
| - private:
|
| std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
|
| scoped_set_supported_scale_factors_;
|
| + testing::StrictMock<MockFaviconService> favicon_service_;
|
| +
|
| + private:
|
| DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest);
|
| };
|
|
|
| @@ -492,7 +495,8 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
|
| const GURL icon_url("http://www.google.com/favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -531,7 +535,8 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
|
| const GURL icon_url("http://www.google.com/favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -598,7 +603,8 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
|
| const GURL new_icon_url("http://www.google.com/new_favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -677,7 +683,8 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
|
| const GURL icon_url("http://www.google.com/favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -747,7 +754,8 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
|
| const GURL new_icon_url("http://www.google.com/new_favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -807,7 +815,8 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
|
| const GURL new_icon_url("http://www.google.com/new_favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::TOUCH_LARGEST);
|
| std::set<GURL> fail_downloads;
|
| fail_downloads.insert(icon_url);
|
| helper.download_handler()->FailDownloadForIconURLs(fail_downloads);
|
| @@ -922,7 +931,8 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
|
| const GURL new_icon_url("http://www.google.com/new_favicon");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::TOUCH_LARGEST);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::TOUCH_LARGEST);
|
|
|
| helper.FetchFavicon(page_url);
|
| HistoryRequestHandler* history_handler = helper.history_handler();
|
| @@ -1044,7 +1054,8 @@ TEST_F(FaviconHandlerTest, UpdateSameIconURLs) {
|
| std::vector<gfx::Size>()));
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| // Initiate a request for favicon data for |page_url|. History does not know
|
| // about the page URL or the icon URLs.
|
| @@ -1090,7 +1101,8 @@ TEST_F(FaviconHandlerTest,
|
| const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png");
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler helper(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| // Initial state:
|
| // - The database does not know about |kPageURL|.
|
| @@ -1203,7 +1215,7 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
|
| // 1) Test that if there are several single resolution favicons to choose from
|
| // that the largest exact match is chosen.
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| const int kSizes1[] = { 16, 24, 32, 48, 256 };
|
| @@ -1224,7 +1236,7 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
|
| // 2) Test that if there are several single resolution favicons to choose
|
| // from, the exact match is preferred even if it results in upsampling.
|
| TestFaviconDriver driver2;
|
| - TestFaviconHandler handler2(&driver2,
|
| + TestFaviconHandler handler2(&favicon_service_, &driver2,
|
| FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| const int kSizes2[] = { 16, 24, 48, 256 };
|
| @@ -1240,7 +1252,7 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
|
| // 3) Test that favicons which need to be upsampled a little or downsampled
|
| // a little are preferred over huge favicons.
|
| TestFaviconDriver driver3;
|
| - TestFaviconHandler handler3(&driver3,
|
| + TestFaviconHandler handler3(&favicon_service_, &driver3,
|
| FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| const int kSizes3[] = { 256, 48 };
|
| @@ -1254,7 +1266,7 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
|
| EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, driver3.icon_url());
|
|
|
| TestFaviconDriver driver4;
|
| - TestFaviconHandler handler4(&driver4,
|
| + TestFaviconHandler handler4(&favicon_service_, &driver4,
|
| FaviconDriverObserver::NON_TOUCH_16_DIP);
|
|
|
| const int kSizes4[] = { 17, 256 };
|
| @@ -1288,7 +1300,8 @@ TEST_F(FaviconHandlerTest, MultipleFavicons404) {
|
| };
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler handler(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| DownloadHandler* download_handler = handler.download_handler();
|
|
|
| std::set<GURL> k404URLs;
|
| @@ -1337,7 +1350,8 @@ TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) {
|
| };
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler handler(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| DownloadHandler* download_handler = handler.download_handler();
|
|
|
| std::set<GURL> k404URLs;
|
| @@ -1378,7 +1392,8 @@ TEST_F(FaviconHandlerTest, FaviconInvalidURL) {
|
| std::vector<gfx::Size>());
|
|
|
| TestFaviconDriver driver;
|
| - TestFaviconHandler handler(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| + TestFaviconHandler handler(&favicon_service_, &driver,
|
| + FaviconDriverObserver::NON_TOUCH_16_DIP);
|
| UpdateFaviconURL(&driver, &handler, kPageURL,
|
| std::vector<FaviconURL>(1u, favicon_url));
|
| EXPECT_EQ(0u, handler.image_urls().size());
|
| @@ -1410,7 +1425,7 @@ TEST_F(FaviconHandlerTest, TestSortFavicon) {
|
| std::vector<gfx::Size>())};
|
|
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_LARGEST);
|
| std::vector<FaviconURL> urls1(kSourceIconURLs,
|
| kSourceIconURLs + arraysize(kSourceIconURLs));
|
| @@ -1473,7 +1488,7 @@ TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) {
|
| std::vector<gfx::Size>())};
|
|
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_LARGEST);
|
|
|
| std::set<GURL> fail_icon_urls;
|
| @@ -1541,7 +1556,7 @@ TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) {
|
| GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)};
|
|
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_LARGEST);
|
| std::vector<FaviconURL> urls1(kSourceIconURLs,
|
| kSourceIconURLs + arraysize(kSourceIconURLs));
|
| @@ -1607,7 +1622,7 @@ TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) {
|
| GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)};
|
|
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_LARGEST);
|
| std::vector<FaviconURL> urls1(kSourceIconURLs,
|
| kSourceIconURLs + arraysize(kSourceIconURLs));
|
| @@ -1668,7 +1683,7 @@ TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) {
|
| std::vector<gfx::Size>())};
|
|
|
| TestFaviconDriver driver1;
|
| - TestFaviconHandler handler1(&driver1,
|
| + TestFaviconHandler handler1(&favicon_service_, &driver1,
|
| FaviconDriverObserver::NON_TOUCH_LARGEST);
|
| std::vector<FaviconURL> urls1(kSourceIconURLs,
|
| kSourceIconURLs + arraysize(kSourceIconURLs));
|
|
|