Diff
Modified: trunk/LayoutTests/ChangeLog (237141 => 237142)
--- trunk/LayoutTests/ChangeLog 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/LayoutTests/ChangeLog 2018-10-15 21:10:56 UTC (rev 237142)
@@ -1,3 +1,14 @@
+2018-10-15 Andy Estes <aes...@apple.com>
+
+ [Apple Pay] New shipping methods are ignored when updating after the shippingaddresschange event
+ https://bugs.webkit.org/show_bug.cgi?id=190560
+ <rdar://problem/44559075>
+
+ Reviewed by Youenn Fablet.
+
+ * http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https-expected.txt:
+ * http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https.html:
+
2018-10-15 Wenson Hsieh <wenson_hs...@apple.com>
[iOS] Can't select text after dismissing the keyboard when changing focus
Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https-expected.txt (237141 => 237142)
--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https-expected.txt 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https-expected.txt 2018-10-15 21:10:56 UTC (rev 237142)
@@ -8,6 +8,11 @@
Testing PaymentDetailsUpdate with an error and shipping options.
PASS internals.mockPaymentCoordinator.errors.length is 0
+PASS internals.mockPaymentCoordinator.shippingMethods.length is 1
+PASS internals.mockPaymentCoordinator.shippingMethods[0].label is 'option 1'
+PASS internals.mockPaymentCoordinator.shippingMethods[0].detail is ''
+PASS internals.mockPaymentCoordinator.shippingMethods[0].amount is '1.00'
+PASS internals.mockPaymentCoordinator.shippingMethods[0].identifier is 'option1'
Testing PaymentDetailsUpdate with an empty error.
PASS internals.mockPaymentCoordinator.errors.length is 1
@@ -69,6 +74,9 @@
PASS internals.mockPaymentCoordinator.errors[2].message is 'error'
PASS internals.mockPaymentCoordinator.errors[2].contactField is 'phoneNumber'
+Testing specifying an invalid shipping option in response to shippingaddresschange.
+PASS paymentRequest.show() rejected promise with TypeError: "EUR" does not match the expected currency of "USD". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code..
+
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https.html (237141 => 237142)
--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https.html 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https.html 2018-10-15 21:10:56 UTC (rev 237142)
@@ -34,6 +34,11 @@
}];
await updateDetailsOnShippingAddressChange(validPaymentDetails(), { requestShipping: true }, detailsUpdate);
shouldBe("internals.mockPaymentCoordinator.errors.length", "0");
+ shouldBe("internals.mockPaymentCoordinator.shippingMethods.length", "1");
+ shouldBe("internals.mockPaymentCoordinator.shippingMethods[0].label", "'option 1'");
+ shouldBe("internals.mockPaymentCoordinator.shippingMethods[0].detail", "''");
+ shouldBe("internals.mockPaymentCoordinator.shippingMethods[0].amount", "'1.00'");
+ shouldBe("internals.mockPaymentCoordinator.shippingMethods[0].identifier", "'option1'");
debug("");
debug("Testing PaymentDetailsUpdate with an empty error.");
@@ -138,7 +143,32 @@
shouldBe("internals.mockPaymentCoordinator.errors[2].message", "'error'");
shouldBe("internals.mockPaymentCoordinator.errors[2].contactField", "'phoneNumber'");
debug("");
+
+ await new Promise((resolve, reject) => {
+ debug("Testing specifying an invalid shipping option in response to shippingaddresschange.");
+ paymentRequest = new PaymentRequest([validPaymentMethod()], validPaymentDetails(), { requestShipping: true });
+ paymentRequest._onshippingaddresschange_ = (event) => {
+ var detailsUpdate = validPaymentDetails();
+ detailsUpdate.shippingOptions = [{
+ id: "option1",
+ label: "option 1",
+ amount: {
+ currency: "EUR",
+ value: "1.00",
+ },
+ }];
+ event.updateWith(detailsUpdate);
+ };
+ paymentRequest._onmerchantvalidation_ = event => event.complete({});
+
+ activateThen(async () => {
+ await shouldReject("paymentRequest.show()");
+ resolve();
+ });
+ });
+ debug("");
+
finishJSTest();
}
Modified: trunk/Source/WebCore/ChangeLog (237141 => 237142)
--- trunk/Source/WebCore/ChangeLog 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/ChangeLog 2018-10-15 21:10:56 UTC (rev 237142)
@@ -1,3 +1,30 @@
+2018-10-15 Andy Estes <aes...@apple.com>
+
+ [Apple Pay] New shipping methods are ignored when updating after the shippingaddresschange event
+ https://bugs.webkit.org/show_bug.cgi?id=190560
+ <rdar://problem/44559075>
+
+ Reviewed by Youenn Fablet.
+
+ When a PaymentDetailsUpdate with shipping options was specified to updateWith() after the
+ shippingaddresschange event fires, ApplePayPaymentHandler needs to convert the shipping
+ options to ShippingMethods and add them to the ShippingContactUpdate so that the Apple Pay
+ UI renders the new options.
+
+ Added test cases to http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrors.https.html.
+
+ * Modules/applepay/ApplePayShippingMethod.idl:
+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+ (WebCore::ApplePayPaymentHandler::computeShippingMethods):
+ (WebCore::ApplePayPaymentHandler::shippingAddressUpdated):
+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+ * testing/MockPaymentCoordinator.cpp:
+ (WebCore::convert):
+ (WebCore::MockPaymentCoordinator::showPaymentUI):
+ (WebCore::MockPaymentCoordinator::completeShippingContactSelection):
+ * testing/MockPaymentCoordinator.h:
+ * testing/MockPaymentCoordinator.idl:
+
2018-10-15 Youenn Fablet <you...@apple.com>
RTCPeerConnection.generateCertificate is not a function
Modified: trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl (237141 => 237142)
--- trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl 2018-10-15 21:10:56 UTC (rev 237142)
@@ -25,7 +25,8 @@
[
Conditional=APPLE_PAY,
- JSGenerateToJSObject
+ ExportMacro=WEBCORE_EXPORT,
+ JSGenerateToJSObject,
] dictionary ApplePayShippingMethod {
required DOMString label;
required DOMString detail;
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (237141 => 237142)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2018-10-15 21:10:56 UTC (rev 237142)
@@ -203,15 +203,10 @@
if (m_paymentRequest->paymentOptions().requestShipping)
request.setShippingType(convert(m_paymentRequest->paymentOptions().shippingType));
- Vector<ApplePaySessionPaymentRequest::ShippingMethod> shippingMethods;
- shippingMethods.reserveInitialCapacity(m_paymentRequest->paymentDetails().shippingOptions.size());
- for (auto& shippingOption : m_paymentRequest->paymentDetails().shippingOptions) {
- auto convertedShippingOption = convertAndValidate(shippingOption, expectedCurrency);
- if (convertedShippingOption.hasException())
- return convertedShippingOption.releaseException();
- shippingMethods.uncheckedAppend(convertedShippingOption.releaseReturnValue());
- }
- request.setShippingMethods(shippingMethods);
+ auto shippingMethods = computeShippingMethods();
+ if (shippingMethods.hasException())
+ return shippingMethods.releaseException();
+ request.setShippingMethods(shippingMethods.releaseReturnValue());
auto exception = PaymentRequestValidator::validate(request);
if (exception.hasException())
@@ -248,7 +243,26 @@
paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler));
}
+
+ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> ApplePayPaymentHandler::computeShippingMethods()
+{
+ auto& details = m_paymentRequest->paymentDetails();
+ auto& currency = details.total.amount.currency;
+ auto& shippingOptions = details.shippingOptions;
+ Vector<ApplePaySessionPaymentRequest::ShippingMethod> shippingMethods;
+ shippingMethods.reserveInitialCapacity(shippingOptions.size());
+
+ for (auto& shippingOption : shippingOptions) {
+ auto shippingMethod = convertAndValidate(shippingOption, currency);
+ if (shippingMethod.hasException())
+ return shippingMethod.releaseException();
+ shippingMethods.uncheckedAppend(shippingMethod.releaseReturnValue());
+ }
+
+ return WTFMove(shippingMethods);
+}
+
ExceptionOr<ApplePaySessionPaymentRequest::TotalAndLineItems> ApplePayPaymentHandler::computeTotalAndLineItems()
{
auto& details = m_paymentRequest->paymentDetails();
@@ -408,6 +422,11 @@
ShippingContactUpdate update;
update.errors = WTFMove(errors);
+ auto newShippingMethods = computeShippingMethods();
+ if (newShippingMethods.hasException())
+ return newShippingMethods.releaseException();
+ update.newShippingMethods = newShippingMethods.releaseReturnValue();
+
auto newTotalAndLineItems = computeTotalAndLineItems();
if (newTotalAndLineItems.hasException())
return newTotalAndLineItems.releaseException();
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h (237141 => 237142)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h 2018-10-15 21:10:56 UTC (rev 237142)
@@ -52,6 +52,7 @@
Document& document() const;
PaymentCoordinator& paymentCoordinator() const;
+ ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> computeShippingMethods();
ExceptionOr<ApplePaySessionPaymentRequest::TotalAndLineItems> computeTotalAndLineItems();
Vector<PaymentError> computeErrors(String&& error, AddressErrors&&, PayerErrorFields&&, JSC::JSObject* paymentMethodErrors) const;
Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp (237141 => 237142)
--- trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp 2018-10-15 21:10:56 UTC (rev 237142)
@@ -106,10 +106,18 @@
});
}
+static Vector<ApplePayShippingMethod> convert(const Vector<ApplePaySessionPaymentRequest::ShippingMethod>& shippingMethods)
+{
+ return WTF::map(shippingMethods, [] (auto& shippingMethod) {
+ return ApplePayShippingMethod { shippingMethod.label, shippingMethod.detail, shippingMethod.amount, shippingMethod.identifier };
+ });
+}
+
bool MockPaymentCoordinator::showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest& request)
{
if (request.shippingContact().pkContact())
m_shippingAddress = request.shippingContact().toApplePayPaymentContact(request.version());
+ m_shippingMethods = convert(request.shippingMethods());
ASSERT(showCount == hideCount);
++showCount;
@@ -154,6 +162,7 @@
if (!shippingContactUpdate)
return;
+ m_shippingMethods = convert(shippingContactUpdate->newShippingMethods);
updateTotalAndLineItems(shippingContactUpdate->newTotalAndLineItems);
m_errors = WTFMove(shippingContactUpdate->errors);
}
Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.h (237141 => 237142)
--- trunk/Source/WebCore/testing/MockPaymentCoordinator.h 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.h 2018-10-15 21:10:56 UTC (rev 237142)
@@ -28,6 +28,7 @@
#if ENABLE(APPLE_PAY)
#include "ApplePayLineItem.h"
+#include "ApplePayShippingMethod.h"
#include "MockPaymentAddress.h"
#include "MockPaymentError.h"
#include "PaymentCoordinatorClient.h"
@@ -52,6 +53,7 @@
const ApplePayLineItem& total() const { return m_total; }
const Vector<ApplePayLineItem>& lineItems() const { return m_lineItems; }
const Vector<MockPaymentError>& errors() const { return m_errors; }
+ const Vector<ApplePayShippingMethod>& shippingMethods() const { return m_shippingMethods; }
void ref() const { }
void deref() const { }
@@ -79,6 +81,7 @@
ApplePayLineItem m_total;
Vector<ApplePayLineItem> m_lineItems;
Vector<MockPaymentError> m_errors;
+ Vector<ApplePayShippingMethod> m_shippingMethods;
HashSet<String, ASCIICaseInsensitiveHash> m_availablePaymentNetworks;
};
Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.idl (237141 => 237142)
--- trunk/Source/WebCore/testing/MockPaymentCoordinator.idl 2018-10-15 20:58:24 UTC (rev 237141)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.idl 2018-10-15 21:10:56 UTC (rev 237142)
@@ -36,4 +36,5 @@
readonly attribute ApplePayLineItem total;
readonly attribute sequence<ApplePayLineItem> lineItems;
readonly attribute sequence<MockPaymentError> errors;
+ readonly attribute sequence<ApplePayShippingMethod> shippingMethods;
};