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

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

Issue 2422633002: [NTP Snippets] Properly restore the status of restored sections (Closed)
Patch Set: 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 746 }
747 } 747 }
748 748
749 TEST_F(NTPSnippetsServiceTest, PersistCategoryInfos) { 749 TEST_F(NTPSnippetsServiceTest, PersistCategoryInfos) {
750 auto service = MakeSnippetsService(); 750 auto service = MakeSnippetsService();
751 751
752 LoadFromJSONString(service.get(), 752 LoadFromJSONString(service.get(),
753 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)}, 753 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)},
754 kUnknownRemoteCategoryId)); 754 kUnknownRemoteCategoryId));
755 755
756 ASSERT_NE(observer().StatusForCategory(articles_category()), 756 ASSERT_EQ(observer().StatusForCategory(articles_category()),
757 CategoryStatus::NOT_PROVIDED); 757 CategoryStatus::AVAILABLE);
758 ASSERT_NE(observer().StatusForCategory(unknown_category()), 758 ASSERT_EQ(observer().StatusForCategory(unknown_category()),
759 CategoryStatus::NOT_PROVIDED); 759 CategoryStatus::AVAILABLE);
760 760
761 CategoryInfo info_articles_before = 761 CategoryInfo info_articles_before =
762 service->GetCategoryInfo(articles_category()); 762 service->GetCategoryInfo(articles_category());
763 CategoryInfo info_unknown_before = 763 CategoryInfo info_unknown_before =
764 service->GetCategoryInfo(unknown_category()); 764 service->GetCategoryInfo(unknown_category());
765 765
766 // Recreate the service to simulate a Chrome restart. 766 // Recreate the service to simulate a Chrome restart.
767 ResetSnippetsService(&service); 767 ResetSnippetsService(&service);
768 768
769 // The categories should have been restored. 769 // The categories should have been restored.
770 ASSERT_NE(observer().StatusForCategory(articles_category()), 770 ASSERT_NE(observer().StatusForCategory(articles_category()),
771 CategoryStatus::NOT_PROVIDED); 771 CategoryStatus::NOT_PROVIDED);
772 ASSERT_NE(observer().StatusForCategory(unknown_category()), 772 ASSERT_NE(observer().StatusForCategory(unknown_category()),
773 CategoryStatus::NOT_PROVIDED); 773 CategoryStatus::NOT_PROVIDED);
774 774
775 EXPECT_EQ(observer().StatusForCategory(articles_category()),
776 CategoryStatus::AVAILABLE);
777 EXPECT_EQ(observer().StatusForCategory(unknown_category()),
778 CategoryStatus::AVAILABLE);
779
775 CategoryInfo info_articles_after = 780 CategoryInfo info_articles_after =
776 service->GetCategoryInfo(articles_category()); 781 service->GetCategoryInfo(articles_category());
777 CategoryInfo info_unknown_after = 782 CategoryInfo info_unknown_after =
778 service->GetCategoryInfo(unknown_category()); 783 service->GetCategoryInfo(unknown_category());
779 784
780 EXPECT_EQ(info_articles_before.title(), info_articles_after.title()); 785 EXPECT_EQ(info_articles_before.title(), info_articles_after.title());
781 EXPECT_EQ(info_unknown_before.title(), info_unknown_after.title()); 786 EXPECT_EQ(info_unknown_before.title(), info_unknown_after.title());
782 } 787 }
783 788
784 TEST_F(NTPSnippetsServiceTest, PersistSuggestions) { 789 TEST_F(NTPSnippetsServiceTest, PersistSuggestions) {
785 auto service = MakeSnippetsService(); 790 auto service = MakeSnippetsService();
786 791
787 LoadFromJSONString(service.get(), 792 LoadFromJSONString(service.get(),
788 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)})); 793 GetMultiCategoryJson({GetSnippetN(0)}, {GetSnippetN(1)}));
789 794
790 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); 795 ASSERT_THAT(observer().SuggestionsForCategory(articles_category()),
791 ASSERT_THAT(service->GetSnippetsForTesting(other_category()), SizeIs(1)); 796 SizeIs(1));
797 ASSERT_THAT(observer().SuggestionsForCategory(other_category()), SizeIs(1));
792 798
793 // Recreate the service to simulate a Chrome restart. 799 // Recreate the service to simulate a Chrome restart.
794 ResetSnippetsService(&service); 800 ResetSnippetsService(&service);
795 801
796 // The suggestions in both categories should have been restored. 802 // The suggestions in both categories should have been restored.
797 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); 803 EXPECT_THAT(observer().SuggestionsForCategory(articles_category()),
798 EXPECT_THAT(service->GetSnippetsForTesting(other_category()), SizeIs(1)); 804 SizeIs(1));
805 EXPECT_THAT(observer().SuggestionsForCategory(other_category()), SizeIs(1));
799 } 806 }
800 807
801 TEST_F(NTPSnippetsServiceTest, Clear) { 808 TEST_F(NTPSnippetsServiceTest, Clear) {
802 auto service = MakeSnippetsService(); 809 auto service = MakeSnippetsService();
803 810
804 std::string json_str(GetTestJson({GetSnippet()})); 811 std::string json_str(GetTestJson({GetSnippet()}));
805 812
806 LoadFromJSONString(service.get(), json_str); 813 LoadFromJSONString(service.get(), json_str);
807 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); 814 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1));
808 815
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 base::StringPrintf("http://localhost/snippet-id-%d", i))); 1296 base::StringPrintf("http://localhost/snippet-id-%d", i)));
1290 } 1297 }
1291 LoadFromJSONString(service.get(), GetTestJson(suggestions)); 1298 LoadFromJSONString(service.get(), GetTestJson(suggestions));
1292 // TODO(tschumann): We should probably trim out any additional results and 1299 // TODO(tschumann): We should probably trim out any additional results and
1293 // only serve the MaxSnippetCount items. 1300 // only serve the MaxSnippetCount items.
1294 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), 1301 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
1295 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); 1302 SizeIs(service->GetMaxSnippetCountForTesting() + 1));
1296 } 1303 }
1297 1304
1298 } // namespace ntp_snippets 1305 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698