| 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..05dd1ca347c2abeceb1b03e72babdef2bd70ef24 100644
|
| --- a/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
|
| +++ b/components/ntp_snippets/remote/ntp_snippets_service_unittest.cc
|
| @@ -388,7 +388,8 @@ class NTPSnippetsServiceTest : public ::testing::Test {
|
| test_url_(kTestContentSuggestionsServerWithAPIKey),
|
| user_classifier_(/*pref_service=*/nullptr),
|
| image_fetcher_(nullptr),
|
| - image_decoder_(nullptr) {
|
| + image_decoder_(nullptr),
|
| + caller_() {
|
| NTPSnippetsService::RegisterProfilePrefs(utils_.pref_service()->registry());
|
| RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry());
|
|
|
| @@ -503,7 +504,34 @@ class NTPSnippetsServiceTest : public ::testing::Test {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| + void LoadMoreFromJSONString(
|
| + NTPSnippetsService* service,
|
| + const std::string& json,
|
| + const NTPSnippetsService::FetchedMoreCallback& callback) {
|
| + SetUpFetchResponse(json);
|
| + service->FetchMore(articles_category(), callback);
|
| + base::RunLoop().RunUntilIdle();
|
| + }
|
| +
|
| + NTPSnippetsService::FetchedMoreCallback MakeDummyCallback() {
|
| + return base::Bind(&MockCaller::EmptyCallback,
|
| + base::Unretained(&this->caller_));
|
| + }
|
| +
|
| + NTPSnippetsService::FetchedMoreCallback MakeMustCallCallback() {
|
| + EXPECT_CALL(this->caller_, MustCallback()).Times(1);
|
| + return base::Bind(&MockCaller::CheckCallback,
|
| + base::Unretained(&this->caller_));
|
| + }
|
| +
|
| private:
|
| + class MockCaller {
|
| + public:
|
| + void EmptyCallback(std::vector<ContentSuggestion>) {}
|
| + void CheckCallback(std::vector<ContentSuggestion> v) { MustCallback(); }
|
| + MOCK_METHOD0(MustCallback, void());
|
| + };
|
| +
|
| variations::testing::VariationParamsManager params_manager_;
|
| test::NTPSnippetsTestUtils utils_;
|
| base::MessageLoop message_loop_;
|
| @@ -520,6 +548,7 @@ class NTPSnippetsServiceTest : public ::testing::Test {
|
| FakeImageDecoder* image_decoder_;
|
|
|
| base::ScopedTempDir database_dir_;
|
| + MockCaller caller_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NTPSnippetsServiceTest);
|
| };
|
| @@ -832,6 +861,33 @@ 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)}),
|
| + MakeDummyCallback());
|
| + // The snippets loaded last are added to the previously loaded.
|
| + EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
|
| + ElementsAre(IdEq(first), IdEq(second)));
|
| +}
|
| +
|
| +TEST_F(NTPSnippetsServiceTest, InvokesOnlyCallbackOnFetchingMore) {
|
| + LoadMoreFromJSONString(MakeSnippetsService().get(),
|
| + GetTestJson({GetSnippetWithUrl("http://some")}),
|
| + MakeMustCallCallback());
|
| +
|
| + // The observer shouldn't have been triggered.
|
| + EXPECT_THAT(observer().SuggestionsForCategory(articles_category()),
|
| + SizeIs(0));
|
| +}
|
| +
|
| TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
|
| auto service = MakeSnippetsService();
|
|
|
|
|