[Apple Pay] Implement a paymentmethodselected event for PaymentRequest
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 00:52:04 +0000 (00:52 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 00:52:04 +0000 (00:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178765

Reviewed by Tim Horton.

Source/WebCore:

When the Apple Pay payment method changes, fire an applepaypaymentmethodchanged event on the
PaymentRequest object. The event has a paymentMethod property and an updateWith() method
which behaves identically to PaymentRequestUpdateEvent.updateWith().

Test: http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html

* DerivedSources.make:
* Modules/applepay/ApplePayPaymentMethod.idl:
* Modules/applepay/ApplePayPaymentMethodSelectedEvent.h:
* Modules/applepay/PaymentMethod.h:
(WebCore::PaymentMethod::PaymentMethod): Deleted.
(WebCore::PaymentMethod::pkPaymentMethod const): Deleted.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::detailsUpdated):
(WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
(WebCore::ApplePayPaymentHandler::didSelectPaymentMethod):
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
* Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.cpp: Added.
(WebCore::ApplePayPaymentMethodUpdateEvent::ApplePayPaymentMethodUpdateEvent):
(WebCore::ApplePayPaymentMethodUpdateEvent::eventInterface const):
* Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.h: Added.
* Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl: Added.
* Modules/paymentrequest/PaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::shippingAddressChanged):
(WebCore::PaymentRequest::shippingOptionChanged):
(WebCore::PaymentRequest::dispatchEvent):
(WebCore::PaymentRequest::updateWith):
(WebCore::PaymentRequest::settleDetailsPromise):
(WebCore::PaymentRequest::dispatchUpdateEvent): Deleted.
* Modules/paymentrequest/PaymentRequest.h:
* Modules/paymentrequest/PaymentRequest.idl:
* Modules/paymentrequest/PaymentRequestUpdateEvent.cpp:
(WebCore::PaymentRequestUpdateEvent::updateWith):
* Modules/paymentrequest/PaymentRequestUpdateEvent.h:
* WebCore.xcodeproj/project.pbxproj:
* dom/EventNames.h:
* dom/EventNames.in:
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::changePaymentMethod):
* testing/MockPaymentCoordinator.h:
* testing/MockPaymentCoordinator.idl:
* testing/MockPaymentMethod.h: Added.

LayoutTests:

* http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https-expected.txt: Added.
* http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html: Added.

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

26 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/applepay/ApplePayPaymentMethod.idl
Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.h
Source/WebCore/Modules/applepay/PaymentMethod.h
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.cpp [new file with mode: 0644]
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.h [new file with mode: 0644]
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl [new file with mode: 0644]
Source/WebCore/Modules/paymentrequest/PaymentHandler.h
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
Source/WebCore/Modules/paymentrequest/PaymentRequest.h
Source/WebCore/Modules/paymentrequest/PaymentRequest.idl
Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp
Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/EventNames.in
Source/WebCore/testing/MockPaymentCoordinator.cpp
Source/WebCore/testing/MockPaymentCoordinator.h
Source/WebCore/testing/MockPaymentCoordinator.idl
Source/WebCore/testing/MockPaymentMethod.h [new file with mode: 0644]

index 7ab5e5d..36690ed 100644 (file)
@@ -1,3 +1,13 @@
+2017-10-24  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Implement a paymentmethodselected event for PaymentRequest
+        https://bugs.webkit.org/show_bug.cgi?id=178765
+
+        Reviewed by Tim Horton.
+
+        * http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https-expected.txt: Added.
+        * http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html: Added.
+
 2017-10-24  Daniel Bates  <dabates@apple.com>
 
         Test fast/writing-mode/english-bt-text-with-spelling-marker.html should wait for editing commands to complete
