Title: [274012] trunk
Revision
274012
Author
[email protected]
Date
2021-03-05 15:29:03 -0800 (Fri, 05 Mar 2021)

Log Message

[Payment Request] if `requestShipping: false` then we should not show any `PaymentShippingOption` in the Apple Pay sheet
https://bugs.webkit.org/show_bug.cgi?id=222810
<rdar://problem/74550889>

Reviewed by Andy Estes and Tim Horton.

Source/WebCore:

When constructing a `PaymentRequest`, the spec has logic for ensuring that `shippingOptions`
is an array by overriding `[[details]].shippingOptions` if `requestShipping: true` [1]. It
also won't update `[[details]].shippingOptions` unless `update.ShippingOptions` is provided
and `requestShipping: true` [2]. Currently, this means that if `requestShipping: false`, we
don't perform any validation of `[[details]].shippingOptions` and even provide that data to
the Apple Pay sheet. Since there is no way to look at the selected (or even the list of)
shipping option without `requestShipping: true`, we now clear `[[details]].shippingOptions`
if `requestShipping: false`.

[1]: https://www.w3.org/TR/payment-request/#constructor
[2]: https://www.w3.org/TR/payment-request/#update-a-paymentrequest-s-details-algorithm

* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::checkAndCanonicalizeDetails):

LayoutTests:

* http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html:
* http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt:
* http/tests/paymentrequest/updateWith-shippingOptions.https.html:
* http/tests/ssl/applepay/PaymentRequest.https.html:
* http/tests/ssl/applepay/PaymentRequest.https-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (274011 => 274012)


--- trunk/LayoutTests/ChangeLog	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/ChangeLog	2021-03-05 23:29:03 UTC (rev 274012)
@@ -1,3 +1,17 @@
+2021-03-05  Devin Rousso  <[email protected]>
+
+        [Payment Request] if `requestShipping: false` then we should not show any `PaymentShippingOption` in the Apple Pay sheet
+        https://bugs.webkit.org/show_bug.cgi?id=222810
+        <rdar://problem/74550889>
+
+        Reviewed by Andy Estes and Tim Horton.
+
+        * http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html:
+        * http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt:
+        * http/tests/paymentrequest/updateWith-shippingOptions.https.html:
+        * http/tests/ssl/applepay/PaymentRequest.https.html:
+        * http/tests/ssl/applepay/PaymentRequest.https-expected.txt:
+
 2021-03-05  Zalan Bujtas  <[email protected]>
 
         word-wrap/overflow-wrap "overwrite" hyphens

Modified: trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt (274011 => 274012)


--- trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt	2021-03-05 23:29:03 UTC (rev 274012)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: WebKit currently uses the first shipping option even if other shipping options are marked as selected.
 Internal properties of a PaymentRequest.
 
 
@@ -78,7 +79,7 @@
   "requestPayerName": false,
   "requestPayerEmail": false,
   "requestPayerPhone": false,
-  "requestShipping": false,
+  "requestShipping": true,
   "shippingType": "shipping"
 }
 
@@ -94,6 +95,7 @@
     },
     "pending": false
   },
+  "shippingOptions": [],
   "modifiers": []
 }
 INTERNAL PROPERTY: options: {
@@ -100,7 +102,7 @@
   "requestPayerName": false,
   "requestPayerEmail": false,
   "requestPayerPhone": false,
-  "requestShipping": false,
+  "requestShipping": true,
   "shippingType": "shipping"
 }
 
@@ -116,6 +118,7 @@
     },
     "pending": false
   },
+  "shippingOptions": [],
   "modifiers": []
 }
 INTERNAL PROPERTY: options: {
@@ -122,7 +125,7 @@
   "requestPayerName": false,
   "requestPayerEmail": false,
   "requestPayerPhone": false,
-  "requestShipping": false,
+  "requestShipping": true,
   "shippingType": "shipping"
 }
 
@@ -138,6 +141,7 @@
     },
     "pending": false
   },
+  "shippingOptions": [],
   "modifiers": []
 }
 INTERNAL PROPERTY: options: {
@@ -144,7 +148,7 @@
   "requestPayerName": false,
   "requestPayerEmail": false,
   "requestPayerPhone": false,
-  "requestShipping": false,
+  "requestShipping": true,
   "shippingType": "shipping"
 }
 

Modified: trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html (274011 => 274012)


--- trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html	2021-03-05 23:29:03 UTC (rev 274012)
@@ -68,12 +68,12 @@
 function createPaymentRequest() {
     if (currentRequest)
         currentRequest.abort().catch(() => {});
-    currentRequest = new PaymentRequest([method], simpleDetails);
+    currentRequest = new PaymentRequest([method], simpleDetails, {requestShipping: true});
     return currentRequest;
 }
 
 function triggerLargePaymentRequest() {
-    let request = new PaymentRequest([method], largeDetails);
+    let request = new PaymentRequest([method], largeDetails, {requestShipping: true});
     Promise.resolve().then(() => { TestPage.dispatchEventToFrontend("Continue"); });
     return request;
 }

Modified: trunk/LayoutTests/http/tests/paymentrequest/updateWith-shippingOptions.https.html (274011 => 274012)


