Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/ntp_snippets/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 base::Bucket(/*min=*/1, /*count=*/3))); | 764 base::Bucket(/*min=*/1, /*count=*/3))); |
| 765 EXPECT_THAT( | 765 EXPECT_THAT( |
| 766 tester.GetAllSamples("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded"), | 766 tester.GetAllSamples("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded"), |
| 767 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | 767 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
| 768 // Recreating the service and loading from prefs shouldn't count as fetched | 768 // Recreating the service and loading from prefs shouldn't count as fetched |
| 769 // articles. | 769 // articles. |
| 770 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1); | 770 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1); |
| 771 CreateSnippetsService(/*enabled=*/true); | 771 CreateSnippetsService(/*enabled=*/true); |
| 772 tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4); | 772 tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4); |
| 773 } | 773 } |
| 774 | |
| 775 const char kChromeReaderResponseMultipleUrls[] = | |
| 776 "{ \"recos\": [{ " | |
| 777 " \"contentInfo\": { " | |
| 778 " \"url\": \"%s\", " | |
| 779 " \"creationTimestampSec\": \"%s\", " | |
| 780 " \"expiryTimestampSec\" : \"%s\"," | |
| 781 " \"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
| |
| 782 "years\", " | |
| 783 " \"snippet\": \"It\'s at least this man\'s best friend.\", " | |
| 784 " \"thumbnailUrl\": \"http://t0.gstatic.com/images?q=tbn:1\", " | |
| 785 " \"sourceCorpusInfo\": [{" | |
| 786 " \"type\" : \"CHROME_LOGS\", " | |
| 787 " \"corpusId\": " | |
| 788 "\"http://mashable.com/2016/05/11/stolen-dog-reunites-with-owner/\", " | |
| 789 " \"publisherData\": { " | |
| 790 " \"sourceName\": \"Mashable\", " | |
| 791 " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " | |
| 792 " }, " | |
| 793 " \"ampUrl\": " | |
| 794 "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " | |
| 795 " }, { " | |
| 796 " \"type\": \"CHROME_LOGS\", " | |
| 797 " \"corpusId\": " | |
| 798 "\"http://www.aol.com/article/2016/05/11/stolen-doggie-finally\", " | |
| 799 " \"publisherData\": { " | |
| 800 " \"sourceName\": \"AOL\", " | |
| 801 " \"sourceLogoUrl\": \"http://t2.gstatic.com/images?q=tbn:3\" " | |
| 802 " }, " | |
| 803 " \"ampUrl\": " | |
| 804 "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " | |
| 805 " }, { " | |
| 806 " \"type\": \"CHROME_LOGS\", " | |
| 807 " \"corpusId\": " | |
| 808 " \"http://mashable.com/2016/05/11/stolen-dog-reunites-with-owner/" | |
| 809 "?utm_cid=mash-com-fb-main-link\"," | |
| 810 " \"publisherData\": { " | |
| 811 " \"sourceName\": \"Mashable\", " | |
| 812 " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " | |
| 813 " }, " | |
| 814 " \"ampUrl\": " | |
| 815 "\"http://mashable-amphtml.googleusercontent.com/amphtml/1\" " | |
| 816 " }] " | |
| 817 " }, " | |
| 818 " \"score\" : \"0.099307865\" " | |
| 819 "}]} "; | |
| 820 | |
| 821 TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) { | |
| 822 const std::string url_mashable = | |
| 823 "http://mashable.com/2016/05/11/stolen-dog-reunites-with-owner"; | |
| 824 const std::string url_aol = | |
| 825 "http://www.aol.com/article/2016/05/11/stolen-doggie-finally"; | |
| 826 | |
| 827 LoadFromJSONString(base::StringPrintf( | |
| 828 kChromeReaderResponseMultipleUrls, url_mashable.c_str(), | |
| 829 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(), | |
| 830 NTPSnippet::TimeToJsonString(base::Time::Now() + | |
| 831 base::TimeDelta::FromHours(1)) | |
| 832 .c_str())); | |
| 833 ASSERT_THAT(service()->snippets(), SizeIs(1)); | |
| 834 // Discard the snippet via the mashable source corpus ID. | |
| 835 EXPECT_TRUE(service()->DiscardSnippet(url_mashable)); | |
| 836 EXPECT_THAT(service()->snippets(), IsEmpty()); | |
| 837 | |
| 838 // The same article from the AOL domain should now be detected as discarded. | |
| 839 LoadFromJSONString(base::StringPrintf( | |
| 840 kChromeReaderResponseMultipleUrls, url_aol.c_str(), | |
| 841 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(), | |
| 842 NTPSnippet::TimeToJsonString(base::Time::Now() + | |
| 843 base::TimeDelta::FromHours(1)) | |
| 844 .c_str())); | |
| 845 ASSERT_THAT(service()->snippets(), IsEmpty()); | |
| 846 } | |
| 847 | |
| 774 } // namespace ntp_snippets | 848 } // namespace ntp_snippets |
| OLD | NEW |