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
<!doctype html>
<meta charset=utf-8>
<title>PaymentResponse.prototype.onpayerdetailchange attribute</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="helpers.js"></script>
<script>
function runTest(button, options, expected){
  button.disabled = true;
  promise_test(async () => {
    const response = await getPaymentResponse(options);
    const eventPromise = new Promise(resolve => {
      response.addEventListener("payerdetailchange", resolve);
    });
    const error = button.previousElementSibling.textContent.trim();
    await response.retry({ error });
    const event = await eventPromise;
    assert_true(event instanceof PaymentRequestUpdateEvent);
    for([prop, value] of Object.entries(expected)){
      if (prop === 'payerPhone') {
        // |payerPhone| may optionally adhere to E164 structure, which does not
        // contain formatting, e.g. +180000000 instead of +1-800-000-0000.
        // Strip out the formatting in case the user agent implements E164.
        // https://w3c.github.io/payment-request/#addressinit-dictionary
        value = value.replace(/[-\(\) ]/g, '');
      }
      assert_equals(response[prop], value);
    }
    await response.complete("success");
  }, button.textContent.trim());
}
</script>
<h2>Handling PaymentResponse.prototype.onpayerdetailchange events</h2>
<p>
  Each button will bring up the Payment Request UI window.
  When shown the payment sheet, use any details and hit pay.
</p>
<p>
  When asked to retry the payment:
</p>
<ol>
  <li>
    <p>
      Change payer's name to "pass".
    </p>
    <button onclick="runTest(this, { requestPayerName: true }, { payerName: 'pass' });">
      PaymentRequestUpdateEvent is dispatched when payer name changes.
    </button>
  </li>
  <li>
    <p>
      Change payer's email to "pass@pass.pass".
    </p>
    <button onclick="runTest(this, {requestPayerEmail: true}, { payerEmail: 'pass@pass.pass' });">
      PaymentRequestUpdateEvent is dispatched when payer email changes.
    </button>
  </li>
  <li>
    <p>
      Change payer's phone to "+1-800-000-0000".
    </p>
    <button onclick="runTest(this, {requestPayerPhone: true}, { payerPhone: '+18000000000' })">
      PaymentRequestUpdateEvent is dispatched when payer phone changes.
    </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">owners</a>.
</small>