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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 2279863002: Support server categories in NTPSnippetsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: rebase Created 4 years, 4 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 6c551c44b47b2b26dae18c2a2fddb40023ff2cf2..251ab814cf69e74b7458c91293eeb87e918da0b8 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -64,6 +64,10 @@ MATCHER_P(IdEq, value, "") {
return arg->id() == value;
}
+MATCHER_P(IsCategory, id, "") {
+ return arg.id() == static_cast<int>(id);
+}
+
const base::Time::Exploded kDefaultCreationTime = {2015, 11, 4, 25, 13, 46, 45};
const char kTestContentSnippetsServerFormat[] =
"https://chromereader-pa.googleapis.com/v1/fetch?key=%s";
@@ -434,8 +438,9 @@ TEST_F(NTPSnippetsServiceTest, Full) {
std::string json_str(GetTestJson({GetSnippet()}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.title(), kSnippetTitle);
@@ -450,21 +455,22 @@ TEST_F(NTPSnippetsServiceTest, Clear) {
std::string json_str(GetTestJson({GetSnippet()}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
service()->ClearCachedSuggestions(articles_category());
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, InsertAtFront) {
std::string first("http://first");
LoadFromJSONString(GetTestJson({GetSnippetWithUrl(first)}));
- EXPECT_THAT(service()->GetSnippetsForTesting(), ElementsAre(IdEq(first)));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
+ ElementsAre(IdEq(first)));
std::string second("http://second");
LoadFromJSONString(GetTestJson({GetSnippetWithUrl(second)}));
// The snippet loaded last should be at the first position in the list now.
- EXPECT_THAT(service()->GetSnippetsForTesting(),
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
ElementsAre(IdEq(second), IdEq(first)));
}
@@ -482,47 +488,49 @@ TEST_F(NTPSnippetsServiceTest, LimitNumSnippets) {
}
LoadFromJSONString(GetTestJson(snippets1));
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(snippets1.size()));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()),
+ SizeIs(snippets1.size()));
LoadFromJSONString(GetTestJson(snippets2));
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(max_snippet_count));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
+ SizeIs(max_snippet_count));
}
TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
LoadFromJSONString(GetTestJson({GetInvalidSnippet()}));
EXPECT_THAT(service()->snippets_fetcher()->last_status(),
StartsWith("Received invalid JSON"));
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
ASSERT_EQ("OK", service()->snippets_fetcher()->last_status());
LoadFromJSONString(GetTestJson({GetInvalidSnippet()}));
EXPECT_THAT(service()->snippets_fetcher()->last_status(),
StartsWith("Received invalid JSON"));
// This should not have changed the existing snippets.
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, LoadIncompleteJson) {
LoadFromJSONString(GetTestJson({GetIncompleteSnippet()}));
EXPECT_EQ("Invalid / empty list.",
service()->snippets_fetcher()->last_status());
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, LoadIncompleteJsonWithExistingSnippets) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
LoadFromJSONString(GetTestJson({GetIncompleteSnippet()}));
EXPECT_EQ("Invalid / empty list.",
service()->snippets_fetcher()->last_status());
// This should not have changed the existing snippets.
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, Dismiss) {
@@ -535,30 +543,30 @@ TEST_F(NTPSnippetsServiceTest, Dismiss) {
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
// Dismissing a non-existent snippet shouldn't do anything.
service()->DismissSuggestion(MakeUniqueID("http://othersite.com"));
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
// Dismiss the snippet.
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
// Make sure that fetching the same snippet again does not re-add it.
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
// The snippet should stay dismissed even after re-creating the service.
RecreateSnippetsService();
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
// The snippet can be added again after clearing dismissed snippets.
service()->ClearDismissedSuggestionsForDebugging(articles_category());
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, GetDismissed) {
@@ -603,8 +611,9 @@ TEST_F(NTPSnippetsServiceTest, CreationTimestampParseFail) {
NTPSnippet::TimeToJsonString(GetDefaultExpirationTime()))}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.title(), kSnippetTitle);
EXPECT_EQ(snippet.snippet(), kSnippetText);
@@ -615,7 +624,7 @@ TEST_F(NTPSnippetsServiceTest, RemoveExpiredContent) {
std::string json_str(GetTestJson({GetExpiredSnippet()}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestSingleSource) {
@@ -627,8 +636,9 @@ TEST_F(NTPSnippetsServiceTest, TestSingleSource) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 1u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -645,7 +655,7 @@ TEST_F(NTPSnippetsServiceTest, TestSingleSourceWithMalformedUrl) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestSingleSourceWithMissingData) {
@@ -657,7 +667,7 @@ TEST_F(NTPSnippetsServiceTest, TestSingleSourceWithMissingData) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestMultipleSources) {
@@ -672,8 +682,9 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
// Expect the first source to be chosen
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
@@ -696,9 +707,10 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleIncompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
{
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -722,9 +734,10 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleIncompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
{
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -749,7 +762,7 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleIncompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestMultipleCompleteSources) {
@@ -768,9 +781,10 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleCompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
{
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -796,9 +810,10 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleCompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
{
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -824,9 +839,10 @@ TEST_F(NTPSnippetsServiceTest, TestMultipleCompleteSources) {
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
{
- const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
+ const NTPSnippet& snippet =
+ *service()->GetSnippetsForTesting(articles_category()).front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -907,15 +923,15 @@ TEST_F(NTPSnippetsServiceTest, DismissShouldRespectAllKnownUrls) {
// Add the snippet from the mashable domain.
LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
source_urls[0], creation, expiry, source_urls, publishers, amp_urls)}));
- ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
// Dismiss the snippet via the mashable source corpus ID.
service()->DismissSuggestion(MakeUniqueID(source_urls[0]));
- EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
// The same article from the AOL domain should now be detected as dismissed.
LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
source_urls[1], creation, expiry, source_urls, publishers, amp_urls)}));
- ASSERT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, StatusChanges) {
@@ -926,7 +942,7 @@ TEST_F(NTPSnippetsServiceTest, StatusChanges) {
service()->OnDisabledReasonChanged(DisabledReason::SIGNED_OUT);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NTPSnippetsService::State::DISABLED, service()->state_);
- EXPECT_THAT(service()->GetSnippetsForTesting(),
+ EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
IsEmpty()); // No fetch should be made.
// Simulate user sign in. The service should be ready again and load snippets.
@@ -939,7 +955,7 @@ TEST_F(NTPSnippetsServiceTest, StatusChanges) {
OnCategoryStatusChanged(_, _, CategoryStatus::AVAILABLE));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_);
- EXPECT_FALSE(service()->GetSnippetsForTesting().empty());
+ EXPECT_FALSE(service()->GetSnippetsForTesting(articles_category()).empty());
}
TEST_F(NTPSnippetsServiceTest, ImageReturnedWithTheSameId) {
« 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