Bug 1509517 [wpt PR 14205] - Test PaymentMethodData data member is converted in constructor, a=testonly
☠☠ backed out by fb94ec981a7d ☠ ☠
authorMarcos Cáceres <marcos@marcosc.com>
Fri, 30 Nov 2018 18:05:03 +0000
changeset 449851 e61986873e7652ec9649366c45eed7d61bea8c0d
parent 449850 e17130d54efc4c22ba81921a6b028ec493a68789
child 449852 ed91c65bb17e888018e1e258e7eed3b11f39491a
push id110426
push userwptsync@mozilla.com
push dateTue, 11 Dec 2018 03:07:11 +0000
treeherdermozilla-inbound@fcd0236d7afa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1509517, 14205
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509517 [wpt PR 14205] - Test PaymentMethodData data member is converted in constructor, a=testonly Automatic update from web-platform-tests Test PaymentMethodData data member is converted in constructor (#14205) -- wpt-commits: 15d978ae5c4edd49f1ca20f26bc6272e5c319ab6 wpt-pr: 14205
testing/web-platform/tests/payment-request/constructor_convert_method_data.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/constructor_convert_method_data.https.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html> <meta charset="utf-8" />
+<title>Validates PaymentMethodData's data member during construction</title>
+<link
+  rel="help"
+  href="https://w3c.github.io/browser-payment-api/#constructor"
+/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+  const details = {
+    total: {
+      label: "Total",
+      amount: {
+        currency: "USD",
+        value: "0.00",
+      },
+    },
+  };
+
+  test(() => {
+    new PaymentRequest([{ supportedMethods: "basic-card" }], details);
+    new PaymentRequest(
+      [{ supportedMethods: "https://apple.com/apple-pay" }],
+      details
+    );
+  }, "Smoke test.");
+
+  const knownPMIs = ["basic-card", "https://apple.com/apple-pay"];
+  const unknownPMIs = ["fake-pmi", "https://does-not.exist"];
+
+  promise_test(async t => {
+    for (const supportedMethods of [].concat(knownPMIs).concat(unknownPMIs)) {
+      const method = { supportedMethods };
+      const request = new PaymentRequest([method], details);
+      assert_throws(
+        new TypeError(),
+        () => {
+          const badMethod = Object.assign(
+            {},
+            method,
+            { data: 123 } // <- this will throw
+          );
+          new PaymentRequest([badMethod], details);
+        },
+        "PaymentMethodData.data can't be converted to an Object."
+      );
+    }
+  }, "Tries to convert data member during Payment Request construction, irrespective of PMI.");
+
+  promise_test(async t => {
+    for (const supportedMethods of knownPMIs) {
+      const method = { supportedMethods };
+      const request = new PaymentRequest([method], details);
+
+      // Only check the PMIs that are actually supported
+      if (!(await request.canMakePayment())) continue;
+
+      assert_throws(
+        new TypeError(),
+        () => {
+          const badMethod = Object.assign(
+            {},
+            method,
+            /* This is invalid in both Apple Pay and Basic Card */
+            { data: { supportedNetworks: "this will throw" } }
+          );
+          new PaymentRequest([badMethod], details);
+        },
+        "PaymentMethodData.data is invalid."
+      );
+    }
+  }, "Converts PaymentMethodData's data to mandated IDL type during PaymentRequest construction.");
+</script>