Bug 1528711 [wpt PR 15386] - [PaymentRequest][WPT] Automate manual tests that need user click., a=testonly
authorDanyao Wang <danyao@chromium.org>
Tue, 05 Mar 2019 12:14:50 +0000
changeset 522445 51e1957476b218de66b0d3587106a8fb7589e244
parent 522444 43322b4cde08eb96eb0ce8837af809d5c69ee508
child 522446 2f840f6a520912ad49da1fc461244b4edf3dfadd
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1528711, 15386, 929773, 1471297, 632259
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 1528711 [wpt PR 15386] - [PaymentRequest][WPT] Automate manual tests that need user click., a=testonly Automatic update from web-platform-tests [PaymentRequest][WPT] Automate manual tests that need user click. Before this patch, test cases that need a user click were implemented as manual tests. This patch automates them using testdriver.bless() API, which simulates a user click action using WebDriver. Bug: 929773 Change-Id: I368e5867c2a889504a360d7d704aa83d3cf9c78e Reviewed-on: https://chromium-review.googlesource.com/c/1471297 Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org> Commit-Queue: Danyao Wang <danyao@chromium.org> Cr-Commit-Position: refs/heads/master@{#632259} -- wpt-commits: 85614961e6ee65fe339a7a8e770499c80cccae28 wpt-pr: 15386
testing/web-platform/tests/payment-request/payment-request-abort-method-manual.https.html
testing/web-platform/tests/payment-request/payment-request-abort-method.https.html
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
testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html
testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method.https.html
deleted file mode 100644
--- a/testing/web-platform/tests/payment-request/payment-request-abort-method-manual.https.html
+++ /dev/null
@@ -1,95 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>Manual tests for PaymentRequest.abort() method</title>
-<link rel="help" href="https://w3c.github.io/payment-request/#abort-method">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
-"use strict";
-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 testShowSameRequestMultipleTimes() {
-  promise_test(async t => {
-    const request = new PaymentRequest(defaultMethods, defaultDetails);
-    const acceptPromise = request.show()
-    try {
-      await request.abort();
-    } catch (err) {
-      assert_unreached("Unexpected promise rejection: " + err.message);
-    }
-    await promise_rejects(t, "AbortError", acceptPromise);
-    // As request is now "closed", trying to show it will fail
-    await promise_rejects(t, "InvalidStateError", request.show());
-  }, "The same request cannot be shown multiple times.");
-}
-
-function testAbortBeforeShow() {
-  promise_test(async t => {
-    // request is in "created" state.
-    const request = new PaymentRequest(defaultMethods, defaultDetails);
-    await promise_rejects(t, "InvalidStateError", request.abort());
-    // Call it again, for good measure.
-    await promise_rejects(t, "InvalidStateError", request.abort());
-    // The request's state is "created", so let's show it
-    // which changes the state to "interactive.".
-    const acceptPromise = request.show()
-    // Let's set request the state to "closed" by calling .abort()
-    try {
-      await request.abort();
-    } catch (err) {
-      assert_unreached("Unexpected promise rejection: " + err.message);
-    }
-    // The request is now "closed", so...
-    await promise_rejects(t, "InvalidStateError", request.abort());
-    await promise_rejects(t, "AbortError", acceptPromise);
-  }, "Aborting a request before it is shown doesn't prevent it from being shown later.");
-}
-</script>
-<h2>Manual tests for PaymentRequest.abort() 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="testShowSameRequestMultipleTimes()">
-      The same request cannot be shown multiple times.
-    </button>
-  </li>
-  <li>
-    <button onclick="testAbortBeforeShow()">
-      Aborting a request before it is shown doesn't prevent it from being shown
-      later.
-    </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-abort-method.https.html
+++ b/testing/web-platform/tests/payment-request/payment-request-abort-method.https.html
@@ -42,13 +42,53 @@ promise_test(async t => {
   await promise_rejects(t, "InvalidStateError", request.abort());
 }, `Throws if the promise [[state]] is not "interactive"`);
 
 promise_test(async t => {
   const request = new PaymentRequest(defaultMethods, defaultDetails);
   const promises = new Set([request.abort(), request.abort(), request.abort()]);
   assert_equals(promises.size, 3, "Must have three unique objects");
 }, "Calling abort() multiple times is always a new object.");
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const [abortPromise, acceptPromise] = await test_driver.bless(
+    "show payment request",
+    () => {
+      const acceptPromise = request.show()
+      acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
+      const abortPromise = request.abort();
+      return [abortPromise, acceptPromise];
+    });
+
+  await abortPromise;
+  await promise_rejects(t, "AbortError", acceptPromise);
+  // As request is now "closed", trying to show it will fail
+  await promise_rejects(t, "InvalidStateError", request.show());
+}, "The same request cannot be shown multiple times.");
+
+promise_test(async t => {
+  // request is in "created" state.
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  await promise_rejects(t, "InvalidStateError", request.abort());
+  // Call it again, for good measure.
+  await promise_rejects(t, "InvalidStateError", request.abort());
+  // The request's state is "created", so let's show it
+  // which changes the state to "interactive.".
+  const [abortPromise, acceptPromise] = await test_driver.bless(
+    "show payment request",
+    () => {
+      const acceptPromise = request.show()
+      // Let's set request the state to "closed" by calling .abort()
+      const abortPromise = request.abort();
+      return [abortPromise, acceptPromise];
+    });
+
+  await abortPromise;
+  // The request is now "closed", so...
+  await promise_rejects(t, "InvalidStateError", request.abort());
+  await promise_rejects(t, "AbortError", acceptPromise);
+}, "Aborting a request before it is shown doesn't prevent it from being shown later.");
 </script>
 <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>
deleted file mode 100644
--- a/testing/web-platform/tests/payment-request/payment-request-canmakepayment-method-manual.https.html
+++ /dev/null
@@ -1,105 +0,0 @@
-<!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
@@ -2,16 +2,17 @@
 <meta charset="utf-8">
 <title>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 src="/resources/testdriver.js"></script>
 <script src='/resources/testdriver-vendor.js'></script>
 <script>
+"use strict";
 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"],
@@ -72,14 +73,48 @@ promise_test(async t => {
 
 promise_test(async t => {
   const someSupported = new PaymentRequest(
     [...unsupportedMethods, ...defaultMethods],
     defaultDetails
   ).canMakePayment();
   assert_true(await someSupported, `At least one method is expected to be supported.`);
 }, `Mix of supported and unsupported methods, at least one method is supported.`);
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const [acceptPromise, canMakePaymentPromise] = await test_driver.bless(
+    "show payment request",
+    () => {
+      const acceptPromise = request.show(); // Sets state to "interactive"
+      const canMakePaymentPromise = request.canMakePayment();
+      return [acceptPromise, canMakePaymentPromise];
+    });
+
+  await promise_rejects(t, "InvalidStateError", canMakePaymentPromise);
+  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 [abortPromise, acceptPromise] = await test_driver.bless(
+    "show payment request",
+    () => {
+      const acceptPromise = request.show(); // Sets state to "interactive"
+      acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
+      const abortPromise = request.abort();  // Sets state to "closed"
+      return [abortPromise, acceptPromise];
+    });
+
+  await abortPromise;
+  await promise_rejects(t, "AbortError", acceptPromise);
+  await promise_rejects(t, "InvalidStateError", request.canMakePayment());
+}, 'If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.');
 </script>
 
 <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-hasenrolledinstrument-method-manual.https.html
+++ b/testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html
@@ -52,55 +52,16 @@ function testHasEnrolledInstrumentAgain(
   promise_test(async t => {
     const request = new PaymentRequest(defaultMethods, defaultDetails);
     assert_true(
       await request.hasEnrolledInstrument(),
       "A card is enrolled in the test profile."
     );
   }, `hasEnrolledInstrument() can be called multiple times if the payment method details are identical.`);
 }
