Bug 1527046 [wpt PR 15306] - [Payment Request] Add Web Platform Tests for hasEnrolledInstrument()., a=testonly
authorDanyao Wang <danyao@chromium.org>
Tue, 19 Feb 2019 11:46:44 +0000
changeset 519224 215f68d94d86a724e0620aec714b61d92d2903a5
parent 519223 f1592f48542df6cd9ee7b5f8a9e58d4b7fe42bcd
child 519225 cd859f2c535d48b4fc1208970b6f7025f99d66d0
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
bugs1527046, 15306, 915907, 1461313, 630578
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 1527046 [wpt PR 15306] - [Payment Request] Add Web Platform Tests for hasEnrolledInstrument()., a=testonly Automatic update from web-platform-tests [Payment Request] Add Web Platform Tests for hasEnrolledInstrument(). The failing expectations are required because hasEnrolledInstrument() is not yet turned on by default in Blink. These tests pass when running Chrome with --enable-features=PaymentRequestHasEnrolledInstrument. Bug: 915907 Change-Id: I2189bfedad813e7942c7ddbd44aac78d1b895a30 Reviewed-on: https://chromium-review.googlesource.com/c/1461313 Commit-Queue: Danyao Wang <danyao@chromium.org> Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org> Cr-Commit-Position: refs/heads/master@{#630578} -- wpt-commits: a7498ddcfeeca02e7b62ab9e9b359fcaa5764c62 wpt-pr: 15306
testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html
testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-protection.https.html
testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Manual 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>
+setup({
+  explicit_done: true,
+  explicit_timeout: true,
+});
+
+const defaultMethods = Object.freeze([
+  {
+    supportedMethods: "basic-card",
+    data: {
+      supportedNetworks: [ 'visa' ],
+    },
+  }
+]);
+const defaultDetails = Object.freeze({
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+function testHasNoEnrolledInstrument() {
+  promise_test(async t => {
+    const request = new PaymentRequest(defaultMethods, defaultDetails);
+    assert_false(
+      await request.hasEnrolledInstrument(),
+      "No test enrolled in the test profile."
+    );
+  }, `hasEnrolledInstrument() resolves to false when user has no enrolled instrument.`);
+}
+
+function testHasEnrolledInstrument() {
+  promise_test(async t => {
+    const request = new PaymentRequest(defaultMethods, defaultDetails);
+    assert_true(
+      await request.hasEnrolledInstrument(),
+      "A card is enrolled in the test profile."
+    );
+  }, `hasEnrolledInstrument() resolves to true when user has an enrolled instrument.`);
+}
+
+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.
+</p>
+<ol>
+  <li>Follow browser-specific instructions to remove all cards from the test profile.</li>
+  <li>
+    <button onclick="testHasNoEnrolledInstrument()">
+      hasEnrolledInstrument() resolves to false when user has no enrolled instrument.
+    </button>
+  </li>
+  <li>Add a test Visa card to your test profile, e.g. 4012888888881881.</li>
+  <li>
+    <button onclick="testHasEnrolledInstrument()">
+      hasEnrolledInstrument() resolves to true when user has an enrolled instrument.
+    </button>
+  </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>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method-protection.https.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<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>
+const visaMethod = Object.freeze({
+    supportedMethods: "basic-card",
+    data: {
+      supportedNetworks: ['visa']
+    }
+});
+const mastercardMethod = Object.freeze({
+    supportedMethods: "basic-card",
+    data: {
+      supportedNetworks: ['mastercard']
+    }
+});
+const defaultDetails = Object.freeze({
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+promise_test(async t => {
+  // This test may never actually hit its assertion, but that's allowed.
+  const request = new PaymentRequest([visaMethod], defaultDetails);
+  for (let i = 0; i < 1000; i++) {
+    try {
+      await request.hasEnrolledInstrument();
+    } catch (err) {
+      assert_equals(
+        err.name,
+        "NotAllowedError",
+        "If it throws, then it must be a NotAllowedError."
+      );
+      break;
+    }
+  }
+
+  for (let i = 0; i < 1000; i++) {
+    try {
+      const request2 = new PaymentRequest([mastercardMethod], defaultDetails);
+      await request2.hasEnrolledInstrument();
+    } catch (err) {
+      assert_equals(
+        err.name,
+        "NotAllowedError",
+        "If it throws, then it must be a NotAllowedError."
+      );
+      break;
+    }
+  }
+}, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" 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>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/payment-request-hasenrolledinstrument-method.https.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<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>
+const unsupportedMethods = [
+  { supportedMethods: "this-is-not-supported" },
+  { supportedMethods: "https://not.supported" },
+];
+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() resolves to false for unsupported payment methods.`);
+</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>