Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_service_unittest.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_service_unittest.cc b/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| index 699a20ff5f506b6ec8a5db9d7bcb0d875aa17c68..4b4cc58025ac6b9786ecec87de73e49e26019097 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| +++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| @@ -167,6 +167,16 @@ TEST_F(NTPSnippetsServiceTest, Full) { |
| } |
| } |
| +TEST_F(NTPSnippetsServiceTest, Clear) { |
| + std::string json_str(GetTestJson(1448459205)); |
| + |
| + ASSERT_TRUE(LoadFromJSONString(json_str)); |
|
Marc Treib
2016/04/13 08:45:52
Heads-up: I changed the setup of these tests sligh
jkrcal
2016/04/14 15:27:01
Done.
|
| + EXPECT_EQ(service()->size(), 1u); |
| + |
| + service()->ClearSnippets(); |
| + EXPECT_EQ(service()->size(), 0u); |
| +} |
| + |
| TEST_F(NTPSnippetsServiceTest, Discard) { |
| std::string json_str( |
| "{ \"recos\": [ { \"contentInfo\": { \"url\" : \"http://site.com\" }}]}"); |
| @@ -193,6 +203,31 @@ TEST_F(NTPSnippetsServiceTest, Discard) { |
| service()->Init(true); |
| ASSERT_TRUE(LoadFromJSONString(json_str)); |
| EXPECT_EQ(0u, service()->size()); |
| + |
| + // The snippet can be added again after clearing discarded snippets. |
| + service()->ClearDiscardedSnippets(); |
| + EXPECT_EQ(0u, service()->size()); |
| + ASSERT_TRUE(LoadFromJSONString(json_str)); |
| + EXPECT_EQ(1u, service()->size()); |
| +} |
| + |
| +TEST_F(NTPSnippetsServiceTest, GetDiscarded) { |
| + std::string json_str( |
| + "{ \"recos\": [ { \"contentInfo\": { \"url\" : \"http://site.com\" }}]}"); |
| + ASSERT_TRUE(LoadFromJSONString(json_str)); |
| + |
| + // For the test, we need the snippet to get discarded. |
| + ASSERT_TRUE(service()->DiscardSnippet(GURL("http://site.com"))); |
| + const NTPSnippetsService::NTPSnippetStorage& snippets = |
| + service()->GetDiscardedSnippets(); |
| + EXPECT_EQ(1u, snippets.size()); |
| + for (auto& snippet : snippets) { |
| + EXPECT_EQ(GURL("http://site.com"), snippet->url()); |
| + } |
| + |
| + // There should be no discarded snippet after clearing the list. |
| + service()->ClearDiscardedSnippets(); |
| + EXPECT_EQ(0u, snippets.size()); |
|
Marc Treib
2016/04/13 08:45:52
Ah, this works because you have a reference to the
jkrcal
2016/04/14 15:27:01
Done.
|
| } |
| TEST_F(NTPSnippetsServiceTest, CreationTimestampParseFail) { |