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

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

Issue 2548343002: NTPSnippets: Set MaxRetriesOn5xx only for interactive requests. (Closed)
Patch Set: Created 4 years 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/ntp_snippets_fetcher_unittest.cc
diff --git a/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc b/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
index e5533de8bd9abf0e84a412e664ea34389b694887..4d408031e88f58c2d13da03f65292bf3ef506e0b 100644
--- a/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
+++ b/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
@@ -13,6 +13,7 @@
#include "base/test/histogram_tester.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/ntp_snippets/category_factory.h"
@@ -27,6 +28,7 @@
#include "components/variations/entropy_provider.h"
#include "components/variations/variations_associated_data.h"
#include "net/url_request/test_url_fetcher_factory.h"
+#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -241,9 +243,7 @@ class NTPSnippetsFetcherTest : public testing::Test {
void ResetSnippetsFetcher() {
snippets_fetcher_ = base::MakeUnique<NTPSnippetsFetcher>(
fake_signin_manager_.get(), fake_token_service_.get(),
- scoped_refptr<net::TestURLRequestContextGetter>(
- new net::TestURLRequestContextGetter(mock_task_runner_.get())),
- pref_service_.get(), &category_factory_, nullptr,
+ CreateContextGetter(), pref_service_.get(), &category_factory_, nullptr,
base::Bind(&ParseJsonDelayed), kAPIKey, user_classifier_.get());
snippets_fetcher_->SetTickClockForTesting(
@@ -270,6 +270,11 @@ class NTPSnippetsFetcherTest : public testing::Test {
return result;
}
+ scoped_refptr<net::TestURLRequestContextGetter> CreateContextGetter() {
+ return scoped_refptr<net::TestURLRequestContextGetter>(
+ new net::TestURLRequestContextGetter(mock_task_runner_.get()));
+ }
+
void InitFakeURLFetcherFactory() {
if (fake_url_fetcher_factory_) {
return;
@@ -1094,4 +1099,24 @@ TEST_F(NTPSnippetsFetcherTest, ShouldProcessConcurrentFetches) {
return os << "null";
}
+TEST_F(NTPSnippetsFetcherTest, BuildRequestFetcherDependingOnInteractivity) {
+ NTPSnippetsFetcher::RequestBuilder builder;
+ base::DefaultTickClock clock;
+ NTPSnippetsFetcher::Params params = test_params();
+ builder.SetUrl(GURL("http://valid-irrelevant-url.com"))
+ .SetUrlRequestContextGetter(CreateContextGetter())
+ .SetPersonalization(NTPSnippetsFetcher::Personalization::kNonPersonal)
+ .SetTickClock(&clock);
+
+ params.interactive_request = false;
+ builder.SetParams(params);
+ EXPECT_THAT(builder.PreviewURLFetcherForTesting()->GetMaxRetriesOn5xx(),
+ Eq(0));
+
+ params.interactive_request = true;
+ builder.SetParams(params);
+ EXPECT_THAT(builder.PreviewURLFetcherForTesting()->GetMaxRetriesOn5xx(),
+ Eq(2));
+}
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698