WebKit Bugzilla
Attachment 349261 Details for
Bug 189386
: [Apple Pay] Dispatch a paymentmethodchange event when the payment method changes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189386-20180908141205.patch (text/plain), 43.26 KB, created by
Andy Estes
on 2018-09-08 14:12:06 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Andy Estes
Created:
2018-09-08 14:12:06 PDT
Size:
43.26 KB
patch
obsolete
>Subversion Revision: 235828 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index dfff4175f9ef5ca37a1147f611d1244cb5c85a80..5dfe4ed1802b408bf8ae5db1cc34478bfe4c7bbd 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,49 @@ >+2018-09-08 Andy Estes <aestes@apple.com> >+ >+ [Apple Pay] Dispatch a paymentmethodchange event when the payment method changes >+ https://bugs.webkit.org/show_bug.cgi?id=189386 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Implemented the "payment method changed" algorithm as defined in the Payment Request API W3C >+ Editor's Draft of 05 September 2018. >+ >+ Payment Request says that the user agent MAY run this algorithm when the payment method >+ changes. In our case, we only wish to dispatch this event when a listener is registered for >+ it. Since PassKit requires merchants to respond to this event by calling updateWith() within >+ 30 seconds, firing the event unconditionally would break compatibility with existing >+ clients. >+ >+ For merchants that do not listen for this event, they can continue to use modifiers to >+ update details based on the selected payment method type. >+ >+ Also made PaymentMethodChangeEvent.methodDetails a cached attribute in a way that avoids >+ potential reference cycles from holding a JSC::Strong in the wrapped object. >+ >+ Test: http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https.html >+ >+ * CMakeLists.txt: >+ * DerivedSources.make: >+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp: >+ (WebCore::toJSDictionary): >+ (WebCore::ApplePayPaymentHandler::didAuthorizePayment): >+ (WebCore::ApplePayPaymentHandler::didSelectPaymentMethod): >+ * Modules/paymentrequest/PaymentMethodChangeEvent.cpp: >+ (WebCore::PaymentMethodChangeEvent::PaymentMethodChangeEvent): >+ * Modules/paymentrequest/PaymentMethodChangeEvent.h: >+ * Modules/paymentrequest/PaymentMethodChangeEvent.idl: >+ * Modules/paymentrequest/PaymentMethodChangeEventInit.idl: Removed. >+ * Modules/paymentrequest/PaymentRequest.cpp: >+ (WebCore::PaymentRequest::paymentMethodChanged): >+ * Modules/paymentrequest/PaymentRequest.h: >+ * Modules/paymentrequest/PaymentRequestUpdateEvent.cpp: >+ (WebCore::PaymentRequestUpdateEvent::updateWith): >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * bindings/js/JSPaymentMethodChangeEventCustom.cpp: Added. >+ (WebCore::JSPaymentMethodChangeEvent::methodDetails const): >+ (WebCore::JSPaymentMethodChangeEvent::visitAdditionalChildren): >+ > 2018-09-07 Fujii Hironori <Hironori.Fujii@sony.com> > > [Win][Clang] exceptionShouldTerminateProgram of StructuredExceptionHandlerSuppressor.cpp should take DWORD >diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt >index e2fa2d92d3fba7fec029764aee4a52852b082347..d46a55cbf1be313a4e28fad4b41dec0c4d0d0413 100644 >--- a/Source/WebCore/CMakeLists.txt >+++ b/Source/WebCore/CMakeLists.txt >@@ -346,7 +346,6 @@ set(WebCore_NON_SVG_IDL_FILES > Modules/paymentrequest/PaymentDetailsUpdate.idl > Modules/paymentrequest/PaymentItem.idl > Modules/paymentrequest/PaymentMethodChangeEvent.idl >- Modules/paymentrequest/PaymentMethodChangeEventInit.idl > Modules/paymentrequest/PaymentMethodData.idl > Modules/paymentrequest/PaymentOptions.idl > Modules/paymentrequest/PaymentRequest.idl >diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make >index a940f94e567d16793bae469ee9a2355ae29a9900..d23648c500c794d7c393e38b71eda28c9d4d3b5d 100644 >--- a/Source/WebCore/DerivedSources.make >+++ b/Source/WebCore/DerivedSources.make >@@ -266,7 +266,6 @@ JS_BINDING_IDLS = \ > $(WebCore)/Modules/paymentrequest/PaymentDetailsUpdate.idl \ > $(WebCore)/Modules/paymentrequest/PaymentItem.idl \ > $(WebCore)/Modules/paymentrequest/PaymentMethodChangeEvent.idl \ >- $(WebCore)/Modules/paymentrequest/PaymentMethodChangeEventInit.idl \ > $(WebCore)/Modules/paymentrequest/PaymentMethodData.idl \ > $(WebCore)/Modules/paymentrequest/PaymentOptions.idl \ > $(WebCore)/Modules/paymentrequest/PaymentRequest.idl \ >diff --git a/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp b/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp >index 98ba84712c111031a54c4eef3bcb2a05584ffa4c..46ebd0f05a59992a53e70f574c73ae71e985e687 100644 >--- a/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp >+++ b/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp >@@ -37,6 +37,7 @@ > #include "EventNames.h" > #include "Frame.h" > #include "JSApplePayPayment.h" >+#include "JSApplePayPaymentMethod.h" > #include "JSApplePayRequest.h" > #include "LinkIconCollector.h" > #include "MerchantValidationEvent.h" >@@ -440,14 +441,19 @@ static Ref<PaymentAddress> convert(const ApplePayPaymentContact& contact) > return PaymentAddress::create(contact.countryCode, contact.addressLines.value_or(Vector<String>()), contact.administrativeArea, contact.locality, contact.subLocality, contact.postalCode, String(), String(), contact.localizedName, contact.phoneNumber); > } > >+template<typename T> >+static JSC::Strong<JSC::JSObject> toJSDictionary(JSC::ExecState& execState, const T& value) >+{ >+ JSC::JSLockHolder lock { &execState }; >+ return { execState.vm(), asObject(toJS<IDLDictionary<T>>(execState, *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject()), value)) }; >+} >+ > void ApplePayPaymentHandler::didAuthorizePayment(const Payment& payment) > { > ASSERT(!m_isUpdating); > > auto applePayPayment = payment.toApplePayPayment(version()); >- auto& execState = *document().execState(); >- auto lock = JSC::JSLockHolder { &execState }; >- auto details = JSC::Strong<JSC::JSObject> { execState.vm(), asObject(toJS<IDLDictionary<ApplePayPayment>>(execState, *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject()), applePayPayment)) }; >+ auto details = toJSDictionary(*document().execState(), applePayPayment); > const auto& shippingContact = applePayPayment.shippingContact.value_or(ApplePayPaymentContact()); > m_paymentRequest->accept(WTF::get<URL>(m_identifier).string(), WTFMove(details), convert(shippingContact), shippingContact.localizedName, shippingContact.emailAddress, shippingContact.phoneNumber); > } >@@ -473,8 +479,11 @@ void ApplePayPaymentHandler::didSelectPaymentMethod(const PaymentMethod& payment > ASSERT(!m_isUpdating); > m_isUpdating = true; > >- m_selectedPaymentMethodType = paymentMethod.toApplePayPaymentMethod().type; >- m_paymentRequest->paymentMethodChanged(); >+ auto applePayPaymentMethod = paymentMethod.toApplePayPaymentMethod(); >+ m_selectedPaymentMethodType = applePayPaymentMethod.type; >+ m_paymentRequest->paymentMethodChanged(WTF::get<URL>(m_identifier).string(), [applePayPaymentMethod = WTFMove(applePayPaymentMethod)](JSC::ExecState& execState) { >+ return toJSDictionary(execState, applePayPaymentMethod); >+ }); > } > > void ApplePayPaymentHandler::didCancelPaymentSession() >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.cpp b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.cpp >index 60082b9c1e6e9197cf46c5ad6dbf93281f0b090c..36a4ac6a35179c1f1aea8c2826476992598adfed 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.cpp >+++ b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.cpp >@@ -28,8 +28,6 @@ > > #if ENABLE(PAYMENT_REQUEST) > >-#include "PaymentMethodChangeEventInit.h" >- > namespace WebCore { > > EventInterface PaymentMethodChangeEvent::eventInterface() const >@@ -37,10 +35,17 @@ EventInterface PaymentMethodChangeEvent::eventInterface() const > return PaymentMethodChangeEventInterfaceType; > } > >-PaymentMethodChangeEvent::PaymentMethodChangeEvent(const AtomicString& type, const PaymentMethodChangeEventInit& eventInit) >+PaymentMethodChangeEvent::PaymentMethodChangeEvent(const AtomicString& type, Init&& eventInit) > : PaymentRequestUpdateEvent { type, eventInit } >- , m_methodName { eventInit.methodName } >- , m_methodDetails { eventInit.methodDetails } >+ , m_methodName { WTFMove(eventInit.methodName) } >+ , m_methodDetails { JSValueInWrappedObject { eventInit.methodDetails.get() } } >+{ >+} >+ >+PaymentMethodChangeEvent::PaymentMethodChangeEvent(const AtomicString& type, PaymentRequest& request, const String& methodName, MethodDetailsFunction&& methodDetailsFunction) >+ : PaymentRequestUpdateEvent { type, request } >+ , m_methodName { methodName } >+ , m_methodDetails { WTFMove(methodDetailsFunction) } > { > } > >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h >index 42754d4f42740ad3598fe5a5433d50e61c68636f..5a3ceac4da398789e64e76d0e738bea5bd75eeae 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h >+++ b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.h >@@ -27,8 +27,10 @@ > > #if ENABLE(PAYMENT_REQUEST) > >+#include "JSValueInWrappedObject.h" > #include "PaymentRequestUpdateEvent.h" > #include <JavaScriptCore/Strong.h> >+#include <wtf/Variant.h> > #include <wtf/text/WTFString.h> > > namespace JSC { >@@ -36,8 +38,6 @@ class JSObject; > } > > namespace WebCore { >- >-struct PaymentMethodChangeEventInit; > > class PaymentMethodChangeEvent final : public PaymentRequestUpdateEvent { > public: >@@ -46,17 +46,28 @@ public: > return adoptRef(*new PaymentMethodChangeEvent(std::forward<Args>(args)...)); > } > >+ using MethodDetailsFunction = std::function<JSC::Strong<JSC::JSObject>(JSC::ExecState&)>; >+ using MethodDetailsType = Variant<JSValueInWrappedObject, MethodDetailsFunction>; >+ > const String& methodName() const { return m_methodName; } >- const JSC::Strong<JSC::JSObject>& methodDetails() const { return m_methodDetails; } >+ const MethodDetailsType& methodDetails() const { return m_methodDetails; } >+ JSValueInWrappedObject& cachedMethodDetails() { return m_cachedMethodDetails; } > > // Event > EventInterface eventInterface() const override; >+ >+ struct Init final : PaymentRequestUpdateEventInit { >+ String methodName; >+ JSC::Strong<JSC::JSObject> methodDetails; >+ }; > > private: >- PaymentMethodChangeEvent(const AtomicString& type, const PaymentMethodChangeEventInit&); >+ PaymentMethodChangeEvent(const AtomicString& type, Init&&); >+ PaymentMethodChangeEvent(const AtomicString& type, PaymentRequest&, const String& methodName, MethodDetailsFunction&&); > > String m_methodName; >- JSC::Strong<JSC::JSObject> m_methodDetails; >+ MethodDetailsType m_methodDetails; >+ JSValueInWrappedObject m_cachedMethodDetails; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.idl b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.idl >index da307f7d56f7a1aafc6ed9d9c3e61aefd5fa7904..8b0e4a119f16661946a1644dfb89f794653c2a43 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.idl >+++ b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEvent.idl >@@ -28,8 +28,16 @@ > Constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict), > EnabledBySetting=PaymentRequest, > Exposed=Window, >+ JSCustomMarkFunction, > SecureContext, > ] interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent { > readonly attribute DOMString methodName; >- readonly attribute object? methodDetails; >+ [CustomGetter] readonly attribute object? methodDetails; >+}; >+ >+[ >+ Conditional=PAYMENT_REQUEST, >+] dictionary PaymentMethodChangeEventInit : PaymentRequestUpdateEventInit { >+ DOMString methodName = ""; >+ object? methodDetails; > }; >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.h b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.h >deleted file mode 100644 >index d3ffd9cfa28e6430d24e2e5ecb5a88a937774dc9..0000000000000000000000000000000000000000 >--- a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.h >+++ /dev/null >@@ -1,46 +0,0 @@ >-/* >- * Copyright (C) 2018 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(PAYMENT_REQUEST) >- >-#include "PaymentRequestUpdateEventInit.h" >-#include <JavaScriptCore/Strong.h> >- >-namespace JSC { >-class JSObject; >-} >- >-namespace WebCore { >- >-struct PaymentMethodChangeEventInit final : PaymentRequestUpdateEventInit { >- String methodName; >- JSC::Strong<JSC::JSObject> methodDetails; >-}; >- >-} // namespace WebCore >- >-#endif // ENABLE(PAYMENT_REQUEST) >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.idl b/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.idl >deleted file mode 100644 >index 11c8d54aa0840c1b92453cafbd2d77e6590f0ce3..0000000000000000000000000000000000000000 >--- a/Source/WebCore/Modules/paymentrequest/PaymentMethodChangeEventInit.idl >+++ /dev/null >@@ -1,31 +0,0 @@ >-/* >- * Copyright (C) 2018 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=PAYMENT_REQUEST, >-] dictionary PaymentMethodChangeEventInit : PaymentRequestUpdateEventInit { >- DOMString methodName = ""; >- object? methodDetails; >-}; >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp b/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp >index 24cb5ee1b9af5743683c0e66bef46bc2b1bb013b..6e3181f07f1000233e2d0b158f9d727f0df34e69 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp >+++ b/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp >@@ -38,6 +38,7 @@ > #include "PaymentCurrencyAmount.h" > #include "PaymentDetailsInit.h" > #include "PaymentHandler.h" >+#include "PaymentMethodChangeEvent.h" > #include "PaymentMethodData.h" > #include "PaymentOptions.h" > #include "PaymentRequestUpdateEvent.h" >@@ -552,10 +553,14 @@ void PaymentRequest::shippingOptionChanged(const String& shippingOption) > }); > } > >-void PaymentRequest::paymentMethodChanged() >+void PaymentRequest::paymentMethodChanged(const String& methodName, PaymentMethodChangeEvent::MethodDetailsFunction&& methodDetailsFunction) > { >- whenDetailsSettled([this, protectedThis = makeRefPtr(this)] { >- m_activePaymentHandler->detailsUpdated(UpdateReason::PaymentMethodChanged, { }); >+ whenDetailsSettled([this, protectedThis = makeRefPtr(this), methodName, methodDetailsFunction = WTFMove(methodDetailsFunction)]() mutable { >+ auto& eventName = eventNames().paymentmethodchangeEvent; >+ if (hasEventListeners(eventName)) >+ dispatchEvent(PaymentMethodChangeEvent::create(eventName, *this, methodName, WTFMove(methodDetailsFunction))); >+ else >+ m_activePaymentHandler->detailsUpdated(UpdateReason::PaymentMethodChanged, { }); > }); > } > >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentRequest.h b/Source/WebCore/Modules/paymentrequest/PaymentRequest.h >index 7457ad7382dac8efe05fa7251a77e4c1d0b42fa5..e532a60b2ae8de66681006e08625a3d5f086a08e 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentRequest.h >+++ b/Source/WebCore/Modules/paymentrequest/PaymentRequest.h >@@ -32,6 +32,7 @@ > #include "ExceptionOr.h" > #include "JSDOMPromiseDeferred.h" > #include "PaymentDetailsInit.h" >+#include "PaymentMethodChangeEvent.h" > #include "PaymentOptions.h" > #include "URL.h" > #include <wtf/Variant.h> >@@ -87,7 +88,7 @@ public: > > void shippingAddressChanged(Ref<PaymentAddress>&&); > void shippingOptionChanged(const String& shippingOption); >- void paymentMethodChanged(); >+ void paymentMethodChanged(const String& methodName, PaymentMethodChangeEvent::MethodDetailsFunction&&); > ExceptionOr<void> updateWith(UpdateReason, Ref<DOMPromise>&&); > ExceptionOr<void> completeMerchantValidation(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); >diff --git a/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp b/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp >index 0eb72ba3a57f3235c8b8fc28da0b2f258f6ec772..61aec48d2223aadf59dd4329c152e3f8e496479f 100644 >--- a/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp >+++ b/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp >@@ -36,12 +36,14 @@ namespace WebCore { > PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, const PaymentRequestUpdateEventInit& eventInit) > : Event { type, eventInit, IsTrusted::No } > { >+ ASSERT(!isTrusted()); > } > > PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, PaymentRequest& paymentRequest) > : Event { type, CanBubble::No, IsCancelable::No } > , m_paymentRequest { &paymentRequest } > { >+ ASSERT(isTrusted()); > } > > PaymentRequestUpdateEvent::~PaymentRequestUpdateEvent() = default; >@@ -51,6 +53,8 @@ ExceptionOr<void> PaymentRequestUpdateEvent::updateWith(Ref<DOMPromise>&& detail > if (!isTrusted()) > return Exception { InvalidStateError }; > >+ ASSERT(m_paymentRequest); >+ > if (m_waitForUpdate) > return Exception { InvalidStateError }; > >@@ -62,6 +66,8 @@ ExceptionOr<void> PaymentRequestUpdateEvent::updateWith(Ref<DOMPromise>&& detail > reason = PaymentRequest::UpdateReason::ShippingAddressChanged; > else if (type() == eventNames().shippingoptionchangeEvent) > reason = PaymentRequest::UpdateReason::ShippingOptionChanged; >+ else if (type() == eventNames().paymentmethodchangeEvent) >+ reason = PaymentRequest::UpdateReason::PaymentMethodChanged; > else { > ASSERT_NOT_REACHED(); > return Exception { TypeError }; >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 7cf364fa90c8aee3361af81f2395016e22171acb..b065ff85f2798d1b1fb64140fe3d371880c5c64c 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -429,6 +429,7 @@ bindings/js/JSNodeCustom.cpp > bindings/js/JSNodeIteratorCustom.cpp > bindings/js/JSNodeListCustom.cpp > bindings/js/JSOffscreenCanvasRenderingContext2DCustom.cpp >+bindings/js/JSPaymentMethodChangeEventCustom.cpp > bindings/js/JSPerformanceEntryCustom.cpp > bindings/js/JSPerformanceObserverCustom.cpp > bindings/js/JSPluginElementFunctions.cpp >@@ -2823,7 +2824,6 @@ JSPaymentDetailsModifier.cpp > JSPaymentDetailsUpdate.cpp > JSPaymentItem.cpp > JSPaymentMethodChangeEvent.cpp >-JSPaymentMethodChangeEventInit.cpp > JSPaymentMethodData.cpp > JSPaymentOptions.cpp > JSPaymentRequest.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 1e3551d59720f211789377f3b94438eb4c5953b6..99c6b6b9d05a3cc44fb979383a15cda6ac43ecd8 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -2925,9 +2925,7 @@ > A15E31F41E0CB0B5004B371C /* QuickLook.h in Headers */ = {isa = PBXBuildFile; fileRef = A15E31F11E0CB0AA004B371C /* QuickLook.h */; settings = {ATTRIBUTES = (Private, ); }; }; > A15E6BF11E212A6A0080AF34 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A15E6BF01E212A6A0080AF34 /* Foundation.framework */; }; > A164A2472134BC7100509156 /* PaymentMethodChangeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A164A2442134BC7100509156 /* PaymentMethodChangeEvent.h */; }; >- A164A24E2134BDD800509156 /* PaymentMethodChangeEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = A164A24B2134BDD800509156 /* PaymentMethodChangeEventInit.h */; }; > A164A2552134C1CC00509156 /* JSPaymentMethodChangeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A164A2512134C1CB00509156 /* JSPaymentMethodChangeEvent.h */; }; >- A164A2562134C1CC00509156 /* JSPaymentMethodChangeEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = A164A2522134C1CB00509156 /* JSPaymentMethodChangeEventInit.h */; }; > A1677DE9213CDFAA00A08C34 /* MerchantValidationEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = A1677DE6213CDFAA00A08C34 /* MerchantValidationEventInit.h */; }; > A1677DF0213CE0B100A08C34 /* JSMerchantValidationEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = A1677DEE213CE0B000A08C34 /* JSMerchantValidationEventInit.h */; }; > A1677DFD213E006600A08C34 /* PaymentValidationErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = A1677DFA213E006600A08C34 /* PaymentValidationErrors.h */; }; >@@ -10960,12 +10958,8 @@ > A164A2442134BC7100509156 /* PaymentMethodChangeEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentMethodChangeEvent.h; sourceTree = "<group>"; }; > A164A2452134BC7100509156 /* PaymentMethodChangeEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaymentMethodChangeEvent.cpp; sourceTree = "<group>"; }; > A164A2462134BC7100509156 /* PaymentMethodChangeEvent.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PaymentMethodChangeEvent.idl; sourceTree = "<group>"; }; >- A164A24B2134BDD800509156 /* PaymentMethodChangeEventInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentMethodChangeEventInit.h; sourceTree = "<group>"; }; >- A164A24D2134BDD800509156 /* PaymentMethodChangeEventInit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PaymentMethodChangeEventInit.idl; sourceTree = "<group>"; }; > A164A2512134C1CB00509156 /* JSPaymentMethodChangeEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentMethodChangeEvent.h; sourceTree = "<group>"; }; >- A164A2522134C1CB00509156 /* JSPaymentMethodChangeEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentMethodChangeEventInit.h; sourceTree = "<group>"; }; > A164A2532134C1CB00509156 /* JSPaymentMethodChangeEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaymentMethodChangeEvent.cpp; sourceTree = "<group>"; }; >- A164A2542134C1CC00509156 /* JSPaymentMethodChangeEventInit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaymentMethodChangeEventInit.cpp; sourceTree = "<group>"; }; > A1677DE6213CDFAA00A08C34 /* MerchantValidationEventInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MerchantValidationEventInit.h; sourceTree = "<group>"; }; > A1677DE8213CDFAA00A08C34 /* MerchantValidationEventInit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MerchantValidationEventInit.idl; sourceTree = "<group>"; }; > A1677DED213CE0AF00A08C34 /* JSMerchantValidationEventInit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMerchantValidationEventInit.cpp; sourceTree = "<group>"; }; >@@ -10982,6 +10976,7 @@ > A1677E12213E03C600A08C34 /* JSAddressErrors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAddressErrors.cpp; sourceTree = "<group>"; }; > A1677E15213E03F000A08C34 /* JSPayerErrorFields.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPayerErrorFields.h; sourceTree = "<group>"; }; > A1677E16213E03F000A08C34 /* JSPayerErrorFields.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPayerErrorFields.cpp; sourceTree = "<group>"; }; >+ A1677E242144532800A08C34 /* JSPaymentMethodChangeEventCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaymentMethodChangeEventCustom.cpp; sourceTree = "<group>"; }; > A1763F3C1E205234001D58DE /* WebArchiveDumpSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveDumpSupport.mm; sourceTree = "<group>"; }; > A1763F3D1E205234001D58DE /* WebArchiveDumpSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebArchiveDumpSupport.h; sourceTree = "<group>"; }; > A1763F401E20586E001D58DE /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; >@@ -19947,6 +19942,7 @@ > 4131F3B11F9552810059995A /* JSFetchEventCustom.cpp */, > BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */, > 410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */, >+ A1677E242144532800A08C34 /* JSPaymentMethodChangeEventCustom.cpp */, > A85F22081430377D007CC884 /* JSPopStateEventCustom.cpp */, > BC348BBD0DB7F531004ABAB9 /* JSXMLHttpRequestCustom.cpp */, > ); >@@ -21336,8 +21332,6 @@ > A1CC564F1F46145200A4555B /* JSPaymentItem.h */, > A164A2532134C1CB00509156 /* JSPaymentMethodChangeEvent.cpp */, > A164A2512134C1CB00509156 /* JSPaymentMethodChangeEvent.h */, >- A164A2542134C1CC00509156 /* JSPaymentMethodChangeEventInit.cpp */, >- A164A2522134C1CB00509156 /* JSPaymentMethodChangeEventInit.h */, > A1CC564D1F46145100A4555B /* JSPaymentMethodData.cpp */, > A1CC564C1F46145000A4555B /* JSPaymentMethodData.h */, > A1CC56531F46145600A4555B /* JSPaymentOptions.cpp */, >@@ -21407,8 +21401,6 @@ > A164A2452134BC7100509156 /* PaymentMethodChangeEvent.cpp */, > A164A2442134BC7100509156 /* PaymentMethodChangeEvent.h */, > A164A2462134BC7100509156 /* PaymentMethodChangeEvent.idl */, >- A164A24B2134BDD800509156 /* PaymentMethodChangeEventInit.h */, >- A164A24D2134BDD800509156 /* PaymentMethodChangeEventInit.idl */, > A1F76B161F44C3900014C318 /* PaymentMethodData.h */, > A1F76B181F44C3900014C318 /* PaymentMethodData.idl */, > A1F76B281F44C4EF0014C318 /* PaymentOptions.h */, >@@ -28896,7 +28888,6 @@ > A1F6005A1F4765050077E83F /* JSPaymentDetailsUpdate.h in Headers */, > A1CC56731F46149800A4555B /* JSPaymentItem.h in Headers */, > A164A2552134C1CC00509156 /* JSPaymentMethodChangeEvent.h in Headers */, >- A164A2562134C1CC00509156 /* JSPaymentMethodChangeEventInit.h in Headers */, > A1CC56751F46149D00A4555B /* JSPaymentMethodData.h in Headers */, > A1CC56771F4614A200A4555B /* JSPaymentOptions.h in Headers */, > A1CC56791F4614A700A4555B /* JSPaymentRequest.h in Headers */, >@@ -29682,7 +29673,6 @@ > 1AE96A891D1A0CEB00B86768 /* PaymentMerchantSession.h in Headers */, > 1A8A643C1D19FC5300D0E00F /* PaymentMethod.h in Headers */, > A164A2472134BC7100509156 /* PaymentMethodChangeEvent.h in Headers */, >- A164A24E2134BDD800509156 /* PaymentMethodChangeEventInit.h in Headers */, > A1F76B191F44C3900014C318 /* PaymentMethodData.h in Headers */, > A1F76B2B1F44C4EF0014C318 /* PaymentOptions.h in Headers */, > A1F76B131F44C2450014C318 /* PaymentRequest.h in Headers */, >diff --git a/Source/WebCore/bindings/js/JSPaymentMethodChangeEventCustom.cpp b/Source/WebCore/bindings/js/JSPaymentMethodChangeEventCustom.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..9716588b50178bb00f127709691e50e2e7a53204 >--- /dev/null >+++ b/Source/WebCore/bindings/js/JSPaymentMethodChangeEventCustom.cpp >@@ -0,0 +1,56 @@ >+/* >+ * Copyright (C) 2018 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 "JSPaymentMethodChangeEvent.h" >+ >+#if ENABLE(PAYMENT_REQUEST) >+ >+namespace WebCore { >+ >+JSC::JSValue JSPaymentMethodChangeEvent::methodDetails(JSC::ExecState& state) const >+{ >+ return cachedPropertyValue(state, *this, wrapped().cachedMethodDetails(), [this, &state] { >+ return WTF::switchOn(wrapped().methodDetails(), [](JSC::JSValue methodDetails) { >+ return methodDetails ? methodDetails : JSC::jsNull(); >+ }, [&state](const PaymentMethodChangeEvent::MethodDetailsFunction& function) { >+ return function(state).get(); >+ }); >+ }); >+} >+ >+void JSPaymentMethodChangeEvent::visitAdditionalChildren(JSC::SlotVisitor& visitor) >+{ >+ WTF::switchOn(wrapped().methodDetails(), [&visitor](const JSValueInWrappedObject& methodDetails) { >+ methodDetails.visit(visitor); >+ }, [](const PaymentMethodChangeEvent::MethodDetailsFunction&) { >+ }); >+ >+ wrapped().cachedMethodDetails().visit(visitor); >+} >+ >+} // namespace WebCore >+ >+#endif // ENABLE(PAYMENT_REQUEST) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index d9d5d5bae155d0f85044cd1326ef42fbd08e54a4..bc547332c8ce7216a1684c3a166d5df355a1a188 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,15 @@ >+2018-09-08 Andy Estes <aestes@apple.com> >+ >+ [Apple Pay] Dispatch a paymentmethodchange event when the payment method changes >+ https://bugs.webkit.org/show_bug.cgi?id=189386 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * fast/dom/reference-cycle-leaks-expected.txt: >+ * fast/dom/reference-cycle-leaks.html: >+ * http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https-expected.txt: Added. >+ * http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https.html: Added. >+ > 2018-09-07 Basuke Suzuki <Basuke.Suzuki@sony.com> > > [LayoutTests] Add digest access authentication test. >diff --git a/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt b/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt >index 56a0c280bcfbb4f64428c881324dcf002568db41..863707d7ca1364ac1678765cc4259a7c3f76c73d 100644 >--- a/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt >+++ b/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt >@@ -13,6 +13,7 @@ PASS checkForNodeLeaks(createCustomEventDetailsCycle) is "did not leak" > PASS checkForNodeLeaks(createErrorEventDataCycle) is "did not leak" > ---- Did not test ExtendableMessageEvent because it is not enabled. > PASS checkForNodeLeaks(createMessageEventDataCycle) is "did not leak" >+PASS checkForNodeLeaks(createPaymentMethodChangeEventMethodDetailsCycle) is "did not leak" > PASS checkForNodeLeaks(createPopStateEventStateCycle) is "did not leak" > FAIL checkForNodeLeaks(createPromiseRejectionEventPromiseCycle) should be did not leak. Was leaked. > PASS checkForNodeLeaks(createPromiseRejectionEventPromiseFunctionCycle) is "did not leak" >diff --git a/LayoutTests/fast/dom/reference-cycle-leaks.html b/LayoutTests/fast/dom/reference-cycle-leaks.html >index e69b2a3540736a98482874ced89d2d948859d5dd..6123965c10ffe421d3b32b01faecf88bf103eb85 100644 >--- a/LayoutTests/fast/dom/reference-cycle-leaks.html >+++ b/LayoutTests/fast/dom/reference-cycle-leaks.html >@@ -83,6 +83,12 @@ function createMessageEventDataCycle() > leakDetectionNode.event = new MessageEvent("x", { data: leakDetectionNode }); > } > >+function createPaymentMethodChangeEventMethodDetailsCycle() >+{ >+ const leakDetectionNode = document.createTextNode(""); >+ leakDetectionNode.event = new PaymentMethodChangeEvent("x", { methodDetails: leakDetectionNode }); >+} >+ > function createPromiseRejectionEventPromiseCycle() > { > const leakDetectionNode = document.createTextNode(""); >@@ -162,6 +168,7 @@ function startTest() > runLeakTest('createErrorEventDataCycle'); > runLeakTest('createExtendableMessageEventDataCycle', 'ExtendableMessageEvent'); > runLeakTest('createMessageEventDataCycle'); >+ runLeakTest('createPaymentMethodChangeEventMethodDetailsCycle', 'PaymentMethodChangeEvent'); > runLeakTest('createPopStateEventStateCycle'); > runLeakTest('createPromiseRejectionEventPromiseCycle'); > runLeakTest('createPromiseRejectionEventPromiseFunctionCycle'); >diff --git a/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https-expected.txt b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..df583f6a42b1a91ed69c61a53b3c4720d41641d0 >--- /dev/null >+++ b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https-expected.txt >@@ -0,0 +1,34 @@ >+CONSOLE MESSAGE: Unhandled Promise Rejection: AbortError: The operation was aborted. >+Test PaymentMethodChangeEvent with Apple Pay. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+Testing that PaymentMethodChangeEvent fires after selecting a 'credit' payment method type. >+PASS event.methodName is 'https://apple.com/apple-pay' >+PASS event.methodDetails.type is 'credit' >+ >+Testing that PaymentMethodChangeEvent.updateWith() updates payment details after selecting a 'credit' payment method type. >+PASS event.methodName is 'https://apple.com/apple-pay' >+PASS event.methodDetails.type is 'credit' >+PASS internals.mockPaymentCoordinator.total.label is 'Total' >+PASS internals.mockPaymentCoordinator.total.amount is '15.00' >+PASS internals.mockPaymentCoordinator.lineItems.length is 1 >+PASS internals.mockPaymentCoordinator.lineItems[0].label is 'Item' >+PASS internals.mockPaymentCoordinator.lineItems[0].amount is '10.00' >+ >+Testing that PaymentMethodChangeEvent.updateWith() applies modifiers after selecting a 'credit' payment method type. >+PASS event.methodName is 'https://apple.com/apple-pay' >+PASS event.methodDetails.type is 'credit' >+PASS internals.mockPaymentCoordinator.total.label is 'Credit total override' >+PASS internals.mockPaymentCoordinator.total.amount is '20.00' >+PASS internals.mockPaymentCoordinator.lineItems.length is 2 >+PASS internals.mockPaymentCoordinator.lineItems[0].label is 'Item' >+PASS internals.mockPaymentCoordinator.lineItems[0].amount is '10.00' >+PASS internals.mockPaymentCoordinator.lineItems[1].label is 'Credit surcharge' >+PASS internals.mockPaymentCoordinator.lineItems[1].amount is '10.00' >+ >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https.html b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https.html >new file mode 100644 >index 0000000000000000000000000000000000000000..a7156f5d4ea1818f107c19d7588918afb86e8e5e >--- /dev/null >+++ b/LayoutTests/http/tests/ssl/applepay/ApplePayPaymentMethodChangeEvent.https.html >@@ -0,0 +1,162 @@ >+<!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> >+<script src="/resources/payment-request.js"></script> >+</head> >+<body> >+<script> >+ >+description("Test PaymentMethodChangeEvent with Apple Pay."); >+ >+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: 'Total', >+ amount: { >+ currency: 'USD', >+ value: '10.00', >+ }, >+ }, >+ displayItems: [{ >+ label: 'Item', >+ amount: { >+ currency: 'USD', >+ value: '10.00', >+ }, >+ }], >+ } >+} >+ >+async function runTests() { >+ await new Promise((resolve, reject) => { >+ debug("Testing that PaymentMethodChangeEvent fires after selecting a 'credit' payment method type."); >+ >+ activateThen(() => { >+ var paymentRequest = new PaymentRequest([validPaymentMethod()], validPaymentDetails()); >+ try { >+ paymentRequest.onpaymentmethodchange = (event) => { >+ shouldBe("event.methodName", "'https://apple.com/apple-pay'"); >+ shouldBe("event.methodDetails.type", "'credit'"); >+ paymentRequest.abort(); >+ resolve(); >+ }; >+ >+ paymentRequest.show(); >+ internals.mockPaymentCoordinator.changePaymentMethod({ type: 'credit' }); >+ } catch (error) { >+ } >+ }); >+ }); >+ debug(""); >+ >+ await new Promise((resolve, reject) => { >+ debug("Testing that PaymentMethodChangeEvent.updateWith() updates payment details after selecting a 'credit' payment method type."); >+ >+ activateThen(() => { >+ var paymentRequest = new PaymentRequest([validPaymentMethod()], validPaymentDetails()); >+ >+ paymentRequest.onpaymentmethodchange = (event) => { >+ shouldBe("event.methodName", "'https://apple.com/apple-pay'"); >+ shouldBe("event.methodDetails.type", "'credit'"); >+ >+ var detailsUpdate = validPaymentDetails(); >+ detailsUpdate.total.amount.value = '15.00'; >+ event.updateWith(detailsUpdate); >+ internals.mockPaymentCoordinator.acceptPayment(); >+ }; >+ >+ paymentRequest.show().then((response) => { >+ shouldBe("internals.mockPaymentCoordinator.total.label", "'Total'"); >+ shouldBe("internals.mockPaymentCoordinator.total.amount", "'15.00'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems.length", "1"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[0].label", "'Item'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[0].amount", "'10.00'"); >+ response.complete("success"); >+ resolve(); >+ }); >+ >+ internals.mockPaymentCoordinator.changePaymentMethod({ type: 'credit' }); >+ }); >+ }); >+ debug(""); >+ >+ await new Promise((resolve, reject) => { >+ debug("Testing that PaymentMethodChangeEvent.updateWith() applies modifiers after selecting a 'credit' payment method type."); >+ >+ activateThen(() => { >+ var paymentRequest = new PaymentRequest([validPaymentMethod()], validPaymentDetails()); >+ >+ paymentRequest.onpaymentmethodchange = (event) => { >+ shouldBe("event.methodName", "'https://apple.com/apple-pay'"); >+ shouldBe("event.methodDetails.type", "'credit'"); >+ >+ var detailsUpdate = validPaymentDetails(); >+ detailsUpdate.total.amount.value = '15.00'; >+ detailsUpdate.modifiers = [{ >+ supportedMethods: 'https://apple.com/apple-pay', >+ total: { >+ label: 'Credit total override', >+ amount: { >+ currency: 'USD', >+ value: '20.00', >+ }, >+ }, >+ additionalDisplayItems: [{ >+ label: 'Credit surcharge', >+ amount: { >+ currency: 'USD', >+ value: '10.00', >+ }, >+ }], >+ data: { >+ paymentMethodType: 'credit', >+ }, >+ }]; >+ >+ event.updateWith(detailsUpdate); >+ internals.mockPaymentCoordinator.acceptPayment(); >+ }; >+ >+ paymentRequest.show().then((response) => { >+ shouldBe("internals.mockPaymentCoordinator.total.label", "'Credit total override'"); >+ shouldBe("internals.mockPaymentCoordinator.total.amount", "'20.00'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems.length", "2"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[0].label", "'Item'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[0].amount", "'10.00'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[1].label", "'Credit surcharge'"); >+ shouldBe("internals.mockPaymentCoordinator.lineItems[1].amount", "'10.00'"); >+ response.complete("success"); >+ resolve(); >+ }); >+ >+ internals.mockPaymentCoordinator.changePaymentMethod({ type: 'credit' }); >+ }); >+ }); >+ debug(""); >+ >+ finishJSTest(); >+} >+ >+runTests(); >+</script> >+<script src="/resources/js-test-post.js"></script> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189386
:
349095
|
349259
|
349261
|
349262
|
349263
|
349264
|
349265