--- trunk/LayoutTests/http/tests/paymentrequest/updateWith-shippingOptions.https.html	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/http/tests/paymentrequest/updateWith-shippingOptions.https.html	2021-03-05 23:29:03 UTC (rev 274012)
@@ -61,12 +61,7 @@
         assert_equals(internals.mockPaymentCoordinator.lineItems[i].label, detailsInit.displayItems[i].label, `display item ${i} label should not change`);
         assert_equals(internals.mockPaymentCoordinator.lineItems[i].amount, detailsInit.displayItems[i].amount.value, `display item ${i} value should not change`);
     }
-    assert_equals(internals.mockPaymentCoordinator.shippingMethods.length, detailsInit.shippingOptions.length, "number of shipping options should not change");
-    for (let i = 0; i < detailsInit.shippingOptions.length; ++i) {
-        assert_equals(internals.mockPaymentCoordinator.shippingMethods[i].identifier, detailsInit.shippingOptions[i].id, `shipping option ${i} id should not change`);
-        assert_equals(internals.mockPaymentCoordinator.shippingMethods[i].label, detailsInit.shippingOptions[i].label, `shipping option ${i} label should not change`);
-        assert_equals(internals.mockPaymentCoordinator.shippingMethods[i].amount, detailsInit.shippingOptions[i].amount.value, `shipping option ${i} amount should not change`);
-    }
+    assert_equals(internals.mockPaymentCoordinator.shippingMethods.length, 0, "number of shipping options should not change");
     assert_equals(request.shippingOption, null, "selected shipping option should not be exposed on the request");
     assert_equals(response.shippingOption, null, "selected shipping option should not be exposed on the response");
 

Modified: trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt (274011 => 274012)


--- trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt	2021-03-05 23:29:03 UTC (rev 274012)
@@ -276,39 +276,39 @@
 Testing PaymentDetails.shippingOptions
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = '';
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Value is not a sequence.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Value is not a sequence.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 'invalid';
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Value is not a sequence.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Value is not a sequence.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = null;
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Value is not a sequence.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Value is not a sequence.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 7;
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Value is not a sequence.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Value is not a sequence.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = { };
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Member PaymentShippingOption.amount is required and must be an instance of PaymentCurrencyAmount.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Member PaymentShippingOption.amount is required and must be an instance of PaymentCurrencyAmount.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '' }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '' }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];
-PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Type error.
+PASS new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true}) threw exception TypeError: Type error.
 
-SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails)
+SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})
 PASS request.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..
 Testing PaymentOptions
 

Modified: trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html (274011 => 274012)


--- trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html	2021-03-05 23:29:03 UTC (rev 274012)
@@ -205,18 +205,18 @@
 
     debug("Testing PaymentDetails.shippingOptions")
     debug("");
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = '';", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 'invalid';", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = null;", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 7;", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = { };", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails)", "request.show()")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = '';", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 'invalid';", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = null;", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = 7;", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = { };", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
+    await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})", "request.show()")
 
     debug("Testing PaymentOptions")
     debug("");

Modified: trunk/Source/WebCore/ChangeLog (274011 => 274012)


--- trunk/Source/WebCore/ChangeLog	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/Source/WebCore/ChangeLog	2021-03-05 23:29:03 UTC (rev 274012)
@@ -1,3 +1,26 @@
+2021-03-05  Devin Rousso  <[email protected]>
+
+        [Payment Request] if `requestShipping: false` then we should not show any `PaymentShippingOption` in the Apple Pay sheet
+        https://bugs.webkit.org/show_bug.cgi?id=222810
+        <rdar://problem/74550889>
+
+        Reviewed by Andy Estes and Tim Horton.
+
+        When constructing a `PaymentRequest`, the spec has logic for ensuring that `shippingOptions`
+        is an array by overriding `[[details]].shippingOptions` if `requestShipping: true` [1]. It
+        also won't update `[[details]].shippingOptions` unless `update.ShippingOptions` is provided
+        and `requestShipping: true` [2]. Currently, this means that if `requestShipping: false`, we
+        don't perform any validation of `[[details]].shippingOptions` and even provide that data to
+        the Apple Pay sheet. Since there is no way to look at the selected (or even the list of)
+        shipping option without `requestShipping: true`, we now clear `[[details]].shippingOptions`
+        if `requestShipping: false`.
+
+        [1]: https://www.w3.org/TR/payment-request/#constructor
+        [2]: https://www.w3.org/TR/payment-request/#update-a-paymentrequest-s-details-algorithm
+
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::checkAndCanonicalizeDetails):
+
 2021-03-05  Zalan Bujtas  <[email protected]>
 
         word-wrap/overflow-wrap "overwrite" hyphens

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (274011 => 274012)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2021-03-05 23:07:35 UTC (rev 274011)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2021-03-05 23:29:03 UTC (rev 274012)
@@ -244,7 +244,8 @@
             }
         } else if (isUpdate == IsUpdate::No)
             details.shippingOptions = { { } };
-    }
+    } else if (isUpdate == IsUpdate::No)
+        details.shippingOptions = WTF::nullopt;
 
     Vector<String> serializedModifierData;
     if (details.modifiers) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to