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/remote_suggestions_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 } | 900 } |
901 | 901 |
902 TEST_F(RemoteSuggestionsProviderImplTest, LoadsAdditionalSuggestions) { | 902 TEST_F(RemoteSuggestionsProviderImplTest, LoadsAdditionalSuggestions) { |
903 auto service = MakeSuggestionsProvider(); | 903 auto service = MakeSuggestionsProvider(); |
904 | 904 |
905 LoadFromJSONString(service.get(), | 905 LoadFromJSONString(service.get(), |
906 GetTestJson({GetSuggestionWithUrl("http://first")})); | 906 GetTestJson({GetSuggestionWithUrl("http://first")})); |
907 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()), | 907 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()), |
908 ElementsAre(IdEq("http://first"))); | 908 ElementsAre(IdEq("http://first"))); |
909 | 909 |
910 auto expect_only_second_suggestion_received = base::Bind([]( | 910 auto expect_only_second_suggestion_received = |
911 Status status, std::vector<ContentSuggestion> suggestions) { | 911 base::Bind([](Status status, std::vector<ContentSuggestion> suggestions) { |
912 EXPECT_THAT(suggestions, SizeIs(1)); | 912 EXPECT_THAT(suggestions, SizeIs(1)); |
913 EXPECT_THAT(suggestions[0].id().id_within_category(), Eq("http://second")); | 913 EXPECT_THAT(suggestions[0].id().id_within_category(), |
914 }); | 914 Eq("http://second")); |
| 915 }); |
915 LoadMoreFromJSONString(service.get(), articles_category(), | 916 LoadMoreFromJSONString(service.get(), articles_category(), |
916 GetTestJson({GetSuggestionWithUrl("http://second")}), | 917 GetTestJson({GetSuggestionWithUrl("http://second")}), |
917 /*known_ids=*/std::set<std::string>(), | 918 /*known_ids=*/std::set<std::string>(), |
918 expect_only_second_suggestion_received); | 919 expect_only_second_suggestion_received); |
919 | 920 |
920 // Verify we can resolve the image of the new suggestions. | 921 // Verify we can resolve the image of the new suggestions. |
921 ServeImageCallback cb = | 922 ServeImageCallback cb = |
922 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); | 923 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
923 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 924 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
924 .Times(2) | 925 .Times(2) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 auto expect_receiving_two_new_suggestions = | 978 auto expect_receiving_two_new_suggestions = |
978 base::Bind([](Status status, std::vector<ContentSuggestion> suggestions) { | 979 base::Bind([](Status status, std::vector<ContentSuggestion> suggestions) { |
979 ASSERT_THAT(suggestions, SizeIs(2)); | 980 ASSERT_THAT(suggestions, SizeIs(2)); |
980 EXPECT_THAT(suggestions[0], IdWithinCategoryEq("http://more-id-1")); | 981 EXPECT_THAT(suggestions[0], IdWithinCategoryEq("http://more-id-1")); |
981 EXPECT_THAT(suggestions[1], IdWithinCategoryEq("http://more-id-2")); | 982 EXPECT_THAT(suggestions[1], IdWithinCategoryEq("http://more-id-2")); |
982 }); | 983 }); |
983 LoadMoreFromJSONString( | 984 LoadMoreFromJSONString( |
984 service.get(), articles_category(), | 985 service.get(), articles_category(), |
985 GetTestJson({GetSuggestionWithUrl("http://more-id-1"), | 986 GetTestJson({GetSuggestionWithUrl("http://more-id-1"), |
986 GetSuggestionWithUrl("http://more-id-2")}), | 987 GetSuggestionWithUrl("http://more-id-2")}), |
987 /*known_ids=*/{"http://id-1", "http://id-2", "http://id-3", "http://id-4", | 988 /*known_ids=*/ |
988 "http://id-5", "http://id-6", "http://id-7", "http://id-8", | 989 {"http://id-1", "http://id-2", "http://id-3", "http://id-4", |
989 "http://id-9", "http://id-10"}, | 990 "http://id-5", "http://id-6", "http://id-7", "http://id-8", |
| 991 "http://id-9", "http://id-10"}, |
990 expect_receiving_two_new_suggestions); | 992 expect_receiving_two_new_suggestions); |
991 | 993 |
992 // Verify that the observer received the update as well. We should see the | 994 // Verify that the observer received the update as well. We should see the |
993 // newly-fetched items filled up with existing ones. The merging is done | 995 // newly-fetched items filled up with existing ones. The merging is done |
994 // mimicking a scrolling behavior. | 996 // mimicking a scrolling behavior. |
995 EXPECT_THAT( | 997 EXPECT_THAT( |
996 observer().SuggestionsForCategory(articles_category()), | 998 observer().SuggestionsForCategory(articles_category()), |
997 ElementsAre( | 999 ElementsAre( |
998 IdWithinCategoryEq("http://id-3"), IdWithinCategoryEq("http://id-4"), | 1000 IdWithinCategoryEq("http://id-3"), IdWithinCategoryEq("http://id-4"), |
999 IdWithinCategoryEq("http://id-5"), IdWithinCategoryEq("http://id-6"), | 1001 IdWithinCategoryEq("http://id-5"), IdWithinCategoryEq("http://id-6"), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 GetTestJson({GetSuggestionWithUrl("http://more-id-1"), | 1091 GetTestJson({GetSuggestionWithUrl("http://more-id-1"), |
1090 GetSuggestionWithUrl("http://more-id-2"), | 1092 GetSuggestionWithUrl("http://more-id-2"), |
1091 GetSuggestionWithUrl("http://more-id-3"), | 1093 GetSuggestionWithUrl("http://more-id-3"), |
1092 GetSuggestionWithUrl("http://more-id-4"), | 1094 GetSuggestionWithUrl("http://more-id-4"), |
1093 GetSuggestionWithUrl("http://more-id-5"), | 1095 GetSuggestionWithUrl("http://more-id-5"), |
1094 GetSuggestionWithUrl("http://more-id-6"), | 1096 GetSuggestionWithUrl("http://more-id-6"), |
1095 GetSuggestionWithUrl("http://more-id-7"), | 1097 GetSuggestionWithUrl("http://more-id-7"), |
1096 GetSuggestionWithUrl("http://more-id-8"), | 1098 GetSuggestionWithUrl("http://more-id-8"), |
1097 GetSuggestionWithUrl("http://more-id-9"), | 1099 GetSuggestionWithUrl("http://more-id-9"), |
1098 GetSuggestionWithUrl("http://more-id-10")}), | 1100 GetSuggestionWithUrl("http://more-id-10")}), |
1099 /*known_ids=*/{"http://id-1", "http://id-2", "http://id-3", "http://id-4", | 1101 /*known_ids=*/ |
1100 "http://id-5", "http://id-6", "http://id-7", "http://id-8", | 1102 {"http://id-1", "http://id-2", "http://id-3", "http://id-4", |
1101 "http://id-9", "http://id-10"}, | 1103 "http://id-5", "http://id-6", "http://id-7", "http://id-8", |
| 1104 "http://id-9", "http://id-10"}, |
1102 expect_receiving_ten_new_suggestions); | 1105 expect_receiving_ten_new_suggestions); |
1103 EXPECT_THAT(observer().SuggestionsForCategory(articles_category()), | 1106 EXPECT_THAT(observer().SuggestionsForCategory(articles_category()), |
1104 ElementsAre(IdWithinCategoryEq("http://more-id-1"), | 1107 ElementsAre(IdWithinCategoryEq("http://more-id-1"), |
1105 IdWithinCategoryEq("http://more-id-2"), | 1108 IdWithinCategoryEq("http://more-id-2"), |
1106 IdWithinCategoryEq("http://more-id-3"), | 1109 IdWithinCategoryEq("http://more-id-3"), |
1107 IdWithinCategoryEq("http://more-id-4"), | 1110 IdWithinCategoryEq("http://more-id-4"), |
1108 IdWithinCategoryEq("http://more-id-5"), | 1111 IdWithinCategoryEq("http://more-id-5"), |
1109 IdWithinCategoryEq("http://more-id-6"), | 1112 IdWithinCategoryEq("http://more-id-6"), |
1110 IdWithinCategoryEq("http://more-id-7"), | 1113 IdWithinCategoryEq("http://more-id-7"), |
1111 IdWithinCategoryEq("http://more-id-8"), | 1114 IdWithinCategoryEq("http://more-id-8"), |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 EXPECT_CALL(scheduler, OnProviderActivated()); | 1816 EXPECT_CALL(scheduler, OnProviderActivated()); |
1814 // The scheduler should be notified of clearing the history. | 1817 // The scheduler should be notified of clearing the history. |
1815 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1818 EXPECT_CALL(scheduler, OnSuggestionsCleared()); |
1816 | 1819 |
1817 service->SetRemoteSuggestionsScheduler(&scheduler); | 1820 service->SetRemoteSuggestionsScheduler(&scheduler); |
1818 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 1821 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
1819 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); | 1822 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); |
1820 } | 1823 } |
1821 | 1824 |
1822 } // namespace ntp_snippets | 1825 } // namespace ntp_snippets |
OLD | NEW |