Chromium Code Reviews| 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 dbaaed7c62e61ef409cb1adba9e8a3b3b67f7356..9142063e8919643185849f57ec0c6d185902b867 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| +++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| @@ -771,4 +771,78 @@ 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 " |
|
Marc Treib
2016/05/18 15:19:33
Would you mind shortening the long titles/URLs, so
tschumann
2016/05/18 17:09:16
yes indeed. Typically I like to use essentially re
|
| + "years\", " |
| + " \"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-dog-reunites-with-owner/\", " |
| + " \"publisherData\": { " |
| + " \"sourceName\": \"Mashable\", " |
| + " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " |
| + " }, " |
| + " \"ampUrl\": " |
| + "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " |
| + " }, { " |
| + " \"type\": \"CHROME_LOGS\", " |
| + " \"corpusId\": " |
| + "\"http://www.aol.com/article/2016/05/11/stolen-doggie-finally\", " |
| + " \"publisherData\": { " |
| + " \"sourceName\": \"AOL\", " |
| + " \"sourceLogoUrl\": \"http://t2.gstatic.com/images?q=tbn:3\" " |
| + " }, " |
| + " \"ampUrl\": " |
| + "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " |
| + " }, { " |
| + " \"type\": \"CHROME_LOGS\", " |
| + " \"corpusId\": " |
| + " \"http://mashable.com/2016/05/11/stolen-dog-reunites-with-owner/" |
| + "?utm_cid=mash-com-fb-main-link\"," |
| + " \"publisherData\": { " |
| + " \"sourceName\": \"Mashable\", " |
| + " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " |
| + " }, " |
| + " \"ampUrl\": " |
| + "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " |
| + " }] " |
| + " }, " |
| + " \"score\" : \"0.099307865\" " |
| + "}]} "; |
| + |
| +TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) { |
| + const std::string url_mashable = |
| + "http://mashable.com/2016/05/11/stolen-dog-reunites-with-owner"; |
| + const std::string url_aol = |
| + "http://www.aol.com/article/2016/05/11/stolen-doggie-finally"; |
| + |
| + 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 |