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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 base::Bucket(/*min=*/1, /*count=*/3))); | 769 base::Bucket(/*min=*/1, /*count=*/3))); |
| 770 EXPECT_THAT( | 770 EXPECT_THAT( |
| 771 tester.GetAllSamples("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded"), | 771 tester.GetAllSamples("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded"), |
| 772 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | 772 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
| 773 // Recreating the service and loading from prefs shouldn't count as fetched | 773 // Recreating the service and loading from prefs shouldn't count as fetched |
| 774 // articles. | 774 // articles. |
| 775 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1); | 775 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1); |
| 776 CreateSnippetsService(/*enabled=*/true); | 776 CreateSnippetsService(/*enabled=*/true); |
| 777 tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4); | 777 tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4); |
| 778 } | 778 } |
| 779 | |
| 780 const char kChromeReaderResponseMultipleUrls[] = | |
| 781 "{ \"recos\": [{ " | |
| 782 " \"contentInfo\": { " | |
| 783 " \"url\": \"%s\", " | |
| 784 " \"creationTimestampSec\": \"%s\", " | |
| 785 " \"expiryTimestampSec\" : \"%s\"," | |
| 786 " \"title\": \"Stolen doggie finally gets returned to owner after two " | |
| 787 "years\", " | |
|
Marc Treib
2016/05/18 18:58:05
One more avoidable line break :)
tschumann
2016/05/18 19:23:29
Done.
| |
| 788 " \"snippet\": \"It\'s at least this man\'s best friend.\", " | |
| 789 " \"thumbnailUrl\": \"http://t0.gstatic.com/images?q=tbn:1\", " | |
| 790 " \"sourceCorpusInfo\": [{" | |
| 791 " \"type\" : \"CHROME_LOGS\", " | |
| 792 " \"corpusId\": \"http://mashable.com/2016/05/11/stolen\", " | |
| 793 " \"publisherData\": { " | |
| 794 " \"sourceName\": \"Mashable\", " | |
| 795 " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " | |
| 796 " }, " | |
| 797 " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" " | |
| 798 " }, { " | |
| 799 " \"type\": \"CHROME_LOGS\", " | |
| 800 " \"corpusId\": \"http://www.aol.com/article/2016/05/stolen-doggie\", " | |
| 801 " \"publisherData\": { " | |
| 802 " \"sourceName\": \"AOL\", " | |
| 803 " \"sourceLogoUrl\": \"http://t2.gstatic.com/images?q=tbn:3\" " | |
| 804 " }, " | |
| 805 " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" " | |
| 806 " }, { " | |
| 807 " \"type\": \"CHROME_LOGS\", " | |
| 808 " \"corpusId\": \"http://mashable.com/2016/05/11/stolen?utm_cid=1\", " | |
| 809 " \"publisherData\": { " | |
| 810 " \"sourceName\": \"Mashable\", " | |
| 811 " \"sourceLogoUrl\": \"http://t3.gstatic.com/images?q=tbn:2\" " | |
| 812 " }, " | |
| 813 " \"ampUrl\": \"http://mashable-amphtml.googleusercontent.com/1\" " | |
| 814 " }] " | |
| 815 " }, " | |
| 816 " \"score\" : \"0.099307865\" " | |
| 817 "}]} "; | |
| 818 | |
| 819 TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) { | |
| 820 const std::string url_mashable = "http://mashable.com/2016/05/11/stolen"; | |
| 821 const std::string url_aol = | |
| 822 "http://www.aol.com/article/2016/05/stolen-doggie"; | |
| 823 | |
| 824 LoadFromJSONString(base::StringPrintf( | |
| 825 kChromeReaderResponseMultipleUrls, url_mashable.c_str(), | |
| 826 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(), | |
| 827 NTPSnippet::TimeToJsonString(base::Time::Now() + | |
| 828 base::TimeDelta::FromHours(1)) | |
| 829 .c_str())); | |
| 830 ASSERT_THAT(service()->snippets(), SizeIs(1)); | |
| 831 // Discard the snippet via the mashable source corpus ID. | |
| 832 EXPECT_TRUE(service()->DiscardSnippet(url_mashable)); | |
| 833 EXPECT_THAT(service()->snippets(), IsEmpty()); | |
| 834 | |
| 835 // The same article from the AOL domain should now be detected as discarded. | |
| 836 LoadFromJSONString(base::StringPrintf( | |
| 837 kChromeReaderResponseMultipleUrls, url_aol.c_str(), | |
| 838 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(), | |
| 839 NTPSnippet::TimeToJsonString(base::Time::Now() + | |
| 840 base::TimeDelta::FromHours(1)) | |
| 841 .c_str())); | |
| 842 ASSERT_THAT(service()->snippets(), IsEmpty()); | |
| 843 } | |
| 844 | |
| 779 } // namespace ntp_snippets | 845 } // namespace ntp_snippets |
| OLD | NEW |