summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/PaymentAddress/attributes-and-toJSON-method-manual.https.html
blob: fc1ce3523e57a0a023041f21e18d4de37b390823 (plain)
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
<!doctype html>
<meta charset="utf8">
<link rel="help" href="https://www.w3.org/TR/payment-request/#ContactAddress-interface">
<title>
  PaymentResponse.prototype.shippingAddress
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../payment-response/helpers.js"></script>
<script>
const options = { requestShipping: true };
function runManualTest(button, expected = {}) {
  button.disabled = true;
  promise_test(async () => {
    const { response } = await getPaymentRequestResponse(options);
    await response.complete();
    assert_idl_attribute(response, "shippingAddress");
    const { shippingAddress: addr } = response;
    assert_true(
      addr instanceof ContactAddress,
      "Expect instance of ContactAddress"
    );
    // An [ISO3166] alpha-2 code. The canonical form is upper case.
    const { country } = addr;
    assert_equals(country.length, 2, "Expected length is 2");
    assert_true(/^[A-Z]{2}$/.test(country), "Canonical form is upper case");
    assert_true(
      addr.addressLine instanceof Array,
      "Expected addressLine to be an array"
    );
    assert_throws_js(
      TypeError,
      () => {
        addr.addressLine.push("this must throw");
      },
      "Array must be frozen"
    );
    for (let [attr, expectedValue] of Object.entries(expected)) {
      assert_idl_attribute(addr, attr);
      const msg = `Expected ContactAddress.${attr} to equal ${expectedValue}.`;
      //.toString() flattens array addressLine,
      //.toLowerCase() because case can't be enforced for some attributes
      const actualValue = addr[attr].toString().toLowerCase();
      expectedValue = expectedValue.toString().toLowerCase();
      assert_equals(actualValue, expectedValue, msg);
    }
    // Check toJSON result
    for (let [prop, jsonValue] of Object.entries(addr.toJSON())) {
      const actualValue = jsonValue.toString().toLowerCase();
      const expectedValue = expected[prop].toString().toLowerCase();
      const msg = `Expected JSON ${prop} to be ${expectedValue}`;
      assert_equals(actualValue, expectedValue, msg);
    }
  }, button.textContent.trim());
  done();
}
</script>
<h2>ContactAddress interface</h2>
<p>
  Click on each button in sequence from top to bottom without refreshing the page.
  Each button will bring up the Payment Request UI window.
</p>
<p>
  When prompted, please enter addresses as follows...
</p>
<ol>
  <li>
    <button onclick="
    const expectedAddress = {
      country: 'AU',
      regionCode: 'QLD',
      addressLine: '55 test st',
      city: 'Chapel Hill',
      dependentLocality: '',
      postalCode: '6095',
      region: 'QLD',
      sortingCode: '',
      organization: 'w3c',
      recipient: 'web platform test',
      phone: '+61733780000',
    };
    runManualTest(this, expectedAddress);">
      If the requestShipping member is true, then shippingAddress's ContactAddress must match the expected values.
    </button>
    Please use:
    <dl>
      <dt>Recipient:</dt>
      <dd>web platform test</dd>
      <dt>Address line:</dt>
      <dd>55 test st</dd>
      <dt>Country</dt>
      <dd>Australia</dd>
      <dt>City</dt>
      <dd>Chapel Hill</dd>
      <dd>State/Region</dd>
      <dd>Queensland</dd>
      <dt>postal code </dt>
      <dd>6095</dd>
      <dt>organization</dt>
      <dd>w3c</dd>
      <dt>Phone number</dt>
      <dd>+61 7 3378 0000</dd>
    </dl>
  </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>