| Index: components/payments/core/autofill_payment_instrument_unittest.cc
|
| diff --git a/components/payments/core/autofill_payment_instrument_unittest.cc b/components/payments/core/autofill_payment_instrument_unittest.cc
|
| index 6735be8965bd719434bf503f7138fd79574b5975..0c17f1bc8a886e514d8f2bcd97922ddbae4033de 100644
|
| --- a/components/payments/core/autofill_payment_instrument_unittest.cc
|
| +++ b/components/payments/core/autofill_payment_instrument_unittest.cc
|
| @@ -11,7 +11,7 @@
|
| #include "components/autofill/core/browser/autofill_test_utils.h"
|
| #include "components/autofill/core/browser/credit_card.h"
|
| #include "components/payments/core/address_normalizer.h"
|
| -#include "components/payments/core/payment_request_delegate.h"
|
| +#include "components/payments/core/test_payment_request_delegate.h"
|
| #include "components/strings/grit/components_strings.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -47,95 +47,6 @@ class FakePaymentInstrumentDelegate : public PaymentInstrument::Delegate {
|
| bool on_instrument_details_error_called_ = false;
|
| };
|
|
|
| -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 {
|
| - profile_ = profile;
|
| - requester_ = requester;
|
| - }
|
| -
|
| - void OnAddressValidationRulesLoaded(const std::string& region_code,
|
| - bool success) override {}
|
| -
|
| - void CompleteAddressNormalization() {
|
| - requester_->OnAddressNormalized(profile_);
|
| - }
|
| -
|
| - private:
|
| - autofill::AutofillProfile profile_;
|
| - AddressNormalizer::Delegate* requester_;
|
| -};
|
| -
|
| -class FakePaymentRequestDelegate : public PaymentRequestDelegate {
|
| - public:
|
| - FakePaymentRequestDelegate()
|
| - : locale_("en-US"), last_committed_url_("https://shop.com") {}
|
| - void ShowDialog(PaymentRequest* request) override {}
|
| -
|
| - void CloseDialog() override {}
|
| -
|
| - void ShowErrorMessage() override {}
|
| -
|
| - autofill::PersonalDataManager* GetPersonalDataManager() override {
|
| - return nullptr;
|
| - }
|
| -
|
| - const std::string& GetApplicationLocale() const override { return locale_; }
|
| -
|
| - bool IsIncognito() const override { return false; }
|
| -
|
| - bool IsSslCertificateValid() override { return true; }
|
| -
|
| - const GURL& GetLastCommittedURL() const override {
|
| - return last_committed_url_;
|
| - }
|
| -
|
| - void DoFullCardRequest(
|
| - const autofill::CreditCard& credit_card,
|
| - base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
|
| - result_delegate) override {
|
| - full_card_request_card_ = credit_card;
|
| - full_card_result_delegate_ = result_delegate;
|
| - }
|
| -
|
| - AddressNormalizer* GetAddressNormalizer() override {
|
| - return &address_normalizer_;
|
| - }
|
| -
|
| - FakeAddressNormalizer* GetTestAddressNormalizer() {
|
| - return &address_normalizer_;
|
| - }
|
| -
|
| - void CompleteFullCardRequest() {
|
| - full_card_result_delegate_->OnFullCardRequestSucceeded(
|
| - full_card_request_card_, base::ASCIIToUTF16("123"));
|
| - }
|
| -
|
| - autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
|
| -
|
| - private:
|
| - std::string locale_;
|
| - const GURL last_committed_url_;
|
| - FakeAddressNormalizer address_normalizer_;
|
| -
|
| - autofill::CreditCard full_card_request_card_;
|
| - base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
|
| - full_card_result_delegate_;
|
| - DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
|
| -};
|
| -
|
| } // namespace
|
|
|
| class AutofillPaymentInstrumentTest : public testing::Test {
|
| @@ -283,7 +194,9 @@ TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoNumber) {
|
| // the billing address has been normalized and the card has been unmasked.
|
| TEST_F(AutofillPaymentInstrumentTest,
|
| InvokePaymentApp_NormalizationBeforeUnmask) {
|
| - FakePaymentRequestDelegate delegate;
|
| + TestPaymentRequestDelegate delegate(/*personal_data_manager=*/nullptr);
|
| + delegate.DelayFullCardRequestCompletion();
|
| + delegate.test_address_normalizer()->DelayNormalization();
|
|
|
| autofill::CreditCard& card = local_credit_card();
|
| card.SetNumber(base::ASCIIToUTF16(""));
|
| @@ -296,7 +209,7 @@ TEST_F(AutofillPaymentInstrumentTest,
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
|
|
|
| - delegate.GetTestAddressNormalizer()->CompleteAddressNormalization();
|
| + delegate.test_address_normalizer()->CompleteAddressNormalization();
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
|
|
|
| @@ -309,7 +222,9 @@ TEST_F(AutofillPaymentInstrumentTest,
|
| // the billing address has been normalized and the card has been unmasked.
|
| TEST_F(AutofillPaymentInstrumentTest,
|
| InvokePaymentApp_UnmaskBeforeNormalization) {
|
| - FakePaymentRequestDelegate delegate;
|
| + TestPaymentRequestDelegate delegate(/*personal_data_manager=*/nullptr);
|
| + delegate.DelayFullCardRequestCompletion();
|
| + delegate.test_address_normalizer()->DelayNormalization();
|
|
|
| autofill::CreditCard& card = local_credit_card();
|
| card.SetNumber(base::ASCIIToUTF16(""));
|
| @@ -326,7 +241,7 @@ TEST_F(AutofillPaymentInstrumentTest,
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
|
|
|
| - delegate.GetTestAddressNormalizer()->CompleteAddressNormalization();
|
| + delegate.test_address_normalizer()->CompleteAddressNormalization();
|
| EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
|
| EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
|
| }
|
|
|