diff --git a/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https-expected.txt b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https-expected.txt
new file mode 100644 (file)
index 0000000..807b18c
--- /dev/null
@@ -0,0 +1,19 @@
+Test the applepaypaymentmethodchanged event.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing ApplePayMerchantValidationEvent
+
+PASS event.paymentMethod.displayName is expectedPaymentMethod.displayName
+PASS event.paymentMethod.network is expectedPaymentMethod.network
+PASS event.paymentMethod.type is expectedPaymentMethod.type
+PASS event.paymentMethod.paymentPass.primaryAccountIdentifier is expectedPaymentMethod.paymentPass.primaryAccountIdentifier
+PASS event.paymentMethod.paymentPass.primaryAccountNumberSuffix is expectedPaymentMethod.paymentPass.primaryAccountNumberSuffix
+PASS event.paymentMethod.paymentPass.deviceAccountIdentifier is expectedPaymentMethod.paymentPass.deviceAccountIdentifier
+PASS event.paymentMethod.paymentPass.deviceAccountNumberSuffix is expectedPaymentMethod.paymentPass.deviceAccountNumberSuffix
+PASS event.paymentMethod.paymentPass.activationState is expectedPaymentMethod.paymentPass.activationState
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html
new file mode 100644 (file)
index 0000000..7d4b0ea
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="/js-test-resources/ui-helper.js"></script>
+<script src="/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+description("Test the applepaypaymentmethodchanged event.");
+
+window.jsTestIsAsync = true;
+
+function validPaymentMethod() {
+    return {
+        supportedMethods: 'https://apple.com/apple-pay',
+        data: {
+            version: 2,
+            merchantIdentifier: '',
+            countryCode: 'US',
+            supportedNetworks: ['visa', 'masterCard'],
+            merchantCapabilities: ['supports3DS'],
+        },
+    }
+}
+
+function validPaymentDetails() {
+    return {
+        total: { label: 'Your label', amount: { currency: 'USD', value: '10.00' } },
+    }
+}
+
+async function go() {
+    debug("Testing ApplePayMerchantValidationEvent");
+    debug("");
+
+    expectedPaymentMethod = {
+        displayName: 'test',
+        network: 'test',
+        type: 'prepaid',
+        paymentPass: {
+            primaryAccountIdentifier: 'test',
+            primaryAccountNumberSuffix: 'test',
+            deviceAccountIdentifier: 'test',
+            deviceAccountNumberSuffix: 'test',
+            activationState: 'requiresActivation',
+        },
+    };
+
+    var paymentRequest = new PaymentRequest([validPaymentMethod()], validPaymentDetails());
+    paymentRequest.onapplepaypaymentmethodchanged = (event) => {
+        shouldBe("event.paymentMethod.displayName", "expectedPaymentMethod.displayName");
+        shouldBe("event.paymentMethod.network", "expectedPaymentMethod.network");
+        shouldBe("event.paymentMethod.type", "expectedPaymentMethod.type");
+        shouldBe("event.paymentMethod.paymentPass.primaryAccountIdentifier", "expectedPaymentMethod.paymentPass.primaryAccountIdentifier");
+        shouldBe("event.paymentMethod.paymentPass.primaryAccountNumberSuffix", "expectedPaymentMethod.paymentPass.primaryAccountNumberSuffix");
+        shouldBe("event.paymentMethod.paymentPass.deviceAccountIdentifier", "expectedPaymentMethod.paymentPass.deviceAccountIdentifier");
+        shouldBe("event.paymentMethod.paymentPass.deviceAccountNumberSuffix", "expectedPaymentMethod.paymentPass.deviceAccountNumberSuffix");
+        shouldBe("event.paymentMethod.paymentPass.activationState", "expectedPaymentMethod.paymentPass.activationState");
+
+        document.querySelector("button").remove();
+        finishJSTest();
+    };
+    
+    paymentRequest.show();
+    internals.mockPaymentCoordinator.changePaymentMethod(expectedPaymentMethod);
+}
+
+window.onload = function() {
+    var button = document.querySelector("button");
+    let x = button.offsetLeft + 2;
+    let y = button.offsetTop + 2;
+    UIHelper.activateAt(x, y);
+}
+
+</script>
+<button onclick='go()'>Go</button>
+<script src="/resources/js-test-post.js"></script>
+</body>
+</html>
index 3d7f353..cf56288 100644 (file)
@@ -1,3 +1,54 @@
+2017-10-24  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Implement a paymentmethodselected event for PaymentRequest
+        https://bugs.webkit.org/show_bug.cgi?id=178765
+
+        Reviewed by Tim Horton.
+
+        When the Apple Pay payment method changes, fire an applepaypaymentmethodchanged event on the
+        PaymentRequest object. The event has a paymentMethod property and an updateWith() method
+        which behaves identically to PaymentRequestUpdateEvent.updateWith().
+
+        Test: http/tests/ssl/applepay/ApplePayPaymentMethodUpdateEvent.https.html
+
+        * DerivedSources.make:
+        * Modules/applepay/ApplePayPaymentMethod.idl:
+        * Modules/applepay/ApplePayPaymentMethodSelectedEvent.h:
+        * Modules/applepay/PaymentMethod.h:
+        (WebCore::PaymentMethod::PaymentMethod): Deleted.
+        (WebCore::PaymentMethod::pkPaymentMethod const): Deleted.
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::ApplePayPaymentHandler::detailsUpdated):
+        (WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
+        (WebCore::ApplePayPaymentHandler::didSelectPaymentMethod):
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+        * Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.cpp: Added.
+        (WebCore::ApplePayPaymentMethodUpdateEvent::ApplePayPaymentMethodUpdateEvent):
+        (WebCore::ApplePayPaymentMethodUpdateEvent::eventInterface const):
+        * Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.h: Added.
+        * Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl: Added.
+        * Modules/paymentrequest/PaymentHandler.h:
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::shippingAddressChanged):
+        (WebCore::PaymentRequest::shippingOptionChanged):
+        (WebCore::PaymentRequest::dispatchEvent):
+        (WebCore::PaymentRequest::updateWith):
+        (WebCore::PaymentRequest::settleDetailsPromise):
+        (WebCore::PaymentRequest::dispatchUpdateEvent): Deleted.
+        * Modules/paymentrequest/PaymentRequest.h:
+        * Modules/paymentrequest/PaymentRequest.idl:
+        * Modules/paymentrequest/PaymentRequestUpdateEvent.cpp:
+        (WebCore::PaymentRequestUpdateEvent::updateWith):
+        * Modules/paymentrequest/PaymentRequestUpdateEvent.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/EventNames.h:
+        * dom/EventNames.in:
+        * testing/MockPaymentCoordinator.cpp:
+        (WebCore::MockPaymentCoordinator::changePaymentMethod):
+        * testing/MockPaymentCoordinator.h:
+        * testing/MockPaymentCoordinator.idl:
+        * testing/MockPaymentMethod.h: Added.
+
 2017-10-24  Youenn Fablet  <youenn@apple.com>
 
         ServiceWorkerClientFetch should return an error that is not null in case of failure
