Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 1922463002: [NTP Snippets] Limit the number of snippets to 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698