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

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: After code review #2 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 c256b6c7f523d2bd294a316e8adde0f3f3045972..a59bc45e9381c0d23e228234376e87f881fc485b 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
@@ -10,6 +10,10 @@
#include "base/strings/stringprintf.h"
#include "base/test/histogram_tester.h"
#include "base/thread_task_runner_handle.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"
@@ -51,7 +55,12 @@ class NTPSnippetsFetcherTest : public testing::Test {
NTPSnippetsFetcherTest()
: fake_url_fetcher_factory_(
/*default_factory=*/&failing_url_fetcher_factory_),
- 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())),
/*is_stable_channel=*/true),
@@ -62,6 +71,7 @@ class NTPSnippetsFetcherTest : public testing::Test {
base::Unretained(&mock_callback_)));
}
+
net::FakeURLFetcherFactory& fake_url_fetcher_factory() {
return fake_url_fetcher_factory_;
}
@@ -77,6 +87,8 @@ class NTPSnippetsFetcherTest : public testing::Test {
FailingFakeURLFetcherFactory failing_url_fetcher_factory_;
// Instantiation of factory automatically sets itself as URLFetcher's factory.
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_;
@@ -107,6 +119,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
/*status_message=*/std::string()))
.Times(1);
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
RunUntilIdle();
EXPECT_THAT(histogram_tester().GetAllSamples(
@@ -124,6 +137,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
/*status_message=*/"URLRequestStatus error -2"))
.Times(1);
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
RunUntilIdle();
EXPECT_THAT(histogram_tester().GetAllSamples(
@@ -140,6 +154,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
/*status_message=*/"HTTP error 404"))
.Times(1);
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
RunUntilIdle();
EXPECT_THAT(histogram_tester().GetAllSamples(
@@ -154,6 +169,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) {
/*status_message=*/Not(IsEmpty())))
.Times(1);
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
RunUntilIdle();
}
@@ -167,10 +183,12 @@ TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) {
/*status_message=*/std::string()))
.Times(1);
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
// Second call to FetchSnippets() overrides/cancels the previous. Callback is
// expected to be called once.
snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
+ /*language_code=*/"en-US",
/*count=*/1);
RunUntilIdle();
EXPECT_THAT(histogram_tester().GetAllSamples(

Powered by Google App Engine
This is Rietveld 408576698