Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |