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

Unified Diff: components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc

Issue 2605353004: [NTP::SectionOrder] Preserve added categories on ClearHistory. (Closed)
Patch Set: rebase. 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc
diff --git a/components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc b/components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc
index 8295a6e31e6c12c546ee3dd9348277d6cce05393..0f14faaacf8d094a7ae8eacc0bfad60ea2315065 100644
--- a/components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc
+++ b/components/ntp_snippets/category_rankers/click_based_category_ranker_unittest.cc
@@ -339,4 +339,43 @@ TEST_F(ClickBasedCategoryRankerTest,
EXPECT_FALSE(CompareCategories(first, second));
}
+TEST_F(ClickBasedCategoryRankerTest, ShouldRestoreDefaultOrderOnClearHistory) {
+ std::vector<KnownCategories> default_order =
+ ConstantCategoryRanker::GetKnownCategoriesDefaultOrder();
+ Category first = Category::FromKnownCategory(default_order[0]);
+ Category second = Category::FromKnownCategory(default_order[1]);
+
+ ASSERT_TRUE(CompareCategories(first, second));
+
+ // Change the order.
+ while (CompareCategories(first, second)) {
+ NotifyOnSuggestionOpened(
+ /*times=*/ClickBasedCategoryRanker::GetPassingMargin(), second);
+ }
+
+ ASSERT_FALSE(CompareCategories(first, second));
+
+ // The user clears history.
+ ranker()->ClearHistory(/*begin=*/base::Time(),
+ /*end=*/base::Time::Max());
+
+ // The default order must be restored.
+ EXPECT_TRUE(CompareCategories(first, second));
+}
+
+TEST_F(ClickBasedCategoryRankerTest,
+ ShouldPreserveRemoteCategoriesOnClearHistory) {
+ Category first = AddUnusedRemoteCategory();
+ Category second = AddUnusedRemoteCategory();
+
+ ASSERT_TRUE(CompareCategories(first, second));
+
+ // The user clears history.
+ ranker()->ClearHistory(/*begin=*/base::Time(),
+ /*end=*/base::Time::Max());
+
+ // The order does not matter, but the ranker should not die.
+ CompareCategories(first, second);
+}
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698