index 89bda75..f6237a0 100644 (file)
@@ -108,6 +108,7 @@ JS_BINDING_IDLS = \
        $(WebCore)/Modules/applepay/ApplePayShippingMethodUpdate.idl \
     $(WebCore)/Modules/applepay/ApplePayValidateMerchantEvent.idl \
     $(WebCore)/Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.idl \
+    $(WebCore)/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl \
     $(WebCore)/Modules/applepay/paymentrequest/ApplePayRequest.idl \
     $(WebCore)/Modules/beacon/NavigatorBeacon.idl \
     $(WebCore)/Modules/cache/DOMWindowCaches.idl \
index 82c4ec2..e090940 100644 (file)
@@ -34,6 +34,7 @@
 
 [
     Conditional=APPLE_PAY,
+    ExportMacro=WEBCORE_EXPORT,
     JSGenerateToJSObject
 ] dictionary ApplePayPaymentMethod {
     DOMString displayName;
index d518324..3ac1a3c 100644 (file)
@@ -34,7 +34,7 @@ namespace WebCore {
 
 class PaymentMethod;
 
-class ApplePayPaymentMethodSelectedEvent final : public Event {
+class ApplePayPaymentMethodSelectedEvent : public Event {
 public:
     static Ref<ApplePayPaymentMethodSelectedEvent> create(const AtomicString& type, const PaymentMethod& paymentMethod)
     {
@@ -45,12 +45,13 @@ public:
 
     const ApplePayPaymentMethod& paymentMethod() { return m_paymentMethod; }
 
-private:
+protected:
     ApplePayPaymentMethodSelectedEvent(const AtomicString& type, const PaymentMethod&);
 
     // Event.
     EventInterface eventInterface() const override;
 
+private:
     const ApplePayPaymentMethod m_paymentMethod;
 };
 
index 69a3770..9ce7baa 100644 (file)
@@ -35,18 +35,17 @@ namespace WebCore {
 
 struct ApplePayPaymentMethod;
 
-class PaymentMethod {
+class WEBCORE_EXPORT PaymentMethod {
 public:
-    PaymentMethod()
-    {
-    }
+    PaymentMethod() = default;
+    virtual ~PaymentMethod() = default;
 
     explicit PaymentMethod(PKPaymentMethod *pkPaymentMethod)
         : m_pkPaymentMethod(pkPaymentMethod)
     {
     }
 
-    ApplePayPaymentMethod toApplePayPaymentMethod() const;
+    virtual ApplePayPaymentMethod toApplePayPaymentMethod() const;
 
     PKPaymentMethod *pkPaymentMethod() const { return m_pkPaymentMethod.get(); }
 
index eef2a0c..8eae376 100644 (file)
@@ -32,6 +32,7 @@
 #include "ApplePayMerchantCapability.h"
 #include "ApplePayMerchantValidationEvent.h"
 #include "ApplePayPayment.h"
+#include "ApplePayPaymentMethodUpdateEvent.h"
 #include "ApplePaySessionPaymentRequest.h"
 #include "Document.h"
 #include "EventNames.h"
@@ -44,6 +45,7 @@
 #include "PaymentAuthorizationStatus.h"
 #include "PaymentContact.h"
 #include "PaymentCoordinator.h"
+#include "PaymentMethod.h"
 #include "PaymentRequestValidator.h"
 #include "PaymentResponse.h"
 #include "Settings.h"
@@ -267,6 +269,21 @@ static ExceptionOr<ApplePaySessionPaymentRequest::TotalAndLineItems> convertAndV
     return ApplePaySessionPaymentRequest::TotalAndLineItems { total.releaseReturnValue(), lineItems.releaseReturnValue() };
 }
 
+ExceptionOr<void> ApplePayPaymentHandler::detailsUpdated(const AtomicString& eventType, const String& error)
+{
+    if (eventType == eventNames().shippingaddresschangeEvent)
+        return shippingAddressUpdated(error);
+
+    if (eventType == eventNames().shippingoptionchangeEvent)
+        return shippingOptionUpdated();
+
+    if (eventType == eventNames().applepaypaymentmethodchangedEvent)
+        return paymentMethodUpdated();
+
+    ASSERT_NOT_REACHED();
+    return { };
+}
+
 ExceptionOr<void> ApplePayPaymentHandler::shippingAddressUpdated(const String& error)
 {
     ShippingContactUpdate update;
@@ -300,6 +317,19 @@ ExceptionOr<void> ApplePayPaymentHandler::shippingOptionUpdated()
     return { };
 }
 
+ExceptionOr<void> ApplePayPaymentHandler::paymentMethodUpdated()
+{
+    PaymentMethodUpdate update;
+
+    auto newTotalAndLineItems = convertAndValidate(m_paymentRequest->paymentDetails());
+    if (newTotalAndLineItems.hasException())
+        return newTotalAndLineItems.releaseException();
+    update.newTotalAndLineItems = newTotalAndLineItems.releaseReturnValue();
+
+    paymentCoordinator().completePaymentMethodSelection(WTFMove(update));
+    return { };
+}
+
 void ApplePayPaymentHandler::complete(std::optional<PaymentComplete>&& result)
 {
     if (!result) {
@@ -353,6 +383,12 @@ void ApplePayPaymentHandler::didSelectShippingContact(const PaymentContact& ship
     m_paymentRequest->shippingAddressChanged(convert(shippingContact.toApplePayPaymentContact()));
 }
 
+void ApplePayPaymentHandler::didSelectPaymentMethod(const PaymentMethod& paymentMethod)
+{
+    auto event = ApplePayPaymentMethodUpdateEvent::create(eventNames().applepaypaymentmethodchangedEvent, paymentMethod.toApplePayPaymentMethod(), m_paymentRequest.get());
+    m_paymentRequest->dispatchEvent(event.get());
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
index 9eaf927..f1b9ea7 100644 (file)
@@ -51,13 +51,16 @@ private:
     Document& document();
     PaymentCoordinator& paymentCoordinator();
 
+    ExceptionOr<void> shippingAddressUpdated(const String& error);
+    ExceptionOr<void> shippingOptionUpdated();
+    ExceptionOr<void> paymentMethodUpdated();
+
     // PaymentHandler
     ExceptionOr<void> convertData(JSC::JSValue&&) final;
     ExceptionOr<void> show() final;
     void hide() final;
     void canMakePayment(WTF::Function<void(bool)>&& completionHandler) final;
-    ExceptionOr<void> shippingAddressUpdated(const String& error) final;
-    ExceptionOr<void> shippingOptionUpdated() final;
+    ExceptionOr<void> detailsUpdated(const AtomicString& eventType, const String& error) final;
     void complete(std::optional<PaymentComplete>&&) final;
 
     // PaymentSession
@@ -65,7 +68,7 @@ private:
     void didAuthorizePayment(const Payment&) final;
     void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final;
     void didSelectShippingContact(const PaymentContact&) final;
-    void didSelectPaymentMethod(const PaymentMethod&) final { }
+    void didSelectPaymentMethod(const PaymentMethod&) final;
     void didCancelPaymentSession() final { }
 
     PaymentRequest::MethodIdentifier m_identifier;
diff --git a/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.cpp b/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.cpp
new file mode 100644 (file)
index 0000000..c8660dc
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ApplePayPaymentMethodUpdateEvent.h"
+
+#if ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
+
+#include "PaymentRequest.h"
+
+namespace WebCore {
+
+ApplePayPaymentMethodUpdateEvent::ApplePayPaymentMethodUpdateEvent(const AtomicString& type, const ApplePayPaymentMethod& paymentMethod, PaymentRequest& paymentRequest)
+    : PaymentRequestUpdateEvent { type, paymentRequest }
+    , m_paymentMethod { paymentMethod }
+{
+}
+
+EventInterface ApplePayPaymentMethodUpdateEvent::eventInterface() const
+{
+    return ApplePayPaymentMethodUpdateEventInterfaceType;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
diff --git a/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.h b/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.h
new file mode 100644 (file)
index 0000000..ac06fae
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
+
+#include "ApplePayPaymentMethod.h"
+#include "PaymentRequestUpdateEvent.h"
+
+namespace WebCore {
+
+class ApplePayPaymentMethodUpdateEvent final : public PaymentRequestUpdateEvent {
+public:
+    template <typename... Args> static Ref<ApplePayPaymentMethodUpdateEvent> create(Args&&... args)
+    {
+        return adoptRef(*new ApplePayPaymentMethodUpdateEvent(std::forward<Args>(args)...));
+    }
+
+    const ApplePayPaymentMethod& paymentMethod() const { return m_paymentMethod; }
+
+private:
+    ApplePayPaymentMethodUpdateEvent(const AtomicString& type, const ApplePayPaymentMethod&, PaymentRequest&);
+
+    // Event
+    EventInterface eventInterface() const final;
+
+    const ApplePayPaymentMethod m_paymentMethod;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
diff --git a/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl b/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentMethodUpdateEvent.idl
new file mode 100644 (file)
index 0000000..c1adfc1
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=APPLE_PAY&PAYMENT_REQUEST,
+    NoInterfaceObject,
+] interface ApplePayPaymentMethodUpdateEvent : PaymentRequestUpdateEvent {
+    [CachedAttribute] readonly attribute ApplePayPaymentMethod paymentMethod;
+};
index c48fa9b..539f1db 100644 (file)
@@ -48,8 +48,7 @@ public:
     virtual ExceptionOr<void> show() = 0;
     virtual void hide() = 0;
     virtual void canMakePayment(WTF::Function<void(bool)>&& completionHandler) = 0;
-    virtual ExceptionOr<void> shippingAddressUpdated(const String& error) = 0;
-    virtual ExceptionOr<void> shippingOptionUpdated() = 0;
+    virtual ExceptionOr<void> detailsUpdated(const AtomicString& eventType, const String& error) = 0;
     virtual void complete(std::optional<PaymentComplete>&&) = 0;
 };
 
index b258820..a37e290 100644 (file)
@@ -524,36 +524,34 @@ void PaymentRequest::shippingAddressChanged(Ref<PaymentAddress>&& shippingAddres
 {
     ASSERT(m_state == State::Interactive);
     m_shippingAddress = WTFMove(shippingAddress);
-    dispatchUpdateEvent(eventNames().shippingaddresschangeEvent);
+    auto event = PaymentRequestUpdateEvent::create(eventNames().shippingaddresschangeEvent, *this);
+    dispatchEvent(event.get());
 }
 
 void PaymentRequest::shippingOptionChanged(const String& shippingOption)
 {
     ASSERT(m_state == State::Interactive);
     m_shippingOption = shippingOption;
-    dispatchUpdateEvent(eventNames().shippingoptionchangeEvent);
+    auto event = PaymentRequestUpdateEvent::create(eventNames().shippingoptionchangeEvent, *this);
+    dispatchEvent(event.get());
 }
 
-void PaymentRequest::dispatchUpdateEvent(const AtomicString& type)
+bool PaymentRequest::dispatchEvent(Event& event)
 {
+    if (!event.isTrusted())
+        return EventTargetWithInlineData::dispatchEvent(event);
+
     if (m_isUpdating)
-        return;
+        return false;
 
     if (m_state != State::Interactive)
-        return;
+        return false;
 
-    auto event = PaymentRequestUpdateEvent::create(type, *this);
-    dispatchEvent(event.get());
+    return EventTargetWithInlineData::dispatchEvent(event);
 }
 
-ExceptionOr<void> PaymentRequest::updateWith(PaymentRequestUpdateEvent& event, Ref<DOMPromise>&& promise)
+ExceptionOr<void> PaymentRequest::updateWith(Event& event, Ref<DOMPromise>&& promise)
 {
-    if (!event.isTrusted())
-        return Exception { InvalidStateError };
-
-    if (event.waitForUpdate())
-        return Exception { InvalidStateError };
-
     if (m_state != State::Interactive)
         return Exception { InvalidStateError };
 
@@ -562,7 +560,6 @@ ExceptionOr<void> PaymentRequest::updateWith(PaymentRequestUpdateEvent& event, R
 
     event.stopPropagation();
     event.stopImmediatePropagation();
-    event.setWaitForUpdate(true);
     m_isUpdating = true;
 
     m_detailsPromise = WTFMove(promise);
@@ -579,6 +576,9 @@ void PaymentRequest::settleDetailsPromise(const AtomicString& type)
         m_isUpdating = false;
     });
 
+    if (m_state != State::Interactive)
+        return;
+
     if (m_detailsPromise->status() == DOMPromise::Status::Rejected) {
         stop();
         return;
@@ -616,12 +616,11 @@ void PaymentRequest::settleDetailsPromise(const AtomicString& type)
     m_details.modifiers = WTFMove(paymentDetailsUpdate.modifiers);
     m_serializedModifierData = WTFMove(std::get<1>(shippingOptionAndModifierData));
 
-    if (type == eventNames().shippingaddresschangeEvent)
-        m_activePaymentHandler->shippingAddressUpdated(paymentDetailsUpdate.error);
-    else if (type == eventNames().shippingoptionchangeEvent)
-        m_activePaymentHandler->shippingOptionUpdated();
-    else
-        ASSERT_NOT_REACHED();
+    auto result = m_activePaymentHandler->detailsUpdated(type, paymentDetailsUpdate.error);
+    if (result.hasException()) {
+        abortWithException(result.releaseException());
+        return;
+    }
 }
 
 void PaymentRequest::accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone)
index 3080aa3..ff315cb 100644 (file)
@@ -39,9 +39,9 @@
 namespace WebCore {
 
 class Document;
+class Event;
 class PaymentAddress;
 class PaymentHandler;
-class PaymentRequestUpdateEvent;
 class PaymentResponse;
 enum class PaymentComplete;
 enum class PaymentShippingType;
@@ -70,10 +70,13 @@ public:
 
     void shippingAddressChanged(Ref<PaymentAddress>&&);
     void shippingOptionChanged(const String& shippingOption);
-    ExceptionOr<void> updateWith(PaymentRequestUpdateEvent&, Ref<DOMPromise>&&);
+    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>&&);
 
+    // EventTarget
+    bool dispatchEvent(Event&) final;
+
     using MethodIdentifier = Variant<String, URL>;
     using RefCounted<PaymentRequest>::ref;
     using RefCounted<PaymentRequest>::deref;
@@ -92,7 +95,6 @@ private:
 
     PaymentRequest(Document&, PaymentOptions&&, PaymentDetailsInit&&, Vector<String>&& serializedModifierData, Vector<Method>&& serializedMethodData, String&& selectedShippingOption);
 
-    void dispatchUpdateEvent(const AtomicString& type);
     void settleDetailsPromise(const AtomicString& type);
     void abortWithException(Exception&&);
 
index 7fa399a..732a743 100644 (file)
@@ -45,4 +45,5 @@
     attribute EventHandler onshippingoptionchange;
 
     [Conditional=APPLE_PAY] attribute EventHandler onapplepayvalidatemerchant;
+    [Conditional=APPLE_PAY] attribute EventHandler onapplepaypaymentmethodchanged;
 };
index ceedbd1..4744fe9 100644 (file)
@@ -47,7 +47,18 @@ PaymentRequestUpdateEvent::~PaymentRequestUpdateEvent() = default;
 
 ExceptionOr<void> PaymentRequestUpdateEvent::updateWith(Ref<DOMPromise>&& detailsPromise)
 {
-    return m_paymentRequest->updateWith(*this, WTFMove(detailsPromise));
+    if (!isTrusted())
+        return Exception { InvalidStateError };
+
+    if (m_waitForUpdate)
+        return Exception { InvalidStateError };
+
+    auto exception = m_paymentRequest->updateWith(*this, WTFMove(detailsPromise));
+    if (exception.hasException())
+        return exception.releaseException();
+
+    m_waitForUpdate = true;
+    return { };
 }
 
 EventInterface PaymentRequestUpdateEvent::eventInterface() const
index 4fad644..30041a2 100644 (file)
@@ -36,7 +36,7 @@ class DOMPromise;
 class PaymentRequest;
 struct PaymentRequestUpdateEventInit;
 
-class PaymentRequestUpdateEvent final : public Event {
+class PaymentRequestUpdateEvent : public Event {
 public:
     template <typename... Args> static Ref<PaymentRequestUpdateEvent> create(Args&&... args)
     {
@@ -45,15 +45,14 @@ public:
     ~PaymentRequestUpdateEvent();
     ExceptionOr<void> updateWith(Ref<DOMPromise>&&);
 
-    bool waitForUpdate() const { return m_waitForUpdate; }
-    void setWaitForUpdate(bool waitForUpdate) { m_waitForUpdate = waitForUpdate; }
-
-private:
-    PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequestUpdateEventInit&&);
+protected:
     PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequest&);
 
     // Event
-    EventInterface eventInterface() const final;
+    EventInterface eventInterface() const override;
+
+private:
+    PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequestUpdateEventInit&&);
 
     RefPtr<PaymentRequest> m_paymentRequest;
     bool m_waitForUpdate { false };
index 4d14256..56c2993 100644 (file)
                A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */; };
                A1C150791E3F2B3E0032C98C /* PreviewConverter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1C150771E3F2B3E0032C98C /* PreviewConverter.mm */; };
                A1C1507A1E3F2B3E0032C98C /* PreviewConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1C150781E3F2B3E0032C98C /* PreviewConverter.h */; };
+               A1CBEF531F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CBEF501F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h */; };
+               A1CBEF541F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CBEF511F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp */; };
+               A1CBEF611F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CBEF5F1F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp */; };
+               A1CBEF621F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CBEF601F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.h */; };
+               A1CBEF641F9F11290028DE7C /* MockPaymentMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CBEF631F9F11290028DE7C /* MockPaymentMethod.h */; };
                A1CC11641E493D0100EFA69C /* FileSystemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1CC11621E493D0100EFA69C /* FileSystemMac.mm */; };
                A1CC56671F46147A00A4555B /* JSPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56651F46146800A4555B /* JSPaymentAddress.h */; };
                A1CC56691F46148000A4555B /* JSPaymentComplete.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC564E1F46145200A4555B /* JSPaymentComplete.h */; };
                A1C150771E3F2B3E0032C98C /* PreviewConverter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreviewConverter.mm; sourceTree = "<group>"; };
                A1C150781E3F2B3E0032C98C /* PreviewConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreviewConverter.h; sourceTree = "<group>"; };
                A1C7FAA1133A5D3500D6732D /* JSXPathResultCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXPathResultCustom.cpp; sourceTree = "<group>"; };
+               A1CBEF501F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayPaymentMethodUpdateEvent.h; sourceTree = "<group>"; };
+               A1CBEF511F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplePayPaymentMethodUpdateEvent.cpp; sourceTree = "<group>"; };
+               A1CBEF521F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ApplePayPaymentMethodUpdateEvent.idl; sourceTree = "<group>"; };
+               A1CBEF5F1F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSApplePayPaymentMethodUpdateEvent.cpp; sourceTree = "<group>"; };
+               A1CBEF601F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSApplePayPaymentMethodUpdateEvent.h; sourceTree = "<group>"; };
+               A1CBEF631F9F11290028DE7C /* MockPaymentMethod.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentMethod.h; sourceTree = "<group>"; };
                A1CC11621E493D0100EFA69C /* FileSystemMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSystemMac.mm; sourceTree = "<group>"; };
                A1CC564C1F46145000A4555B /* JSPaymentMethodData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentMethodData.h; sourceTree = "<group>"; };
                A1CC564D1F46145100A4555B /* JSPaymentMethodData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaymentMethodData.cpp; sourceTree = "<group>"; };
                                1AE96A7D1D1A0A8000B86768 /* JSApplePayPaymentMethodSelectedEvent.h */,
                                1ADFDFE51E71DCA0008F5D34 /* JSApplePayPaymentMethodUpdate.cpp */,
                                1ADFDFE61E71DCA0008F5D34 /* JSApplePayPaymentMethodUpdate.h */,
