[Payment Request] Implement the "user aborts the payment request" algorithm
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 18:00:28 +0000 (18:00 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 18:00:28 +0000 (18:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178810

Reviewed by Tim Horton.

Source/WebCore:

* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::didCancelPaymentSession):
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::cancel):
* Modules/paymentrequest/PaymentRequest.h:
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::cancelPayment):
* testing/MockPaymentCoordinator.h:
* testing/MockPaymentCoordinator.idl:

LayoutTests:

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

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

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

index f8f1125..2dd65f2 100644 (file)
@@ -1,3 +1,13 @@
+2017-10-25  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] Implement the "user aborts the payment request" algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178810
+
+        Reviewed by Tim Horton.
+
+        * http/tests/paymentrequest/payment-request-show-method.https-expected.txt:
+        * http/tests/paymentrequest/payment-request-show-method.https.html:
+
 2017-10-25  Daniel Bates  <dabates@apple.com>
 
         Attempt to fix flaky test fast/writing-mode/english-bt-text-with-spelling-marker.html following r223938
index 0c71560..8c991c6 100644 (file)
@@ -3,4 +3,5 @@ PASS Must be possible to construct a payment request
 PASS Throws if the promise [[state]] is not "created" 
 PASS If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException. 
 PASS If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException. 
+PASS If the user aborts the payment request algorithm, then return a promise rejected with an "AbortError" DOMException. 
 
index 40eae83..e3ec4ef 100644 (file)
@@ -65,4 +65,11 @@ promise_test(async t => {
   const acceptPromise = request.show();
   await promise_rejects(t, "NotSupportedError", acceptPromise);
 }, `If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.`);
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const acceptPromise = request.show(); // Sets state to "interactive"
+  internals.mockPaymentCoordinator.cancelPayment();
+  await promise_rejects(t, "AbortError", acceptPromise);
+}, `If the user aborts the payment request algorithm, then return a promise rejected with an "AbortError" DOMException.`);
 </script>
index 5e6893b..f1460d6 100644 (file)
@@ -1,3 +1,21 @@
+2017-10-25  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] Implement the "user aborts the payment request" algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178810
+
+        Reviewed by Tim Horton.
+
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::ApplePayPaymentHandler::didCancelPaymentSession):
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::cancel):
+        * Modules/paymentrequest/PaymentRequest.h:
+        * testing/MockPaymentCoordinator.cpp:
+        (WebCore::MockPaymentCoordinator::cancelPayment):
+        * testing/MockPaymentCoordinator.h:
+        * testing/MockPaymentCoordinator.idl:
+
 2017-10-25  Jer Noble  <jer.noble@apple.com>
 
         Autoplay muted videos still stop playback of other streaming apps in the background
index 8eae376..1544298 100644 (file)
@@ -389,6 +389,11 @@ void ApplePayPaymentHandler::didSelectPaymentMethod(const PaymentMethod& payment
     m_paymentRequest->dispatchEvent(event.get());
 }
 
+void ApplePayPaymentHandler::didCancelPaymentSession()
+{
+    m_paymentRequest->cancel();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
index f1b9ea7..8129cba 100644 (file)
@@ -69,7 +69,7 @@ private:
     void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final;
     void didSelectShippingContact(const PaymentContact&) final;
     void didSelectPaymentMethod(const PaymentMethod&) final;
-    void didCancelPaymentSession() final { }
+    void didCancelPaymentSession() final;
 
     PaymentRequest::MethodIdentifier m_identifier;
     Ref<PaymentRequest> m_paymentRequest;
index a37e290..a6afb21 100644 (file)
@@ -656,6 +656,18 @@ void PaymentRequest::complete(std::optional<PaymentComplete>&& result)
     std::exchange(m_activePaymentHandler, nullptr)->complete(WTFMove(result));
 }
 
+void PaymentRequest::cancel()
+{
+    if (m_state != State::Interactive)
+        return;
+
+    if (m_isUpdating)
+        return;
+
+    m_activePaymentHandler = nullptr;
+    stop();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(PAYMENT_REQUEST)
index ff315cb..295272d 100644 (file)
@@ -73,6 +73,7 @@ public:
     ExceptionOr<void> updateWith(Event&, Ref<DOMPromise>&&);
     void accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone);
     void complete(std::optional<PaymentComplete>&&);
+    void cancel();
 
     // EventTarget
     bool dispatchEvent(Event&) final;
index ae05f24..7e675c9 100644 (file)
@@ -130,6 +130,15 @@ void MockPaymentCoordinator::acceptPayment()
     });
 }
 
+void MockPaymentCoordinator::cancelPayment()
+{
+    dispatchIfShowing([mainFrame = makeRef(m_mainFrame)] {
+        mainFrame->paymentCoordinator().didCancelPaymentSession();
+        ++hideCount;
+        ASSERT(showCount == hideCount);
+    });
+}
+
 void MockPaymentCoordinator::completePaymentSession(std::optional<PaymentAuthorizationResult>&&)
 {
     ++hideCount;
index 7535eb4..bbfb398 100644 (file)
@@ -43,6 +43,7 @@ public:
     void changeShippingOption(String&& shippingOption);
     void changePaymentMethod(ApplePayPaymentMethod&&);
     void acceptPayment();
+    void cancelPayment();
 
     void ref() const { }
     void deref() const { }
index 64e96ce..99ebf82 100644 (file)
@@ -31,4 +31,5 @@
     void changeShippingOption(DOMString shippingOption);
     void changePaymentMethod(ApplePayPaymentMethod paymentMethod);
     void acceptPayment();
+    void cancelPayment();
 };