[Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple...
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2018 18:12:21 +0000 (18:12 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2018 18:12:21 +0000 (18:12 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237594 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt
LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/testing/MockPaymentCoordinator.cpp
Source/WebCore/testing/MockPaymentCoordinator.h
Source/WebCore/testing/MockPaymentCoordinator.idl

index 56d7b2f..0482c89 100644 (file)
@@ -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
index df6fb85..41acef6 100644 (file)
@@ -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. 
 
index 6f4e887..24ecdfd 100644 (file)
@@ -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",
@@ -182,4 +183,14 @@ promise_test(async t => {
     }
   }
 }, `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>
index 2cc72cf..25f6597 100644 (file)
@@ -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
index fdd088e..37387fe 100644 (file)
@@ -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();
index e9b4c9a..7d3b539 100644 (file)
@@ -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);
     });
 }
 
index 477107c..8be4d35 100644 (file)
@@ -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&&);
@@ -77,6 +79,8 @@ private:
     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;
index 8ee0b9c..702d595 100644 (file)
@@ -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);