+                               A1CBEF5F1F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp */,
+                               A1CBEF601F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.h */,
                                7C65230F1E00DBB400677F22 /* JSApplePayPaymentPass.cpp */,
                                7C6523101E00DBB400677F22 /* JSApplePayPaymentPass.h */,
                                7C6579EB1E00856600E3A27A /* JSApplePayPaymentRequest.cpp */,
                                A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */,
                                A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */,
                                A146D3161F99B53D00D29196 /* MockPaymentCoordinator.idl */,
+                               A1CBEF631F9F11290028DE7C /* MockPaymentMethod.h */,
                                A14061891E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp */,
                                A140618A1E2ECA0A0032B34E /* MockPreviewLoaderClient.h */,
                                EB081CD81696084400553730 /* TypeConversions.h */,
                                A1F929681F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.idl */,
                                A1DF5AA11F7EE1130058A477 /* ApplePayPaymentHandler.cpp */,
                                A1DF5AA01F7EE1130058A477 /* ApplePayPaymentHandler.h */,
+                               A1CBEF511F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp */,
+                               A1CBEF501F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h */,
+                               A1CBEF521F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.idl */,
                                A1DF5A7C1F7EBD0B0058A477 /* ApplePayRequest.h */,
                                A1DF5A7E1F7EBD0B0058A477 /* ApplePayRequest.idl */,
                        );
                                A146D3211F99CB1A00D29196 /* MockPaymentAddress.h in Headers */,
                                A146D3251F99D69800D29196 /* MockPaymentContact.h in Headers */,
                                A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */,
