payerdetailschange-updateWith-immediate-manual.https.html (2108B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Dispatching PaymentRequestUpdateEvent for "payerdetailschange"</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <script src="helpers.js"></script> 7 <script> 8 function testImmediateUpdate({ textContent: testName }) { 9 promise_test(async t => { 10 const response = await getPaymentResponse({ requestPayerName: true }); 11 const eventPromise = new Promise((resolve, reject) => { 12 response.addEventListener( 13 "payerdetailchange", 14 ev => { 15 // Forces updateWith() to be run in the next event loop tick so that 16 // [[waitForUpdate]] is already true when it runs. 17 t.step_timeout(() => { 18 try { 19 ev.updateWith({}); 20 resolve(); // This is bad. 21 } catch (err) { 22 reject(err); // this is good. 23 } 24 }); 25 }, 26 { once: true } 27 ); 28 }); 29 30 const retryPromise = response.retry({ 31 payer: { name: "Change me!" }, 32 }); 33 await promise_rejects_dom( 34 t, 35 "InvalidStateError", 36 eventPromise, 37 "The event loop already spun, so [[waitForUpdate]] is now true" 38 ); 39 await retryPromise; 40 await response.complete("success"); 41 }, testName.trim()); 42 } 43 </script> 44 <h2>Handling PaymentResponse.prototype.onpayerdetailchange events</h2> 45 <p> 46 The test brings up the Payment Request UI window. 47 When shown the payment sheet, use any details and hit pay. 48 </p> 49 <p> 50 When asked to retry the payment: 51 </p> 52 <ol> 53 <li> 54 <p> 55 Change payer's name to anything. 56 </p> 57 <button onclick="testImmediateUpdate(this);"> 58 updateWith() must be called immediately, otherwise must throw an InvalidStateError. 59 </button> 60 </li> 61 <li> 62 <button onclick="done();">DONE!</button> 63 </li> 64 </ol> 65 <small> 66 If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a> 67 and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">owners</a>. 68 </small>