Skip to content

Commit 66064ce

Browse files
authored
Test addEventListener works with EventListener & EventHandler (#4393)
`addEventListener` can take both an `EventHandler` (a callback) and an `EventListener` (an object with a `handleEvent` method)
1 parent 00bbf54 commit 66064ce

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/webgpu/idl/javascript.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,53 @@ Test some repercussions of the fact that GPUDevice extends EventTarget
676676
.fn(async t => {
677677
await kDispatchTests[t.params.test](t);
678678
});
679+
680+
const kAddEventListenerTests = {
681+
EventHandler: async (t: GPUTest) => {
682+
const result = await raceWithRejectOnTimeout(
683+
new Promise(resolve => {
684+
t.device.addEventListener('foo', resolve, { once: true });
685+
t.device.dispatchEvent(new Event('foo'));
686+
}),
687+
500,
688+
'timeout'
689+
);
690+
const event = result as Event;
691+
t.expect(() => event instanceof Event, 'event');
692+
t.expect(() => event.type === 'foo');
693+
},
694+
EventListener: async (t: GPUTest) => {
695+
const result = await raceWithRejectOnTimeout(
696+
new Promise(resolve => {
697+
t.device.addEventListener(
698+
'foo',
699+
{
700+
handleEvent: resolve,
701+
},
702+
{ once: true }
703+
);
704+
t.device.dispatchEvent(new Event('foo'));
705+
}),
706+
500,
707+
'timeout'
708+
);
709+
const event = result as Event;
710+
t.expect(() => event instanceof Event, 'event');
711+
t.expect(() => event.type === 'foo');
712+
},
713+
} as const;
714+
715+
g.test('device,addEventListener')
716+
.desc(
717+
`
718+
Test that addEventListener works with both an EventListener and an EventHandler
719+
720+
* https://dom.spec.whatwg.org/#interface-eventtarget
721+
* https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler
722+
723+
`
724+
)
725+
.params(u => u.combine('test', keysOf(kAddEventListenerTests)))
726+
.fn(async t => {
727+
await kAddEventListenerTests[t.params.test](t);
728+
});

0 commit comments

Comments
 (0)