Skip to content

Commit

Permalink
Check MIDIMessageEvent, don't check undefined objects in WebMIDI WPT
Browse files Browse the repository at this point in the history
The WebMIDI API does not have constructors for MIDIAccess,
MIDIInputMap, or MIDIOutputMap.  If the call to
navigator.requestMIDIAccess() fails all three of these will be
undefined references.

This results in additional failures logged for user agents which have
security policies that prevent navigator.requestMIDIAccess() from
working in the WPT test run environment.  However, we don't actually
know if those tests would pass or not if the MIDIAccess object could
be constructed.  The tests that require an object should be omitted
instead.

This CL only adds these objects to the IDL array after the factory
method succeeds.  User agents that can construct MIDIAccess will
test as normal, but agents that cannot will simply omit the tests
that require objects.

This CL also adds MIDIMessageEvent which was missing from the test,
and explicitly adds MIDIPort to the list of objects for completeness.

Change-Id: If004cda1a69fdb37097dbf52011e63f8dfa166ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4482975
Commit-Queue: Michael Wilson <[email protected]>
Reviewed-by: Hongchan Choi <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1136694}
  • Loading branch information
Michael Wilson authored and chromium-wpt-export-bot committed Apr 27, 2023
1 parent 4d07bf6 commit 06b1f3f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions webmidi/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ idl_test(
['html', 'dom', 'permissions'],
async idl_array => {
idl_array.add_objects({
MIDIAccess: ['access'],
MIDIInputMap: ['inputs'],
MIDIOutputMap: ['outputs'],
MIDIPort: [],
MIDIMessageEvent: [
'new MIDIMessageEvent("type", { data: new Uint8Array([0]) })'
],
MIDIConnectionEvent: ['new MIDIConnectionEvent("type")'],
})

self.access = await navigator.requestMIDIAccess();
self.inputs = access.inputs;
self.outputs = access.outputs;
idl_array.add_objects({ MIDIInputMap: ['inputs'] });
idl_array.add_objects({ MIDIOutputMap: ['outputs'] });
idl_array.add_objects({ MIDIAccess: ['access'] });
if (inputs.size) {
self.input = Array.from(access.inputs.values())[0];
idl_array.add_objects({ MIDIInput: ['input'] });
}
self.outputs = access.outputs;
if (outputs.size) {
self.output = Array.from(access.outputs.values())[0];
idl_array.add_objects({ MIDIOutput: ['output'] });
Expand Down

0 comments on commit 06b1f3f

Please sign in to comment.