Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: ios/chrome/browser/ui/history/favicon_view_provider_unittest.mm

Issue 2698473004: Split FaviconService and FaviconServiceImpl. (Closed)
Patch Set: Revert changes in ios/.../history_collection_view_controller_unittest.mm Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/history/BUILD.gn ('k') | ios/chrome/browser/ui/reading_list/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b6b3d83ed58202ec9b272bb95daedfb4365e49bb 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,9 @@
namespace {
+using favicon::PostReply;
+using testing::_;
+
// Dummy URL for the favicon case.
const char kTestFaviconURL[] = "http://test/favicon";
// Dummy URL for the fallback case.
@@ -49,81 +52,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(PostReply<5>(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_;
};
@@ -150,6 +116,10 @@ TEST_F(FaviconViewProviderTest, Favicon) {
// Tests that fallback data is set when no favicon is returned from
// LargeIconService.
TEST_F(FaviconViewProviderTest, FallbackIcon) {
+ EXPECT_CALL(mock_favicon_service_, GetLargestRawFaviconForPageURL(
+ GURL(kTestFallbackURL), _, _, _, _))
+ .WillRepeatedly(PostReply<5>(favicon_base::FaviconRawBitmapResult()));
+
id mock_delegate =
[OCMockObject mockForProtocol:@protocol(FaviconViewProviderDelegate)];
base::scoped_nsobject<FaviconViewProvider> item([[FaviconViewProvider alloc]
« no previous file with comments | « ios/chrome/browser/ui/history/BUILD.gn ('k') | ios/chrome/browser/ui/reading_list/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698