Chromium Code Reviews| Index: components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc |
| diff --git a/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc b/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc |
| index f5716a1e768d5328cb295b129ae56e903b1db1d4..60c8f3b58f2b66bd309afcacf519a3abcc17b4bc 100644 |
| --- a/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc |
| +++ b/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc |
| @@ -23,14 +23,14 @@ |
| #include "components/ntp_snippets/ntp_snippets_constants.h" |
| #include "components/ntp_snippets/remote/remote_suggestion.h" |
| #include "components/ntp_snippets/remote/request_params.h" |
| +#include "components/ntp_snippets/remote/test_utils.h" |
| #include "components/ntp_snippets/user_classifier.h" |
| #include "components/prefs/testing_pref_service.h" |
| -#include "components/signin/core/browser/account_tracker_service.h" |
| #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| #include "components/signin/core/browser/fake_signin_manager.h" |
| -#include "components/signin/core/browser/test_signin_client.h" |
| #include "components/variations/entropy_provider.h" |
| #include "components/variations/variations_params_manager.h" |
| +#include "google_apis/gaia/fake_oauth2_token_service_delegate.h" |
| #include "net/url_request/test_url_fetcher_factory.h" |
| #include "net/url_request/url_request_test_util.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -60,6 +60,10 @@ const char kTestChromeReaderUrl[] = |
| const char kTestChromeContentSuggestionsUrl[] = |
|
Marc Treib
2017/02/06 11:03:17
nit: Maybe rename this to ...SignedOutUrl to make
jkrcal
2017/02/07 08:44:18
Done.
|
| "https://chromecontentsuggestions-pa.googleapis.com/v1/suggestions/" |
| "fetch?key=fakeAPIkey"; |
| +const char kTestChromeContentSuggestionsSignedInUrl[] = |
| + "https://chromecontentsuggestions-pa.googleapis.com/v1/suggestions/fetch"; |
| + |
| +const char kTestEmail[] = "foo@bar.com"; |
| // Artificial time delay for JSON parsing. |
| const int64_t kTestJsonParsingLatencyMs = 20; |
| @@ -271,42 +275,62 @@ void ParseJsonDelayed(const std::string& json, |
| // sign-in / refresh tokens / access token code). crbug.com/688310 |
| class RemoteSuggestionsFetcherTestBase : public testing::Test { |
| public: |
| - explicit RemoteSuggestionsFetcherTestBase(const GURL& gurl) |
| + explicit RemoteSuggestionsFetcherTestBase() |
| : default_variation_params_( |
| {{"send_top_languages", "true"}, {"send_user_class", "true"}}), |
| params_manager_(ntp_snippets::kStudyName, |
| default_variation_params_, |
| {ntp_snippets::kArticleSuggestionsFeature.name}), |
| mock_task_runner_(new base::TestMockTimeTaskRunner()), |
| - mock_task_runner_handle_(mock_task_runner_), |
| - signin_client_(base::MakeUnique<TestSigninClient>(nullptr)), |
| - account_tracker_(base::MakeUnique<AccountTrackerService>()), |
| - fake_signin_manager_( |
| - base::MakeUnique<FakeSigninManagerBase>(signin_client_.get(), |
| - account_tracker_.get())), |
| - fake_token_service_(base::MakeUnique<FakeProfileOAuth2TokenService>()), |
| - pref_service_(base::MakeUnique<TestingPrefServiceSimple>()), |
| - test_url_(gurl) { |
| - RequestThrottler::RegisterProfilePrefs(pref_service_->registry()); |
| - UserClassifier::RegisterProfilePrefs(pref_service_->registry()); |
| - user_classifier_ = base::MakeUnique<UserClassifier>(pref_service_.get()); |
| + mock_task_runner_handle_(mock_task_runner_) { |
| + RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| + UserClassifier::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| + user_classifier_ = |
| + base::MakeUnique<UserClassifier>(utils_.pref_service()); |
| // Increase initial time such that ticks are non-zero. |
| mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); |
| ResetSnippetsFetcher(); |
| } |
| void ResetSnippetsFetcher() { |
| + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = |
| + new net::TestURLRequestContextGetter(mock_task_runner_.get()); |
| + |
| + request_context_getter_ = |
| + new net::TestURLRequestContextGetter(mock_task_runner_.get()); |
|
Marc Treib
2017/02/06 11:03:17
Why do we create another request context getter he
jkrcal
2017/02/07 08:44:18
Done. Sorry, this was a rest from my experiments h
|
| + fake_token_service_delegate_ = |
| + new FakeOAuth2TokenServiceDelegate(request_context_getter_.get()); |
|
Marc Treib
2017/02/06 11:03:17
This looks like a memleak?
jkrcal
2017/02/07 08:44:18
It does but it is not. Added a comment to explain.
Marc Treib
2017/02/07 09:18:12
Acknowledged.
|
| + fake_token_service_ = base::MakeUnique<FakeProfileOAuth2TokenService>( |
| + fake_token_service_delegate_); |
| + |
| snippets_fetcher_ = base::MakeUnique<RemoteSuggestionsFetcher>( |
| - fake_signin_manager_.get(), fake_token_service_.get(), |
| - scoped_refptr<net::TestURLRequestContextGetter>( |
| - new net::TestURLRequestContextGetter(mock_task_runner_.get())), |
| - pref_service_.get(), nullptr, base::Bind(&ParseJsonDelayed), kAPIKey, |
| - user_classifier_.get()); |
| + utils_.fake_signin_manager(), fake_token_service_.get(), |
| + std::move(request_context_getter), utils_.pref_service(), nullptr, |
| + base::Bind(&ParseJsonDelayed), kAPIKey, user_classifier_.get()); |
| snippets_fetcher_->SetTickClockForTesting( |
| mock_task_runner_->GetMockTickClock()); |
| } |
| + void IssueRefreshToken() { |
| + fake_token_service_delegate_->UpdateCredentials(kTestEmail, "token"); |
| + } |
| + |
| + void IssueOAuth2Token() { |
| + fake_token_service_->IssueAllTokensForAccount(kTestEmail, "access_token", |
| + base::Time::Max()); |
| + } |
| + |
| + void CancelOAuth2TokenRequests() { |
| + fake_token_service_->IssueErrorForAllPendingRequestsForAccount( |
| + kTestEmail, GoogleServiceAuthError( |
| + GoogleServiceAuthError::State::REQUEST_CANCELED)); |
| + } |
| + |
| + void SignIn() { |
|
Marc Treib
2017/02/06 11:03:17
nitty nit: Put this before IssueRefreshToken? That
jkrcal
2017/02/07 08:44:18
Done.
|
| + utils_.fake_signin_manager()->SignIn(kTestEmail); |
| + } |
| + |
| RemoteSuggestionsFetcher::SnippetsAvailableCallback |
| ToSnippetsAvailableCallback(MockSnippetsAvailableCallback* callback) { |
| return base::BindOnce(&MockSnippetsAvailableCallback::WrappedRun, |
| @@ -347,36 +371,33 @@ class RemoteSuggestionsFetcherTestBase : public testing::Test { |
| {ntp_snippets::kArticleSuggestionsFeature.name}); |
| } |
| - void SetFakeResponse(const std::string& response_data, |
| + void SetFakeResponse(const std::string& test_url, |
|
Marc Treib
2017/02/06 11:03:17
Should this be a GURL?
jkrcal
2017/02/07 08:44:18
Removed (see below).
|
| + const std::string& response_data, |
| net::HttpStatusCode response_code, |
| net::URLRequestStatus::Status status) { |
| InitFakeURLFetcherFactory(); |
| - fake_url_fetcher_factory_->SetFakeResponse(test_url_, response_data, |
| + fake_url_fetcher_factory_->SetFakeResponse(GURL(test_url), response_data, |
| response_code, status); |
| } |
| - TestingPrefServiceSimple* pref_service() const { return pref_service_.get(); } |
| - |
| protected: |
| std::map<std::string, std::string> default_variation_params_; |
| private: |
| + test::RemoteSuggestionsTestUtils utils_; |
| variations::testing::VariationParamsManager params_manager_; |
| scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_; |
| base::ThreadTaskRunnerHandle mock_task_runner_handle_; |
| FailingFakeURLFetcherFactory failing_url_fetcher_factory_; |
| // Initialized lazily in SetFakeResponse(). |
| std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; |
| - std::unique_ptr<TestSigninClient> signin_client_; |
| - std::unique_ptr<AccountTrackerService> account_tracker_; |
| - std::unique_ptr<SigninManagerBase> fake_signin_manager_; |
| - std::unique_ptr<OAuth2TokenService> fake_token_service_; |
| + FakeOAuth2TokenServiceDelegate* fake_token_service_delegate_; |
| + std::unique_ptr<FakeProfileOAuth2TokenService> fake_token_service_; |
| std::unique_ptr<RemoteSuggestionsFetcher> snippets_fetcher_; |
| - std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| std::unique_ptr<UserClassifier> user_classifier_; |
| MockSnippetsAvailableCallback mock_callback_; |
| - const GURL test_url_; |
| base::HistogramTester histogram_tester_; |
| + scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcherTestBase); |
| }; |
| @@ -385,7 +406,7 @@ class ChromeReaderSnippetsFetcherTest |
| : public RemoteSuggestionsFetcherTestBase { |
| public: |
| ChromeReaderSnippetsFetcherTest() |
| - : RemoteSuggestionsFetcherTestBase(GURL(kTestChromeReaderUrl)) { |
| + : RemoteSuggestionsFetcherTestBase() { |
| default_variation_params_["content_suggestions_backend"] = |
| kChromeReaderServer; |
| SetVariationParam("content_suggestions_backend", kChromeReaderServer); |
| @@ -397,8 +418,7 @@ class NTPSnippetsContentSuggestionsFetcherTest |
| : public RemoteSuggestionsFetcherTestBase { |
| public: |
| NTPSnippetsContentSuggestionsFetcherTest() |
| - : RemoteSuggestionsFetcherTestBase( |
| - GURL(kTestChromeContentSuggestionsUrl)) {} |
| + : RemoteSuggestionsFetcherTestBase() {} |
|
Marc Treib
2017/02/06 11:03:17
Possible alternative: Keep the TestUrl in the ctor
jkrcal
2017/02/07 08:44:18
Done.
|
| }; |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldNotFetchOnCreation) { |
| @@ -424,8 +444,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfully) { |
| " }]" |
| " }" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeReaderUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), |
| Run(IsSuccess(), |
| AllOf(IsSingleArticle("http://localhost/foobar"), |
| @@ -461,15 +481,108 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ShouldFetchSuccessfully) { |
| " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| " }]" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| + EXPECT_CALL(mock_callback(), |
| + Run(IsSuccess(), |
| + AllOf(IsSingleArticle("http://localhost/foobar"), |
| + FirstCategoryHasInfo(IsCategoryInfoForArticles())))); |
| + snippets_fetcher().FetchSnippets( |
| + test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| + FastForwardUntilNoTasksRemain(); |
| + EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); |
| + EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); |
| + EXPECT_THAT(histogram_tester().GetAllSamples( |
| + "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), |
| + ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); |
| + EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), |
| + ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, |
| + /*count=*/1))); |
| +} |
| + |
| +TEST_F(NTPSnippetsContentSuggestionsFetcherTest, |
| + ShouldFetchSuccessfullyWhenSignedIn) { |
| + SignIn(); |
| + IssueRefreshToken(); |
| + |
| + const std::string kJsonStr = |
|
Marc Treib
2017/02/06 11:03:17
Completely orthogonal to this CL, but at some poin
jkrcal
2017/02/07 08:44:18
Acknowledged.
|
| + "{\"categories\" : [{" |
| + " \"id\": 1," |
| + " \"localizedTitle\": \"Articles for You\"," |
| + " \"suggestions\" : [{" |
| + " \"ids\" : [\"http://localhost/foobar\"]," |
| + " \"title\" : \"Foo Barred from Baz\"," |
| + " \"snippet\" : \"...\"," |
| + " \"fullPageUrl\" : \"http://localhost/foobar\"," |
| + " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," |
| + " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," |
| + " \"attribution\" : \"Foo News\"," |
| + " \"imageUrl\" : \"http://localhost/foobar.jpg\"," |
| + " \"ampUrl\" : \"http://localhost/amp\"," |
| + " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| + " }]" |
| + "}]}"; |
| + SetFakeResponse(kTestChromeContentSuggestionsSignedInUrl, |
| + /*response_data=*/kJsonStr, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), |
| Run(IsSuccess(), |
| AllOf(IsSingleArticle("http://localhost/foobar"), |
| FirstCategoryHasInfo(IsCategoryInfoForArticles())))); |
| + |
| snippets_fetcher().FetchSnippets( |
| test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| + |
| + IssueOAuth2Token(); |
| FastForwardUntilNoTasksRemain(); |
|
Marc Treib
2017/02/06 11:03:17
This is necessary for the fake response, right? Wo
jkrcal
2017/02/07 08:44:18
Done.
|
| + |
| + EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); |
| + EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); |
| + EXPECT_THAT(histogram_tester().GetAllSamples( |
| + "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), |
| + ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); |
| + EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), |
| + ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, |
| + /*count=*/1))); |
| +} |
| + |
| +TEST_F(NTPSnippetsContentSuggestionsFetcherTest, |
| + ShouldFetchSuccessfullyWhenSignedInAndOAuthCancelled) { |
|
Marc Treib
2017/02/06 11:03:17
This really tests the retry, correct? Maybe someth
jkrcal
2017/02/07 08:44:18
Done.
|
| + SignIn(); |
| + IssueRefreshToken(); |
| + |
| + const std::string kJsonStr = |
| + "{\"categories\" : [{" |
| + " \"id\": 1," |
| + " \"localizedTitle\": \"Articles for You\"," |
| + " \"suggestions\" : [{" |
| + " \"ids\" : [\"http://localhost/foobar\"]," |
| + " \"title\" : \"Foo Barred from Baz\"," |
| + " \"snippet\" : \"...\"," |
| + " \"fullPageUrl\" : \"http://localhost/foobar\"," |
| + " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," |
| + " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," |
| + " \"attribution\" : \"Foo News\"," |
| + " \"imageUrl\" : \"http://localhost/foobar.jpg\"," |
| + " \"ampUrl\" : \"http://localhost/amp\"," |
| + " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| + " }]" |
| + "}]}"; |
| + SetFakeResponse(kTestChromeContentSuggestionsSignedInUrl, |
| + /*response_data=*/kJsonStr, net::HTTP_OK, |
| + net::URLRequestStatus::SUCCESS); |
| + EXPECT_CALL(mock_callback(), |
| + Run(IsSuccess(), |
| + AllOf(IsSingleArticle("http://localhost/foobar"), |
| + FirstCategoryHasInfo(IsCategoryInfoForArticles())))); |
| + |
| + snippets_fetcher().FetchSnippets( |
| + test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| + |
| + CancelOAuth2TokenRequests(); |
| + IssueOAuth2Token(); |
| + FastForwardUntilNoTasksRemain(); |
| + |
| EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); |
| EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); |
| EXPECT_THAT(histogram_tester().GetAllSamples( |
| @@ -486,8 +599,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, EmptyCategoryIsOK) { |
| " \"id\": 1," |
| " \"localizedTitle\": \"Articles for You\"" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), IsEmptyArticleList())); |
| snippets_fetcher().FetchSnippets( |
| test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| @@ -536,8 +649,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ServerCategories) { |
| " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| " }]" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) |
| .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); |
| @@ -597,8 +710,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, |
| " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| " }]" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) |
| .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); |
| @@ -661,8 +774,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) { |
| " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| " }]" |
| "}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) |
| .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); |
| @@ -686,8 +799,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) { |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { |
| const std::string kJsonStr = "{\"recos\": []}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), IsEmptyArticleList())); |
| snippets_fetcher().FetchSnippets( |
| test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| @@ -746,7 +859,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, |
| } |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportUrlStatusError) { |
| - SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND, |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, |
| + /*response_data=*/std::string(), net::HTTP_NOT_FOUND, |
| net::URLRequestStatus::FAILED); |
| EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::TEMPORARY_ERROR), |
| /*snippets=*/Not(HasValue()))) |
| @@ -768,7 +882,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportUrlStatusError) { |
| } |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportHttpError) { |
| - SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND, |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, |
| + /*response_data=*/std::string(), net::HTTP_NOT_FOUND, |
| net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::TEMPORARY_ERROR), |
| /*snippets=*/Not(HasValue()))) |
| @@ -789,7 +904,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportHttpError) { |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonError) { |
| const std::string kInvalidJsonStr = "{ \"recos\": []"; |
| - SetFakeResponse(/*response_data=*/kInvalidJsonStr, net::HTTP_OK, |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, |
| + /*response_data=*/kInvalidJsonStr, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::TEMPORARY_ERROR), |
| /*snippets=*/Not(HasValue()))) |
| @@ -812,7 +928,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonError) { |
| } |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { |
| - SetFakeResponse(/*response_data=*/std::string(), net::HTTP_OK, |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, |
| + /*response_data=*/std::string(), net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::TEMPORARY_ERROR), |
| /*snippets=*/Not(HasValue()))) |
| @@ -832,8 +949,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportInvalidListError) { |
| const std::string kJsonStr = |
| "{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::TEMPORARY_ERROR), |
| /*snippets=*/Not(HasValue()))) |
| .Times(1); |
| @@ -866,8 +983,8 @@ TEST_F(ChromeReaderSnippetsFetcherTest, |
| TEST_F(ChromeReaderSnippetsFetcherTest, ShouldProcessConcurrentFetches) { |
| const std::string kJsonStr = "{ \"recos\": [] }"; |
| - SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| - net::URLRequestStatus::SUCCESS); |
| + SetFakeResponse(kTestChromeContentSuggestionsUrl, /*response_data=*/kJsonStr, |
| + net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(mock_callback(), Run(IsSuccess(), IsEmptyArticleList())).Times(5); |
| snippets_fetcher().FetchSnippets( |
| test_params(), ToSnippetsAvailableCallback(&mock_callback())); |