tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

attributes-and-toJSON-method-manual.https.html (3720B)


      1 <!doctype html>
      2 <meta charset="utf8">
      3 <link rel="help" href="https://www.w3.org/TR/payment-request/#ContactAddress-interface">
      4 <title>
      5  PaymentResponse.prototype.shippingAddress
      6 </title>
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <script src="../payment-response/helpers.js"></script>
     10 <script>
     11 const options = { requestShipping: true };
     12 function runManualTest(button, expected = {}) {
     13  button.disabled = true;
     14  promise_test(async () => {
     15    const { response } = await getPaymentRequestResponse(options);
     16    await response.complete();
     17    assert_idl_attribute(response, "shippingAddress");
     18    const { shippingAddress: addr } = response;
     19    assert_true(
     20      addr instanceof ContactAddress,
     21      "Expect instance of ContactAddress"
     22    );
     23    // An [ISO3166] alpha-2 code. The canonical form is upper case.
     24    const { country } = addr;
     25    assert_equals(country.length, 2, "Expected length is 2");
     26    assert_true(/^[A-Z]{2}$/.test(country), "Canonical form is upper case");
     27    assert_true(
     28      addr.addressLine instanceof Array,
     29      "Expected addressLine to be an array"
     30    );
     31    assert_throws_js(
     32      TypeError,
     33      () => {
     34        addr.addressLine.push("this must throw");
     35      },
     36      "Array must be frozen"
     37    );
     38    for (let [attr, expectedValue] of Object.entries(expected)) {
     39      assert_idl_attribute(addr, attr);
     40      const msg = `Expected ContactAddress.${attr} to equal ${expectedValue}.`;
     41      //.toString() flattens array addressLine,
     42      //.toLowerCase() because case can't be enforced for some attributes
     43      const actualValue = addr[attr].toString().toLowerCase();
     44      expectedValue = expectedValue.toString().toLowerCase();
     45      assert_equals(actualValue, expectedValue, msg);
     46    }
     47    // Check toJSON result
     48    for (let [prop, jsonValue] of Object.entries(addr.toJSON())) {
     49      const actualValue = jsonValue.toString().toLowerCase();
     50      const expectedValue = expected[prop].toString().toLowerCase();
     51      const msg = `Expected JSON ${prop} to be ${expectedValue}`;
     52      assert_equals(actualValue, expectedValue, msg);
     53    }
     54  }, button.textContent.trim());
     55  done();
     56 }
     57 </script>
     58 <h2>ContactAddress interface</h2>
     59 <p>
     60  Click on each button in sequence from top to bottom without refreshing the page.
     61  Each button will bring up the Payment Request UI window.
     62 </p>
     63 <p>
     64  When prompted, please enter addresses as follows...
     65 </p>
     66 <ol>
     67  <li>
     68    <button onclick="
     69    const expectedAddress = {
     70      country: 'AU',
     71      regionCode: 'QLD',
     72      addressLine: '55 test st',
     73      city: 'Chapel Hill',
     74      dependentLocality: '',
     75      postalCode: '6095',
     76      region: 'QLD',
     77      sortingCode: '',
     78      organization: 'w3c',
     79      recipient: 'web platform test',
     80      phone: '+61733780000',
     81    };
     82    runManualTest(this, expectedAddress);">
     83      If the requestShipping member is true, then shippingAddress's ContactAddress must match the expected values.
     84    </button>
     85    Please use:
     86    <dl>
     87      <dt>Recipient:</dt>
     88      <dd>web platform test</dd>
     89      <dt>Address line:</dt>
     90      <dd>55 test st</dd>
     91      <dt>Country</dt>
     92      <dd>Australia</dd>
     93      <dt>City</dt>
     94      <dd>Chapel Hill</dd>
     95      <dd>State/Region</dd>
     96      <dd>Queensland</dd>
     97      <dt>postal code </dt>
     98      <dd>6095</dd>
     99      <dt>organization</dt>
    100      <dd>w3c</dd>
    101      <dt>Phone number</dt>
    102      <dd>+61 7 3378 0000</dd>
    103    </dl>
    104  </li>
    105 </ol>
    106 <small>
    107  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
    108  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
    109 </small>