Commit cf1181e9 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make payment tests use two argument ResponseHeader manipulation calls

We want to get rid of the single argument AddHeader() method as the two
argument AddHeader() and SetHeader() methods are safer and more flexible.

Bug: 1068194
Change-Id: Id950858f00c584a99af69faab6f70ed4c984db9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150009
Auto-Submit: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759406}
parent 2c63bfd4
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/payments/core/payment_manifest_downloader.h" #include "components/payments/core/payment_manifest_downloader.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/optional.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -24,7 +25,8 @@ using testing::_; ...@@ -24,7 +25,8 @@ using testing::_;
static constexpr char kNoContent[] = ""; static constexpr char kNoContent[] = "";
static constexpr char kNoError[] = ""; static constexpr char kNoError[] = "";
static constexpr char kNoLinkHeader[] = ""; static constexpr base::nullopt_t kNoLinkHeader = base::nullopt;
static constexpr char kEmptyLinkHeader[] = "";
static constexpr char kNoResponseBody[] = ""; static constexpr char kNoResponseBody[] = "";
} // namespace } // namespace
...@@ -56,7 +58,7 @@ class PaymentMethodManifestDownloaderTest : public testing::Test { ...@@ -56,7 +58,7 @@ class PaymentMethodManifestDownloaderTest : public testing::Test {
void ServerResponse(int response_code, void ServerResponse(int response_code,
Headers send_headers, Headers send_headers,
const std::string& link_header, base::Optional<std::string> link_header,
const std::string& response_body) { const std::string& response_body) {
scoped_refptr<net::HttpResponseHeaders> headers; scoped_refptr<net::HttpResponseHeaders> headers;
if (send_headers == Headers::kSend) { if (send_headers == Headers::kSend) {
...@@ -66,8 +68,8 @@ class PaymentMethodManifestDownloaderTest : public testing::Test { ...@@ -66,8 +68,8 @@ class PaymentMethodManifestDownloaderTest : public testing::Test {
net::GetHttpReasonPhrase( net::GetHttpReasonPhrase(
static_cast<net::HttpStatusCode>(response_code)))); static_cast<net::HttpStatusCode>(response_code))));
if (!link_header.empty()) if (link_header.has_value())
headers->AddHeader(link_header); headers->SetHeader("Link", *link_header);
} }
downloader_.OnURLLoaderCompleteInternal( downloader_.OnURLLoaderCompleteInternal(
...@@ -151,14 +153,14 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -151,14 +153,14 @@ TEST_F(PaymentMethodManifestDownloaderTest,
"No content and no \"Link: rel=payment-method-manifest\" " "No content and no \"Link: rel=payment-method-manifest\" "
"HTTP header found at \"https://bobpay.com/\".")); "HTTP header found at \"https://bobpay.com/\"."));
ServerResponse(200, Headers::kSend, "Link:", kNoResponseBody); ServerResponse(200, Headers::kSend, kEmptyLinkHeader, kNoResponseBody);
} }
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
EmptyHttpLinkHeaderButWithResponseBodyIsSuccess) { EmptyHttpLinkHeaderButWithResponseBodyIsSuccess) {
EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError));
ServerResponse(200, Headers::kSend, "Link:", "response body"); ServerResponse(200, Headers::kSend, kEmptyLinkHeader, "response body");
} }
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
...@@ -169,14 +171,14 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -169,14 +171,14 @@ TEST_F(PaymentMethodManifestDownloaderTest,
"No content and no \"Link: rel=payment-method-manifest\" " "No content and no \"Link: rel=payment-method-manifest\" "
"HTTP header found at \"https://bobpay.com/\".")); "HTTP header found at \"https://bobpay.com/\"."));
ServerResponse(200, Headers::kSend, "Link: <manifest.json>", kNoResponseBody); ServerResponse(200, Headers::kSend, "<manifest.json>", kNoResponseBody);
} }
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
NoRelInHttpLinkHeaderButWithResponseBodyIsSuccess) { NoRelInHttpLinkHeaderButWithResponseBodyIsSuccess) {
EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError));
ServerResponse(200, Headers::kSend, "Link: <manifest.json>", "response body"); ServerResponse(200, Headers::kSend, "<manifest.json>", "response body");
} }
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
...@@ -187,7 +189,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -187,7 +189,7 @@ TEST_F(PaymentMethodManifestDownloaderTest,
"No content and no \"Link: rel=payment-method-manifest\" " "No content and no \"Link: rel=payment-method-manifest\" "
"HTTP header found at \"https://bobpay.com/\".")); "HTTP header found at \"https://bobpay.com/\"."));
ServerResponse(200, Headers::kSend, "Link: rel=payment-method-manifest", ServerResponse(200, Headers::kSend, "rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
} }
...@@ -195,7 +197,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -195,7 +197,7 @@ TEST_F(PaymentMethodManifestDownloaderTest,
NoUrlInHttpLinkHeaderButWithResponseBodyIsSuccess) { NoUrlInHttpLinkHeaderButWithResponseBodyIsSuccess) {
EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError));
ServerResponse(200, Headers::kSend, "Link: rel=payment-method-manifest", ServerResponse(200, Headers::kSend, "rel=payment-method-manifest",
"response body"); "response body");
} }
...@@ -207,8 +209,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -207,8 +209,7 @@ TEST_F(PaymentMethodManifestDownloaderTest,
"No content and no \"Link: rel=payment-method-manifest\" " "No content and no \"Link: rel=payment-method-manifest\" "
"HTTP header found at \"https://bobpay.com/\".")); "HTTP header found at \"https://bobpay.com/\"."));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend, "<manifest.json>; rel=web-app-manifest",
"Link: <manifest.json>; rel=web-app-manifest",
kNoResponseBody); kNoResponseBody);
} }
...@@ -216,14 +217,13 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -216,14 +217,13 @@ TEST_F(PaymentMethodManifestDownloaderTest,
NoManifestRellInHttpLinkHeaderButWithResponseBodyIsSuccess) { NoManifestRellInHttpLinkHeaderButWithResponseBodyIsSuccess) {
EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "response body", kNoError));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend, "<manifest.json>; rel=web-app-manifest",
"Link: <manifest.json>; rel=web-app-manifest",
"response body"); "response body");
} }
TEST_F(PaymentMethodManifestDownloaderTest, SecondHttpResponse404IsFailure) { TEST_F(PaymentMethodManifestDownloaderTest, SecondHttpResponse404IsFailure) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, EXPECT_CALL(*this,
...@@ -236,7 +236,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, SecondHttpResponse404IsFailure) { ...@@ -236,7 +236,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, SecondHttpResponse404IsFailure) {
TEST_F(PaymentMethodManifestDownloaderTest, EmptySecondResponseIsFailure) { TEST_F(PaymentMethodManifestDownloaderTest, EmptySecondResponseIsFailure) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, EXPECT_CALL(*this,
...@@ -250,7 +250,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, EmptySecondResponseIsFailure) { ...@@ -250,7 +250,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, EmptySecondResponseIsFailure) {
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithoutHeadersIsFailure) { SecondResponseWithoutHeadersIsFailure) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, EXPECT_CALL(*this,
...@@ -263,7 +263,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -263,7 +263,7 @@ TEST_F(PaymentMethodManifestDownloaderTest,
TEST_F(PaymentMethodManifestDownloaderTest, NonEmptySecondResponseIsSuccess) { TEST_F(PaymentMethodManifestDownloaderTest, NonEmptySecondResponseIsSuccess) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
...@@ -273,7 +273,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, NonEmptySecondResponseIsSuccess) { ...@@ -273,7 +273,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, NonEmptySecondResponseIsSuccess) {
TEST_F(PaymentMethodManifestDownloaderTest, FirstResponseCode204IsSuccess) { TEST_F(PaymentMethodManifestDownloaderTest, FirstResponseCode204IsSuccess) {
ServerResponse(204, Headers::kSend, ServerResponse(204, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
...@@ -283,7 +283,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, FirstResponseCode204IsSuccess) { ...@@ -283,7 +283,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, FirstResponseCode204IsSuccess) {
TEST_F(PaymentMethodManifestDownloaderTest, SecondResponseCode204IsFailure) { TEST_F(PaymentMethodManifestDownloaderTest, SecondResponseCode204IsFailure) {
ServerResponse(204, Headers::kSend, ServerResponse(204, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, EXPECT_CALL(*this,
...@@ -297,7 +297,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, SecondResponseCode204IsFailure) { ...@@ -297,7 +297,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, SecondResponseCode204IsFailure) {
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithLinkHeaderAndNoContentIsFailure) { SecondResponseWithLinkHeaderAndNoContentIsFailure) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, EXPECT_CALL(*this,
...@@ -306,26 +306,26 @@ TEST_F(PaymentMethodManifestDownloaderTest, ...@@ -306,26 +306,26 @@ TEST_F(PaymentMethodManifestDownloaderTest,
"\"https://bobpay.com/manifest.json\".")); "\"https://bobpay.com/manifest.json\"."));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
} }
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithLinkHeaderAndWithContentReturnsTheContent) { SecondResponseWithLinkHeaderAndWithContentReturnsTheContent) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
"manifest content"); "manifest content");
} }
TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) { TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_EQ("https://bobpay.com/manifest.json", GetOriginalURL()); EXPECT_EQ("https://bobpay.com/manifest.json", GetOriginalURL());
...@@ -333,7 +333,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) { ...@@ -333,7 +333,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) {
TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) { TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <https://bobpay.com/manifest.json>; " "<https://bobpay.com/manifest.json>; "
"rel=payment-method-manifest", "rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
...@@ -350,7 +350,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) { ...@@ -350,7 +350,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) {
ServerResponse( ServerResponse(
200, Headers::kSend, 200, Headers::kSend,
"Link: <http://bobpay.com/manifest.json>; rel=payment-method-manifest", "<http://bobpay.com/manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
} }
...@@ -374,7 +374,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 301And302AreSupportedRedirects) { ...@@ -374,7 +374,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 301And302AreSupportedRedirects) {
EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com")); EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com"));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
...@@ -385,7 +385,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 301And302AreSupportedRedirects) { ...@@ -385,7 +385,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 301And302AreSupportedRedirects) {
TEST_F(PaymentMethodManifestDownloaderTest, TEST_F(PaymentMethodManifestDownloaderTest,
CannotRedirectAfterFollowingLinkHeader) { CannotRedirectAfterFollowingLinkHeader) {
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload( EXPECT_CALL(*this, OnManifestDownload(
...@@ -406,7 +406,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 302And303AreSupportedRedirects) { ...@@ -406,7 +406,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 302And303AreSupportedRedirects) {
EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com")); EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com"));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
...@@ -443,7 +443,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 307And308AreSupportedRedirects) { ...@@ -443,7 +443,7 @@ TEST_F(PaymentMethodManifestDownloaderTest, 307And308AreSupportedRedirects) {
EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com")); EXPECT_EQ(GetOriginalURL(), GURL("https://newpay.bobpay.com"));
ServerResponse(200, Headers::kSend, ServerResponse(200, Headers::kSend,
"Link: <manifest.json>; rel=payment-method-manifest", "<manifest.json>; rel=payment-method-manifest",
kNoResponseBody); kNoResponseBody);
EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError)); EXPECT_CALL(*this, OnManifestDownload(_, "manifest content", kNoError));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment