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

Side by Side Diff: components/ntp_snippets/content_suggestions_service_unittest.cc

Issue 2277743002: [NTP Snippets] Always show the bookmarks section, but at the end if it's empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_proguard
Patch Set: fix Linux debug build Created 4 years, 3 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/content_suggestions_service.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/content_suggestions_service.h" 5 #include "components/ntp_snippets/content_suggestions_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 providers() { 171 providers() {
172 return service()->providers_by_category_; 172 return service()->providers_by_category_;
173 } 173 }
174 174
175 CategoryFactory* category_factory() { return service()->category_factory(); } 175 CategoryFactory* category_factory() { return service()->category_factory(); }
176 176
177 Category FromKnownCategory(KnownCategories known_category) { 177 Category FromKnownCategory(KnownCategories known_category) {
178 return service()->category_factory()->FromKnownCategory(known_category); 178 return service()->category_factory()->FromKnownCategory(known_category);
179 } 179 }
180 180
181 Category FromRemoteCategory(int remote_category) {
182 return service()->category_factory()->FromRemoteCategory(remote_category);
183 }
184
181 MockProvider* RegisterProvider(Category provided_category) { 185 MockProvider* RegisterProvider(Category provided_category) {
182 return RegisterProvider(std::vector<Category>({provided_category})); 186 return RegisterProvider(std::vector<Category>({provided_category}));
183 } 187 }
184 188
185 MockProvider* RegisterProvider( 189 MockProvider* RegisterProvider(
186 const std::vector<Category>& provided_categories) { 190 const std::vector<Category>& provided_categories) {
187 std::unique_ptr<MockProvider> provider = base::MakeUnique<MockProvider>( 191 std::unique_ptr<MockProvider> provider = base::MakeUnique<MockProvider>(
188 service(), category_factory(), provided_categories); 192 service(), category_factory(), provided_categories);
189 MockProvider* result = provider.get(); 193 MockProvider* result = provider.get();
190 service()->RegisterProvider(std::move(provider)); 194 service()->RegisterProvider(std::move(provider));
(...skipping 24 matching lines...) Expand all
215 void SetUp() override { 219 void SetUp() override {
216 CreateContentSuggestionsService(ContentSuggestionsService::State::DISABLED); 220 CreateContentSuggestionsService(ContentSuggestionsService::State::DISABLED);
217 } 221 }
218 }; 222 };
219 223
220 TEST_F(ContentSuggestionsServiceTest, ShouldRegisterProviders) { 224 TEST_F(ContentSuggestionsServiceTest, ShouldRegisterProviders) {
221 EXPECT_THAT(service()->state(), 225 EXPECT_THAT(service()->state(),
222 Eq(ContentSuggestionsService::State::ENABLED)); 226 Eq(ContentSuggestionsService::State::ENABLED));
223 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 227 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
224 Category offline_pages_category = 228 Category offline_pages_category =
225 FromKnownCategory(KnownCategories::BOOKMARKS); 229 FromKnownCategory(KnownCategories::DOWNLOADS);
226 ASSERT_THAT(providers(), IsEmpty()); 230 ASSERT_THAT(providers(), IsEmpty());
227 EXPECT_THAT(service()->GetCategories(), IsEmpty()); 231 EXPECT_THAT(service()->GetCategories(), IsEmpty());
228 EXPECT_THAT(service()->GetCategoryStatus(articles_category), 232 EXPECT_THAT(service()->GetCategoryStatus(articles_category),
229 Eq(CategoryStatus::NOT_PROVIDED)); 233 Eq(CategoryStatus::NOT_PROVIDED));
230 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category), 234 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category),
231 Eq(CategoryStatus::NOT_PROVIDED)); 235 Eq(CategoryStatus::NOT_PROVIDED));
232 236
233 MockProvider* provider1 = RegisterProvider(articles_category); 237 MockProvider* provider1 = RegisterProvider(articles_category);
234 provider1->FireCategoryStatusChangedWithCurrentStatus(articles_category); 238 provider1->FireCategoryStatusChangedWithCurrentStatus(articles_category);
235 EXPECT_THAT(providers().count(offline_pages_category), Eq(0ul)); 239 EXPECT_THAT(providers().count(offline_pages_category), Eq(0ul));
(...skipping 17 matching lines...) Expand all
253 ElementsAre(offline_pages_category, articles_category)); 257 ElementsAre(offline_pages_category, articles_category));
254 EXPECT_THAT(service()->GetCategoryStatus(articles_category), 258 EXPECT_THAT(service()->GetCategoryStatus(articles_category),
255 Eq(CategoryStatus::AVAILABLE)); 259 Eq(CategoryStatus::AVAILABLE));
256 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category), 260 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category),
257 Eq(CategoryStatus::AVAILABLE)); 261 Eq(CategoryStatus::AVAILABLE));
258 } 262 }
259 263
260 TEST_F(ContentSuggestionsServiceDisabledTest, ShouldDoNothingWhenDisabled) { 264 TEST_F(ContentSuggestionsServiceDisabledTest, ShouldDoNothingWhenDisabled) {
261 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 265 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
262 Category offline_pages_category = 266 Category offline_pages_category =
263 FromKnownCategory(KnownCategories::BOOKMARKS); 267 FromKnownCategory(KnownCategories::DOWNLOADS);
264 EXPECT_THAT(service()->state(), 268 EXPECT_THAT(service()->state(),
265 Eq(ContentSuggestionsService::State::DISABLED)); 269 Eq(ContentSuggestionsService::State::DISABLED));
266 EXPECT_THAT(providers(), IsEmpty()); 270 EXPECT_THAT(providers(), IsEmpty());
267 EXPECT_THAT(service()->GetCategoryStatus(articles_category), 271 EXPECT_THAT(service()->GetCategoryStatus(articles_category),
268 Eq(CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED)); 272 Eq(CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED));
269 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category), 273 EXPECT_THAT(service()->GetCategoryStatus(offline_pages_category),
270 Eq(CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED)); 274 Eq(CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED));
271 EXPECT_THAT(service()->GetCategories(), IsEmpty()); 275 EXPECT_THAT(service()->GetCategories(), IsEmpty());
272 EXPECT_THAT(service()->GetSuggestionsForCategory(articles_category), 276 EXPECT_THAT(service()->GetSuggestionsForCategory(articles_category),
273 IsEmpty()); 277 IsEmpty());
274 } 278 }
275 279
276 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectFetchSuggestionImage) { 280 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectFetchSuggestionImage) {
277 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 281 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
278 Category offline_pages_category = 282 Category offline_pages_category =
279 FromKnownCategory(KnownCategories::BOOKMARKS); 283 FromKnownCategory(KnownCategories::DOWNLOADS);
280 MockProvider* provider1 = RegisterProvider(articles_category); 284 MockProvider* provider1 = RegisterProvider(articles_category);
281 MockProvider* provider2 = RegisterProvider(offline_pages_category); 285 MockProvider* provider2 = RegisterProvider(offline_pages_category);
282 286
283 provider1->FireSuggestionsChanged(articles_category, {1}); 287 provider1->FireSuggestionsChanged(articles_category, {1});
284 std::string suggestion_id = CreateSuggestion(1).id(); 288 std::string suggestion_id = CreateSuggestion(1).id();
285 289
286 EXPECT_CALL(*provider1, FetchSuggestionImage(suggestion_id, _)); 290 EXPECT_CALL(*provider1, FetchSuggestionImage(suggestion_id, _));
287 EXPECT_CALL(*provider2, FetchSuggestionImage(_, _)).Times(0); 291 EXPECT_CALL(*provider2, FetchSuggestionImage(_, _)).Times(0);
288 service()->FetchSuggestionImage( 292 service()->FetchSuggestionImage(
289 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, 293 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
(...skipping 12 matching lines...) Expand all
302 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 306 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
303 service()->FetchSuggestionImage( 307 service()->FetchSuggestionImage(
304 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched, 308 suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
305 base::Unretained(this))); 309 base::Unretained(this)));
306 run_loop.Run(); 310 run_loop.Run();
307 } 311 }
308 312
309 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) { 313 TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) {
310 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 314 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
311 Category offline_pages_category = 315 Category offline_pages_category =
312 FromKnownCategory(KnownCategories::BOOKMARKS); 316 FromKnownCategory(KnownCategories::DOWNLOADS);
313 MockProvider* provider1 = RegisterProvider(articles_category); 317 MockProvider* provider1 = RegisterProvider(articles_category);
314 MockProvider* provider2 = RegisterProvider(offline_pages_category); 318 MockProvider* provider2 = RegisterProvider(offline_pages_category);
315 319
316 provider2->FireSuggestionsChanged(offline_pages_category, {11}); 320 provider2->FireSuggestionsChanged(offline_pages_category, {11});
317 std::string suggestion_id = CreateSuggestion(11).id(); 321 std::string suggestion_id = CreateSuggestion(11).id();
318 322
319 EXPECT_CALL(*provider1, DismissSuggestion(_)).Times(0); 323 EXPECT_CALL(*provider1, DismissSuggestion(_)).Times(0);
320 EXPECT_CALL(*provider2, DismissSuggestion(suggestion_id)); 324 EXPECT_CALL(*provider2, DismissSuggestion(suggestion_id));
321 service()->DismissSuggestion(suggestion_id); 325 service()->DismissSuggestion(suggestion_id);
322 } 326 }
(...skipping 23 matching lines...) Expand all
346 provider->FireSuggestionInvalidated(articles_category, unknown_id); 350 provider->FireSuggestionInvalidated(articles_category, unknown_id);
347 ExpectThatSuggestionsAre(articles_category, {11, 13}); 351 ExpectThatSuggestionsAre(articles_category, {11, 13});
348 Mock::VerifyAndClearExpectations(&observer); 352 Mock::VerifyAndClearExpectations(&observer);
349 353
350 service()->RemoveObserver(&observer); 354 service()->RemoveObserver(&observer);
351 } 355 }
352 356
353 TEST_F(ContentSuggestionsServiceTest, ShouldForwardSuggestions) { 357 TEST_F(ContentSuggestionsServiceTest, ShouldForwardSuggestions) {
354 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES); 358 Category articles_category = FromKnownCategory(KnownCategories::ARTICLES);
355 Category offline_pages_category = 359 Category offline_pages_category =
356 FromKnownCategory(KnownCategories::BOOKMARKS); 360 FromKnownCategory(KnownCategories::DOWNLOADS);
357 361
358 // Create and register providers 362 // Create and register providers
359 MockProvider* provider1 = RegisterProvider(articles_category); 363 MockProvider* provider1 = RegisterProvider(articles_category);
360 provider1->FireCategoryStatusChangedWithCurrentStatus(articles_category); 364 provider1->FireCategoryStatusChangedWithCurrentStatus(articles_category);
361 MockProvider* provider2 = RegisterProvider(offline_pages_category); 365 MockProvider* provider2 = RegisterProvider(offline_pages_category);
362 provider2->FireCategoryStatusChangedWithCurrentStatus(offline_pages_category); 366 provider2->FireCategoryStatusChangedWithCurrentStatus(offline_pages_category);
363 ASSERT_THAT(providers().count(articles_category), Eq(1ul)); 367 ASSERT_THAT(providers().count(articles_category), Eq(1ul));
364 EXPECT_THAT(providers().at(articles_category), Eq(provider1)); 368 EXPECT_THAT(providers().at(articles_category), Eq(provider1));
365 ASSERT_THAT(providers().count(offline_pages_category), Eq(1ul)); 369 ASSERT_THAT(providers().count(offline_pages_category), Eq(1ul));
366 EXPECT_THAT(providers().at(offline_pages_category), Eq(provider2)); 370 EXPECT_THAT(providers().at(offline_pages_category), Eq(provider2));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 416
413 // Shutdown the service 417 // Shutdown the service
414 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown()); 418 EXPECT_CALL(observer, ContentSuggestionsServiceShutdown());
415 service()->Shutdown(); 419 service()->Shutdown();
416 service()->RemoveObserver(&observer); 420 service()->RemoveObserver(&observer);
417 // The service will receive two Shutdown() calls. 421 // The service will receive two Shutdown() calls.
418 } 422 }
419 423
420 TEST_F(ContentSuggestionsServiceTest, 424 TEST_F(ContentSuggestionsServiceTest,
421 ShouldNotReturnCategoryInfoForNonexistentCategory) { 425 ShouldNotReturnCategoryInfoForNonexistentCategory) {
422 Category category = FromKnownCategory(KnownCategories::BOOKMARKS); 426 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
423 base::Optional<CategoryInfo> result = service()->GetCategoryInfo(category); 427 base::Optional<CategoryInfo> result = service()->GetCategoryInfo(category);
424 EXPECT_FALSE(result.has_value()); 428 EXPECT_FALSE(result.has_value());
425 } 429 }
426 430
427 TEST_F(ContentSuggestionsServiceTest, ShouldReturnCategoryInfo) { 431 TEST_F(ContentSuggestionsServiceTest, ShouldReturnCategoryInfo) {
428 Category category = FromKnownCategory(KnownCategories::BOOKMARKS); 432 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
429 MockProvider* provider = RegisterProvider(category); 433 MockProvider* provider = RegisterProvider(category);
430 provider->FireCategoryStatusChangedWithCurrentStatus(category); 434 provider->FireCategoryStatusChangedWithCurrentStatus(category);
431 base::Optional<CategoryInfo> result = service()->GetCategoryInfo(category); 435 base::Optional<CategoryInfo> result = service()->GetCategoryInfo(category);
432 ASSERT_TRUE(result.has_value()); 436 ASSERT_TRUE(result.has_value());
433 CategoryInfo expected = provider->GetCategoryInfo(category); 437 CategoryInfo expected = provider->GetCategoryInfo(category);
434 const CategoryInfo& actual = result.value(); 438 const CategoryInfo& actual = result.value();
435 EXPECT_THAT(expected.title(), Eq(actual.title())); 439 EXPECT_THAT(expected.title(), Eq(actual.title()));
436 EXPECT_THAT(expected.card_layout(), Eq(actual.card_layout())); 440 EXPECT_THAT(expected.card_layout(), Eq(actual.card_layout()));
437 EXPECT_THAT(expected.has_more_button(), Eq(actual.has_more_button())); 441 EXPECT_THAT(expected.has_more_button(), Eq(actual.has_more_button()));
438 } 442 }
439 443
440 TEST_F(ContentSuggestionsServiceTest, 444 TEST_F(ContentSuggestionsServiceTest,
441 ShouldRegisterNewCategoryOnNewSuggestions) { 445 ShouldRegisterNewCategoryOnNewSuggestions) {
442 Category category = FromKnownCategory(KnownCategories::BOOKMARKS); 446 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
443 MockProvider* provider = RegisterProvider(category); 447 MockProvider* provider = RegisterProvider(category);
444 provider->FireCategoryStatusChangedWithCurrentStatus(category); 448 provider->FireCategoryStatusChangedWithCurrentStatus(category);
445 MockServiceObserver observer; 449 MockServiceObserver observer;
446 service()->AddObserver(&observer); 450 service()->AddObserver(&observer);
447 451
448 // Provider starts providing |new_category| without calling 452 // Provider starts providing |new_category| without calling
449 // |OnCategoryStatusChanged|. This is supported for now until further 453 // |OnCategoryStatusChanged|. This is supported for now until further
450 // reconsideration. 454 // reconsideration.
451 Category new_category = FromKnownCategory(KnownCategories::ARTICLES); 455 Category new_category = FromKnownCategory(KnownCategories::ARTICLES);
452 provider->SetProvidedCategories( 456 provider->SetProvidedCategories(
(...skipping 12 matching lines...) Expand all
465 ASSERT_THAT(providers().count(new_category), Eq(1ul)); 469 ASSERT_THAT(providers().count(new_category), Eq(1ul));
466 EXPECT_THAT(providers().at(new_category), Eq(provider)); 470 EXPECT_THAT(providers().at(new_category), Eq(provider));
467 EXPECT_THAT(service()->GetCategoryStatus(new_category), 471 EXPECT_THAT(service()->GetCategoryStatus(new_category),
468 Eq(CategoryStatus::AVAILABLE)); 472 Eq(CategoryStatus::AVAILABLE));
469 473
470 service()->RemoveObserver(&observer); 474 service()->RemoveObserver(&observer);
471 } 475 }
472 476
473 TEST_F(ContentSuggestionsServiceTest, 477 TEST_F(ContentSuggestionsServiceTest,
474 ShouldRegisterNewCategoryOnCategoryStatusChanged) { 478 ShouldRegisterNewCategoryOnCategoryStatusChanged) {
475 Category category = FromKnownCategory(KnownCategories::BOOKMARKS); 479 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
476 MockProvider* provider = RegisterProvider(category); 480 MockProvider* provider = RegisterProvider(category);
477 provider->FireCategoryStatusChangedWithCurrentStatus(category); 481 provider->FireCategoryStatusChangedWithCurrentStatus(category);
478 MockServiceObserver observer; 482 MockServiceObserver observer;
479 service()->AddObserver(&observer); 483 service()->AddObserver(&observer);
480 484
481 // Provider starts providing |new_category| and calls 485 // Provider starts providing |new_category| and calls
482 // |OnCategoryStatusChanged|, but the category is not yet available. 486 // |OnCategoryStatusChanged|, but the category is not yet available.
483 Category new_category = FromKnownCategory(KnownCategories::ARTICLES); 487 Category new_category = FromKnownCategory(KnownCategories::ARTICLES);
484 provider->SetProvidedCategories( 488 provider->SetProvidedCategories(
485 std::vector<Category>({category, new_category})); 489 std::vector<Category>({category, new_category}));
486 EXPECT_CALL(observer, OnCategoryStatusChanged(new_category, 490 EXPECT_CALL(observer, OnCategoryStatusChanged(new_category,
487 CategoryStatus::INITIALIZING)); 491 CategoryStatus::INITIALIZING));
488 provider->FireCategoryStatusChanged(new_category, 492 provider->FireCategoryStatusChanged(new_category,
489 CategoryStatus::INITIALIZING); 493 CategoryStatus::INITIALIZING);
490 494
491 ASSERT_THAT(providers().count(new_category), Eq(1ul)); 495 ASSERT_THAT(providers().count(new_category), Eq(1ul));
492 EXPECT_THAT(providers().at(new_category), Eq(provider)); 496 EXPECT_THAT(providers().at(new_category), Eq(provider));
493 ExpectThatSuggestionsAre(new_category, std::vector<int>()); 497 ExpectThatSuggestionsAre(new_category, std::vector<int>());
494 EXPECT_THAT(service()->GetCategoryStatus(new_category), 498 EXPECT_THAT(service()->GetCategoryStatus(new_category),
495 Eq(CategoryStatus::INITIALIZING)); 499 Eq(CategoryStatus::INITIALIZING));
496 EXPECT_THAT(service()->GetCategories(), 500 EXPECT_THAT(service()->GetCategories(),
497 Eq(std::vector<Category>({category, new_category}))); 501 Eq(std::vector<Category>({category, new_category})));
498 502
499 service()->RemoveObserver(&observer); 503 service()->RemoveObserver(&observer);
500 } 504 }
501 505
502 TEST_F(ContentSuggestionsServiceTest, ShouldRemoveCategoryWhenNotProvided) { 506 TEST_F(ContentSuggestionsServiceTest, ShouldRemoveCategoryWhenNotProvided) {
503 Category category = FromKnownCategory(KnownCategories::BOOKMARKS); 507 Category category = FromKnownCategory(KnownCategories::DOWNLOADS);
504 MockProvider* provider = RegisterProvider(category); 508 MockProvider* provider = RegisterProvider(category);
505 MockServiceObserver observer; 509 MockServiceObserver observer;
506 service()->AddObserver(&observer); 510 service()->AddObserver(&observer);
507 511
508 provider->FireSuggestionsChanged(category, {1, 2}); 512 provider->FireSuggestionsChanged(category, {1, 2});
509 ExpectThatSuggestionsAre(category, {1, 2}); 513 ExpectThatSuggestionsAre(category, {1, 2});
510 514
511 EXPECT_CALL(observer, 515 EXPECT_CALL(observer,
512 OnCategoryStatusChanged(category, CategoryStatus::NOT_PROVIDED)); 516 OnCategoryStatusChanged(category, CategoryStatus::NOT_PROVIDED));
513 provider->FireCategoryStatusChanged(category, CategoryStatus::NOT_PROVIDED); 517 provider->FireCategoryStatusChanged(category, CategoryStatus::NOT_PROVIDED);
514 518
515 EXPECT_THAT(service()->GetCategoryStatus(category), 519 EXPECT_THAT(service()->GetCategoryStatus(category),
516 Eq(CategoryStatus::NOT_PROVIDED)); 520 Eq(CategoryStatus::NOT_PROVIDED));
517 EXPECT_TRUE(service()->GetCategories().empty()); 521 EXPECT_TRUE(service()->GetCategories().empty());
518 ExpectThatSuggestionsAre(category, std::vector<int>()); 522 ExpectThatSuggestionsAre(category, std::vector<int>());
519 523
520 service()->RemoveObserver(&observer); 524 service()->RemoveObserver(&observer);
521 } 525 }
522 526
527 // This tests the temporary special-casing of the bookmarks section: If it is
528 // empty, it should appear at the end; see crbug.com/640568.
529 TEST_F(ContentSuggestionsServiceTest, ShouldPutBookmarksAtEndIfEmpty) {
530 // Register a bookmarks provider and an arbitrary remote provider.
531 Category bookmarks = FromKnownCategory(KnownCategories::BOOKMARKS);
532 MockProvider* bookmarks_provider = RegisterProvider(bookmarks);
533 bookmarks_provider->FireCategoryStatusChangedWithCurrentStatus(bookmarks);
534 Category remote = FromRemoteCategory(123);
535 MockProvider* remote_provider = RegisterProvider(remote);
536 remote_provider->FireCategoryStatusChangedWithCurrentStatus(remote);
537
538 // By default, the bookmarks category is empty, so it should be at the end.
539 EXPECT_THAT(service()->GetCategories(), ElementsAre(remote, bookmarks));
540
541 // Add two bookmark suggestions; now bookmarks should be in the front.
542 bookmarks_provider->FireSuggestionsChanged(bookmarks, {1, 2});
543 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
544 // Dismiss the first suggestion; bookmarks should stay in the front.
545 service()->DismissSuggestion(CreateSuggestion(1).id());
546 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
547 // Dismiss the second suggestion; now bookmarks should go back to the end.
548 service()->DismissSuggestion(CreateSuggestion(2).id());
549 EXPECT_THAT(service()->GetCategories(), ElementsAre(remote, bookmarks));
550
551 // Same thing, but invalidate instead of dismissing.
552 bookmarks_provider->FireSuggestionsChanged(bookmarks, {1, 2});
553 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
554 bookmarks_provider->FireSuggestionInvalidated(bookmarks,
555 CreateSuggestion(1).id());
556 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
557 bookmarks_provider->FireSuggestionInvalidated(bookmarks,
558 CreateSuggestion(2).id());
559 EXPECT_THAT(service()->GetCategories(), ElementsAre(remote, bookmarks));
560
561 // Same thing, but now the bookmarks category updates "naturally".
562 bookmarks_provider->FireSuggestionsChanged(bookmarks, {1, 2});
563 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
564 bookmarks_provider->FireSuggestionsChanged(bookmarks, {1});
565 EXPECT_THAT(service()->GetCategories(), ElementsAre(bookmarks, remote));
566 bookmarks_provider->FireSuggestionsChanged(bookmarks, std::vector<int>());
567 EXPECT_THAT(service()->GetCategories(), ElementsAre(remote, bookmarks));
568 }
569
523 } // namespace ntp_snippets 570 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698