Commit 7e61913a authored by sebsg's avatar sebsg Committed by Commit bot

[Payments] Normalize shipping address change on Desktop

Also make sure that the user cannot click pay until we
get the callback from the merchant.

BUG=715170,715597

Review-Url: https://codereview.chromium.org/2836353002
Cr-Commit-Position: refs/heads/master@{#467698}
parent 923beb5a
......@@ -82,6 +82,7 @@ source_set("unit_tests") {
"//components/autofill/core/browser",
"//components/autofill/core/browser:test_support",
"//components/payments/core",
"//components/payments/core:test_support",
"//components/payments/mojom",
"//content/test:test_support",
"//net:test_support",
......
......@@ -9,11 +9,11 @@
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/payments/content/payment_request_spec.h"
#include "components/payments/content/payment_response_helper.h"
#include "components/payments/core/autofill_payment_instrument.h"
#include "components/payments/core/payment_instrument.h"
......@@ -29,6 +29,7 @@ PaymentRequestState::PaymentRequestState(
autofill::PersonalDataManager* personal_data_manager,
PaymentRequestDelegate* payment_request_delegate)
: is_ready_to_pay_(false),
is_waiting_for_merchant_validation_(false),
app_locale_(app_locale),
spec_(spec),
delegate_(delegate),
......@@ -39,6 +40,7 @@ PaymentRequestState::PaymentRequestState(
payment_request_delegate_(payment_request_delegate) {
PopulateProfileCache();
SetDefaultProfileSelections();
spec_->AddObserver(this);
}
PaymentRequestState::~PaymentRequestState() {}
......@@ -47,6 +49,25 @@ void PaymentRequestState::OnPaymentResponseReady(
delegate_->OnPaymentResponseAvailable(std::move(payment_response));
}
void PaymentRequestState::OnAddressNormalized(
const autofill::AutofillProfile& normalized_profile) {
delegate_->OnShippingAddressSelected(
PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile(
normalized_profile, app_locale_));
}
void PaymentRequestState::OnCouldNotNormalize(
const autofill::AutofillProfile& profile) {
// Since the phone number is formatted in either case, this profile should be
// used.
OnAddressNormalized(profile);
}
void PaymentRequestState::OnSpecUpdated() {
is_waiting_for_merchant_validation_ = false;
UpdateIsReadyToPayAndNotifyObservers();
}
bool PaymentRequestState::CanMakePayment() const {
for (const std::unique_ptr<PaymentInstrument>& instrument :
available_instruments_) {
......@@ -133,10 +154,21 @@ void PaymentRequestState::SetSelectedShippingProfile(
spec_->StartWaitingForUpdateWith(
PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS);
selected_shipping_profile_ = profile;
// The user should not be able to click on pay until the callback from the
// merchant.
is_waiting_for_merchant_validation_ = true;
UpdateIsReadyToPayAndNotifyObservers();
delegate_->OnShippingAddressSelected(
PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile(
selected_shipping_profile_, app_locale_));
// Start the normalization of the shipping address.
// Use the country code from the profile if it is set, otherwise infer it
// from the |app_locale_|.
std::string country_code = base::UTF16ToUTF8(
selected_shipping_profile_->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
if (!autofill::data_util::IsValidCountryCode(country_code))
country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale_);
payment_request_delegate_->GetAddressNormalizer()->StartAddressNormalization(
*selected_shipping_profile_, country_code, /*timeout_seconds=*/2, this);
}
void PaymentRequestState::SetSelectedContactProfile(
......@@ -246,6 +278,9 @@ bool PaymentRequestState::ArePaymentOptionsSatisfied() {
if (spec_->request_shipping() && selected_shipping_profile_ == nullptr)
return false;
if (is_waiting_for_merchant_validation_)
return false;
profile_util::PaymentsProfileComparator comparator(app_locale_, *spec_);
return comparator.IsContactInfoComplete(selected_contact_profile_);
}
......
......@@ -11,7 +11,9 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "components/payments/content/payment_request_spec.h"
#include "components/payments/content/payment_response_helper.h"
#include "components/payments/core/address_normalizer.h"
#include "components/payments/mojom/payment_request.mojom.h"
namespace autofill {
......@@ -25,13 +27,14 @@ namespace payments {
class PaymentInstrument;
class PaymentRequestDelegate;
class PaymentRequestSpec;
// Keeps track of the information currently selected by the user and whether the
// user is ready to pay. Uses information from the PaymentRequestSpec, which is
// what the merchant has specified, as input into the "is ready to pay"
// computation.
class PaymentRequestState : public PaymentResponseHelper::Delegate {
class PaymentRequestState : public PaymentResponseHelper::Delegate,
public AddressNormalizer::Delegate,
public PaymentRequestSpec::Observer {
public:
// Any class call add itself as Observer via AddObserver() and receive
// notification about the state changing.
......@@ -73,6 +76,15 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate {
void OnPaymentResponseReady(
mojom::PaymentResponsePtr payment_response) override;
// AddressNormalizer::Delegate
void OnAddressNormalized(
const autofill::AutofillProfile& normalized_profile) override;
void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override;
// PaymentRequestSpec::Observer
void OnStartUpdating(PaymentRequestSpec::UpdateReason reason) override {}
void OnSpecUpdated() override;
// Returns whether the user has at least one instrument that satisfies the
// specified supported payment methods.
bool CanMakePayment() const;
......@@ -172,6 +184,9 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate {
bool is_ready_to_pay_;
// Whether the data is currently being validated by the merchant.
bool is_waiting_for_merchant_validation_;
const std::string app_locale_;
// Not owned. Never null. Both outlive this object.
......
......@@ -13,6 +13,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/test_payment_request_delegate.h"
#include "components/payments/mojom/payment_request.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -24,6 +25,7 @@ class PaymentRequestStateTest : public testing::Test,
protected:
PaymentRequestStateTest()
: num_on_selected_information_changed_called_(0),
test_payment_request_delegate_(/*personal_data_manager=*/nullptr),
address_(autofill::test::GetFullProfile()),
credit_card_visa_(autofill::test::GetCreditCard()) {
test_personal_data_manager_.AddTestingProfile(&address_);
......@@ -43,7 +45,9 @@ class PaymentRequestStateTest : public testing::Test,
payment_response_ = std::move(response);
};
void OnShippingOptionIdSelected(std::string shipping_option_id) override {}
void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override {}
void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override {
selected_shipping_address_ = std::move(address);
}
void RecreateStateWithOptionsAndDetails(
mojom::PaymentOptionsPtr options,
......@@ -54,14 +58,21 @@ class PaymentRequestStateTest : public testing::Test,
std::move(options), std::move(details), std::move(method_data), nullptr,
"en-US");
state_ = base::MakeUnique<PaymentRequestState>(
spec_.get(), this, "en-US", &test_personal_data_manager_, nullptr);
spec_.get(), this, "en-US", &test_personal_data_manager_,
&test_payment_request_delegate_);
state_->AddObserver(this);
}
// Convenience method to create a PaymentRequestState with default details
// (one shipping option) and method data (only supports visa).
void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) {
// Create dummy PaymentDetails with a single shipping option.
RecreateStateWithOptionsAndDetails(
std::move(options), CreateDefaultDetails(), GetMethodDataForVisa());
}
// Convenience method that returns a dummy PaymentDetails with a single
// shipping option.
mojom::PaymentDetailsPtr CreateDefaultDetails() {
std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
mojom::PaymentShippingOptionPtr option =
mojom::PaymentShippingOption::New();
......@@ -69,9 +80,7 @@ class PaymentRequestStateTest : public testing::Test,
shipping_options.push_back(std::move(option));
mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
details->shipping_options = std::move(shipping_options);
RecreateStateWithOptionsAndDetails(std::move(options), std::move(details),
GetMethodDataForVisa());
return details;
}
// Convenience method that returns MethodData that supports Visa.
......@@ -84,19 +93,28 @@ class PaymentRequestStateTest : public testing::Test,
}
PaymentRequestState* state() { return state_.get(); }
PaymentRequestSpec* spec() { return spec_.get(); }
const mojom::PaymentResponsePtr& response() { return payment_response_; }
const mojom::PaymentAddressPtr& selected_shipping_address() {
return selected_shipping_address_;
}
int num_on_selected_information_changed_called() {
return num_on_selected_information_changed_called_;
}
autofill::AutofillProfile* test_address() { return &address_; }
TestPaymentRequestDelegate* test_payment_request_delegate() {
return &test_payment_request_delegate_;
}
private:
std::unique_ptr<PaymentRequestState> state_;
std::unique_ptr<PaymentRequestSpec> spec_;
int num_on_selected_information_changed_called_;
mojom::PaymentResponsePtr payment_response_;
mojom::PaymentAddressPtr selected_shipping_address_;
autofill::TestPersonalDataManager test_personal_data_manager_;
TestPaymentRequestDelegate test_payment_request_delegate_;
// Test data.
autofill::AutofillProfile address_;
......@@ -206,6 +224,9 @@ TEST_F(PaymentRequestStateTest, ReadyToPay_DefaultSelections) {
state()->SetSelectedShippingProfile(test_address());
EXPECT_EQ(1, num_on_selected_information_changed_called());
// Simulate that the merchant has validated the shipping address change.
spec()->UpdateWith(CreateDefaultDetails());
EXPECT_EQ(2, num_on_selected_information_changed_called());
EXPECT_TRUE(state()->is_ready_to_pay());
}
......@@ -247,4 +268,49 @@ TEST_F(PaymentRequestStateTest, ReadyToPay_ContactInfo) {
EXPECT_TRUE(state()->is_ready_to_pay());
}
TEST_F(PaymentRequestStateTest, SelectedShippingAddressMessage_Normalized) {
mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
options->request_shipping = true;
RecreateStateWithOptions(std::move(options));
// Make the normalization not be instantaneous.
test_payment_request_delegate()
->GetTestAddressNormalizer()
->DelayNormalization();
EXPECT_EQ(0, num_on_selected_information_changed_called());
// Select an address, nothing should happen until the normalization is
// completed and the merchant has validated the address.
state()->SetSelectedShippingProfile(test_address());
EXPECT_EQ(1, num_on_selected_information_changed_called());
EXPECT_FALSE(state()->is_ready_to_pay());
// Complete the normalization.
test_payment_request_delegate()
->GetTestAddressNormalizer()
->CompleteAddressNormalization();
EXPECT_EQ(1, num_on_selected_information_changed_called());
EXPECT_FALSE(state()->is_ready_to_pay());
// Simulate that the merchant has validated the shipping address change.
spec()->UpdateWith(CreateDefaultDetails());
EXPECT_EQ(2, num_on_selected_information_changed_called());
EXPECT_TRUE(state()->is_ready_to_pay());
// Check that all the expected values were set for the shipping address.
EXPECT_EQ("US", selected_shipping_address()->country);
EXPECT_EQ("666 Erebus St.", selected_shipping_address()->address_line[0]);
EXPECT_EQ("Apt 8", selected_shipping_address()->address_line[1]);
EXPECT_EQ("CA", selected_shipping_address()->region);
EXPECT_EQ("Elysium", selected_shipping_address()->city);
EXPECT_EQ("", selected_shipping_address()->dependent_locality);
EXPECT_EQ("91111", selected_shipping_address()->postal_code);
EXPECT_EQ("", selected_shipping_address()->sorting_code);
EXPECT_EQ("", selected_shipping_address()->language_code);
EXPECT_EQ("Underworld", selected_shipping_address()->organization);
EXPECT_EQ("John H. Doe", selected_shipping_address()->recipient);
EXPECT_EQ("16502111111", selected_shipping_address()->phone);
}
} // namespace payments
......@@ -68,36 +68,36 @@ PaymentResponseHelper::~PaymentResponseHelper(){};
// static
mojom::PaymentAddressPtr
PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile(
const autofill::AutofillProfile* const profile,
const autofill::AutofillProfile& profile,
const std::string& app_locale) {
mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New();
payment_address->country =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
payment_address->address_line = base::SplitString(
base::UTF16ToUTF8(profile->GetInfo(
base::UTF16ToUTF8(profile.GetInfo(
autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS),
app_locale)),
"\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
payment_address->region =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_STATE));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_STATE));
payment_address->city =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_CITY));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_CITY));
payment_address->dependent_locality = base::UTF16ToUTF8(
profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY));
profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY));
payment_address->postal_code =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP));
payment_address->sorting_code = base::UTF16ToUTF8(
profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE));
payment_address->language_code = profile->language_code();
profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE));
payment_address->language_code = profile.language_code();
payment_address->organization =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::COMPANY_NAME));
payment_address->recipient = base::UTF16ToUTF8(profile->GetInfo(
autofill::AutofillType(autofill::NAME_FULL), app_locale));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME));
payment_address->recipient = base::UTF16ToUTF8(
profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale));
// TODO(crbug.com/705945): Format phone number according to spec.
payment_address->phone =
base::UTF16ToUTF8(profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER));
return payment_address;
}
......@@ -149,7 +149,7 @@ void PaymentResponseHelper::GeneratePaymentResponse() {
// Shipping Address section
if (spec_->request_shipping()) {
payment_response->shipping_address =
GetMojomPaymentAddressFromAutofillProfile(&shipping_address_,
GetMojomPaymentAddressFromAutofillProfile(shipping_address_,
app_locale_);
payment_response->shipping_option = spec_->selected_shipping_option()->id;
}
......
......@@ -43,7 +43,7 @@ class PaymentResponseHelper : public PaymentInstrument::Delegate,
// Returns a new mojo PaymentAddress based on the specified
// |profile| and |app_locale|.
static mojom::PaymentAddressPtr GetMojomPaymentAddressFromAutofillProfile(
const autofill::AutofillProfile* const profile,
const autofill::AutofillProfile& profile,
const std::string& app_locale);
// PaymentInstrument::Delegate
......@@ -74,6 +74,8 @@ class PaymentResponseHelper : public PaymentInstrument::Delegate,
// Not owned, can be null (dependent on the spec).
autofill::AutofillProfile* selected_contact_profile_;
// A normalized copy of the shipping address, which will be included in the
// PaymentResponse.
autofill::AutofillProfile shipping_address_;
// Instrument Details.
......
......@@ -16,95 +16,18 @@
#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/core/test_payment_request_delegate.h"
#include "components/payments/mojom/payment_request.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
namespace {
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(
autofill::PersonalDataManager* personal_data_manager)
: personal_data_manager_(personal_data_manager),
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 personal_data_manager_;
}
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 {
result_delegate->OnFullCardRequestSucceeded(credit_card,
base::ASCIIToUTF16("123"));
}
AddressNormalizer* GetAddressNormalizer() override {
return &address_normalizer_;
}
autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
private:
autofill::PersonalDataManager* personal_data_manager_;
std::string locale_;
const GURL last_committed_url_;
FakeAddressNormalizer address_normalizer_;
DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
};
} // namespace
class PaymentResponseHelperTest : public testing::Test,
public PaymentResponseHelper::Delegate {
protected:
PaymentResponseHelperTest()
: payment_request_delegate_(&test_personal_data_manager_),
: test_payment_request_delegate_(&test_personal_data_manager_),
address_(autofill::test::GetFullProfile()),
billing_addresses_({&address_}) {
test_personal_data_manager_.AddTestingProfile(&address_);
......@@ -115,7 +38,7 @@ class PaymentResponseHelperTest : public testing::Test,
visa_card.set_use_count(5u);
autofill_instrument_ = base::MakeUnique<AutofillPaymentInstrument>(
"visa", visa_card, billing_addresses_, "en-US",
&payment_request_delegate_);
&test_payment_request_delegate_);
}
~PaymentResponseHelperTest() override {}
......@@ -166,14 +89,14 @@ class PaymentResponseHelperTest : public testing::Test,
autofill::AutofillProfile* test_address() { return &address_; }
PaymentInstrument* test_instrument() { return autofill_instrument_.get(); }
PaymentRequestDelegate* test_payment_request_delegate() {
return &payment_request_delegate_;
return &test_payment_request_delegate_;
}
private:
std::unique_ptr<PaymentRequestSpec> spec_;
mojom::PaymentResponsePtr payment_response_;
autofill::TestPersonalDataManager test_personal_data_manager_;
FakePaymentRequestDelegate payment_request_delegate_;
TestPaymentRequestDelegate test_payment_request_delegate_;
// Test data.
autofill::AutofillProfile address_;
......
......@@ -47,6 +47,22 @@ static_library("core") {
]
}
static_library("test_support") {
testonly = true
sources = [
"test_address_normalizer.cc",
"test_address_normalizer.h",
"test_payment_request_delegate.cc",
"test_payment_request_delegate.h",
]
deps = [
":core",
"//base",
"//components/autofill/core/browser",
]
}
source_set("unit_tests") {
testonly = true
sources = [
......@@ -63,6 +79,7 @@ source_set("unit_tests") {
deps = [
":core",
":test_support",
"//base",
"//base/test:test_support",
"//components/autofill/core/browser",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/core/test_address_normalizer.h"
namespace payments {
bool TestAddressNormalizer::AreRulesLoadedForRegion(
const std::string& region_code) {
return true;
}
void TestAddressNormalizer::StartAddressNormalization(
const autofill::AutofillProfile& profile,
const std::string& region_code,
int timeout_seconds,
AddressNormalizer::Delegate* requester) {
if (instantaneous_normalization_) {
requester->OnAddressNormalized(profile);
return;
}
// Setup the necessary variables for the delayed normalization.
profile_ = profile;
requester_ = requester;
}
void TestAddressNormalizer::DelayNormalization() {
instantaneous_normalization_ = false;
}
void TestAddressNormalizer::CompleteAddressNormalization() {
requester_->OnAddressNormalized(profile_);
}
} // namespace payments
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAYMENTS_CORE_TEST_ADDRESS_NORMALIZER_H_
#define COMPONENTS_PAYMENTS_CORE_TEST_ADDRESS_NORMALIZER_H_
#include "components/payments/core/address_normalizer.h"
#include "components/autofill/core/browser/autofill_profile.h"
namespace payments {
// A simpler version of the address normalizer to be used in tests. Can be set
// to normalize instantaneously or to wait for a call.
class TestAddressNormalizer : public AddressNormalizer {
public:
TestAddressNormalizer() {}
void LoadRulesForRegion(const std::string& region_code) override {}
bool AreRulesLoadedForRegion(const std::string& region_code) override;
void StartAddressNormalization(
const autofill::AutofillProfile& profile,
const std::string& region_code,
int timeout_seconds,
AddressNormalizer::Delegate* requester) override;
void OnAddressValidationRulesLoaded(const std::string& region_code,
bool success) override {}
void DelayNormalization();
void CompleteAddressNormalization();
private:
autofill::AutofillProfile profile_;
AddressNormalizer::Delegate* requester_;
bool instantaneous_normalization_ = true;
};
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CORE_TEST_ADDRESS_NORMALIZER_H_
\ No newline at end of file
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/core/test_payment_request_delegate.h"
#include "base/strings/utf_string_conversions.h"
namespace payments {
TestPaymentRequestDelegate::TestPaymentRequestDelegate(
autofill::PersonalDataManager* personal_data_manager)
: personal_data_manager_(personal_data_manager),
locale_("en-US"),
last_committed_url_("https://shop.com") {}
TestPaymentRequestDelegate::~TestPaymentRequestDelegate() {}
autofill::PersonalDataManager*
TestPaymentRequestDelegate::GetPersonalDataManager() {
return personal_data_manager_;
}
const std::string& TestPaymentRequestDelegate::GetApplicationLocale() const {
return locale_;
}
bool TestPaymentRequestDelegate::IsIncognito() const {
return false;
}
bool TestPaymentRequestDelegate::IsSslCertificateValid() {
return true;
}
const GURL& TestPaymentRequestDelegate::GetLastCommittedURL() const {
return last_committed_url_;
}
void TestPaymentRequestDelegate::DoFullCardRequest(
const autofill::CreditCard& credit_card,
base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
result_delegate) {
result_delegate->OnFullCardRequestSucceeded(credit_card,
base::ASCIIToUTF16("123"));
}
AddressNormalizer* TestPaymentRequestDelegate::GetAddressNormalizer() {
return &address_normalizer_;
}
TestAddressNormalizer* TestPaymentRequestDelegate::GetTestAddressNormalizer() {
return &address_normalizer_;
}
autofill::RegionDataLoader* TestPaymentRequestDelegate::GetRegionDataLoader() {
return nullptr;
}
} // namespace payments
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAYMENTS_CORE_TEST_PAYMENT_REQUEST_DELEGATE_H_
#define COMPONENTS_PAYMENTS_CORE_TEST_PAYMENT_REQUEST_DELEGATE_H_
#include "components/payments/core/payment_request_delegate.h"
#include "components/payments/core/test_address_normalizer.h"
namespace payments {
class TestPaymentRequestDelegate : public PaymentRequestDelegate {
public:
TestPaymentRequestDelegate(
autofill::PersonalDataManager* personal_data_manager);
~TestPaymentRequestDelegate() override;
// PaymentRequestDelegate
void ShowDialog(PaymentRequest* request) override {}
void CloseDialog() override {}
void ShowErrorMessage() override {}
autofill::PersonalDataManager* GetPersonalDataManager() override;
const std::string& GetApplicationLocale() const override;
bool IsIncognito() const override;
bool IsSslCertificateValid() override;
const GURL& GetLastCommittedURL() const override;
void DoFullCardRequest(
const autofill::CreditCard& credit_card,
base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
result_delegate) override;
AddressNormalizer* GetAddressNormalizer() override;
autofill::RegionDataLoader* GetRegionDataLoader() override;
TestAddressNormalizer* GetTestAddressNormalizer();
private:
autofill::PersonalDataManager* personal_data_manager_;
std::string locale_;
const GURL last_committed_url_;
TestAddressNormalizer address_normalizer_;
autofill::CreditCard full_card_request_card_;
base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
full_card_result_delegate_;
DISALLOW_COPY_AND_ASSIGN(TestPaymentRequestDelegate);
};
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CORE_TEST_PAYMENT_REQUEST_DELEGATE_H_
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