Title: [211446] trunk
Revision
211446
Author
ander...@apple.com
Date
2017-01-31 14:03:59 -0800 (Tue, 31 Jan 2017)

Log Message

Apple Pay button does nothing on nytimes.com
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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (211445 => 211446)


--- trunk/LayoutTests/ChangeLog	2017-01-31 21:04:27 UTC (rev 211445)
+++ trunk/LayoutTests/ChangeLog	2017-01-31 22:03:59 UTC (rev 211446)
@@ -1,3 +1,16 @@
+2017-01-31  Anders Carlsson  <ander...@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  <cdu...@apple.com>
 
         Unreviewed, fix layout tests added in r211435.

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt (211445 => 211446)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt	2017-01-31 21:04:27 UTC (rev 211445)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt	2017-01-31 22:03:59 UTC (rev 211446)
@@ -169,6 +169,9 @@
 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.
 

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html (211445 => 211446)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html	2017-01-31 21:04:27 UTC (rev 211445)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html	2017-01-31 22:03:59 UTC (rev 211446)
@@ -112,7 +112,7 @@
     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)")

Modified: trunk/Source/WebCore/ChangeLog (211445 => 211446)


--- trunk/Source/WebCore/ChangeLog	2017-01-31 21:04:27 UTC (rev 211445)
+++ trunk/Source/WebCore/ChangeLog	2017-01-31 22:03:59 UTC (rev 211446)
@@ -1,3 +1,25 @@
+2017-01-31  Anders Carlsson  <ander...@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  <you...@apple.com>
 
         [WebRTC] Add a libwebrtc AudioModule specific to WebKit

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (211445 => 211446)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2017-01-31 21:04:27 UTC (rev 211445)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2017-01-31 22:03:59 UTC (rev 211446)
@@ -162,7 +162,7 @@
     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 @@
     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 @@
 {
     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 @@
     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 @@
     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 @@
     if (!canCompletePaymentMethodSelection())
         return Exception { INVALID_ACCESS_ERR };
 
-    auto convertedNewTotal = convertAndValidate(WTFMove(newTotal));
+    auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal));
     if (convertedNewTotal.hasException())
         return convertedNewTotal.releaseException();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to