shipping-address-changed-manual.https.html (3447B)
1 <!DOCTYPE html> 2 <!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> 3 <meta charset="utf-8"> 4 <title>Test for PaymentRequest shippingAddress attribute</title> 5 <link rel="help" href="https://w3c.github.io/payment-request/#shippingaddress-attribute"> 6 <link rel="help" href="https://w3c.github.io/payment-request/#onshippingaddresschange-attribute"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script> 10 setup({ explicit_done: true, explicit_timeout: true }); 11 const applePay = Object.freeze({ 12 supportedMethods: "https://apple.com/apple-pay", 13 data: { 14 version: 3, 15 merchantIdentifier: "merchant.com.example", 16 countryCode: "US", 17 merchantCapabilities: ["supports3DS"], 18 supportedNetworks: ["visa"], 19 } 20 }); 21 const validMethod = Object.freeze({ supportedMethods: "basic-card" }); 22 const validMethods = Object.freeze([validMethod, applePay]); 23 const validAmount = Object.freeze({ currency: "USD", value: "5.00" }); 24 const validTotal = Object.freeze({ 25 label: "label", 26 amount: validAmount, 27 }); 28 const validShippingOption = Object.freeze({ 29 id: "valid", 30 label: "Shipping Option", 31 amount: validAmount, 32 selected: false, 33 }); 34 const validDetails = Object.freeze({ 35 total: validTotal, 36 shippingOptions: [validShippingOption], 37 }); 38 const requestShipping = Object.freeze({ 39 requestShipping: true, 40 }); 41 42 function testShippingAddressChange() { 43 promise_test(async t => { 44 const request = new PaymentRequest( 45 validMethods, 46 validDetails, 47 requestShipping 48 ); 49 assert_equals( 50 request.shippingAddress, 51 null, 52 "request.shippingAddress must initially be null" 53 ); 54 const listenerPromise = new Promise(resolve => { 55 request.addEventListener("shippingaddresschange", () => { 56 resolve(request.shippingAddress); 57 }); 58 }); 59 const handlerPromise = new Promise(resolve => { 60 request.onshippingaddresschange = () => { 61 resolve(request.shippingAddress); 62 }; 63 }); 64 request.show().catch(err => err); 65 const results = await Promise.all([listenerPromise, handlerPromise]); 66 results.forEach(obj => { 67 assert_true(obj instanceof ContactAddress, 68 "Expected instance of ContactAddress"); 69 assert_equals(obj.organization, "", "organization should be redacted"); 70 assert_equals(obj.phone, "", "phone should be redacted"); 71 assert_equals(obj.recipient, "", "recipient should be redacted"); 72 assert_equals(obj.addressLine.length, 0, "addressLine should be redacted"); 73 }); 74 await request.abort(); 75 }); 76 done(); 77 } 78 79 </script> 80 81 <h2>PaymentRequest shippingAddress attribute</h2> 82 <p> 83 Click on each button in sequence from top to bottom without refreshing the page. 84 Each button will bring up the Payment Request UI window. 85 </p> 86 <p> 87 When the payment sheet is presented, enter or select a shipping address. 88 </p> 89 <ol> 90 <li> 91 <button onclick="testShippingAddressChange()"> 92 When the shipping address is manually changed, request.shippingAddress is a ContactAddress. 93 </button> 94 </li> 95 </ol> 96 <small> 97 If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a> 98 and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>. 99 </small>