| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_control
ler.h" | 5 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_control
ler.h" |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/favicon/core/favicon_client.h" | |
| 16 #include "components/favicon/core/favicon_service.h" | |
| 17 #include "components/favicon/core/large_icon_service.h" | 15 #include "components/favicon/core/large_icon_service.h" |
| 16 #include "components/favicon/core/test/mock_favicon_service.h" |
| 18 #include "components/reading_list/ios/reading_list_model.h" | 17 #include "components/reading_list/ios/reading_list_model.h" |
| 19 #include "components/reading_list/ios/reading_list_model_impl.h" | 18 #include "components/reading_list/ios/reading_list_model_impl.h" |
| 20 #include "components/reading_list/ios/reading_list_model_storage.h" | 19 #include "components/reading_list/ios/reading_list_model_storage.h" |
| 21 #include "components/url_formatter/url_formatter.h" | 20 #include "components/url_formatter/url_formatter.h" |
| 22 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 21 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 23 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" | 22 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" |
| 24 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 25 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" | 24 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" |
| 26 #include "ios/web/public/test/test_web_thread_bundle.h" | 25 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "testing/platform_test.h" | 28 #include "testing/platform_test.h" |
| 29 #import "third_party/ocmock/OCMock/OCMock.h" | 29 #import "third_party/ocmock/OCMock/OCMock.h" |
| 30 #import "third_party/ocmock/gtest_support.h" | 30 #import "third_party/ocmock/gtest_support.h" |
| 31 | 31 |
| 32 namespace { | 32 using favicon::PostReply; |
| 33 | 33 using testing::_; |
| 34 #pragma mark - MockFaviconService | |
| 35 | |
| 36 // A mock FaviconService that emits an empty response. | |
| 37 class MockFaviconService : public favicon::FaviconService { | |
| 38 public: | |
| 39 MockFaviconService() : FaviconService(nullptr, nullptr) {} | |
| 40 | |
| 41 ~MockFaviconService() override {} | |
| 42 | |
| 43 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | |
| 44 const GURL& page_url, | |
| 45 const std::vector<int>& icon_types, | |
| 46 int minimum_size_in_pixels, | |
| 47 const favicon_base::FaviconRawBitmapCallback& callback, | |
| 48 base::CancelableTaskTracker* tracker) override { | |
| 49 favicon_base::FaviconRawBitmapResult mock_result; | |
| 50 return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(), | |
| 51 FROM_HERE, base::Bind(callback, mock_result)); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(MockFaviconService); | |
| 56 }; | |
| 57 | |
| 58 } // namespace | |
| 59 | 34 |
| 60 #pragma mark - ReadingListCollectionViewControllerTest | 35 #pragma mark - ReadingListCollectionViewControllerTest |
| 61 | 36 |
| 62 class ReadingListCollectionViewControllerTest : public testing::Test { | 37 class ReadingListCollectionViewControllerTest : public testing::Test { |
| 63 public: | 38 public: |
| 64 ReadingListCollectionViewControllerTest() {} | 39 ReadingListCollectionViewControllerTest() {} |
| 65 ~ReadingListCollectionViewControllerTest() override {} | 40 ~ReadingListCollectionViewControllerTest() override {} |
| 66 | 41 |
| 42 testing::StrictMock<favicon::MockFaviconService> mock_favicon_service_; |
| 67 std::unique_ptr<ReadingListModelImpl> reading_list_model_; | 43 std::unique_ptr<ReadingListModelImpl> reading_list_model_; |
| 68 std::unique_ptr<favicon::LargeIconService> large_icon_service_; | 44 std::unique_ptr<favicon::LargeIconService> large_icon_service_; |
| 69 std::unique_ptr<MockFaviconService> mock_favicon_service_; | |
| 70 | 45 |
| 71 base::scoped_nsobject<ReadingListCollectionViewController> | 46 base::scoped_nsobject<ReadingListCollectionViewController> |
| 72 reading_list_view_controller_; | 47 reading_list_view_controller_; |
| 73 id mock_delegate_; | 48 id mock_delegate_; |
| 74 | 49 |
| 75 // TODO(crbug.com/625617) When offline url can be opened, use a mock for the | 50 // TODO(crbug.com/625617) When offline url can be opened, use a mock for the |
| 76 // readinglistdownloadservice. | 51 // readinglistdownloadservice. |
| 77 void SetUp() override { | 52 void SetUp() override { |
| 78 testing::Test::SetUp(); | 53 testing::Test::SetUp(); |
| 79 mock_favicon_service_.reset(new MockFaviconService()); | 54 |
| 55 EXPECT_CALL(mock_favicon_service_, |
| 56 GetLargestRawFaviconForPageURL(_, _, _, _, _)) |
| 57 .WillRepeatedly(PostReply<5>(favicon_base::FaviconRawBitmapResult())); |
| 80 | 58 |
| 81 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); | 59 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); |
| 82 large_icon_service_.reset(new favicon::LargeIconService( | 60 large_icon_service_.reset(new favicon::LargeIconService( |
| 83 mock_favicon_service_.get(), base::ThreadTaskRunnerHandle::Get())); | 61 &mock_favicon_service_, base::ThreadTaskRunnerHandle::Get())); |
| 84 reading_list_view_controller_.reset( | 62 reading_list_view_controller_.reset( |
| 85 [[ReadingListCollectionViewController alloc] | 63 [[ReadingListCollectionViewController alloc] |
| 86 initWithModel:reading_list_model_.get() | 64 initWithModel:reading_list_model_.get() |
| 87 largeIconService:large_icon_service_.get() | 65 largeIconService:large_icon_service_.get() |
| 88 readingListDownloadService:nil | 66 readingListDownloadService:nil |
| 89 toolbar:nil]); | 67 toolbar:nil]); |
| 90 | 68 |
| 91 mock_delegate_ = [OCMockObject | 69 mock_delegate_ = [OCMockObject |
| 92 niceMockForProtocol:@protocol( | 70 niceMockForProtocol:@protocol( |
| 93 ReadingListCollectionViewControllerDelegate)]; | 71 ReadingListCollectionViewControllerDelegate)]; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( | 199 base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( |
| 222 [[reading_list_view_controller_ collectionViewModel] | 200 [[reading_list_view_controller_ collectionViewModel] |
| 223 itemAtIndexPath:indexPath]); | 201 itemAtIndexPath:indexPath]); |
| 224 EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); | 202 EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); |
| 225 EXPECT_EQ([readingListItem url], url); | 203 EXPECT_EQ([readingListItem url], url); |
| 226 EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), | 204 EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), |
| 227 url_formatter::FormatUrl(url)); | 205 url_formatter::FormatUrl(url)); |
| 228 EXPECT_EQ([readingListItem faviconPageURL], distilled_url); | 206 EXPECT_EQ([readingListItem faviconPageURL], distilled_url); |
| 229 EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED); | 207 EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED); |
| 230 } | 208 } |
| OLD | NEW |