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

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

Issue 2402323002: [NTP Snippets] Persist non-article remote suggestions in the DB (Closed)
Patch Set: 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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 773
774 CategoryInfo info_articles_after = 774 CategoryInfo info_articles_after =
775 service->GetCategoryInfo(articles_category()); 775 service->GetCategoryInfo(articles_category());
776 CategoryInfo info_unknown_after = 776 CategoryInfo info_unknown_after =
777 service->GetCategoryInfo(unknown_category()); 777 service->GetCategoryInfo(unknown_category());
778 778
779 EXPECT_EQ(info_articles_before.title(), info_articles_after.title()); 779 EXPECT_EQ(info_articles_before.title(), info_articles_after.title());
780 EXPECT_EQ(info_unknown_before.title(), info_unknown_after.title()); 780 EXPECT_EQ(info_unknown_before.title(), info_unknown_after.title());
781 } 781 }
782 782
783 TEST_F(NTPSnippetsServiceTest, PersistSuggestions) {
784 auto service = MakeSnippetsService();
785
786 LoadFromJSONString(service.get(),
787 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)}));
788
789 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1));
790 ASSERT_THAT(service->GetSnippetsForTesting(other_category()), SizeIs(1));
791
792 // Recreate the service to simulate a Chrome restart.
793 ResetSnippetsService(&service);
794
795 // The suggestions in both categories should have been restored.
796 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1));
797 EXPECT_THAT(service->GetSnippetsForTesting(other_category()), SizeIs(1));
798 }
799
783 TEST_F(NTPSnippetsServiceTest, Clear) { 800 TEST_F(NTPSnippetsServiceTest, Clear) {
784 auto service = MakeSnippetsService(); 801 auto service = MakeSnippetsService();
785 802
786 std::string json_str(GetTestJson({GetSnippet()})); 803 std::string json_str(GetTestJson({GetSnippet()}));
787 804
788 LoadFromJSONString(service.get(), json_str); 805 LoadFromJSONString(service.get(), json_str);
789 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); 806 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1));
790 807
791 service->ClearCachedSuggestions(articles_category()); 808 service->ClearCachedSuggestions(articles_category());
792 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty()); 809 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty());
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 base::StringPrintf("http://localhost/snippet-id-%d", i))); 1289 base::StringPrintf("http://localhost/snippet-id-%d", i)));
1273 } 1290 }
1274 LoadFromJSONString(service.get(), GetTestJson(suggestions)); 1291 LoadFromJSONString(service.get(), GetTestJson(suggestions));
1275 // TODO(tschumann): We should probably trim out any additional results and 1292 // TODO(tschumann): We should probably trim out any additional results and
1276 // only serve the MaxSnippetCount items. 1293 // only serve the MaxSnippetCount items.
1277 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), 1294 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
1278 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); 1295 SizeIs(service->GetMaxSnippetCountForTesting() + 1));
1279 } 1296 }
1280 1297
1281 } // namespace ntp_snippets 1298 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/ntp_snippets_service.cc ('k') | components/ntp_snippets/remote/proto/ntp_snippets.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698