+                               A1CBEF641F9F11290028DE7C /* MockPaymentMethod.h in Headers */,
                                A140618C1E2ECA0A0032B34E /* MockPreviewLoaderClient.h in Headers */,
                                AA5F3B8D16CC33D100455EB0 /* PlatformSpeechSynthesizerMock.h in Headers */,
                                A1763F3F1E205234001D58DE /* WebArchiveDumpSupport.h in Headers */,
                                A1DF5AA21F7EE1130058A477 /* ApplePayPaymentHandler.h in Headers */,
                                7C6522EF1E00A4C700677F22 /* ApplePayPaymentMethod.h in Headers */,
                                1A8A64561D19FCFC00D0E00F /* ApplePayPaymentMethodSelectedEvent.h in Headers */,
+                               A1CBEF531F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h in Headers */,
                                7C6522F51E00A51700677F22 /* ApplePayPaymentPass.h in Headers */,
                                7C6579E01E0079F900E3A27A /* ApplePayPaymentRequest.h in Headers */,
                                A1DF5A7F1F7EBD0B0058A477 /* ApplePayRequest.h in Headers */,
                                7C6523161E00DBB500677F22 /* JSApplePayPaymentContact.h in Headers */,
                                7C6523181E00DBB500677F22 /* JSApplePayPaymentMethod.h in Headers */,
                                1AE96A8D1D1A0DDD00B86768 /* JSApplePayPaymentMethodSelectedEvent.h in Headers */,
