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

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher_unittest.cc

Issue 1922083004: Allow fetching personalized snippets from ChromeReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fixes Created 4 years, 7 months 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/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..768539797584cc463f04d089ffd52221937cc3af 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,10 +77,14 @@ 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),
/*is_stable_channel=*/true),
test_url_(base::StringPrintf(kTestContentSnippetsServerFormat,
google_apis::GetAPIKey().c_str())) {
@@ -114,6 +122,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 +160,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(
@@ -215,7 +227,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 +243,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(
@@ -293,7 +309,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 +322,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"),

Powered by Google App Engine
This is Rietveld 408576698