author Marcos Cáceres <marcos@marcosc.com>
Tue, 05 Mar 2019 12:14:35 +0000
changeset 522163 be42c83c6e9797698bac9eb972158fde092dbc18
parent 502151 10967382f5a4ad9982a0122c5a6593e87766f967
child 522313 66b1aba3fb4372ec47986e728b1da9b32dd3d368
permissions -rw-r--r--
Bug 1509034 [wpt PR 14163] - fix: make PMIs conform to spec, a=testonly Automatic update from web-platform-tests fix: make PMIs conform to spec (#14163) -- wpt-commits: 94dd52b3f5a6e768d25a3cc459aeeb1e69fb9381 wpt-pr: 14163

<!doctype html>
<meta charset="utf8">
<title>Payment Method Basic Card - test passing empty BasicCardRequest members</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
setup({ explicit_done: true, explicit_timeout: true });

const amount = { value: "1.0", currency: "USD" };
const details = {
  total: {
    label: "Total",
const method = {
  supportedMethods: "basic-card",

const defaultBillingAddress = {
  country: 'AF',
  addressLine: '1 wpt street',
  region: '',
  city: 'Kabul',
  dependentLocality: '',
  postalCode: '1001',
  sortingCode: '',
  organization: 'w3c',
  recipient: 'web platform test',
  phone: '+93555555555',

const visaCredit = {
  cardNumber: "4111111111111111",
  cardSecurityCode: "123",
  cardholderName: "web platform test",
  expiryMonth: "01",
  expiryYear: "2026",

async function getCardResponse(data) {
  const payMethod = Object.assign({ data }, method);
  const response = await new PaymentRequest([payMethod], details).show();
  await response.complete("success");
  return response.details;

 * All tests expect the same return data, so we can just check the
 * same result over and over again.
function runPromiseTest(button, data, expectedCard = visaCredit, expectedAddress = defaultBillingAddress ) {
  button.disabled = true;
  promise_test(async () => {
    const card = await getCardResponse(data);
    for (const [member, expectedValue] of Object.entries(expectedCard)) {
      const msg = `Expected "card.${member}" to equal "${expectedValue}".`;
      assert_equals(card[member], expectedValue, msg);
    const { billingAddress } = card;
    for (const [member, expectedValue] of Object.entries(expectedAddress)) {
      const msg = `billingAddress.${member} to equal ${expectedValue}.`;
      assert_equals(billingAddress[member], expectedValue);
  }, button.textContent.trim());
  Payment Method Basic Card - test passing empty BasicCardRequest values
  This test checks that the Basic Card payment handler can accept any card.
  Click on each button in sequence from top to bottom without refreshing the page.
  Each button will bring up the Payment Request UI window.
  The test expects the following credit card.
  <li>Add card:
      <dt>Cardholder name:</dt>
      <dd>web platform test</dd>
      <dt>Card number:</dt>
      <dt>Security code (CVV):</dt>
      <dt>Expiry month:</dt>
      <dt>Expiry year:</dt>
  <li>Add billing address:
      <dd>web platform test</dd>
      <dd>1 web st</dd>
      <dt>Post code:</dt>
    <button onclick="runPromiseTest(this, {});">
      When passed BasicCardRequest without members, allow the user to input a card on any network.
    <button onclick="runPromiseTest(this, { supportedNetworks: [] });">
      Returns a card on any network, because zero length supportedNetworks.
    <button onclick="done();">

  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>.