+                               A1CBEF621F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.h in Headers */,
                                7C65231A1E00DBB500677F22 /* JSApplePayPaymentPass.h in Headers */,
                                7C6579F21E00856600E3A27A /* JSApplePayPaymentRequest.h in Headers */,
                                A1DF5A8F1F7EC0020058A477 /* JSApplePayRequest.h in Headers */,
                                1A8A64511D19FCFB00D0E00F /* ApplePayPaymentAuthorizedEvent.cpp in Sources */,
                                A1DF5AA31F7EE1130058A477 /* ApplePayPaymentHandler.cpp in Sources */,
                                1A8A64541D19FCFC00D0E00F /* ApplePayPaymentMethodSelectedEvent.cpp in Sources */,
+                               A1CBEF541F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp in Sources */,
                                A1DF5AAE1F8075F10058A477 /* ApplePayRequestBase.cpp in Sources */,
                                1A8A64581D19FCFC00D0E00F /* ApplePaySession.cpp in Sources */,
                                1A58E8671D19D80E00C0EA73 /* ApplePaySessionPaymentRequest.cpp in Sources */,
                                7C6523171E00DBB500677F22 /* JSApplePayPaymentMethod.cpp in Sources */,
                                1AE96A8C1D1A0DDD00B86768 /* JSApplePayPaymentMethodSelectedEvent.cpp in Sources */,
                                1ADFDFED1E71E475008F5D34 /* JSApplePayPaymentMethodUpdate.cpp in Sources */,
