| Index: components/payments/content/payment_response_helper_unittest.cc
|
| diff --git a/components/payments/content/payment_response_helper_unittest.cc b/components/payments/content/payment_response_helper_unittest.cc
|
| index ed9757c551825cfb04a5c2f4d5eca236824d3811..a79d8d1dde150ee2d209b67dd45d8ecf4af005d1 100644
|
| --- a/components/payments/content/payment_response_helper_unittest.cc
|
| +++ b/components/payments/content/payment_response_helper_unittest.cc
|
| @@ -16,6 +16,7 @@
|
| #include "components/autofill/core/browser/credit_card.h"
|
| #include "components/autofill/core/browser/test_personal_data_manager.h"
|
| #include "components/payments/content/payment_request_spec.h"
|
| +#include "components/payments/core/address_normalizer.h"
|
| #include "components/payments/core/autofill_payment_instrument.h"
|
| #include "components/payments/core/payment_request_delegate.h"
|
| #include "components/payments/mojom/payment_request.mojom.h"
|
| @@ -23,6 +24,28 @@
|
|
|
| namespace payments {
|
|
|
| +class FakeAddressNormalizer : public AddressNormalizer {
|
| + public:
|
| + FakeAddressNormalizer() {}
|
| +
|
| + void LoadRulesForRegion(const std::string& region_code) override {}
|
| +
|
| + bool AreRulesLoadedForRegion(const std::string& region_code) override {
|
| + return true;
|
| + }
|
| +
|
| + void StartAddressNormalization(
|
| + const autofill::AutofillProfile& profile,
|
| + const std::string& region_code,
|
| + int timeout_seconds,
|
| + AddressNormalizer::Delegate* requester) override {
|
| + requester->OnAddressNormalized(profile);
|
| + }
|
| +
|
| + void OnAddressValidationRulesLoaded(const std::string& region_code,
|
| + bool success) override {}
|
| +};
|
| +
|
| class FakePaymentRequestDelegate : public PaymentRequestDelegate {
|
| public:
|
| FakePaymentRequestDelegate(
|
| @@ -58,7 +81,7 @@ class FakePaymentRequestDelegate : public PaymentRequestDelegate {
|
| base::ASCIIToUTF16("123"));
|
| }
|
|
|
| - std::unique_ptr<const ::i18n::addressinput::Source> GetAddressInputSource()
|
| + std::unique_ptr<::i18n::addressinput::Source> GetAddressInputSource()
|
| override {
|
| return nullptr;
|
| }
|
| @@ -68,10 +91,15 @@ class FakePaymentRequestDelegate : public PaymentRequestDelegate {
|
| return nullptr;
|
| }
|
|
|
| + AddressNormalizer* GetAddressNormalizer() override {
|
| + return &address_normalizer_;
|
| + }
|
| +
|
| private:
|
| autofill::PersonalDataManager* personal_data_manager_;
|
| std::string locale_;
|
| const GURL last_committed_url_;
|
| + FakeAddressNormalizer address_normalizer_;
|
| DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
|
| };
|
|
|
| @@ -140,6 +168,9 @@ class PaymentResponseHelperTest : public testing::Test,
|
| const mojom::PaymentResponsePtr& response() { return payment_response_; }
|
| autofill::AutofillProfile* test_address() { return &address_; }
|
| PaymentInstrument* test_instrument() { return autofill_instrument_.get(); }
|
| + PaymentRequestDelegate* test_payment_request_delegate() {
|
| + return &payment_request_delegate_;
|
| + }
|
|
|
| private:
|
| std::unique_ptr<PaymentRequestSpec> spec_;
|
| @@ -162,7 +193,8 @@ TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_SupportedMethod) {
|
| // "visa" is specified directly in the supportedMethods so it is returned
|
| // as the method name.
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
| EXPECT_EQ("visa", response()->method_name);
|
| EXPECT_EQ(
|
| "{\"billingAddress\":"
|
| @@ -198,7 +230,8 @@ TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_BasicCard) {
|
| // TODO(mathp): Currently synchronous, when async will need a RunLoop.
|
| // "basic-card" is specified so it is returned as the method name.
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
| EXPECT_EQ("basic-card", response()->method_name);
|
| EXPECT_EQ(
|
| "{\"billingAddress\":"
|
| @@ -235,7 +268,8 @@ TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_ShippingAddress) {
|
| GetMethodDataForVisa());
|
|
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
|
|
| // Check that all the expected values were set.
|
| EXPECT_EQ("US", response()->shipping_address->country);
|
| @@ -263,7 +297,8 @@ TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_ContactDetails_All) {
|
| RecreateSpecWithOptions(std::move(options));
|
|
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
|
|
| // Check that all the expected values were set.
|
| EXPECT_EQ("John H. Doe", response()->payer_name.value());
|
| @@ -280,7 +315,8 @@ TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_ContactDetails_Some) {
|
| RecreateSpecWithOptions(std::move(options));
|
|
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
|
|
| // Check that the name was set, but not the other values.
|
| EXPECT_EQ("John H. Doe", response()->payer_name.value());
|
| @@ -300,7 +336,8 @@ TEST_F(PaymentResponseHelperTest,
|
| RecreateSpecWithOptions(std::move(options));
|
|
|
| PaymentResponseHelper helper("en-US", spec(), test_instrument(),
|
| - test_address(), test_address(), this);
|
| + test_payment_request_delegate(), test_address(),
|
| + test_address(), this);
|
|
|
| // Check that the phone was formatted.
|
| EXPECT_EQ("+15151231234", response()->payer_phone.value());
|
|
|