Use step_timeout() to force spin the EventLoop (#16142)
Use step_timeout() to force spin the EventLoop. Also allow eventPromise to reject before acceptPromise resolves.
diff --git a/payment-request/PaymentRequestUpdateEvent/updateWith-call-immediate-manual.https.html b/payment-request/PaymentRequestUpdateEvent/updateWith-call-immediate-manual.https.html
index 28dfe1e..2432500 100644
--- a/payment-request/PaymentRequestUpdateEvent/updateWith-call-immediate-manual.https.html
+++ b/payment-request/PaymentRequestUpdateEvent/updateWith-call-immediate-manual.https.html
@@ -55,26 +55,29 @@
const eventPromise = new Promise((resolve, reject) => {
request.addEventListener(
"shippingaddresschange",
- async ev => {
- // spin the event loop, sets [[waitForUpdate]] to true.
- await Promise.resolve();
- try {
- ev.updateWith(validDetails);
- resolve(); // This is bad.
- } catch (err) {
- reject(err); // this is good.
- }
+ ev => {
+ // Forces updateWith() to be run in the next event loop tick so that
+ // [[waitForUpdate]] is already true when it runs.
+ t.step_timeout(() => {
+ try {
+ ev.updateWith(validDetails);
+ resolve(); // This is bad.
+ } catch (err) {
+ reject(err); // this is good.
+ }
+ });
},
{ once: true }
);
});
- const response = await request.show();
+ const acceptPromise = request.show();
await promise_rejects(
t,
"InvalidStateError",
eventPromise,
"The event loop already spun, so [[waitForUpdate]] is now true"
);
+ const response = await acceptPromise;
await response.complete();
}, testName.trim());
}