| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // CreateSnippetsServiceEnabled checks that Schedule is called. | 183 // CreateSnippetsServiceEnabled checks that Schedule is called. |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(NTPSnippetsServiceDisabledTest, Unschedule) { | 186 TEST_F(NTPSnippetsServiceDisabledTest, Unschedule) { |
| 187 // CreateSnippetsServiceEnabled checks that Unschedule is called. | 187 // CreateSnippetsServiceEnabled checks that Unschedule is called. |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(NTPSnippetsServiceTest, Loop) { | 190 TEST_F(NTPSnippetsServiceTest, Loop) { |
| 191 std::string json_str( | 191 std::string json_str( |
| 192 "{ \"recos\": [ " | 192 "{ \"recos\": [ " |
| 193 "{ \"contentInfo\": { \"url\" : \"http://localhost/foobar\" }}" | 193 " { \"contentInfo\": { \"url\" : \"http://localhost/foobar\" }}" |
| 194 "]}"); | 194 "]}"); |
| 195 LoadFromJSONString(json_str); | 195 LoadFromJSONString(json_str); |
| 196 | 196 |
| 197 // The same for loop without the '&' should not compile. | 197 // The same for loop without the '&' should not compile. |
| 198 for (auto& snippet : *service()) { | 198 for (auto& snippet : *service()) { |
| 199 // Snippet here is a const. | 199 // Snippet here is a const. |
| 200 EXPECT_EQ(snippet.url(), GURL("http://localhost/foobar")); | 200 EXPECT_EQ(snippet.url(), GURL("http://localhost/foobar")); |
| 201 } | 201 } |
| 202 // Without the const, this should not compile. | 202 // Without the const, this should not compile. |
| 203 for (const NTPSnippet& snippet : *service()) { | 203 for (const NTPSnippet& snippet : *service()) { |
| (...skipping 25 matching lines...) Expand all 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\" }}" |
| 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 |