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/remote/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 EXPECT_EQ(MakeOtherID(std::string(kSnippetUrl) + "/1"), suggestion.id()); | 731 EXPECT_EQ(MakeOtherID(std::string(kSnippetUrl) + "/1"), suggestion.id()); |
732 EXPECT_EQ(kSnippetTitle, base::UTF16ToUTF8(suggestion.title())); | 732 EXPECT_EQ(kSnippetTitle, base::UTF16ToUTF8(suggestion.title())); |
733 EXPECT_EQ(kSnippetText, base::UTF16ToUTF8(suggestion.snippet_text())); | 733 EXPECT_EQ(kSnippetText, base::UTF16ToUTF8(suggestion.snippet_text())); |
734 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); | 734 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); |
735 EXPECT_EQ(kSnippetPublisherName, | 735 EXPECT_EQ(kSnippetPublisherName, |
736 base::UTF16ToUTF8(suggestion.publisher_name())); | 736 base::UTF16ToUTF8(suggestion.publisher_name())); |
737 EXPECT_EQ(GURL(kSnippetAmpUrl), suggestion.amp_url()); | 737 EXPECT_EQ(GURL(kSnippetAmpUrl), suggestion.amp_url()); |
738 } | 738 } |
739 } | 739 } |
740 | 740 |
741 TEST_F(NTPSnippetsServiceTest, PersistCategoryInfos) { | |
742 std::string json_str( | |
743 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)})); | |
tschumann
2016/10/07 14:45:55
inline json_str?
Marc Treib
2016/10/07 15:29:55
Done.
| |
744 | |
745 auto service = MakeSnippetsService(); | |
746 | |
747 LoadFromJSONString(service.get(), json_str); | |
748 | |
749 ASSERT_NE(observer().StatusForCategory(articles_category()), | |
750 CategoryStatus::NOT_PROVIDED); | |
751 ASSERT_NE(observer().StatusForCategory(other_category()), | |
tschumann
2016/10/07 14:45:55
ideally, this method would be called unknown_categ
Marc Treib
2016/10/07 15:29:55
Hm. There's corresponding MakeArticleID/MakeOtherI
tschumann
2016/10/07 16:12:45
The problem I'm seeing is that in this case, we do
Marc Treib
2016/10/10 08:33:42
Alright, made an unknown_category.
| |
752 CategoryStatus::NOT_PROVIDED); | |
753 | |
754 CategoryInfo info_articles_before = | |
755 service->GetCategoryInfo(articles_category()); | |
756 CategoryInfo info_other_before = service->GetCategoryInfo(other_category()); | |
757 | |
758 // Recreate the service to simulate a Chrome restart. | |
759 ResetSnippetsService(&service); | |
760 | |
761 // The categories should have been restored. | |
762 ASSERT_NE(observer().StatusForCategory(articles_category()), | |
763 CategoryStatus::NOT_PROVIDED); | |
764 ASSERT_NE(observer().StatusForCategory(other_category()), | |
765 CategoryStatus::NOT_PROVIDED); | |
766 | |
767 CategoryInfo info_articles_after = | |
768 service->GetCategoryInfo(articles_category()); | |
769 CategoryInfo info_other_after = service->GetCategoryInfo(other_category()); | |
770 | |
771 EXPECT_EQ(info_articles_before.title(), info_articles_after.title()); | |
772 EXPECT_EQ(info_other_before.title(), info_other_after.title()); | |
773 } | |
774 | |
741 TEST_F(NTPSnippetsServiceTest, Clear) { | 775 TEST_F(NTPSnippetsServiceTest, Clear) { |
742 auto service = MakeSnippetsService(); | 776 auto service = MakeSnippetsService(); |
743 | 777 |
744 std::string json_str(GetTestJson({GetSnippet()})); | 778 std::string json_str(GetTestJson({GetSnippet()})); |
745 | 779 |
746 LoadFromJSONString(service.get(), json_str); | 780 LoadFromJSONString(service.get(), json_str); |
747 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); | 781 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); |
748 | 782 |
749 service->ClearCachedSuggestions(articles_category()); | 783 service->ClearCachedSuggestions(articles_category()); |
750 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty()); | 784 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty()); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 base::StringPrintf("http://localhost/snippet-id-%d", i))); | 1264 base::StringPrintf("http://localhost/snippet-id-%d", i))); |
1231 } | 1265 } |
1232 LoadFromJSONString(service.get(), GetTestJson(suggestions)); | 1266 LoadFromJSONString(service.get(), GetTestJson(suggestions)); |
1233 // TODO(tschumann): We should probably trim out any additional results and | 1267 // TODO(tschumann): We should probably trim out any additional results and |
1234 // only serve the MaxSnippetCount items. | 1268 // only serve the MaxSnippetCount items. |
1235 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), | 1269 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), |
1236 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); | 1270 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); |
1237 } | 1271 } |
1238 | 1272 |
1239 } // namespace ntp_snippets | 1273 } // namespace ntp_snippets |
OLD | NEW |