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

Side by Side Diff: components/ntp_snippets/remote/ntp_snippets_service_unittest.cc

Issue 2395273003: [NTP Snippets] Persist remote categories in prefs (Closed)
Patch Set: tschumann review Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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
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 auto service = MakeSnippetsService();
743
744 LoadFromJSONString(service.get(),
745 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)}));
746
747 ASSERT_NE(observer().StatusForCategory(articles_category()),
748 CategoryStatus::NOT_PROVIDED);
749 ASSERT_NE(observer().StatusForCategory(other_category()),
750 CategoryStatus::NOT_PROVIDED);
751
752 CategoryInfo info_articles_before =
753 service->GetCategoryInfo(articles_category());
754 CategoryInfo info_other_before = service->GetCategoryInfo(other_category());
755
756 // Recreate the service to simulate a Chrome restart.
757 ResetSnippetsService(&service);
758
759 // The categories should have been restored.
760 ASSERT_NE(observer().StatusForCategory(articles_category()),
761 CategoryStatus::NOT_PROVIDED);
762 ASSERT_NE(observer().StatusForCategory(other_category()),
763 CategoryStatus::NOT_PROVIDED);
764
765 CategoryInfo info_articles_after =
766 service->GetCategoryInfo(articles_category());
767 CategoryInfo info_other_after = service->GetCategoryInfo(other_category());
768
769 EXPECT_EQ(info_articles_before.title(), info_articles_after.title());
770 EXPECT_EQ(info_other_before.title(), info_other_after.title());
771 }
772
741 TEST_F(NTPSnippetsServiceTest, Clear) { 773 TEST_F(NTPSnippetsServiceTest, Clear) {
742 auto service = MakeSnippetsService(); 774 auto service = MakeSnippetsService();
743 775
744 std::string json_str(GetTestJson({GetSnippet()})); 776 std::string json_str(GetTestJson({GetSnippet()}));
745 777
746 LoadFromJSONString(service.get(), json_str); 778 LoadFromJSONString(service.get(), json_str);
747 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); 779 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1));
748 780
749 service->ClearCachedSuggestions(articles_category()); 781 service->ClearCachedSuggestions(articles_category());
750 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty()); 782 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty());
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 base::StringPrintf("http://localhost/snippet-id-%d", i))); 1262 base::StringPrintf("http://localhost/snippet-id-%d", i)));
1231 } 1263 }
1232 LoadFromJSONString(service.get(), GetTestJson(suggestions)); 1264 LoadFromJSONString(service.get(), GetTestJson(suggestions));
1233 // TODO(tschumann): We should probably trim out any additional results and 1265 // TODO(tschumann): We should probably trim out any additional results and
1234 // only serve the MaxSnippetCount items. 1266 // only serve the MaxSnippetCount items.
1235 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), 1267 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
1236 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); 1268 SizeIs(service->GetMaxSnippetCountForTesting() + 1));
1237 } 1269 }
1238 1270
1239 } // namespace ntp_snippets 1271 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698