Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Apple Pay] PaymentRequest.canMakePayment() should resolve to true wh…
…enever Apple Pay is available

https://bugs.webkit.org/show_bug.cgi?id=191039

Reviewed by Megan Gardner.

Source/WebCore:

During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
whenever the user agent supports one or more of the specified payment methods, even if those
payment methods do not have active instruments.

Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().

Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.

* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::canMakePayment):
(WebCore::shouldDiscloseApplePayCapability): Deleted.
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
* testing/MockPaymentCoordinator.h:
* testing/MockPaymentCoordinator.idl:

LayoutTests:

* http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
* http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:


Canonical link: https://commits.webkit.org/205882@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237594 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aestes committed Oct 30, 2018
1 parent b0dfa4b commit 265e6ea
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 19 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2018-10-30 Andy Estes <aestes@apple.com>

[Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
https://bugs.webkit.org/show_bug.cgi?id=191039

Reviewed by Megan Gardner.

* http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
* http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:

2018-10-30 Dawei Fenton <realdawei@apple.com>

[ Mojave Debug ] Layout Test http/tests/workers/service/self_registration.html is flaky
Expand Down
Expand Up @@ -6,4 +6,5 @@ PASS If payment method identifier and serialized parts are supported, resolve pr
PASS If a payment method identifier is supported but its serialized parts are not, resolve promise with false.
PASS If payment method identifier is unknown, resolve promise with false.
PASS Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.
PASS Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card.

Expand Up @@ -9,6 +9,7 @@
<script src="/resources/payment-request.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
const applePay = Object.freeze({
supportedMethods: "https://apple.com/apple-pay",
Expand Down Expand Up @@ -182,4 +183,14 @@
}
}
}, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);

promise_test(async t => {
internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(false);
const request = new PaymentRequest(defaultMethods, defaultDetails);
assert_true(
await request.canMakePayment(),
`canMakePaymentPromise should be true`
);
internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(true);
}, `Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card.`);
</script>
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
2018-10-30 Andy Estes <aestes@apple.com>

[Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
https://bugs.webkit.org/show_bug.cgi?id=191039

Reviewed by Megan Gardner.

During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
whenever the user agent supports one or more of the specified payment methods, even if those
payment methods do not have active instruments.

Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().

Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.

* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::canMakePayment):
(WebCore::shouldDiscloseApplePayCapability): Deleted.
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
* testing/MockPaymentCoordinator.h:
* testing/MockPaymentCoordinator.idl:

2018-10-30 Sihui Liu <sihui_liu@apple.com>

Add a deprecation warning to console for Web SQL
Expand Down
Expand Up @@ -225,25 +225,11 @@ void ApplePayPaymentHandler::hide()
paymentCoordinator().abortPaymentSession();
}

static bool shouldDiscloseApplePayCapability(Document& document)
{
auto* page = document.page();
if (!page || page->usesEphemeralSession())
return false;

return document.settings().applePayCapabilityDisclosureAllowed();
}

void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler)
{
if (!shouldDiscloseApplePayCapability(document())) {
completionHandler(paymentCoordinator().canMakePayments());
return;
}

paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler));
completionHandler(paymentCoordinator().canMakePayments());
}

ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> ApplePayPaymentHandler::computeShippingMethods()
{
auto& details = m_paymentRequest->paymentDetails();
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/testing/MockPaymentCoordinator.cpp
Expand Up @@ -77,13 +77,13 @@ std::optional<String> MockPaymentCoordinator::validatedPaymentNetwork(const Stri

bool MockPaymentCoordinator::canMakePayments()
{
return true;
return m_canMakePayments;
}

void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, Function<void(bool)>&& completionHandler)
{
RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] {
completionHandler(true);
RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), canMakePaymentsWithActiveCard = m_canMakePaymentsWithActiveCard] {
completionHandler(canMakePaymentsWithActiveCard);
});
}

Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/testing/MockPaymentCoordinator.h
Expand Up @@ -44,6 +44,8 @@ class MockPaymentCoordinator final : public PaymentCoordinatorClient {
public:
explicit MockPaymentCoordinator(Page&);

void setCanMakePayments(bool canMakePayments) { m_canMakePayments = canMakePayments; }
void setCanMakePaymentsWithActiveCard(bool canMakePaymentsWithActiveCard) { m_canMakePaymentsWithActiveCard = canMakePaymentsWithActiveCard; }
void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); }
void changeShippingOption(String&& shippingOption);
void changePaymentMethod(ApplePayPaymentMethod&&);
Expand Down Expand Up @@ -77,6 +79,8 @@ class MockPaymentCoordinator final : public PaymentCoordinatorClient {
void updateTotalAndLineItems(const ApplePaySessionPaymentRequest::TotalAndLineItems&);

Page& m_page;
bool m_canMakePayments { true };
bool m_canMakePaymentsWithActiveCard { true };
ApplePayPaymentContact m_shippingAddress;
ApplePayLineItem m_total;
Vector<ApplePayLineItem> m_lineItems;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/testing/MockPaymentCoordinator.idl
Expand Up @@ -27,6 +27,8 @@
Conditional=APPLE_PAY,
NoInterfaceObject,
] interface MockPaymentCoordinator {
void setCanMakePayments(boolean canMakePayments);
void setCanMakePaymentsWithActiveCard(boolean canMakePaymentsWithActiveCard);
void setShippingAddress(MockPaymentAddress shippingAddress);
void changeShippingOption(DOMString shippingOption);
void changePaymentMethod(ApplePayPaymentMethod paymentMethod);
Expand Down

0 comments on commit 265e6ea

Please sign in to comment.