| Index: components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| diff --git a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| index 3c8eb846357110c64110788900c042ac943d1b94..12105f934647ba2e7faa3881e123955ecceb6b60 100644
|
| --- a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| +++ b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| @@ -13,6 +13,10 @@
|
| #include "base/thread_task_runner_handle.h"
|
| #include "base/values.h"
|
| #include "components/ntp_snippets/ntp_snippet.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 "google_apis/google_api_keys.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| @@ -73,7 +77,12 @@ void ParseJson(
|
| class NTPSnippetsFetcherTest : public testing::Test {
|
| public:
|
| NTPSnippetsFetcherTest()
|
| - : snippets_fetcher_(scoped_refptr<net::TestURLRequestContextGetter>(
|
| + : signin_client_(new TestSigninClient(nullptr)),
|
| + account_tracker_(new AccountTrackerService()),
|
| + snippets_fetcher_(new FakeSigninManagerBase(signin_client_.get(),
|
| + account_tracker_.get()),
|
| + new FakeProfileOAuth2TokenService(),
|
| + scoped_refptr<net::TestURLRequestContextGetter>(
|
| new net::TestURLRequestContextGetter(
|
| base::ThreadTaskRunnerHandle::Get())),
|
| base::Bind(&ParseJson),
|
| @@ -114,6 +123,8 @@ class NTPSnippetsFetcherTest : public testing::Test {
|
| 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_;
|
| // Needed to use ThreadTaskRunnerHandle.
|
| base::MessageLoop message_loop_;
|
| NTPSnippetsFetcher snippets_fetcher_;
|
| @@ -150,7 +161,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/SizeIs(1),
|
| /*status_message=*/std::string()))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -165,7 +178,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/std::string()))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -179,6 +194,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportEmptyHostsError) {
|
| /*status_message=*/"Cannot fetch for empty hosts list."))
|
| .Times(1);
|
| snippets_fetcher().FetchSnippetsFromHosts(/*hosts=*/std::set<std::string>(),
|
| + /*language_code=*/"en-US",
|
| /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
|
| @@ -189,7 +205,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportEmptyHostsError) {
|
|
|
| TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) {
|
| net::TestURLFetcherFactory test_url_fetcher_factory;
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/17);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/17);
|
| net::TestURLFetcher* fetcher = test_url_fetcher_factory.GetFetcherByID(0);
|
| ASSERT_THAT(fetcher, NotNull());
|
| std::unique_ptr<base::Value> value =
|
| @@ -215,7 +233,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
|
| Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/"URLRequestStatus error -2"))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -229,7 +249,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/"HTTP error 404"))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -246,7 +268,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) {
|
| Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/StartsWith("Received invalid JSON (error ")))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), Eq(kInvalidJsonStr));
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -262,7 +286,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) {
|
| Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/StartsWith("Received invalid JSON (error ")))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), std::string());
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -278,7 +304,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/"Invalid / empty list."))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| @@ -293,7 +321,9 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/Not(IsEmpty())))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| }
|
|
|
| @@ -304,10 +334,14 @@ TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) {
|
| EXPECT_CALL(mock_callback(), Run(/*snippets=*/IsEmpty(),
|
| /*status_message=*/std::string()))
|
| .Times(1);
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| // Second call to FetchSnippetsFromHosts() overrides/cancels the previous.
|
| // Callback is expected to be called once.
|
| - snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), /*count=*/1);
|
| + snippets_fetcher().FetchSnippetsFromHosts(test_hosts(),
|
| + /*language_code=*/"en-US",
|
| + /*count=*/1);
|
| RunUntilIdle();
|
| EXPECT_THAT(histogram_tester().GetAllSamples(
|
| "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
|
|
|