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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 1883523002: chrome://snippets-internals page for debugging NTP snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding the chrome://snippets-internals page in the auto-suggest list. Created 4 years, 8 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/ntp_snippets_service_unittest.cc
diff --git a/components/ntp_snippets/ntp_snippets_service_unittest.cc b/components/ntp_snippets/ntp_snippets_service_unittest.cc
index dd58c1b6a2717b1839201336e59a0d1d856858ce..47eef4f88856657fcaf35d74d2c9afc948c1ee84 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -159,6 +159,16 @@ TEST_F(NTPSnippetsServiceTest, Full) {
}
}
+TEST_F(NTPSnippetsServiceTest, Clear) {
+ std::string json_str(GetTestJson());
+
+ LoadFromJSONString(json_str);
+ EXPECT_EQ(service()->size(), 1u);
+
+ service()->ClearSnippets();
+ EXPECT_EQ(service()->size(), 0u);
+}
+
TEST_F(NTPSnippetsServiceTest, Discard) {
std::string json_str(
"{ \"recos\": [ { \"contentInfo\": { \"url\" : \"http://site.com\" }}]}");
@@ -182,6 +192,31 @@ TEST_F(NTPSnippetsServiceTest, Discard) {
CreateSnippetsService();
LoadFromJSONString(json_str);
EXPECT_EQ(0u, service()->size());
+
+ // The snippet can be added again after clearing discarded snippets.
+ service()->ClearDiscardedSnippets();
+ EXPECT_EQ(0u, service()->size());
+ ASSERT_TRUE(LoadFromJSONString(json_str));
+ EXPECT_EQ(1u, service()->size());
+}
+
+TEST_F(NTPSnippetsServiceTest, GetDiscarded) {
+ std::string json_str(
+ "{ \"recos\": [ { \"contentInfo\": { \"url\" : \"http://site.com\" }}]}");
+ LoadFromJSONString(json_str);
+
+ // For the test, we need the snippet to get discarded.
+ ASSERT_TRUE(service()->DiscardSnippet(GURL("http://site.com")));
+ const NTPSnippetsService::NTPSnippetStorage& snippets =
+ service()->GetDiscardedSnippets();
+ EXPECT_EQ(1u, snippets.size());
+ for (auto& snippet : snippets) {
+ EXPECT_EQ(GURL("http://site.com"), snippet->url());
+ }
+
+ // There should be no discarded snippet after clearing the list.
+ service()->ClearDiscardedSnippets();
+ EXPECT_EQ(0u, service()->GetDiscardedSnippets().size());
}
TEST_F(NTPSnippetsServiceTest, CreationTimestampParseFail) {

Powered by Google App Engine
This is Rietveld 408576698