+                               A1CBEF611F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp in Sources */,
                                7C6523191E00DBB500677F22 /* JSApplePayPaymentPass.cpp in Sources */,
                                7C6579F11E00856600E3A27A /* JSApplePayPaymentRequest.cpp in Sources */,
                                A1DF5A901F7EC0020058A477 /* JSApplePayRequest.cpp in Sources */,
index 9f49570..9fb045d 100644 (file)
@@ -53,6 +53,7 @@ namespace WebCore {
     macro(animationend) \
     macro(animationiteration) \
     macro(animationstart) \
+    macro(applepaypaymentmethodchanged) \
     macro(applepayvalidatemerchant) \
     macro(audioend) \
     macro(audioprocess) \
index 7c6b3a5..1baac9e 100644 (file)
@@ -41,6 +41,7 @@ XMLHttpRequestProgressEvent
 ApplePayMerchantValidationEvent conditional=APPLE_PAY
 ApplePayPaymentAuthorizedEvent conditional=APPLE_PAY
 ApplePayPaymentMethodSelectedEvent conditional=APPLE_PAY
+ApplePayPaymentMethodUpdateEvent conditional=APPLE_PAY
 ApplePayShippingContactSelectedEvent conditional=APPLE_PAY
 ApplePayShippingMethodSelectedEvent conditional=APPLE_PAY
 ApplePayValidateMerchantEvent conditional=APPLE_PAY
index f97a285..ae05f24 100644 (file)
@@ -31,6 +31,7 @@
 #include "MainFrame.h"
 #include "MockPayment.h"
 #include "MockPaymentContact.h"
+#include "MockPaymentMethod.h"
 #include "PaymentCoordinator.h"
 #include "URL.h"
 #include <wtf/RunLoop.h>
@@ -113,6 +114,13 @@ void MockPaymentCoordinator::changeShippingOption(String&& shippingOption)
     });
 }
 
