Commit 5a14e98f authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Payment Request] Update obsolete method name.

PaymentApp::IsValidForCanMakePayment() is only used to compute
hasEnrolledInstrument(). Update this name to HasEnrolledInstrument() to
more accurately reflect the behavior.

Bug: 915907
Change-Id: Ib6281ef0856f1acc6a8d67bbc8ff7b06a69a8684
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052190
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740827}
parent d82ad3a9
...@@ -38,14 +38,6 @@ ...@@ -38,14 +38,6 @@
namespace payments { namespace payments {
namespace { namespace {
// Checks whether any of the |apps| return true in IsValidForCanMakePayment().
bool GetHasEnrolledInstrument(
const std::vector<std::unique_ptr<PaymentApp>>& apps) {
return std::any_of(apps.begin(), apps.end(), [](const auto& app) {
return app->IsValidForCanMakePayment();
});
}
// Invokes the |callback| with |status|. // Invokes the |callback| with |status|.
void CallStatusCallback(PaymentRequestState::StatusCallback callback, void CallStatusCallback(PaymentRequestState::StatusCallback callback,
bool status) { bool status) {
...@@ -174,7 +166,9 @@ void PaymentRequestState::OnDoneCreatingPaymentApps() { ...@@ -174,7 +166,9 @@ void PaymentRequestState::OnDoneCreatingPaymentApps() {
SetDefaultProfileSelections(); SetDefaultProfileSelections();
get_all_apps_finished_ = true; get_all_apps_finished_ = true;
has_enrolled_instrument_ = GetHasEnrolledInstrument(available_apps_); has_enrolled_instrument_ =
std::any_of(available_apps_.begin(), available_apps_.end(),
[](const auto& app) { return app->HasEnrolledInstrument(); });
are_requested_methods_supported_ |= !available_apps_.empty(); are_requested_methods_supported_ |= !available_apps_.empty();
NotifyOnGetAllPaymentAppsFinished(); NotifyOnGetAllPaymentAppsFinished();
NotifyInitialized(); NotifyInitialized();
......
...@@ -394,7 +394,7 @@ base::string16 ServiceWorkerPaymentApp::GetMissingInfoLabel() const { ...@@ -394,7 +394,7 @@ base::string16 ServiceWorkerPaymentApp::GetMissingInfoLabel() const {
return base::string16(); return base::string16();
} }
bool ServiceWorkerPaymentApp::IsValidForCanMakePayment() const { bool ServiceWorkerPaymentApp::HasEnrolledInstrument() const {
// This app should not be used when can_make_payment_result_ is false, so this // This app should not be used when can_make_payment_result_ is false, so this
// interface should not be invoked. // interface should not be invoked.
DCHECK(can_make_payment_result_); DCHECK(can_make_payment_result_);
......
...@@ -82,7 +82,7 @@ class ServiceWorkerPaymentApp : public PaymentApp { ...@@ -82,7 +82,7 @@ class ServiceWorkerPaymentApp : public PaymentApp {
uint32_t GetCompletenessScore() const override; uint32_t GetCompletenessScore() const override;
bool CanPreselect() const override; bool CanPreselect() const override;
base::string16 GetMissingInfoLabel() const override; base::string16 GetMissingInfoLabel() const override;
bool IsValidForCanMakePayment() const override; bool HasEnrolledInstrument() const override;
void RecordUse() override; void RecordUse() override;
bool NeedsInstallation() const override; bool NeedsInstallation() const override;
base::string16 GetLabel() const override; base::string16 GetLabel() const override;
......
...@@ -223,7 +223,7 @@ TEST_F(ServiceWorkerPaymentAppTest, ValidateCanMakePayment) { ...@@ -223,7 +223,7 @@ TEST_F(ServiceWorkerPaymentAppTest, ValidateCanMakePayment) {
CreateServiceWorkerPaymentApp(/*with_url_method=*/true); CreateServiceWorkerPaymentApp(/*with_url_method=*/true);
GetApp()->ValidateCanMakePayment(base::BindOnce( GetApp()->ValidateCanMakePayment(base::BindOnce(
[](ServiceWorkerPaymentApp*, bool result) { EXPECT_TRUE(result); })); [](ServiceWorkerPaymentApp*, bool result) { EXPECT_TRUE(result); }));
EXPECT_FALSE(GetApp()->IsValidForCanMakePayment()); EXPECT_FALSE(GetApp()->HasEnrolledInstrument());
} }
// Test modifiers can be matched based on capabilities. // Test modifiers can be matched based on capabilities.
......
...@@ -101,7 +101,7 @@ base::string16 AutofillPaymentApp::GetMissingInfoLabel() const { ...@@ -101,7 +101,7 @@ base::string16 AutofillPaymentApp::GetMissingInfoLabel() const {
GetCompletionStatusForCard(credit_card_, app_locale_, billing_profiles_)); GetCompletionStatusForCard(credit_card_, app_locale_, billing_profiles_));
} }
bool AutofillPaymentApp::IsValidForCanMakePayment() const { bool AutofillPaymentApp::HasEnrolledInstrument() const {
CreditCardCompletionStatus status = CreditCardCompletionStatus status =
GetCompletionStatusForCard(credit_card_, app_locale_, billing_profiles_); GetCompletionStatusForCard(credit_card_, app_locale_, billing_profiles_);
if (PaymentsExperimentalFeatures::IsEnabled( if (PaymentsExperimentalFeatures::IsEnabled(
......
...@@ -43,7 +43,7 @@ class AutofillPaymentApp ...@@ -43,7 +43,7 @@ class AutofillPaymentApp
uint32_t GetCompletenessScore() const override; uint32_t GetCompletenessScore() const override;
bool CanPreselect() const override; bool CanPreselect() const override;
base::string16 GetMissingInfoLabel() const override; base::string16 GetMissingInfoLabel() const override;
bool IsValidForCanMakePayment() const override; bool HasEnrolledInstrument() const override;
void RecordUse() override; void RecordUse() override;
bool NeedsInstallation() const override; bool NeedsInstallation() const override;
base::string16 GetLabel() const override; base::string16 GetLabel() const override;
......
...@@ -271,36 +271,36 @@ TEST_F(AutofillPaymentAppTest, IsCompleteForPayment_ExpiredMaskedCard) { ...@@ -271,36 +271,36 @@ TEST_F(AutofillPaymentAppTest, IsCompleteForPayment_ExpiredMaskedCard) {
} }
// An expired card is a valid app for canMakePayment. // An expired card is a valid app for canMakePayment.
TEST_F(AutofillPaymentAppTest, IsValidForCanMakePayment_Minimal) { TEST_F(AutofillPaymentAppTest, HasEnrolledInstrument_Minimal) {
autofill::CreditCard& card = local_credit_card(); autofill::CreditCard& card = local_credit_card();
card.SetExpirationYear(2016); // Expired. card.SetExpirationYear(2016); // Expired.
AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr); AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr);
EXPECT_TRUE(app.IsValidForCanMakePayment()); EXPECT_TRUE(app.HasEnrolledInstrument());
} }
// An expired Masked (server) card is a valid app for canMakePayment. // An expired Masked (server) card is a valid app for canMakePayment.
TEST_F(AutofillPaymentAppTest, IsValidForCanMakePayment_MaskedCard) { TEST_F(AutofillPaymentAppTest, HasEnrolledInstrument_MaskedCard) {
autofill::CreditCard card = autofill::test::GetMaskedServerCard(); autofill::CreditCard card = autofill::test::GetMaskedServerCard();
card.SetExpirationYear(2016); // Expired. card.SetExpirationYear(2016); // Expired.
AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr); AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr);
EXPECT_TRUE(app.IsValidForCanMakePayment()); EXPECT_TRUE(app.HasEnrolledInstrument());
} }
// A card with no name is not a valid app for canMakePayment. // A card with no name is not a valid app for canMakePayment.
TEST_F(AutofillPaymentAppTest, IsValidForCanMakePayment_NoName) { TEST_F(AutofillPaymentAppTest, HasEnrolledInstrument_NoName) {
autofill::CreditCard& card = local_credit_card(); autofill::CreditCard& card = local_credit_card();
card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
base::ASCIIToUTF16(""), "en-US"); base::ASCIIToUTF16(""), "en-US");
AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr); AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr);
EXPECT_FALSE(app.IsValidForCanMakePayment()); EXPECT_FALSE(app.HasEnrolledInstrument());
} }
// A card with no number is not a valid app for canMakePayment. // A card with no number is not a valid app for canMakePayment.
TEST_F(AutofillPaymentAppTest, IsValidForCanMakePayment_NoNumber) { TEST_F(AutofillPaymentAppTest, HasEnrolledInstrument_NoNumber) {
autofill::CreditCard& card = local_credit_card(); autofill::CreditCard& card = local_credit_card();
card.SetNumber(base::ASCIIToUTF16("")); card.SetNumber(base::ASCIIToUTF16(""));
AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr); AutofillPaymentApp app("visa", card, billing_profiles(), "en-US", nullptr);
EXPECT_FALSE(app.IsValidForCanMakePayment()); EXPECT_FALSE(app.HasEnrolledInstrument());
} }
// Tests that the autofill app only calls OnappDetailsReady when // Tests that the autofill app only calls OnappDetailsReady when
......
...@@ -60,10 +60,8 @@ class PaymentApp { ...@@ -60,10 +60,8 @@ class PaymentApp {
// Returns a message to indicate to the user what's missing for the app to be // Returns a message to indicate to the user what's missing for the app to be
// complete for payment. // complete for payment.
virtual base::string16 GetMissingInfoLabel() const = 0; virtual base::string16 GetMissingInfoLabel() const = 0;
// Returns whether the app is valid for the purposes of responding to // Returns this app's answer for PaymentRequest.hasEnrolledInstrument().
// canMakePayment. virtual bool HasEnrolledInstrument() const = 0;
// TODO(crbug.com/915907): rename to IsValidForHasEnrolledInstrument.
virtual bool IsValidForCanMakePayment() const = 0;
// Records the use of this payment app. // Records the use of this payment app.
virtual void RecordUse() = 0; virtual void RecordUse() = 0;
// Check whether this payment app needs installation before it can be used. // Check whether this payment app needs installation before it can be used.
......
...@@ -54,7 +54,7 @@ class IOSPaymentInstrument : public PaymentApp { ...@@ -54,7 +54,7 @@ class IOSPaymentInstrument : public PaymentApp {
uint32_t GetCompletenessScore() const override; uint32_t GetCompletenessScore() const override;
bool CanPreselect() const override; bool CanPreselect() const override;
base::string16 GetMissingInfoLabel() const override; base::string16 GetMissingInfoLabel() const override;
bool IsValidForCanMakePayment() const override; bool HasEnrolledInstrument() const override;
void RecordUse() override; void RecordUse() override;
bool NeedsInstallation() const override; bool NeedsInstallation() const override;
base::string16 GetLabel() const override; base::string16 GetLabel() const override;
......
...@@ -80,7 +80,7 @@ base::string16 IOSPaymentInstrument::GetMissingInfoLabel() const { ...@@ -80,7 +80,7 @@ base::string16 IOSPaymentInstrument::GetMissingInfoLabel() const {
return base::string16(); return base::string16();
} }
bool IOSPaymentInstrument::IsValidForCanMakePayment() const { bool IOSPaymentInstrument::HasEnrolledInstrument() const {
// Same as IsCompleteForPayment, as long as the native app is installed // Same as IsCompleteForPayment, as long as the native app is installed
// and found on the user's device then it is valid for payment. // and found on the user's device then it is valid for payment.
return true; return true;
......
...@@ -417,7 +417,7 @@ const PaymentsProfileComparator* PaymentRequest::profile_comparator() const { ...@@ -417,7 +417,7 @@ const PaymentsProfileComparator* PaymentRequest::profile_comparator() const {
bool PaymentRequest::CanMakePayment() const { bool PaymentRequest::CanMakePayment() const {
for (PaymentApp* payment_method : payment_methods_) { for (PaymentApp* payment_method : payment_methods_) {
if (payment_method->IsValidForCanMakePayment()) { if (payment_method->HasEnrolledInstrument()) {
return true; return true;
} }
} }
......
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