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 532385cfd1109a0effe8fc18d199dbe4cd68803f..567d18451e4eb96c34268e209798fc0d28844773 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| +++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/macros.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| @@ -256,6 +257,29 @@ TEST_F(NTPSnippetsServiceTest, InsertAtFront) { |
| EXPECT_EQ(first_snippet.url(), GURL("http://second")); |
| } |
| +TEST_F(NTPSnippetsServiceTest, LimitNumSnippets) { |
| + int max_snippet_count = NTPSnippetsService::GetMaxSnippetCountForTesting(); |
| + int snippets_per_load = max_snippet_count / 2 + 1; |
| + |
| + std::string snippet_format = |
|
Bernhard Bauer
2016/04/25 10:38:25
You could make this a plain char[] if you're only
Marc Treib
2016/04/25 11:21:49
Done.
|
| + "{ \"contentInfo\": { \"url\" : \"http://localhost/%i\" }}"; |
| + std::vector<std::string> snippets1; |
| + std::vector<std::string> snippets2; |
| + for (int i = 0; i < snippets_per_load; i++) { |
| + snippets1.push_back(base::StringPrintf(snippet_format.c_str(), i)); |
| + snippets2.push_back(base::StringPrintf(snippet_format.c_str(), |
| + snippets_per_load + i)); |
| + } |
| + |
| + LoadFromJSONString( |
| + "{ \"recos\": [ " + base::JoinString(snippets1, ", ") + "]}"); |
| + ASSERT_EQ(snippets1.size(), service()->size()); |
| + |
| + LoadFromJSONString( |
| + "{ \"recos\": [ " + base::JoinString(snippets2, ", ") + "]}"); |
| + EXPECT_EQ(max_snippet_count, (int)service()->size()); |
| +} |
| + |
| TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) { |
| SetExpectJsonParseSuccess(false); |
| LoadFromJSONString(GetInvalidJson()); |