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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 1992803002: Use multiple IDs when discarding or merging snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 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 678fa81da66f669f74de533a464e8fffcd495adb..cf723f4662d4da1855bda4381b22c046b99108a4 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -776,4 +776,70 @@ TEST_F(NTPSnippetsServiceTest, LogNumArticlesHistogram) {
CreateSnippetsService(/*enabled=*/true);
tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4);
}
+
+const char kChromeReaderResponseMultipleUrls[] =
+ "{ \"recos\": [{ "
+ " \"contentInfo\": { "
+ " \"url\": \"%s\", "
+ " \"creationTimestampSec\": \"%s\", "
+ " \"expiryTimestampSec\" : \"%s\","
+ " \"title\": \"Stolen doggie finally gets returned to owner after two "
+ "years\", "
Marc Treib 2016/05/18 18:58:05 One more avoidable line break :)
tschumann 2016/05/18 19:23:29 Done.
+ " \"snippet\": \"It\'s at least this man\'s best friend.\", "
+ " \"thumbnailUrl\": \"http://t0.gstatic.com/images?q=tbn:1\", "
+ " \"sourceCorpusInfo\": [{"
+ " \"type\" : \"CHROME_LOGS\", "
+ " \"corpusId\": \"http://mashable.com/2016/05/11/stolen\", "
+ " \"publisherData\": { "
+ " \"sourceName\": \"Mashable\", "
+ " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" "
+ " }, "
+ " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" "
+ " }, { "
+ " \"type\": \"CHROME_LOGS\", "
+ " \"corpusId\": \"http://www.aol.com/article/2016/05/stolen-doggie\", "
+ " \"publisherData\": { "
+ " \"sourceName\": \"AOL\", "
+ " \"sourceLogoUrl\": \"http://t2.gstatic.com/images?q=tbn:3\" "
+ " }, "
+ " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" "
+ " }, { "
+ " \"type\": \"CHROME_LOGS\", "
+ " \"corpusId\": \"http://mashable.com/2016/05/11/stolen?utm_cid=1\", "
+ " \"publisherData\": { "
+ " \"sourceName\": \"Mashable\", "
+ " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" "
+ " }, "
+ " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" "
+ " }] "
+ " }, "
+ " \"score\" : \"0.099307865\" "
+ "}]} ";
+
+TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) {
+ const std::string url_mashable = "http://mashable.com/2016/05/11/stolen";
+ const std::string url_aol =
+ "http://www.aol.com/article/2016/05/stolen-doggie";
+
+ LoadFromJSONString(base::StringPrintf(
+ kChromeReaderResponseMultipleUrls, url_mashable.c_str(),
+ NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
+ NTPSnippet::TimeToJsonString(base::Time::Now() +
+ base::TimeDelta::FromHours(1))
+ .c_str()));
+ ASSERT_THAT(service()->snippets(), SizeIs(1));
+ // Discard the snippet via the mashable source corpus ID.
+ EXPECT_TRUE(service()->DiscardSnippet(url_mashable));
+ EXPECT_THAT(service()->snippets(), IsEmpty());
+
+ // The same article from the AOL domain should now be detected as discarded.
+ LoadFromJSONString(base::StringPrintf(
+ kChromeReaderResponseMultipleUrls, url_aol.c_str(),
+ NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
+ NTPSnippet::TimeToJsonString(base::Time::Now() +
+ base::TimeDelta::FromHours(1))
+ .c_str()));
+ ASSERT_THAT(service()->snippets(), IsEmpty());
+}
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698