| Index: ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm b/ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm
|
| index 01faa948bdf4c77938f3ac112490edbf865c12f6..21fd173bc069025c1f25858a97cd04958ccbf66a 100644
|
| --- a/ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm
|
| +++ b/ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm
|
| @@ -14,15 +14,15 @@
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| -#include "components/favicon/core/favicon_client.h"
|
| -#include "components/favicon/core/favicon_service.h"
|
| #include "components/favicon/core/large_icon_service.h"
|
| +#include "components/favicon/core/test/mock_favicon_service.h"
|
| #include "components/favicon_base/fallback_icon_style.h"
|
| #include "components/favicon_base/favicon_types.h"
|
| #include "ios/chrome/browser/chrome_paths.h"
|
| #include "ios/web/public/test/test_web_thread.h"
|
| #include "ios/web/public/test/test_web_thread_bundle.h"
|
| #include "skia/ext/skia_utils_ios.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest_mac.h"
|
| #include "testing/platform_test.h"
|
| #include "third_party/ocmock/OCMock/OCMock.h"
|
| @@ -39,6 +39,10 @@
|
|
|
| namespace {
|
|
|
| +using favicon::PostCallbackWithResult;
|
| +using testing::WithArg;
|
| +using testing::_;
|
| +
|
| // Dummy URL for the favicon case.
|
| const char kTestFaviconURL[] = "http://test/favicon";
|
| // Dummy URL for the fallback case.
|
| @@ -49,81 +53,44 @@ const char kTestFaviconIconURL[] = "http://test/icons/favicon";
|
| // Size of dummy favicon image.
|
| const CGFloat kTestFaviconSize = 57;
|
|
|
| -// Returns a dummy bitmap result for favicon test URL, and an empty result
|
| -// otherwise.
|
| -favicon_base::FaviconRawBitmapResult CreateTestBitmap(const GURL& url) {
|
| +favicon_base::FaviconRawBitmapResult CreateTestBitmap() {
|
| favicon_base::FaviconRawBitmapResult result;
|
| - if (url == GURL(kTestFaviconURL)) {
|
| - result.expired = false;
|
| - base::FilePath favicon_path;
|
| - PathService::Get(ios::DIR_TEST_DATA, &favicon_path);
|
| - favicon_path =
|
| - favicon_path.Append(FILE_PATH_LITERAL("favicon/test_favicon.png"));
|
| - NSData* favicon_data = [NSData
|
| - dataWithContentsOfFile:base::SysUTF8ToNSString(favicon_path.value())];
|
| - scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes(
|
| - static_cast<const unsigned char*>([favicon_data bytes]),
|
| - [favicon_data length]));
|
| -
|
| - result.bitmap_data = data;
|
| - CGFloat scaled_size = [UIScreen mainScreen].scale * kTestFaviconSize;
|
| - result.pixel_size = gfx::Size(scaled_size, scaled_size);
|
| - result.icon_url = GURL(kTestFaviconIconURL);
|
| - result.icon_type = favicon_base::TOUCH_ICON;
|
| - CHECK(result.is_valid());
|
| - }
|
| + result.expired = false;
|
| + base::FilePath favicon_path;
|
| + PathService::Get(ios::DIR_TEST_DATA, &favicon_path);
|
| + favicon_path =
|
| + favicon_path.Append(FILE_PATH_LITERAL("favicon/test_favicon.png"));
|
| + NSData* favicon_data = [NSData
|
| + dataWithContentsOfFile:base::SysUTF8ToNSString(favicon_path.value())];
|
| + scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes(
|
| + static_cast<const unsigned char*>([favicon_data bytes]),
|
| + [favicon_data length]));
|
| +
|
| + result.bitmap_data = data;
|
| + CGFloat scaled_size = [UIScreen mainScreen].scale * kTestFaviconSize;
|
| + result.pixel_size = gfx::Size(scaled_size, scaled_size);
|
| + result.icon_url = GURL(kTestFaviconIconURL);
|
| + result.icon_type = favicon_base::TOUCH_ICON;
|
| + CHECK(result.is_valid());
|
| return result;
|
| }
|
|
|
| -// A mock FaviconService that emits pre-programmed response.
|
| -class MockFaviconService : public favicon::FaviconService {
|
| - public:
|
| - MockFaviconService() : FaviconService(nullptr, nullptr) {}
|
| -
|
| - ~MockFaviconService() override {}
|
| -
|
| - base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL(
|
| - const GURL& page_url,
|
| - const std::vector<int>& icon_types,
|
| - int minimum_size_in_pixels,
|
| - const favicon_base::FaviconRawBitmapCallback& callback,
|
| - base::CancelableTaskTracker* tracker) override {
|
| - favicon_base::FaviconRawBitmapResult mock_result =
|
| - CreateTestBitmap(page_url);
|
| - return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(),
|
| - FROM_HERE, base::Bind(callback, mock_result));
|
| - }
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(MockFaviconService);
|
| -};
|
| -
|
| -// This class provides access to LargeIconService internals, using the current
|
| -// thread's task runner for testing.
|
| -class TestLargeIconService : public favicon::LargeIconService {
|
| - public:
|
| - explicit TestLargeIconService(MockFaviconService* mock_favicon_service)
|
| - : LargeIconService(mock_favicon_service,
|
| - base::ThreadTaskRunnerHandle::Get()) {}
|
| - ~TestLargeIconService() override {}
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(TestLargeIconService);
|
| -};
|
| -
|
| class FaviconViewProviderTest : public PlatformTest {
|
| protected:
|
| void SetUp() override {
|
| DCHECK_CURRENTLY_ON(web::WebThread::UI);
|
| PlatformTest::SetUp();
|
| - mock_favicon_service_.reset(new MockFaviconService());
|
| - large_icon_service_.reset(
|
| - new TestLargeIconService(mock_favicon_service_.get()));
|
| + large_icon_service_.reset(new favicon::LargeIconService(
|
| + &mock_favicon_service_, base::ThreadTaskRunnerHandle::Get()));
|
| +
|
| + EXPECT_CALL(mock_favicon_service_, GetLargestRawFaviconForPageURL(
|
| + GURL(kTestFaviconURL), _, _, _, _))
|
| + .WillRepeatedly(WithArg<3>(PostCallbackWithResult(CreateTestBitmap())));
|
| }
|
|
|
| web::TestWebThreadBundle thread_bundle_;
|
| - std::unique_ptr<MockFaviconService> mock_favicon_service_;
|
| - std::unique_ptr<TestLargeIconService> large_icon_service_;
|
| + testing::StrictMock<favicon::MockFaviconService> mock_favicon_service_;
|
| + std::unique_ptr<favicon::LargeIconService> large_icon_service_;
|
| base::CancelableTaskTracker cancelable_task_tracker_;
|
| };
|
|
|
|
|