[Payment Request] Only process shipping options if shipping is requested, and throw...
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 20:02:29 +0000 (20:02 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 20:02:29 +0000 (20:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178535

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/payment-request/payment-request-constructor.https-expected.txt:

Source/WebCore:

Progresses four tests in web-platform-tests/payment-request/payment-request-constructor.https.html.

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

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-constructor.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp

index 7280d8b..82dcb4d 100644 (file)
@@ -1,3 +1,12 @@
+2017-10-19  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] Only process shipping options if shipping is requested, and throw an exception on duplicate shipping option IDs
+        https://bugs.webkit.org/show_bug.cgi?id=178535
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/payment-request/payment-request-constructor.https-expected.txt:
+
 2017-10-19  Dean Jackson  <dino@apple.com>
 
         Import W3C Web Platform Tests for createImageBitmap
index c1bdc9d..20cc8b1 100644 (file)
@@ -15,14 +15,10 @@ PASS Negative values are allowed for displayItems.amount.value, irrespective of
 PASS it handles high precision currency values without throwing 
 PASS For each option in details.shippingOptions: if option.amount.value is not a valid decimal monetary value, then throw a TypeError 
 PASS If there is no selected shipping option, then PaymentRequest.shippingOption remains null 
-FAIL If there is a selected shipping option, and requestShipping is set, then that option becomes synchronously selected assert_equals: Must be null when no shipping is requested (defaults to false) expected (object) null but got (string) "the-id"
-FAIL If requestShipping is set, and if there is a multiple selected shipping options, only the last is selected. assert_equals: shippingOption must be null, as requestShipping is false expected (object) null but got (string) "the-id"
-FAIL If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError assert_throws: Expected to throw a TypeError because duplicate IDs function "() => {
-      new PaymentRequest(defaultMethods, details, { requestShipping: true });
-    }" did not throw
-FAIL Throw when there are duplicate shippingOption ids, even if other values are different assert_throws: Expected to throw a TypeError because duplicate IDs function "() => {
-      new PaymentRequest(defaultMethods, details, { requestShipping: true });
-    }" did not throw
+PASS If there is a selected shipping option, and requestShipping is set, then that option becomes synchronously selected 
+PASS If requestShipping is set, and if there is a multiple selected shipping options, only the last is selected. 
+PASS If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError 
+PASS Throw when there are duplicate shippingOption ids, even if other values are different 
 PASS Throw TypeError if modifier.total.amount.value is not a valid decimal monetary value 
 PASS If amount.value of additionalDisplayItems is not a valid decimal monetary value, then throw a TypeError 
 PASS Modifier data must be JSON-serializable object (an Array in this case) 
index 11bed0e..3743ae9 100644 (file)
@@ -1,3 +1,15 @@
+2017-10-19  Andy Estes  <aestes@apple.com>
+
+        [Payment Request] Only process shipping options if shipping is requested, and throw an exception on duplicate shipping option IDs
+        https://bugs.webkit.org/show_bug.cgi?id=178535
+
+        Reviewed by Alex Christensen.
+
+        Progresses four tests in web-platform-tests/payment-request/payment-request-constructor.https.html.
+
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::create):
+
 2017-10-19  Daniel Bates  <dabates@apple.com>
 
         Share logic in InlineTextBox to compute selection rect
index 209bfcf..bfecf5f 100644 (file)
@@ -278,21 +278,20 @@ ExceptionOr<Ref<PaymentRequest>> PaymentRequest::create(Document& document, Vect
     }
 
     String selectedShippingOption;
-    HashSet<String> seenShippingOptionIDs;
-    for (auto& shippingOption : details.shippingOptions) {
-        auto exception = checkAndCanonicalizeAmount(shippingOption.amount);
-        if (exception.hasException())
-            return exception.releaseException();
+    if (options.requestShipping) {
+        HashSet<String> seenShippingOptionIDs;
+        for (auto& shippingOption : details.shippingOptions) {
+            auto exception = checkAndCanonicalizeAmount(shippingOption.amount);
+            if (exception.hasException())
+                return exception.releaseException();
 
-        auto addResult = seenShippingOptionIDs.add(shippingOption.id);
-        if (!addResult.isNewEntry) {
-            details.shippingOptions = { };
-            selectedShippingOption = { };
-            break;
-        }
+            auto addResult = seenShippingOptionIDs.add(shippingOption.id);
+            if (!addResult.isNewEntry)
+                return Exception { TypeError, "Shipping option IDs must be unique." };
 
-        if (shippingOption.selected)
-            selectedShippingOption = shippingOption.id;
+            if (shippingOption.selected)
+                selectedShippingOption = shippingOption.id;
+        }
     }
 
     Vector<String> serializedModifierData;