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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc

Issue 2750393002: [NTP Snippets] Don't attempt to fetch remote suggestions without API key (Closed)
Patch Set: Created 3 years, 9 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/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 4771148b96458086b2a96ea91c6722d1c0be6c7e..1b1ec9c0b031951f28fb97dc9b56cc82352cafbf 100644
--- a/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc
@@ -290,7 +290,9 @@ class RemoteSuggestionsFetcherTestBase : public testing::Test {
ResetFetcher();
}
- void ResetFetcher() {
+ void ResetFetcher() { ResetFetcherWithAPIKey(kAPIKey); }
+
+ void ResetFetcherWithAPIKey(const std::string& api_key) {
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter =
new net::TestURLRequestContextGetter(mock_task_runner_.get());
@@ -302,7 +304,7 @@ class RemoteSuggestionsFetcherTestBase : public testing::Test {
utils_.fake_signin_manager(), fake_token_service_.get(),
std::move(request_context_getter), utils_.pref_service(), nullptr,
base::Bind(&ParseJsonDelayed),
- GetFetchEndpoint(version_info::Channel::STABLE), kAPIKey,
+ GetFetchEndpoint(version_info::Channel::STABLE), api_key,
user_classifier_.get());
fetcher_->SetClockForTesting(mock_task_runner_->GetMockClock());
@@ -800,6 +802,24 @@ TEST_F(RemoteSuggestionsSignedOutFetcherTest, ExclusiveCategoryOnly) {
Eq("http://localhost/foo2"));
}
+TEST_F(RemoteSuggestionsSignedOutFetcherTest, ShouldNotFetchWithoutApiKey) {
+ ResetFetcherWithAPIKey(std::string());
+
+ EXPECT_CALL(mock_callback(), Run(HasCode(StatusCode::PERMANENT_ERROR),
+ /*snippets=*/Not(HasValue())))
+ .Times(1);
+ fetcher().FetchSnippets(test_params(),
+ ToSnippetsAvailableCallback(&mock_callback()));
+ FastForwardUntilNoTasksRemain();
+
+ EXPECT_THAT(fetcher().last_status(), Eq("No API key available."));
+ EXPECT_THAT(histogram_tester().GetAllSamples(
+ "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
+ IsEmpty());
+ EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
+ IsEmpty());
+}
+
TEST_F(RemoteSuggestionsChromeReaderFetcherTest,
ShouldFetchSuccessfullyEmptyList) {
const std::string kJsonStr = "{\"recos\": []}";

Powered by Google App Engine
This is Rietveld 408576698