Bug 1526739 [wpt PR 15281] - [Payment Request][WPT] Fix canMakePayment() tests., a=testonly
authorRouslan Solomakhin <rouslan@chromium.org>
Tue, 19 Feb 2019 11:46:24 +0000
changeset 519216 b2d1b24dd99b273b6b1d0db52c1839d9e1ab8faf
parent 519215 dcf9f8a30353c00c97b288f85ea84f95bd4d3d19
child 519217 a5965112ab0f2f3fdd6dde49af8081ebb9a2edeb
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1526739, 15281, 929773, 1459061, 630358
milestone67.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 1526739 [wpt PR 15281] - [Payment Request][WPT] Fix canMakePayment() tests., a=testonly Automatic update from web-platform-tests [Payment Request][WPT] Fix canMakePayment() tests. Before this patch, a couple of WPT test cases for canMakePayment() would fail when attempting to issue an automated click with a user gesture to to show the payment sheet. This patch splits the test cases that need user gestures into a manual test that solicits a real user gesture click to show the payment sheet. After this patch, the canMakePayment() tests are passing. Bug: 929773 Change-Id: Ide9a310f39c69957b2b182f00e6db37ea6391e12 Reviewed-on: https://chromium-review.googlesource.com/c/1459061 Reviewed-by: Danyao Wang <danyao@chromium.org> Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org> Cr-Commit-Position: refs/heads/master@{#630358} -- wpt-commits: 7d5d8b89aba590b018d7ac402c233df89b42dcbd wpt-pr: 15281
testing/web-platform/tests/payment-request/payment-request-canmakepayment-method-manual.https.html
testing/web-platform/tests/payment-request/payment-request-canmakepayment-method.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/payment-request-canmakepayment-method-manual.https.html
@@ -0,0 +1,105 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Manual tests for PaymentRequest.canMakePayment() method</title>
+<link rel="help" href="https://w3c.github.io/payment-request/#canmakepayment-method">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+setup({
+  explicit_done: true,
+  explicit_timeout: true,
+});
+
+const basicCard = Object.freeze({ supportedMethods: "basic-card" });
+const applePay = Object.freeze({
+  supportedMethods: "https://apple.com/apple-pay",
+  data: {
+    version: 3,
+    merchantIdentifier: "merchant.com.example",
+    countryCode: "US",
+    merchantCapabilities: ["supports3DS"],
+    supportedNetworks: ["visa"],
+  }
+});
+const defaultMethods = Object.freeze([basicCard, applePay]);
+const defaultDetails = Object.freeze({
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+function testInteractiveState() {
+  promise_test(async t => {
+    const request = new PaymentRequest(defaultMethods, defaultDetails);
+    const acceptPromise = request.show(); // Sets state to "interactive"
+    const canMakePaymentPromise = request.canMakePayment();
+    try {
+      const result = await canMakePaymentPromise;
+      assert_true(
+        false,
+        `canMakePaymentPromise should have thrown InvalidStateError`
+      );
+    } catch (err) {
+      await promise_rejects(t, "InvalidStateError", canMakePaymentPromise);
+    } finally {
+      await request.abort();
+      await promise_rejects(t, "AbortError", acceptPromise);
+    }
+    // The state should be "closed"
+    await promise_rejects(t, "InvalidStateError", request.canMakePayment());
+  }, 'If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException.');
+}
+
+function testClosedState() {
+  promise_test(async t => {
+    const request = new PaymentRequest(defaultMethods, defaultDetails);
+    const acceptPromise = request.show(); // Sets state to "interactive"
+    acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
+    await request.abort(); // The state is now "closed"
+    await promise_rejects(t, "InvalidStateError", request.canMakePayment());
+    try {
+      const result = await request.canMakePayment();
+      assert_true(
+        false,
+        `should have thrown InvalidStateError, but instead returned "${result}"`
+      );
+    } catch (err) {
+      assert_equals(
+        err.name,
+        "InvalidStateError",
+        "must be an InvalidStateError."
+      );
+    }
+  }, 'If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.');
+}
+</script>
+
+<h2>Manual tests for PaymentRequest.canMakePayment() method</h2>
+<p>
+  Click on each button in sequence from top to bottom without refreshing the
+  page. Each button will bring up the Payment Request UI window and then will
+  close it automatically. (If a payment sheet stays open, the test has failed.)
+</p>
+<ol>
+  <li>
+    <button onclick="testInteractiveState()">
+      If request.[[state]] is "interactive", then return a promise rejected with
+      an "InvalidStateError" DOMException.
+    </button>
+  </li>
+  <li>
+    <button onclick="testClosedState()">
+      If request.[[state]] is "closed", then return a promise rejected with an
+      "InvalidStateError" DOMException.
+    </button>
+  </li>
+  <li><button onclick="done()">Done!</button></li>
+</ol>
+<small>
+  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
+  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
+</small>
--- a/testing/web-platform/tests/payment-request/payment-request-canmakepayment-method.https.html
+++ b/testing/web-platform/tests/payment-request/payment-request-canmakepayment-method.https.html
@@ -1,16 +1,16 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <title>Tests for PaymentRequest.canMakePayment() method</title>
-<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
+<link rel="help" href="https://w3c.github.io/payment-request/#canmakepayment-method">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
 <script src='/resources/testdriver-vendor.js'></script>
-<script src="/resources/testdriver.js"></script>
 <script>
 const basicCard = Object.freeze({ supportedMethods: "basic-card" });
 const applePay = Object.freeze({
   supportedMethods: "https://apple.com/apple-pay",
   data: {
     version: 3,
     merchantIdentifier: "merchant.com.example",
     countryCode: "US",
@@ -39,61 +39,16 @@ promise_test(async t => {
   assert_true(
     await request.canMakePayment(),
     "one of the methods should be supported"
   );
 }, `If payment method identifier are supported, resolve promise with true.`);
 
 promise_test(async t => {
   const request = new PaymentRequest(defaultMethods, defaultDetails);
-  const acceptPromise = test_driver.bless("show payment request", () => {
-    request.show(); // Sets state to "interactive"
-  });
-  const canMakePaymentPromise = request.canMakePayment();
-  try {
-    const result = await canMakePaymentPromise;
-    assert_true(
-      false,
-      `canMakePaymentPromise should have thrown InvalidStateError`
-    );
-  } catch (err) {
-    await promise_rejects(t, "InvalidStateError", canMakePaymentPromise);
-  } finally {
-    await request.abort();
-    await promise_rejects(t, "AbortError", acceptPromise);
-  }
-  // The state should be "closed"
-  await promise_rejects(t, "InvalidStateError", request.canMakePayment());
-}, 'If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException.');
-
-promise_test(async t => {
-  const request = new PaymentRequest(defaultMethods, defaultDetails);
-  const acceptPromise = test_driver.bless("show payment request", () => {
-    request.show(); // Sets state to "interactive"
-  });
-  acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
-  await request.abort(); // The state is now "closed"
-  await promise_rejects(t, "InvalidStateError", request.canMakePayment());
-  try {
-    const result = await request.canMakePayment();
-    assert_true(
-      false,
-      `should have thrown InvalidStateError, but instead returned "${result}"`
-    );
-  } catch (err) {
-    assert_equals(
-      err.name,
-      "InvalidStateError",
-      "must be an InvalidStateError."
-    );
-  }
-}, 'If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.');
-
-promise_test(async t => {
-  const request = new PaymentRequest(defaultMethods, defaultDetails);
   try {
     assert_true(
       await request.canMakePayment(),
       `canMakePaymentPromise should be true`
     );
     assert_true(
       await request.canMakePayment(),
       `canMakePaymentPromise should be true`