| 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 e79d79ca5cb4aa48b17018157061004d7ca987ea..c69d7ebaaf2ce3b19a9ea7310bda0314f7bdd70b 100644
|
| --- a/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
|
| +++ b/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
|
| @@ -503,6 +503,15 @@ class NTPSnippetsServiceTest : public ::testing::Test {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| + void LoadMoreFromJSONString(
|
| + NTPSnippetsService* service,
|
| + const std::string& json,
|
| + NTPSnippetsService::FetchedMoreCallback callback) {
|
| + SetUpFetchResponse(json);
|
| + service->FetchMore(articles_category(), callback);
|
| + base::RunLoop().RunUntilIdle();
|
| + }
|
| +
|
| private:
|
| variations::testing::VariationParamsManager params_manager_;
|
| test::NTPSnippetsTestUtils utils_;
|
| @@ -832,6 +841,49 @@ TEST_F(NTPSnippetsServiceTest, ReplaceSnippets) {
|
| ElementsAre(IdEq(second)));
|
| }
|
|
|
| +TEST_F(NTPSnippetsServiceTest, LoadsAdditionalSnippets) {
|
| + auto service = MakeSnippetsService();
|
| +
|
| + std::string first("http://first");
|
| + LoadFromJSONString(service.get(), GetTestJson({GetSnippetWithUrl(first)}));
|
| + EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
|
| + ElementsAre(IdEq(first)));
|
| +
|
| + std::string second("http://second");
|
| + LoadMoreFromJSONString(service.get(),
|
| + GetTestJson({GetSnippetWithUrl(second)}),
|
| + base::Bind([](std::vector<ContentSuggestion>) {}));
|
| + // The snippets loaded last are added to the previously loaded.
|
| + EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
|
| + ElementsAre(IdEq(first), IdEq(second)));
|
| +}
|
| +
|
| +namespace {
|
| +
|
| +// Workaround for gMock's lack of support for movable types.
|
| +void SuggestionsLoaded(
|
| + MockFunction<void(const std::vector<ContentSuggestion>& v)>* loaded,
|
| + std::vector<ContentSuggestion> v) {
|
| + loaded->Call(v);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(NTPSnippetsServiceTest, InvokesOnlyCallbackOnFetchingMore) {
|
| + auto service = MakeSnippetsService();
|
| +
|
| + MockFunction<void(const std::vector<ContentSuggestion>&)> loaded;
|
| + EXPECT_CALL(loaded, Call(SizeIs(1)));
|
| +
|
| + LoadMoreFromJSONString(service.get(),
|
| + GetTestJson({GetSnippetWithUrl("http://some")}),
|
| + base::Bind(&SuggestionsLoaded, &loaded));
|
| +
|
| + // The observer shouldn't have been triggered.
|
| + EXPECT_THAT(observer().SuggestionsForCategory(articles_category()),
|
| + IsEmpty());
|
| +}
|
| +
|
| TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
|
| auto service = MakeSnippetsService();
|
|
|
|
|