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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 2283743002: Revert of Support server categories in NTPSnippetsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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 251ab814cf69e74b7458c91293eeb87e918da0b8..6c551c44b47b2b26dae18c2a2fddb40023ff2cf2 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -64,10 +64,6 @@
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";
@@ -438,9 +434,8 @@
std::string json_str(GetTestJson({GetSnippet()}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.title(), kSnippetTitle);
@@ -455,22 +450,21 @@
std::string json_str(GetTestJson({GetSnippet()}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
service()->ClearCachedSuggestions(articles_category());
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, InsertAtFront) {
std::string first("http://first");
LoadFromJSONString(GetTestJson({GetSnippetWithUrl(first)}));
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
- ElementsAre(IdEq(first)));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), 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(articles_category()),
+ EXPECT_THAT(service()->GetSnippetsForTesting(),
ElementsAre(IdEq(second), IdEq(first)));
}
@@ -488,49 +482,47 @@
}
LoadFromJSONString(GetTestJson(snippets1));
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()),
- SizeIs(snippets1.size()));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(snippets1.size()));
LoadFromJSONString(GetTestJson(snippets2));
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
- SizeIs(max_snippet_count));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), 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(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), 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(articles_category()), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, LoadIncompleteJson) {
LoadFromJSONString(GetTestJson({GetIncompleteSnippet()}));
EXPECT_EQ("Invalid / empty list.",
service()->snippets_fetcher()->last_status());
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, LoadIncompleteJsonWithExistingSnippets) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), 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(articles_category()), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, Dismiss) {
@@ -543,30 +535,30 @@
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
// Dismissing a non-existent snippet shouldn't do anything.
service()->DismissSuggestion(MakeUniqueID("http://othersite.com"));
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
// Dismiss the snippet.
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
// Make sure that fetching the same snippet again does not re-add it.
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
// The snippet should stay dismissed even after re-creating the service.
RecreateSnippetsService();
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
// The snippet can be added again after clearing dismissed snippets.
service()->ClearDismissedSuggestionsForDebugging(articles_category());
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
- LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
+ LoadFromJSONString(json_str);
+ EXPECT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, GetDismissed) {
@@ -611,9 +603,8 @@
NTPSnippet::TimeToJsonString(GetDefaultExpirationTime()))}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.title(), kSnippetTitle);
EXPECT_EQ(snippet.snippet(), kSnippetText);
@@ -624,7 +615,7 @@
std::string json_str(GetTestJson({GetExpiredSnippet()}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestSingleSource) {
@@ -636,9 +627,8 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 1u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -655,7 +645,7 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestSingleSourceWithMissingData) {
@@ -667,7 +657,7 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestMultipleSources) {
@@ -682,9 +672,8 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
// Expect the first source to be chosen
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
@@ -707,10 +696,9 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
{
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -734,10 +722,9 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
{
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 2u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -762,7 +749,7 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, TestMultipleCompleteSources) {
@@ -781,10 +768,9 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)}));
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
{
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source1.com"));
@@ -810,10 +796,9 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
{
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -839,10 +824,9 @@
GetTestJson({GetSnippetWithSources(source_urls, publishers, amp_urls)});
LoadFromJSONString(json_str);
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
{
- const NTPSnippet& snippet =
- *service()->GetSnippetsForTesting(articles_category()).front();
+ const NTPSnippet& snippet = *service()->GetSnippetsForTesting().front();
EXPECT_EQ(snippet.sources().size(), 3u);
EXPECT_EQ(snippet.id(), kSnippetUrl);
EXPECT_EQ(snippet.best_source().url, GURL("http://source2.com"));
@@ -923,15 +907,15 @@
// Add the snippet from the mashable domain.
LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
source_urls[0], creation, expiry, source_urls, publishers, amp_urls)}));
- ASSERT_THAT(service()->GetSnippetsForTesting(articles_category()), SizeIs(1));
+ ASSERT_THAT(service()->GetSnippetsForTesting(), SizeIs(1));
// Dismiss the snippet via the mashable source corpus ID.
service()->DismissSuggestion(MakeUniqueID(source_urls[0]));
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()), IsEmpty());
+ EXPECT_THAT(service()->GetSnippetsForTesting(), 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(articles_category()), IsEmpty());
+ ASSERT_THAT(service()->GetSnippetsForTesting(), IsEmpty());
}
TEST_F(NTPSnippetsServiceTest, StatusChanges) {
@@ -942,7 +926,7 @@
service()->OnDisabledReasonChanged(DisabledReason::SIGNED_OUT);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NTPSnippetsService::State::DISABLED, service()->state_);
- EXPECT_THAT(service()->GetSnippetsForTesting(articles_category()),
+ EXPECT_THAT(service()->GetSnippetsForTesting(),
IsEmpty()); // No fetch should be made.
// Simulate user sign in. The service should be ready again and load snippets.
@@ -955,7 +939,7 @@
OnCategoryStatusChanged(_, _, CategoryStatus::AVAILABLE));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_);
- EXPECT_FALSE(service()->GetSnippetsForTesting(articles_category()).empty());
+ EXPECT_FALSE(service()->GetSnippetsForTesting().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