shippingAddress-attribute-manual.https.html (3527B)
1 <!doctype html> 2 <meta charset="utf8"> 3 <link rel="help" href="https://w3c.github.io/payment-request/#dom-paymentresponse-shippingaddress"> 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="helpers.js"></script> 10 <script> 11 async function checkNullShippingAddress(button, options) { 12 button.disabled = true; 13 const { request, response } = await getPaymentRequestResponse(options); 14 await response.complete(); 15 test(() => { 16 assert_idl_attribute(response, "shippingAddress"); 17 assert_equals( 18 response.shippingAddress, 19 null, 20 "Expected response.shippingAddress to be null" 21 ); 22 assert_equals( 23 request.shippingAddress, 24 null, 25 "Expected request.shippingAddress to be null" 26 ); 27 }, button.textContent.trim()); 28 } 29 30 async function runManualTest(button, options = {}, expected = {}, id) { 31 button.disabled = true; 32 const { request, response } = await getPaymentRequestResponse(options, id); 33 await response.complete(); 34 test(() => { 35 assert_equals(response.requestId, request.id, `Expected ids to match`); 36 assert_idl_attribute(response, "shippingAddress"); 37 const { shippingAddress: addr } = request; 38 assert_true( 39 addr instanceof ContactAddress, 40 "Expect instance of ContactAddress" 41 ); 42 try { 43 addr.toJSON(); 44 } catch (err) { 45 assert_unreached( 46 `Unexpected exception calling ContactAddress.toJSON(): ${err}` 47 ); 48 } 49 if (expected.shippingAddress === null) { 50 return; 51 } 52 assert_equals(addr.country, "AF", "Expected AF for country"); 53 assert_true( 54 addr.addressLine instanceof Array, 55 "Expected addressLine to be an array" 56 ); 57 assert_equals( 58 addr.addressLine.toString(), 59 "1 wpt street", 60 "Expected '1 wpt street' for addressLine" 61 ); 62 assert_equals(addr.city, "Kabul", "Expected city to be Kabul"); 63 assert_equals(addr.postalCode, "1001", "Expect postalCode to be 1001"); 64 assert_equals(addr.recipient, "web platform test"); 65 }, button.textContent.trim()); 66 } 67 </script> 68 <h2>shippingAddress attribute</h2> 69 <p> 70 Click on each button in sequence from top to bottom without refreshing the page. 71 Each button will bring up the Payment Request UI window. 72 </p> 73 <p> 74 When prompted, please enter "web platform test" as recipient, at address "1 wpt street" in "Kabul, Afghanistan", zip/postal code 1001. 75 </p> 76 <ol> 77 <li> 78 <button onclick="checkNullShippingAddress(this, undefined)"> 79 If options is undefined, then shippingAddress must be null. 80 </button> 81 </li> 82 <li> 83 <button onclick="checkNullShippingAddress(this, {})"> 84 If the requestShipping member is missing, then shippingAddress must be null. 85 </button> 86 </li> 87 <li> 88 <button onclick="checkNullShippingAddress(this, {requestShipping: false})"> 89 If the requestShipping member is false, then shippingAddress must be null. 90 </button> 91 </li> 92 <li> 93 <button onclick="runManualTest(this, {requestShipping: true}).then(done)"> 94 If the requestShipping member is true, then shippingAddress must be "1 wpt street" in "Kabul, Afghanistan", zip code 1001. 95 </button> 96 </li> 97 </ol> 98 <small> 99 If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a> 100 and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>. 101 </small>