Commit 159e5131 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Return true in canMakePayment().

Before this patch, calling PaymentRequest.canMakePayment() after its
value has been calculated would return "false", ignoring the fact that
secure payment confirmation is being requested, for which
canMakePayment() should return "true" if an authenticator device is
available, even if there are no credentials on file.

This patch changes PaymentRequestState::CanMakePayment() to use
GetCanMakePaymentValue() after all apps have finished queried. This
method takes into account whether secure payment confirmation is being
requested and an authenticator is available.

After this patch, PaymentRequestState.canMakePayment() always returns
"true" for secure payment confirmation when an authenticator is
available (if the secure payment confirmation feature is enabled).

Bug: 1123148
Change-Id: I4bb4895cbc1c7db1d84a19c9d753d5766769ad84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383693Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802927}
parent 2ee75d9b
......@@ -220,6 +220,11 @@ IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
base::StringPrintf("canMakePaymentForMethodData(%s)", kTestMethodData);
EXPECT_EQ("true", content::EvalJs(GetActiveWebContents(), snippet));
}
{
std::string snippet = base::StringPrintf(
"canMakePaymentForMethodDataTwice(%s)", kTestMethodData);
EXPECT_EQ("true", content::EvalJs(GetActiveWebContents(), snippet));
}
{
std::string snippet = base::StringPrintf(
"hasEnrolledInstrumentForMethodData(%s)", kTestMethodData);
......
......@@ -300,7 +300,7 @@ void PaymentRequestState::CanMakePayment(StatusCallback callback) {
return;
}
PostStatusCallback(std::move(callback), are_requested_methods_supported_);
PostStatusCallback(std::move(callback), GetCanMakePaymentValue());
}
void PaymentRequestState::HasEnrolledInstrument(StatusCallback callback) {
......
......@@ -38,6 +38,23 @@ async function canMakePaymentForMethodData(methodData) { // eslint-disable-line
}
}
/**
* Creates a PaymentRequest with |methodData|, checks canMakePayment twice, and
* returns the second value.
* @param {object} methodData - The payment method data to build the request.
* @return {string} - 'true', 'false', or error message on failure.
*/
async function canMakePaymentForMethodDataTwice(methodData) { // eslint-disable-line no-unused-vars, max-len
try {
const request = new PaymentRequest(methodData, kDetails);
await request.canMakePayment(); // Discard first result.
const result = await request.canMakePayment();
return result ? 'true' : 'false';
} catch (e) {
return e.message;
}
}
/**
* Creates a PaymentRequest with |methodData| and checks hasEnrolledInstrument.
* @param {object} methodData - The payment method data to build the request.
......
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