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

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

Issue 1908973002: [NTP Snippets] Add newly-fetched snippets at the front instead of at the end (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 TEST_F(NTPSnippetsServiceTest, Clear) { 229 TEST_F(NTPSnippetsServiceTest, Clear) {
230 std::string json_str(GetTestJson()); 230 std::string json_str(GetTestJson());
231 231
232 LoadFromJSONString(json_str); 232 LoadFromJSONString(json_str);
233 EXPECT_EQ(service()->size(), 1u); 233 EXPECT_EQ(service()->size(), 1u);
234 234
235 service()->ClearSnippets(); 235 service()->ClearSnippets();
236 EXPECT_EQ(service()->size(), 0u); 236 EXPECT_EQ(service()->size(), 0u);
237 } 237 }
238 238
239 TEST_F(NTPSnippetsServiceTest, InsertAtFront) {
240 std::string json_str(
241 "{ \"recos\": [ "
242 "{ \"contentInfo\": { \"url\" : \"http://first\" }}"
Bernhard Bauer 2016/04/21 16:21:28 Maybe indent the opening brace inside the string,
Marc Treib 2016/04/22 08:16:47 Done.
243 "]}");
244 LoadFromJSONString(json_str);
245 ASSERT_EQ(service()->size(), 1u);
246
247 std::string json_str2(
248 "{ \"recos\": [ "
249 "{ \"contentInfo\": { \"url\" : \"http://second\" }}"
250 "]}");
251 LoadFromJSONString(json_str2);
252 ASSERT_EQ(service()->size(), 2u);
253
254 // The snippet loaded last should be at the first position in the list now.
255 const NTPSnippet& first_snippet = *service()->begin();
256 EXPECT_EQ(first_snippet.url(), GURL("http://second"));
257 }
258
239 TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) { 259 TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
240 SetExpectJsonParseSuccess(false); 260 SetExpectJsonParseSuccess(false);
241 LoadFromJSONString(GetInvalidJson()); 261 LoadFromJSONString(GetInvalidJson());
242 EXPECT_EQ(service()->size(), 0u); 262 EXPECT_EQ(service()->size(), 0u);
243 } 263 }
244 264
245 TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) { 265 TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) {
246 LoadFromJSONString(GetTestJson()); 266 LoadFromJSONString(GetTestJson());
247 ASSERT_EQ(service()->size(), 1u); 267 ASSERT_EQ(service()->size(), 1u);
248 268
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 353 }
334 354
335 TEST_F(NTPSnippetsServiceTest, RemoveExpiredContent) { 355 TEST_F(NTPSnippetsServiceTest, RemoveExpiredContent) {
336 std::string json_str(GetTestExpiredJson()); 356 std::string json_str(GetTestExpiredJson());
337 357
338 LoadFromJSONString(json_str); 358 LoadFromJSONString(json_str);
339 EXPECT_EQ(service()->size(), 0u); 359 EXPECT_EQ(service()->size(), 0u);
340 } 360 }
341 361
342 } // namespace ntp_snippets 362 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698