Apple Pay button does nothing on nytimes.com
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2017 22:03:59 +0000 (22:03 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2017 22:03:59 +0000 (22:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167664
rdar://problem/30273885

Reviewed by Sam Weinig.

Source/WebCore:

Separate line item validation into convertAndValidateTotal and convertAndValidate. The former
works on totals (which require an amount), and the latter works on regular line items that do not require an amount
if the item type is "pending".

* Modules/applepay/ApplePaySession.cpp:
(WebCore::convertAndValidateTotal):
(WebCore::convertAndValidate):
Only check the amount if the type is not pending.

(WebCore::ApplePaySession::completeShippingMethodSelection):
(WebCore::ApplePaySession::completeShippingContactSelection):
(WebCore::ApplePaySession::completePaymentMethodSelection):
Call convertAndValidateTotal for totals.

LayoutTests:

Add a new test.

* http/tests/ssl/applepay/ApplePaySession-expected.txt:
* http/tests/ssl/applepay/ApplePaySession.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt
LayoutTests/http/tests/ssl/applepay/ApplePaySession.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePaySession.cpp

index 591a3e1..60f38ae 100644 (file)
@@ -1,3 +1,16 @@
+2017-01-31  Anders Carlsson  <andersca@apple.com>
+
+        Apple Pay button does nothing on nytimes.com
+        https://bugs.webkit.org/show_bug.cgi?id=167664
+        rdar://problem/30273885
+
+        Reviewed by Sam Weinig.
+
+        Add a new test.
+
+        * http/tests/ssl/applepay/ApplePaySession-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySession.html:
+
 2017-01-31  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, fix layout tests added in r211435.
index 1b1bc47..47c02e9 100644 (file)
@@ -169,6 +169,9 @@ PASS new ApplePaySession(2, request) threw exception TypeError: Value is not a s
 SETUP: request = validRequest(); request.lineItems = { };
 PASS new ApplePaySession(2, request) threw exception TypeError: Type error.
 
+SETUP: request = validRequest(); request.lineItems = [{ label: 'label', type: 'pending' }];
+PASS new ApplePaySession(2, request) did not throw exception.
+
 SETUP: request = validRequest(); request.lineItems = [];
 PASS new ApplePaySession(2, request) did not throw exception.
 
index cae52db..3e2b24c 100644 (file)
@@ -112,7 +112,7 @@ function go() {
     logAndShouldThrow("request = validRequest(); request.lineItems = null;", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.lineItems = 7;", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.lineItems = { };", "new ApplePaySession(2, request)")
-    // FIXME: Should we allow an empty lineItems sequence?
+    logAndShouldNotThrow("request = validRequest(); request.lineItems = [{ label: 'label', type: 'pending' }];", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.lineItems = [];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.lineItems = [''];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.lineItems = [null];", "new ApplePaySession(2, request)")
index ce56ab1..e1c7e01 100644 (file)
@@ -1,3 +1,25 @@
+2017-01-31  Anders Carlsson  <andersca@apple.com>
+
+        Apple Pay button does nothing on nytimes.com
+        https://bugs.webkit.org/show_bug.cgi?id=167664
+        rdar://problem/30273885
+
+        Reviewed by Sam Weinig.
+
+        Separate line item validation into convertAndValidateTotal and convertAndValidate. The former
+        works on totals (which require an amount), and the latter works on regular line items that do not require an amount
+        if the item type is "pending".
+
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::convertAndValidateTotal):
+        (WebCore::convertAndValidate):
+        Only check the amount if the type is not pending.
+
+        (WebCore::ApplePaySession::completeShippingMethodSelection):
+        (WebCore::ApplePaySession::completeShippingContactSelection):
+        (WebCore::ApplePaySession::completePaymentMethodSelection):
+        Call convertAndValidateTotal for totals.
+
 2017-01-31  Youenn Fablet  <youenn@apple.com>
 
         [WebRTC] Add a libwebrtc AudioModule specific to WebKit
index 8322ac6..57b8bb5 100644 (file)
@@ -162,7 +162,7 @@ static std::optional<int64_t> parseAmount(const String& amountString)
     return amount;
 }
 
-static ExceptionOr<PaymentRequest::LineItem> convertAndValidate(ApplePayLineItem&& lineItem)
+static ExceptionOr<PaymentRequest::LineItem> convertAndValidateTotal(ApplePayLineItem&& lineItem)
 {
     auto amount = parseAmount(lineItem.amount);
     if (!amount)
@@ -176,6 +176,25 @@ static ExceptionOr<PaymentRequest::LineItem> convertAndValidate(ApplePayLineItem
     return WTFMove(result);
 }
 
+static ExceptionOr<PaymentRequest::LineItem> convertAndValidate(ApplePayLineItem&& lineItem)
+{
+    PaymentRequest::LineItem result;
+
+    // It is OK for pending types to not have an amount.
+    if (lineItem.type != PaymentRequest::LineItem::Type::Pending) {
+        auto amount = parseAmount(lineItem.amount);
+        if (!amount)
+            return Exception { TypeError, makeString("\"" + lineItem.amount, "\" is not a valid amount.") };
+
+        result.amount = *amount;
+    }
+
+    result.type = lineItem.type;
+    result.label = lineItem.label;
+
+    return WTFMove(result);
+}
+
 static ExceptionOr<Vector<PaymentRequest::LineItem>> convertAndValidate(std::optional<Vector<ApplePayLineItem>>&& lineItems)
 {
     Vector<PaymentRequest::LineItem> result;
@@ -298,7 +317,7 @@ static ExceptionOr<PaymentRequest> convertAndValidate(unsigned version, ApplePay
 {
     PaymentRequest result;
 
-    auto total = convertAndValidate(WTFMove(paymentRequest.total));
+    auto total = convertAndValidateTotal(WTFMove(paymentRequest.total));
     if (total.hasException())
         return total.releaseException();
     result.setTotal(total.releaseReturnValue());
@@ -611,7 +630,7 @@ ExceptionOr<void> ApplePaySession::completeShippingMethodSelection(unsigned shor
     if (!authorizationStatus)
         return Exception { INVALID_ACCESS_ERR };
 
-    auto convertedNewTotal = convertAndValidate(WTFMove(newTotal));
+    auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal));
     if (convertedNewTotal.hasException())
         return convertedNewTotal.releaseException();
 
@@ -648,7 +667,7 @@ ExceptionOr<void> ApplePaySession::completeShippingContactSelection(unsigned sho
     if (convertedNewShippingMethods.hasException())
         return convertedNewShippingMethods.releaseException();
 
-    auto convertedNewTotal = convertAndValidate(WTFMove(newTotal));
+    auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal));
     if (convertedNewTotal.hasException())
         return convertedNewTotal.releaseException();
 
@@ -677,7 +696,7 @@ ExceptionOr<void> ApplePaySession::completePaymentMethodSelection(ApplePayLineIt
     if (!canCompletePaymentMethodSelection())
         return Exception { INVALID_ACCESS_ERR };
 
-    auto convertedNewTotal = convertAndValidate(WTFMove(newTotal));
+    auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal));
     if (convertedNewTotal.hasException())
         return convertedNewTotal.releaseException();