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

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: fixed new tests (they didn't expect de-duping based on corpus-ids.). 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
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..797759b77f88767ea2a0aa0b2707a32eb97b3a3e 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -335,32 +335,34 @@ TEST_F(NTPSnippetsServiceTest, InsertAtFront) {
"\"thumbnailUrl\" : \"http://localhost/salient_image\","
"\"creationTimestampSec\" : \"%s\","
"\"expiryTimestampSec\" : \"%s\","
- "\"sourceCorpusInfo\" : [{\"corpusId\": \"http://first\","
+ "\"sourceCorpusInfo\" : [{\"corpusId\": \"%s\","
"\"publisherData\": {"
"\"sourceName\": \"Source 1\""
"},"
"\"ampUrl\": \"\"}]"
"}}"
"]}";
+ const std::string first_url = "http://first";
std::string json_str(base::StringPrintf(
- json_str_format, "http://first",
+ json_str_format, first_url.c_str(),
NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
- NTPSnippet::TimeToJsonString(expiry_time).c_str()));
+ NTPSnippet::TimeToJsonString(expiry_time).c_str(), first_url.c_str()));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->snippets(), ElementsAre(IdEq("http://first")));
+ EXPECT_THAT(service()->snippets(), ElementsAre(IdEq(first_url)));
+ const std::string second_url = "http://second";
json_str = base::StringPrintf(
- json_str_format, "http://second",
+ json_str_format, second_url.c_str(),
NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
- NTPSnippet::TimeToJsonString(expiry_time).c_str());
+ NTPSnippet::TimeToJsonString(expiry_time).c_str(), second_url.c_str());
LoadFromJSONString(json_str);
// The snippet loaded last should be at the first position in the list now.
EXPECT_THAT(service()->snippets(),
- ElementsAre(IdEq("http://second"), IdEq("http://first")));
+ ElementsAre(IdEq(second_url), IdEq(first_url)));
}
TEST_F(NTPSnippetsServiceTest, LimitNumSnippets) {
@@ -376,7 +378,7 @@ TEST_F(NTPSnippetsServiceTest, LimitNumSnippets) {
"\"thumbnailUrl\" : \"http://localhost/salient_image\","
"\"creationTimestampSec\" : \"%s\","
"\"expiryTimestampSec\" : \"%s\","
- "\"sourceCorpusInfo\" : [{\"corpusId\": \"http://first\","
+ "\"sourceCorpusInfo\" : [{\"corpusId\": \"http://localhost/%i\","
"\"publisherData\": {"
"\"sourceName\": \"Source 1\""
"},"
@@ -389,11 +391,13 @@ TEST_F(NTPSnippetsServiceTest, LimitNumSnippets) {
snippets1.push_back(base::StringPrintf(
json_str_format, i,
NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
- NTPSnippet::TimeToJsonString(expiry_time).c_str()));
+ NTPSnippet::TimeToJsonString(expiry_time).c_str(), i /* for corpusId */
+ ));
snippets2.push_back(base::StringPrintf(
json_str_format, snippets_per_load + i,
NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
- NTPSnippet::TimeToJsonString(expiry_time).c_str()));
+ NTPSnippet::TimeToJsonString(expiry_time).c_str(),
+ snippets_per_load + i /* for corpusId */));
}
LoadFromJSONString(
@@ -776,4 +780,69 @@ 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\", "
+ " \"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
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698