| 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..a2c6d7a8370d9589776bfc4a3d5f9265e7ed9a3f 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;
|
| +
|
| + const char snippet_format[] =
|
| + "{ \"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, i));
|
| + snippets2.push_back(base::StringPrintf(snippet_format,
|
| + 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());
|
|
|