#include "components/payments/core/payment_manifest_downloader.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/functional/bind.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/payments/core/const_csp_checker.h"
#include "components/payments/core/error_logger.h"
#include "components/payments/core/features.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
namespace {
_;
static constexpr char kNoContent[] = …;
static constexpr char kNoError[] = …;
static constexpr std::nullopt_t kNoLinkHeader = …;
static constexpr char kEmptyLinkHeader[] = …;
static constexpr char kNoResponseBody[] = …;
}
class PaymentManifestDownloaderTestBase : public testing::Test { … };
class PaymentMethodManifestDownloaderTest
: public PaymentManifestDownloaderTestBase { … };
TEST_F(PaymentMethodManifestDownloaderTest, FirstHttpResponse404IsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoHttpHeadersAndEmptyResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoHttpHeadersButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
EmptyHttpHeaderAndEmptyResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
EmptyHttpHeaderButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
EmptyHttpLinkHeaderWithoutResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
EmptyHttpLinkHeaderButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoRelInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoRelInHttpLinkHeaderButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoUrlInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoUrlInHttpLinkHeaderButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoManifestRellInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
NoManifestRellInHttpLinkHeaderButWithResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest, SecondHttpResponse404IsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest, EmptySecondResponseIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithoutHeadersButWithContentIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithoutContentIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest, NonEmptySecondResponseIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
InsufficientResourcesInHttpLinkFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
InsufficientResourcesAfterHttpLinkFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest, FirstResponseCode204IsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderTest, SecondResponseCode204IsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithLinkHeaderAndNoContentIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
SecondResponseWithLinkHeaderAndWithContentReturnsTheContent) { … }
TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) { … }
TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) { … }
TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 300IsUnsupportedRedirect) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 301And302AreSupportedRedirects) { … }
TEST_F(PaymentMethodManifestDownloaderTest,
CannotRedirectAfterFollowingLinkHeader) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 302And303AreSupportedRedirects) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 304IsUnsupportedRedirect) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 305IsUnsupportedRedirect) { … }
TEST_F(PaymentMethodManifestDownloaderTest, 307And308AreSupportedRedirects) { … }
TEST_F(PaymentMethodManifestDownloaderTest, NoMoreThanThreeRedirects) { … }
TEST_F(PaymentMethodManifestDownloaderTest, InvalidRedirectUrlIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderTest, NotAllowCrossSiteRedirects) { … }
class PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest
: public PaymentManifestDownloaderTestBase { … };
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoHttpHeadersAndEmptyResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoHttpHeadersButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
EmptyHttpHeaderAndEmptyResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
EmptyHttpHeaderButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
EmptyHttpLinkHeaderWithoutResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
EmptyHttpLinkHeaderButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoRelInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoUrlInHttpLinkHeaderButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoManifestRellInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoManifestRellInHttpLinkHeaderButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoRelInHttpLinkHeaderButWithResponseBodyIsSuccess) { … }
TEST_F(PaymentMethodManifestDownloaderLinkHeaderNotRequiredTest,
NoUrlInHttpLinkHeaderAndNoResponseBodyIsFailure) { … }
class WebAppManifestDownloaderTest : public PaymentManifestDownloaderTestBase { … };
TEST_F(WebAppManifestDownloaderTest, HttpGetResponse404IsFailure) { … }
TEST_F(WebAppManifestDownloaderTest, EmptyHttpGetResponseIsFailure) { … }
TEST_F(WebAppManifestDownloaderTest, NonEmptyHttpGetResponseIsSuccess) { … }
TEST_F(WebAppManifestDownloaderTest, InsufficientResourcesFailure) { … }
PaymentManifestDownloaderCSPTest;
TEST_F(PaymentManifestDownloaderCSPTest,
PaymentMethodManifestCSPCheckerMissing) { … }
TEST_F(PaymentManifestDownloaderCSPTest, WebAppManifestCSPCheckerMissing) { … }
TEST_F(PaymentManifestDownloaderCSPTest, PaymentMethodManifestCSPDenied) { … }
TEST_F(PaymentManifestDownloaderCSPTest, WebAppManifestCSPDenied) { … }
}