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

Side by Side Diff: components/ntp_snippets/offline_pages/recent_tab_suggestions_provider_unittest.cc

Issue 2595873002: [NTP::RecentTabs] Do not fetch all pages when not a recent tab is added. (Closed)
Patch Set: jkrcal@ nits. Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { 175 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) {
176 EXPECT_FALSE( 176 EXPECT_FALSE(
177 provider()->GetCategoryInfo(recent_tabs_category()).has_more_action()); 177 provider()->GetCategoryInfo(recent_tabs_category()).has_more_action());
178 EXPECT_FALSE( 178 EXPECT_FALSE(
179 provider()->GetCategoryInfo(recent_tabs_category()).has_reload_action()); 179 provider()->GetCategoryInfo(recent_tabs_category()).has_reload_action());
180 EXPECT_FALSE(provider() 180 EXPECT_FALSE(provider()
181 ->GetCategoryInfo(recent_tabs_category()) 181 ->GetCategoryInfo(recent_tabs_category())
182 .has_view_all_action()); 182 .has_view_all_action());
183 } 183 }
184 184
185 // TODO(vitaliii): Break this test into multiple tests. Currently if it fails,
186 // it takes long time to find which part of it actually fails.
185 TEST_F(RecentTabSuggestionsProviderTest, ShouldDismiss) { 187 TEST_F(RecentTabSuggestionsProviderTest, ShouldDismiss) {
186 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(4); 188 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(3);
187 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3, 4}); 189 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3});
188 for (OfflinePageItem& recent_tab : recent_tabs_list) 190 for (OfflinePageItem& recent_tab : recent_tabs_list) {
189 AddOfflinePageToModel(recent_tab); 191 AddOfflinePageToModel(recent_tab);
192 }
190 193
191 // Dismiss 2 and 3. 194 // Dismiss 2 and 3.
192 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); 195 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0);
193 provider()->DismissSuggestion(GetDummySuggestionId(2)); 196 provider()->DismissSuggestion(GetDummySuggestionId(2));
194 provider()->DismissSuggestion(GetDummySuggestionId(3)); 197 provider()->DismissSuggestion(GetDummySuggestionId(3));
195 Mock::VerifyAndClearExpectations(observer()); 198 Mock::VerifyAndClearExpectations(observer());
196 199
197 // They should disappear from the reported suggestions. 200 // They should disappear from the reported suggestions.
198 EXPECT_CALL( 201 EXPECT_CALL(
199 *observer(), 202 *observer(),
200 OnNewSuggestions(_, recent_tabs_category(), 203 OnNewSuggestions(
201 UnorderedElementsAre( 204 _, recent_tabs_category(),
202 Property(&ContentSuggestion::url, 205 UnorderedElementsAre(
203 GURL("http://dummy.com/1")), 206 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")),
204 Property(&ContentSuggestion::url, 207 Property(&ContentSuggestion::url, GURL("http://dummy.com/4")))));
205 GURL("http://dummy.com/4")))));
206 208
207 AddOfflinePageToModel(ntp_snippets::test::CreateDummyOfflinePageItem( 209 AddOfflinePageToModel(CreateDummyRecentTab(4));
208 4, offline_pages::kDefaultNamespace));
209 Mock::VerifyAndClearExpectations(observer()); 210 Mock::VerifyAndClearExpectations(observer());
210 211
211 // And appear in the dismissed suggestions. 212 // And appear in the dismissed suggestions.
212 std::vector<ContentSuggestion> dismissed_suggestions; 213 std::vector<ContentSuggestion> dismissed_suggestions;
213 provider()->GetDismissedSuggestionsForDebugging( 214 provider()->GetDismissedSuggestionsForDebugging(
214 recent_tabs_category(), 215 recent_tabs_category(),
215 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 216 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
216 EXPECT_THAT( 217 EXPECT_THAT(
217 dismissed_suggestions, 218 dismissed_suggestions,
218 UnorderedElementsAre(Property(&ContentSuggestion::url, 219 UnorderedElementsAre(Property(&ContentSuggestion::url,
219 GURL("http://dummy.com/2")), 220 GURL("http://dummy.com/2")),
220 Property(&ContentSuggestion::url, 221 Property(&ContentSuggestion::url,
221 GURL("http://dummy.com/3")))); 222 GURL("http://dummy.com/3"))));
222 223
223 // Clear dismissed suggestions. 224 // Clear dismissed suggestions.
224 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); 225 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category());
225 226
226 // They should be gone from the dismissed suggestions. 227 // They should be gone from the dismissed suggestions.
227 dismissed_suggestions.clear(); 228 dismissed_suggestions.clear();
228 provider()->GetDismissedSuggestionsForDebugging( 229 provider()->GetDismissedSuggestionsForDebugging(
229 recent_tabs_category(), 230 recent_tabs_category(),
230 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 231 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
231 EXPECT_THAT(dismissed_suggestions, IsEmpty()); 232 EXPECT_THAT(dismissed_suggestions, IsEmpty());
232 233
233 // And appear in the reported suggestions for the category again. 234 // And appear in the reported suggestions for the category again.
234 EXPECT_CALL(*observer(), 235 EXPECT_CALL(*observer(),
235 OnNewSuggestions(_, recent_tabs_category(), SizeIs(4))); 236 OnNewSuggestions(_, recent_tabs_category(), SizeIs(5)));
236 AddOfflinePageToModel(ntp_snippets::test::CreateDummyOfflinePageItem( 237 AddOfflinePageToModel(CreateDummyRecentTab(5));
237 5, offline_pages::kDefaultNamespace));
238 Mock::VerifyAndClearExpectations(observer()); 238 Mock::VerifyAndClearExpectations(observer());
239 } 239 }
240 240
241 TEST_F(RecentTabSuggestionsProviderTest, 241 TEST_F(RecentTabSuggestionsProviderTest,
242 ShouldInvalidateWhenOfflinePageDeleted) { 242 ShouldInvalidateWhenOfflinePageDeleted) {
243 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(3); 243 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(3);
244 std::vector<OfflinePageItem> offline_pages = CreateDummyRecentTabs({1, 2, 3}); 244 std::vector<OfflinePageItem> offline_pages = CreateDummyRecentTabs({1, 2, 3});
245 for (OfflinePageItem& recent_tab : offline_pages) 245 for (OfflinePageItem& recent_tab : offline_pages)
246 AddOfflinePageToModel(recent_tab); 246 AddOfflinePageToModel(recent_tab);
247 247
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 EXPECT_CALL(*observer(), 299 EXPECT_CALL(*observer(),
300 OnNewSuggestions( 300 OnNewSuggestions(
301 _, recent_tabs_category(), 301 _, recent_tabs_category(),
302 UnorderedElementsAre( 302 UnorderedElementsAre(
303 Property(&ContentSuggestion::publish_date, now), 303 Property(&ContentSuggestion::publish_date, now),
304 Property(&ContentSuggestion::publish_date, tomorrow)))); 304 Property(&ContentSuggestion::publish_date, tomorrow))));
305 305
306 AddOfflinePageToModel(offline_pages[2]); 306 AddOfflinePageToModel(offline_pages[2]);
307 } 307 }
308 308
309 TEST_F(RecentTabSuggestionsProviderTest,
310 ShouldNotFetchIfAddedOfflinePageIsNotRecentTab) {
311 // The provider is not notified about the first recent tab yet.
312 model()->mutable_items()->push_back(CreateDummyRecentTab(1));
313 // It should not fetch when not a recent tab is added, thus, it should not
314 // report the first recent tab (which it is not aware about).
315 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0);
316 AddOfflinePageToModel(ntp_snippets::test::CreateDummyOfflinePageItem(
317 2, offline_pages::kDefaultNamespace));
318 }
319
320 TEST_F(RecentTabSuggestionsProviderTest,
321 ShouldFetchIfAddedOfflinePageIsRecentTab) {
322 // The provider is not notified about the first recent tab yet.
323 model()->mutable_items()->push_back(CreateDummyRecentTab(1));
324 // However, it must return the first recent tab (i.e. manually fetch it) even
325 // when notified about a different recent tab.
326 EXPECT_CALL(
327 *observer(),
328 OnNewSuggestions(
329 _, recent_tabs_category(),
330 UnorderedElementsAre(
331 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")),
332 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")))));
333 AddOfflinePageToModel(CreateDummyRecentTab(2));
334 }
335
309 } // namespace ntp_snippets 336 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698