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

Unified Diff: components/ntp_snippets/remote/ntp_snippets_service_unittest.cc

Issue 2466863003: Finalize backend for fetching more NTPSnippets. (Closed)
Patch Set: Known suggestion are now a parameter for Fetch. Created 4 years, 1 month 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
Index: components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
diff --git a/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc b/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
index c69d7ebaaf2ce3b19a9ea7310bda0314f7bdd70b..a31e0c6b8ca754c7b0727fa8170a69e4e2396e66 100644
--- a/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
@@ -503,12 +503,12 @@ class NTPSnippetsServiceTest : public ::testing::Test {
base::RunLoop().RunUntilIdle();
}
- void LoadMoreFromJSONString(
- NTPSnippetsService* service,
- const std::string& json,
- NTPSnippetsService::FetchedMoreCallback callback) {
+ void LoadMoreFromJSONString(NTPSnippetsService* service,
+ const std::string& json,
+ std::set<std::string> known,
dgn 2016/11/02 11:10:11 |known_ids| maybe? name is too unspecific as it is
fhorschig 2016/11/03 01:53:14 Done.
+ NTPSnippetsService::FetchingCallback callback) {
SetUpFetchResponse(json);
- service->FetchMore(articles_category(), callback);
+ service->Fetch(articles_category(), known, callback);
base::RunLoop().RunUntilIdle();
}
@@ -852,6 +852,7 @@ TEST_F(NTPSnippetsServiceTest, LoadsAdditionalSnippets) {
std::string second("http://second");
LoadMoreFromJSONString(service.get(),
GetTestJson({GetSnippetWithUrl(second)}),
+ std::set<std::string>(),
base::Bind([](std::vector<ContentSuggestion>) {}));
// The snippets loaded last are added to the previously loaded.
EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
@@ -875,15 +876,24 @@ TEST_F(NTPSnippetsServiceTest, InvokesOnlyCallbackOnFetchingMore) {
MockFunction<void(const std::vector<ContentSuggestion>&)> loaded;
EXPECT_CALL(loaded, Call(SizeIs(1)));
- LoadMoreFromJSONString(service.get(),
- GetTestJson({GetSnippetWithUrl("http://some")}),
- base::Bind(&SuggestionsLoaded, &loaded));
+ LoadMoreFromJSONString(
+ service.get(), GetTestJson({GetSnippetWithUrl("http://some")}),
+ std::set<std::string>(), base::Bind(&SuggestionsLoaded, &loaded));
// The observer shouldn't have been triggered.
EXPECT_THAT(observer().SuggestionsForCategory(articles_category()),
IsEmpty());
}
+TEST_F(NTPSnippetsServiceTest, ReturnFetchRequestEmptyBeforeInit) {
+ auto service = MakeSnippetsServiceWithoutInitialization();
+ MockFunction<void(const std::vector<ContentSuggestion>&)> loaded;
+ EXPECT_CALL(loaded, Call(SizeIs(0)));
+ service->Fetch(articles_category(), std::set<std::string>(),
+ base::Bind(&SuggestionsLoaded, &loaded));
+ base::RunLoop().RunUntilIdle();
+}
+
TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
auto service = MakeSnippetsService();

Powered by Google App Engine
This is Rietveld 408576698