+void MockPaymentCoordinator::changePaymentMethod(ApplePayPaymentMethod&& paymentMethod)
+{
+    dispatchIfShowing([mainFrame = makeRef(m_mainFrame), paymentMethod = WTFMove(paymentMethod)]() mutable {
+        mainFrame->paymentCoordinator().didSelectPaymentMethod(MockPaymentMethod { WTFMove(paymentMethod) });
+    });
+}
+
 void MockPaymentCoordinator::acceptPayment()
 {
     dispatchIfShowing([mainFrame = makeRef(m_mainFrame), shippingAddress = m_shippingAddress]() mutable {
index 6e7b5f7..7535eb4 100644 (file)
@@ -31,8 +31,9 @@
 #include "PaymentCoordinatorClient.h"
 
 namespace WebCore {
-    
+
 class MainFrame;
+struct ApplePayPaymentMethod;
 
 class MockPaymentCoordinator final : public PaymentCoordinatorClient {
 public:
@@ -40,6 +41,7 @@ public:
 
     void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); }
     void changeShippingOption(String&& shippingOption);
+    void changePaymentMethod(ApplePayPaymentMethod&&);
     void acceptPayment();
 
     void ref() const { }
index 1b4dc01..64e96ce 100644 (file)
@@ -29,5 +29,6 @@
 ] interface MockPaymentCoordinator {
     void setShippingAddress(MockPaymentAddress shippingAddress);
     void changeShippingOption(DOMString shippingOption);
+    void changePaymentMethod(ApplePayPaymentMethod paymentMethod);
     void acceptPayment();
 };
diff --git a/Source/WebCore/testing/MockPaymentMethod.h b/Source/WebCore/testing/MockPaymentMethod.h
new file mode 100644 (file)
index 0000000..314f4d7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY)
+
+#include "ApplePayPaymentMethod.h"
+#include "PaymentMethod.h"
+
+namespace WebCore {
+
+class MockPaymentMethod final : public PaymentMethod {
+public:
+    explicit MockPaymentMethod(ApplePayPaymentMethod&& applePayPaymentMethod)
+        : m_applePayPaymentMethod { WTFMove(applePayPaymentMethod) }
+    {
+    }
+
+    ApplePayPaymentMethod toApplePayPaymentMethod() const final { return m_applePayPaymentMethod; }
+
+private:
+    ApplePayPaymentMethod m_applePayPaymentMethod;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)