-
-function testInteractiveState() {
-  promise_test(async t => {
-    const request = new PaymentRequest(defaultMethods, defaultDetails);
-    const acceptPromise = request.show();  // Sets state to "interactive"
-    const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
-    try {
-      const result = await hasEnrolledInstrumentPromise;
-      assert_true(
-        false,
-        "hasEnrolledInstrument() should have thrown InvalidStateError"
-      );
-    } catch(err) {
-      await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
-    } finally {
-      request.abort();
-      await promise_rejects(t, "AbortError", acceptPromise);
-    }
-  }, `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 handle unhandled rejection in devtools.
-    await request.abort();  // Sets state to "closed"
-    const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
-    try {
-      const result = await hasEnrolledInstrumentPromise;
-      assert_true(
-        false,
-        "hasEnrolledInstrument() should have thrown InvalidStateError"
-      );
-    } catch(err) {
-      await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
-    }
-  }, `If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.`);
-}
 </script>
 
 <h2>Manual tests for hasEnrolledInstrument() method</h2>
 <p>
   Follow the instructions from top to bottom. Click on each button in sequence
   without refreshing the page. Some of the tests will bring up the Payment
   Request UI and close them automatically. If a payment sheet stays open, the
   test has failed.
@@ -120,27 +81,15 @@ function testClosedState() {
   </li>
   <li>
     <button onclick="testHasEnrolledInstrumentAgain()">
       hasEnrolledInstrument() can be called multiple times if the payment method
       details are identical.
     </button>
   </li>
   <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-hasenrolledinstrument-method.https.html
+++ b/testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method.https.html
@@ -2,35 +2,74 @@
 <meta charset="utf-8">
 <title>Tests for PaymentRequest.hasEnrolledInstrument() method</title>
 <link rel="help" href="https://w3c.github.io/payment-request/#hasenrolledinstrument-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>
+"use strict";
 const unsupportedMethods = [
   { supportedMethods: "this-is-not-supported" },
   { supportedMethods: "https://not.supported" },
 ];
+const defaultMethods = Object.freeze([
+  {
+    supportedMethods: "basic-card",
+    data: {
+      supportedNetworks: [ 'visa' ],
+    },
+  }
+]);
 const defaultDetails = Object.freeze({
   total: {
     label: "Total",
     amount: {
       currency: "USD",
       value: "1.00",
     },
   },
 });
 
 promise_test(async t => {
   const request = new PaymentRequest(unsupportedMethods, defaultDetails);
   assert_false(
     await request.hasEnrolledInstrument(),
-    "Payment method is supported."
+    "hasEnrolledInstrument() should resolve to false."
   );
 }, `hasEnrolledInstrument() resolves to false for unsupported payment methods.`);
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const [acceptPromise, hasEnrolledInstrumentPromise] = await test_driver.bless(
+      "show payment request",
+      () => {
+        const acceptPromise = request.show();  // Sets state to "interactive"
+        const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
+        return [acceptPromise, hasEnrolledInstrumentPromise];
+      });
+  await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
+
+  await request.abort();
+  await promise_rejects(t, "AbortError", acceptPromise);
+}, `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 [abortPromise, acceptPromise] = await test_driver.bless( "show payment request", () => {
+    const acceptPromise = request.show();  // Sets state to "interactive"
+    acceptPromise.catch(() => {});  // no-op, just to handle unhandled rejection in devtools.
+    const abortPromise =request.abort();  // Sets state to "closed"
+    return [abortPromise, acceptPromise];
+  });
+  await abortPromise;
+  await promise_rejects(t, "AbortError", acceptPromise);
+
+  const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
+  await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
+}, `If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.`);
 </script>
 
 <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>