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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 LoadFromJSONString(service.get(), | 1165 LoadFromJSONString(service.get(), |
1166 GetTestJson({GetSnippetWithUrl( | 1166 GetTestJson({GetSnippetWithUrl( |
1167 "http://something.com/pletely/unrelated")})); | 1167 "http://something.com/pletely/unrelated")})); |
1168 // The image should still be available until a restart happens. | 1168 // The image should still be available until a restart happens. |
1169 EXPECT_FALSE(FetchImage(service.get(), MakeArticleID(kSnippetUrl)).IsEmpty()); | 1169 EXPECT_FALSE(FetchImage(service.get(), MakeArticleID(kSnippetUrl)).IsEmpty()); |
1170 ResetSnippetsService(&service); | 1170 ResetSnippetsService(&service); |
1171 // After the restart, the image should be garbage collected. | 1171 // After the restart, the image should be garbage collected. |
1172 EXPECT_TRUE(FetchImage(service.get(), MakeArticleID(kSnippetUrl)).IsEmpty()); | 1172 EXPECT_TRUE(FetchImage(service.get(), MakeArticleID(kSnippetUrl)).IsEmpty()); |
1173 } | 1173 } |
1174 | 1174 |
| 1175 TEST_F(NTPSnippetsServiceTest, ShouldHandleMoreThanMaxSnippetsInResponse) { |
| 1176 auto service = MakeSnippetsService(); |
| 1177 |
| 1178 std::vector<std::string> suggestions; |
| 1179 for (int i = 0 ; i < service->GetMaxSnippetCountForTesting() + 1; ++i) { |
| 1180 suggestions.push_back(GetSnippetWithUrl( |
| 1181 base::StringPrintf("http://localhost/snippet-id-%d", i))); |
| 1182 } |
| 1183 LoadFromJSONString(service.get(), GetTestJson(suggestions)); |
| 1184 // TODO(tschumann): We should probably trim out any additional results and |
| 1185 // only serve the MaxSnippetCount items. |
| 1186 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), |
| 1187 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); |
| 1188 } |
| 1189 |
1175 } // namespace ntp_snippets | 1190 } // namespace ntp_snippets |
OLD | NEW |