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 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.
h" | 5 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.
h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 private: | 160 private: |
161 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest); | 161 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest); |
162 }; | 162 }; |
163 | 163 |
164 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { | 164 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { |
165 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2); | 165 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2); |
166 EXPECT_CALL( | 166 EXPECT_CALL( |
167 *observer(), | 167 *observer(), |
168 OnNewSuggestions(_, recent_tabs_category(), | 168 OnNewSuggestions( |
169 UnorderedElementsAre( | 169 _, recent_tabs_category(), |
170 Property(&ContentSuggestion::url, | 170 UnorderedElementsAre( |
171 GURL("http://dummy.com/1")), | 171 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")), |
172 Property(&ContentSuggestion::url, | 172 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")), |
173 GURL("http://dummy.com/2")), | 173 Property(&ContentSuggestion::url, GURL("http://dummy.com/3"))))); |
174 Property(&ContentSuggestion::url, | |
175 GURL("http://dummy.com/3"))))); | |
176 | 174 |
177 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3}); | 175 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3}); |
178 for (OfflinePageItem& recent_tab : recent_tabs_list) { | 176 for (OfflinePageItem& recent_tab : recent_tabs_list) { |
179 AddTabAndOfflinePageToModel(recent_tab); | 177 AddTabAndOfflinePageToModel(recent_tab); |
180 } | 178 } |
181 } | 179 } |
182 | 180 |
183 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByCreationTime) { | 181 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByCreationTime) { |
184 base::Time now = base::Time::Now(); | 182 base::Time now = base::Time::Now(); |
185 base::Time yesterday = now - base::TimeDelta::FromDays(1); | 183 base::Time yesterday = now - base::TimeDelta::FromDays(1); |
(...skipping 19 matching lines...) Expand all Loading... |
205 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); | 203 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); |
206 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2, yesterday)); | 204 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2, yesterday)); |
207 | 205 |
208 offline_pages[1].last_access_time = | 206 offline_pages[1].last_access_time = |
209 offline_pages[0].last_access_time + base::TimeDelta::FromHours(1); | 207 offline_pages[0].last_access_time + base::TimeDelta::FromHours(1); |
210 | 208 |
211 EXPECT_CALL( | 209 EXPECT_CALL( |
212 *observer(), | 210 *observer(), |
213 OnNewSuggestions( | 211 OnNewSuggestions( |
214 _, recent_tabs_category(), | 212 _, recent_tabs_category(), |
215 ElementsAre(Property(&ContentSuggestion::url, | 213 ElementsAre( |
216 GURL("http://dummy.com/3")), | 214 Property(&ContentSuggestion::url, GURL("http://dummy.com/3")), |
217 Property(&ContentSuggestion::url, | 215 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")), |
218 GURL("http://dummy.com/1")), | 216 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); |
219 Property(&ContentSuggestion::url, | |
220 GURL("http://dummy.com/2"))))); | |
221 AddTabAndOfflinePageToModel(CreateDummyRecentTab(3, tomorrow)); | 217 AddTabAndOfflinePageToModel(CreateDummyRecentTab(3, tomorrow)); |
222 } | 218 } |
223 | 219 |
224 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { | 220 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { |
225 EXPECT_FALSE( | 221 EXPECT_FALSE( |
226 provider()->GetCategoryInfo(recent_tabs_category()).has_fetch_action()); | 222 provider()->GetCategoryInfo(recent_tabs_category()).has_fetch_action()); |
227 EXPECT_FALSE(provider() | 223 EXPECT_FALSE(provider() |
228 ->GetCategoryInfo(recent_tabs_category()) | 224 ->GetCategoryInfo(recent_tabs_category()) |
229 .has_view_all_action()); | 225 .has_view_all_action()); |
230 } | 226 } |
(...skipping 25 matching lines...) Expand all Loading... |
256 AddTabAndOfflinePageToModel(CreateDummyRecentTab(4)); | 252 AddTabAndOfflinePageToModel(CreateDummyRecentTab(4)); |
257 Mock::VerifyAndClearExpectations(observer()); | 253 Mock::VerifyAndClearExpectations(observer()); |
258 | 254 |
259 // And appear in the dismissed suggestions. | 255 // And appear in the dismissed suggestions. |
260 std::vector<ContentSuggestion> dismissed_suggestions; | 256 std::vector<ContentSuggestion> dismissed_suggestions; |
261 provider()->GetDismissedSuggestionsForDebugging( | 257 provider()->GetDismissedSuggestionsForDebugging( |
262 recent_tabs_category(), | 258 recent_tabs_category(), |
263 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); | 259 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); |
264 EXPECT_THAT( | 260 EXPECT_THAT( |
265 dismissed_suggestions, | 261 dismissed_suggestions, |
266 UnorderedElementsAre(Property(&ContentSuggestion::url, | 262 UnorderedElementsAre( |
267 GURL("http://dummy.com/2")), | 263 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")), |
268 Property(&ContentSuggestion::url, | 264 Property(&ContentSuggestion::url, GURL("http://dummy.com/3")))); |
269 GURL("http://dummy.com/3")))); | |
270 | 265 |
271 // Clear dismissed suggestions. | 266 // Clear dismissed suggestions. |
272 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); | 267 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); |
273 | 268 |
274 // They should be gone from the dismissed suggestions. | 269 // They should be gone from the dismissed suggestions. |
275 dismissed_suggestions.clear(); | 270 dismissed_suggestions.clear(); |
276 provider()->GetDismissedSuggestionsForDebugging( | 271 provider()->GetDismissedSuggestionsForDebugging( |
277 recent_tabs_category(), | 272 recent_tabs_category(), |
278 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); | 273 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); |
279 EXPECT_THAT(dismissed_suggestions, IsEmpty()); | 274 EXPECT_THAT(dismissed_suggestions, IsEmpty()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); | 428 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); |
434 | 429 |
435 AddTabAndOfflinePageToModel(CreateDummyRecentTab(1)); | 430 AddTabAndOfflinePageToModel(CreateDummyRecentTab(1)); |
436 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2)); | 431 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2)); |
437 // The provider is not notified about the recent tabs yet. | 432 // The provider is not notified about the recent tabs yet. |
438 task_runner()->RunUntilIdle(); | 433 task_runner()->RunUntilIdle(); |
439 // However, it must return both tabs when the model is loaded. | 434 // However, it must return both tabs when the model is loaded. |
440 } | 435 } |
441 | 436 |
442 } // namespace ntp_snippets | 437 } // namespace ntp_snippets |
OLD | NEW |