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

Unified Diff: components/ntp_snippets/content_suggestions_service_unittest.cc

Issue 2400783003: Ntp: show AllDismissedItem when all sections have been dismissed. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/content_suggestions_service_unittest.cc
diff --git a/components/ntp_snippets/content_suggestions_service_unittest.cc b/components/ntp_snippets/content_suggestions_service_unittest.cc
index a2245bfd6cbe91ea5bae71ae8abed3cff4320fd8..71de5fb68f21cd7c3a1492e51088869397f59642 100644
--- a/components/ntp_snippets/content_suggestions_service_unittest.cc
+++ b/components/ntp_snippets/content_suggestions_service_unittest.cc
@@ -164,6 +164,11 @@ class ContentSuggestionsServiceTest : public testing::Test {
return service()->providers_by_category_;
}
+ const std::map<Category, ContentSuggestionsProvider*, Category::CompareByID>&
+ dismissed_providers() {
+ return service()->dismissed_providers_by_category_;
+ }
+
CategoryFactory* category_factory() { return service()->category_factory(); }
Category FromKnownCategory(KnownCategories known_category) {
@@ -601,4 +606,40 @@ TEST_F(ContentSuggestionsServiceTest, ShouldForwardClearHistory) {
service()->ClearHistory(begin, end, filter);
}
+TEST_F(ContentSuggestionsServiceTest, DismissAndRestoreCategory) {
+ // Register a category with one suggestion.
+ Category category = FromKnownCategory(KnownCategories::ARTICLES);
+ MockProvider* provider = RegisterProvider(category);
+ provider->FireCategoryStatusChangedWithCurrentStatus(category);
+ provider->FireSuggestionsChanged(category, CreateSuggestions(category, {42}));
+
+ EXPECT_THAT(service()->GetCategories(), ElementsAre(category));
+ EXPECT_THAT(service()->GetCategoryStatus(category),
+ Eq(CategoryStatus::AVAILABLE));
+ ExpectThatSuggestionsAre(category, {42});
+ EXPECT_THAT(providers().count(category), Eq(1ul));
+ EXPECT_THAT(dismissed_providers(), IsEmpty());
+
+ // Dismissing the category clears the suggestions for it.
+ service()->DismissCategory(category);
+
+ EXPECT_THAT(service()->GetCategories(), IsEmpty());
+ EXPECT_THAT(service()->GetCategoryStatus(category),
+ Eq(CategoryStatus::NOT_PROVIDED));
+ EXPECT_THAT(service()->GetSuggestionsForCategory(category), IsEmpty());
+ EXPECT_THAT(providers(), IsEmpty());
+ EXPECT_THAT(dismissed_providers().count(category), Eq(1ul));
+
+ // Restoring the dismissed category makes it available again but it is still
+ // empty.
+ service()->RestoreDismissedCategories();
+
+ EXPECT_THAT(service()->GetCategories(), ElementsAre(category));
+ EXPECT_THAT(service()->GetCategoryStatus(category),
+ Eq(CategoryStatus::AVAILABLE));
+ EXPECT_THAT(service()->GetSuggestionsForCategory(category), IsEmpty());
+ EXPECT_THAT(providers().count(category), Eq(1ul));
+ EXPECT_THAT(dismissed_providers(), IsEmpty());
+}
+
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698