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::PostCallbackWithResult; |
33 | 33 using testing::WithArg; |
34 #pragma mark - MockFaviconService | 34 using testing::_; |
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 | 35 |
60 #pragma mark - ReadingListCollectionViewControllerTest | 36 #pragma mark - ReadingListCollectionViewControllerTest |
61 | 37 |
62 class ReadingListCollectionViewControllerTest : public testing::Test { | 38 class ReadingListCollectionViewControllerTest : public testing::Test { |
63 public: | 39 public: |
64 ReadingListCollectionViewControllerTest() {} | 40 ReadingListCollectionViewControllerTest() {} |
65 ~ReadingListCollectionViewControllerTest() override {} | 41 ~ReadingListCollectionViewControllerTest() override {} |
66 | 42 |
| 43 testing::StrictMock<favicon::MockFaviconService> mock_favicon_service_; |
67 std::unique_ptr<ReadingListModelImpl> reading_list_model_; | 44 std::unique_ptr<ReadingListModelImpl> reading_list_model_; |
68 std::unique_ptr<favicon::LargeIconService> large_icon_service_; | 45 std::unique_ptr<favicon::LargeIconService> large_icon_service_; |
69 std::unique_ptr<MockFaviconService> mock_favicon_service_; | |
70 | 46 |
71 base::scoped_nsobject<ReadingListCollectionViewController> | 47 base::scoped_nsobject<ReadingListCollectionViewController> |
72 reading_list_view_controller_; | 48 reading_list_view_controller_; |
73 id mock_delegate_; | 49 id mock_delegate_; |
74 | 50 |
75 // TODO(crbug.com/625617) When offline url can be opened, use a mock for the | 51 // TODO(crbug.com/625617) When offline url can be opened, use a mock for the |
76 // readinglistdownloadservice. | 52 // readinglistdownloadservice. |
77 void SetUp() override { | 53 void SetUp() override { |
78 testing::Test::SetUp(); | 54 testing::Test::SetUp(); |
79 mock_favicon_service_.reset(new MockFaviconService()); | 55 |
| 56 EXPECT_CALL(mock_favicon_service_, |
| 57 GetLargestRawFaviconForPageURL(_, _, _, _, _)) |
| 58 .WillRepeatedly(WithArg<3>( |
| 59 PostCallbackWithResult(favicon_base::FaviconRawBitmapResult()))); |
80 | 60 |
81 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); | 61 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); |
82 large_icon_service_.reset(new favicon::LargeIconService( | 62 large_icon_service_.reset(new favicon::LargeIconService( |
83 mock_favicon_service_.get(), base::ThreadTaskRunnerHandle::Get())); | 63 &mock_favicon_service_, base::ThreadTaskRunnerHandle::Get())); |
84 reading_list_view_controller_.reset( | 64 reading_list_view_controller_.reset( |
85 [[ReadingListCollectionViewController alloc] | 65 [[ReadingListCollectionViewController alloc] |
86 initWithModel:reading_list_model_.get() | 66 initWithModel:reading_list_model_.get() |
87 largeIconService:large_icon_service_.get() | 67 largeIconService:large_icon_service_.get() |
88 readingListDownloadService:nil | 68 readingListDownloadService:nil |
89 toolbar:nil]); | 69 toolbar:nil]); |
90 | 70 |
91 mock_delegate_ = [OCMockObject | 71 mock_delegate_ = [OCMockObject |
92 niceMockForProtocol:@protocol( | 72 niceMockForProtocol:@protocol( |
93 ReadingListCollectionViewControllerDelegate)]; | 73 ReadingListCollectionViewControllerDelegate)]; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( | 201 base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( |
222 [[reading_list_view_controller_ collectionViewModel] | 202 [[reading_list_view_controller_ collectionViewModel] |
223 itemAtIndexPath:indexPath]); | 203 itemAtIndexPath:indexPath]); |
224 EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); | 204 EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); |
225 EXPECT_EQ([readingListItem url], url); | 205 EXPECT_EQ([readingListItem url], url); |
226 EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), | 206 EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), |
227 url_formatter::FormatUrl(url)); | 207 url_formatter::FormatUrl(url)); |
228 EXPECT_EQ([readingListItem faviconPageURL], distilled_url); | 208 EXPECT_EQ([readingListItem faviconPageURL], distilled_url); |
229 EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED); | 209 EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED); |
230 } | 210 } |
OLD | NEW |