DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
<!DOCTYPE html> <meta charset="utf-8" />
<title>Warn when errorFields don't match request[[options]]</title>
<link rel="help" href="https://github.com/w3c/payment-request/pull/807" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="helpers.js"></script>
<script>
  test(() => {
    assert_true(
      "retry" in PaymentResponse.prototype,
      "retry must be in prototype"
    );
    assert_true(
      PaymentResponse.prototype.retry instanceof Function,
      "retry must be a function"
    );
  }, "PaymentResponse.prototype must have a retry() function (smoke test).");

  const defaultOptions = {
    requestPayerName: false,
    requestPayerEmail: false,
    requestPayerPhone: false,
    requestShipping: false,
  };
  function testShowWarning(button, errorFields) {
    button.disabled = true;
    promise_test(async () => {
      const { response } = await getPaymentRequestResponse(defaultOptions);
      await response.retry(errorFields);
      await response.complete();
    });
  }
</script>
<h2>Manual Tests - Please run in order!</h2>
<p>
  Please open the developer console. Each of the tests below should generate a
  warning in the developer console.
</p>
<p>When presented with the payment sheet, hit pay twice.</p>
<ol>
  <li>
    <button onclick="testShowWarning(this, {payer: {name: 'Dont show this'}});">
      Show warning if `requestPayerName` if false, and `errorFields.payer.name` is
      present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {payer: {email: 'Dont show this'}});"
    >
      Show warning if `requestPayerEmail` if false, and `errorFields.payer.email`
      is present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {payer: {phone: 'Dont show this'}});"
    >
      Show warning if `requestPayerPhone` if false, and `errorFields.payer.phone`
      is present.
    </button>
  </li>
  <li>
    <button onclick="testShowWarning(this, {shippingAddress: {}});">
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {addressLine: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.addressLine` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {city: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.city` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {country: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.country` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {dependentLocality: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.dependentLocality` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {organization: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.organization` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {phone: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.phone` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {postalCode: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.postalCode` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {recipient: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.recipient` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {region: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.region` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {regionCode: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.regionCode` member present.
    </button>
  </li>
  <li>
    <button
      onclick="testShowWarning(this, {shippingAddress: {sortingCode: 'Dont show this'}});"
    >
      Show warning if `requestShipping` if false, and
      `errorFields.shippingAddress.sortingCode` member present.
    </button>
  </li>
  <li><button onclick="done()">Done!</button></li>
</ol>