OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_coordinator.h" | 5 #import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "components/favicon/core/favicon_client.h" | |
11 #include "components/favicon/core/favicon_service.h" | |
12 #include "components/favicon/core/large_icon_service.h" | 10 #include "components/favicon/core/large_icon_service.h" |
| 11 #include "components/favicon/core/test/mock_favicon_service.h" |
13 #include "components/reading_list/ios/reading_list_entry.h" | 12 #include "components/reading_list/ios/reading_list_entry.h" |
14 #include "components/reading_list/ios/reading_list_model_impl.h" | 13 #include "components/reading_list/ios/reading_list_model_impl.h" |
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
17 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_control
ler.h" | 16 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_control
ler.h" |
18 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" | 17 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" |
19 #import "ios/chrome/browser/ui/url_loader.h" | 18 #import "ios/chrome/browser/ui/url_loader.h" |
20 #include "ios/web/public/referrer.h" | 19 #include "ios/web/public/referrer.h" |
21 #import "ios/web/public/test/web_test_with_web_state.h" | 20 #import "ios/web/public/test/web_test_with_web_state.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #import "third_party/ocmock/OCMock/OCMock.h" | 22 #import "third_party/ocmock/OCMock/OCMock.h" |
23 #import "third_party/ocmock/gtest_support.h" | 23 #import "third_party/ocmock/gtest_support.h" |
24 #include "ui/base/page_transition_types.h" | 24 #include "ui/base/page_transition_types.h" |
25 | 25 |
26 namespace { | 26 using favicon::PostReply; |
27 | 27 using testing::_; |
28 #pragma mark - MockFaviconService | |
29 | |
30 // A mock FaviconService that emits an empty response. | |
31 class MockFaviconService : public favicon::FaviconService { | |
32 public: | |
33 MockFaviconService() : FaviconService(nullptr, nullptr) {} | |
34 | |
35 ~MockFaviconService() override {} | |
36 | |
37 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | |
38 const GURL& page_url, | |
39 const std::vector<int>& icon_types, | |
40 int minimum_size_in_pixels, | |
41 const favicon_base::FaviconRawBitmapCallback& callback, | |
42 base::CancelableTaskTracker* tracker) override { | |
43 favicon_base::FaviconRawBitmapResult mock_result; | |
44 return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(), | |
45 FROM_HERE, base::Bind(callback, mock_result)); | |
46 } | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(MockFaviconService); | |
50 }; | |
51 | |
52 } // namespace | |
53 | 28 |
54 #pragma mark - UrlLoader | 29 #pragma mark - UrlLoader |
55 | 30 |
56 @interface UrlLoaderStub : NSObject<UrlLoader> { | 31 @interface UrlLoaderStub : NSObject<UrlLoader> { |
57 GURL _url; | 32 GURL _url; |
58 web::Referrer _referrer; | 33 web::Referrer _referrer; |
59 } | 34 } |
60 | 35 |
61 @property(nonatomic, readonly) const GURL& url; | 36 @property(nonatomic, readonly) const GURL& url; |
62 @property(nonatomic, readonly) const web::Referrer& referrer; | 37 @property(nonatomic, readonly) const web::Referrer& referrer; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 85 } |
111 | 86 |
112 @end | 87 @end |
113 | 88 |
114 #pragma mark - ReadingListCoordinatorTest | 89 #pragma mark - ReadingListCoordinatorTest |
115 | 90 |
116 class ReadingListCoordinatorTest : public web::WebTestWithWebState { | 91 class ReadingListCoordinatorTest : public web::WebTestWithWebState { |
117 public: | 92 public: |
118 ReadingListCoordinatorTest() { | 93 ReadingListCoordinatorTest() { |
119 loader_mock_.reset([[UrlLoaderStub alloc] init]); | 94 loader_mock_.reset([[UrlLoaderStub alloc] init]); |
120 mock_favicon_service_.reset(new MockFaviconService()); | |
121 | 95 |
122 TestChromeBrowserState::Builder builder; | 96 TestChromeBrowserState::Builder builder; |
123 browser_state_ = builder.Build(); | 97 browser_state_ = builder.Build(); |
124 | 98 |
125 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); | 99 reading_list_model_.reset(new ReadingListModelImpl(nullptr, nullptr)); |
126 large_icon_service_.reset(new favicon::LargeIconService( | 100 large_icon_service_.reset(new favicon::LargeIconService( |
127 mock_favicon_service_.get(), base::ThreadTaskRunnerHandle::Get())); | 101 &mock_favicon_service_, base::ThreadTaskRunnerHandle::Get())); |
128 coordinator_.reset([[ReadingListCoordinator alloc] | 102 coordinator_.reset([[ReadingListCoordinator alloc] |
129 initWithBaseViewController:nil | 103 initWithBaseViewController:nil |
130 browserState:browser_state_.get() | 104 browserState:browser_state_.get() |
131 loader:loader_mock_]); | 105 loader:loader_mock_]); |
| 106 |
| 107 EXPECT_CALL(mock_favicon_service_, |
| 108 GetLargestRawFaviconForPageURL(_, _, _, _, _)) |
| 109 .WillRepeatedly(PostReply<5>(favicon_base::FaviconRawBitmapResult())); |
132 } | 110 } |
| 111 |
133 ~ReadingListCoordinatorTest() override {} | 112 ~ReadingListCoordinatorTest() override {} |
134 | 113 |
135 ReadingListCoordinator* GetCoordinator() { return coordinator_; } | 114 ReadingListCoordinator* GetCoordinator() { return coordinator_; } |
136 | 115 |
137 ReadingListModel* GetReadingListModel() { return reading_list_model_.get(); } | 116 ReadingListModel* GetReadingListModel() { return reading_list_model_.get(); } |
138 UrlLoaderStub* GetLoaderStub() { return loader_mock_; } | 117 UrlLoaderStub* GetLoaderStub() { return loader_mock_; } |
139 | 118 |
140 ReadingListCollectionViewController* | 119 ReadingListCollectionViewController* |
141 GetAReadingListCollectionViewController() { | 120 GetAReadingListCollectionViewController() { |
142 return [[[ReadingListCollectionViewController alloc] | 121 return [[[ReadingListCollectionViewController alloc] |
143 initWithModel:reading_list_model_.get() | 122 initWithModel:reading_list_model_.get() |
144 largeIconService:large_icon_service_.get() | 123 largeIconService:large_icon_service_.get() |
145 readingListDownloadService:nil | 124 readingListDownloadService:nil |
146 toolbar:nil] autorelease]; | 125 toolbar:nil] autorelease]; |
147 } | 126 } |
148 | 127 |
149 private: | 128 private: |
150 base::scoped_nsobject<ReadingListCoordinator> coordinator_; | 129 base::scoped_nsobject<ReadingListCoordinator> coordinator_; |
151 std::unique_ptr<ReadingListModelImpl> reading_list_model_; | 130 std::unique_ptr<ReadingListModelImpl> reading_list_model_; |
152 base::scoped_nsobject<UrlLoaderStub> loader_mock_; | 131 base::scoped_nsobject<UrlLoaderStub> loader_mock_; |
| 132 testing::StrictMock<favicon::MockFaviconService> mock_favicon_service_; |
153 std::unique_ptr<favicon::LargeIconService> large_icon_service_; | 133 std::unique_ptr<favicon::LargeIconService> large_icon_service_; |
154 std::unique_ptr<MockFaviconService> mock_favicon_service_; | |
155 std::unique_ptr<TestChromeBrowserState> browser_state_; | 134 std::unique_ptr<TestChromeBrowserState> browser_state_; |
156 }; | 135 }; |
157 | 136 |
158 // Tests that the implementation of ReadingListCoordinator openItemAtIndexPath | 137 // Tests that the implementation of ReadingListCoordinator openItemAtIndexPath |
159 // opens the entry. | 138 // opens the entry. |
160 TEST_F(ReadingListCoordinatorTest, OpenItem) { | 139 TEST_F(ReadingListCoordinatorTest, OpenItem) { |
161 // Setup. | 140 // Setup. |
162 GURL url("https://chromium.org"); | 141 GURL url("https://chromium.org"); |
163 std::string title("Chromium"); | 142 std::string title("Chromium"); |
164 std::unique_ptr<ReadingListEntry> entry = | 143 std::unique_ptr<ReadingListEntry> entry = |
(...skipping 13 matching lines...) Expand all Loading... |
178 GetAReadingListCollectionViewController() | 157 GetAReadingListCollectionViewController() |
179 openItem:item]; | 158 openItem:item]; |
180 | 159 |
181 // Tests. | 160 // Tests. |
182 UrlLoaderStub* loader = GetLoaderStub(); | 161 UrlLoaderStub* loader = GetLoaderStub(); |
183 EXPECT_EQ(url, loader.url); | 162 EXPECT_EQ(url, loader.url); |
184 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_AUTO_BOOKMARK, | 163 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(ui::PAGE_TRANSITION_AUTO_BOOKMARK, |
185 loader.transition)); | 164 loader.transition)); |
186 EXPECT_EQ(NO, loader.rendererInitiated); | 165 EXPECT_EQ(NO, loader.rendererInitiated); |
187 } | 166 } |
OLD | NEW |