blob: b2c312e3acb27ad405a27366847a884332d2650a [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../http/tests/resources/permissions-helper.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/media/midi/midi_service.mojom.js"></script>
<script src="../http/tests/webmidi/mock-midiservice.js"></script>
<script>
async_test(t => {
let noteOn = [ 0x90, 0x45, 0x7f ];
t.step(() => {
Promise.all([
PermissionsHelper.setPermission('midi', 'granted'),
]).then(() => {
return navigator.requestMIDIAccess();
}).then(a => {
var started = false;
var receivedMessages = 0;
var receiveMessage = e => {
t.step(() => {
assert_array_equals(
e.data, noteOn, 'received message should be noteOn');
});
if (++receivedMessages != 2)
return;
t.done();
};
a.onstatechange = e => {
// Wait until three outputs and three inputs appear.
if (a.inputs.size != 3 || a.outputs.size != 3 || started)
return;
started = true;
// Set an event handler respectively for newly connected ports.
var inputs = a.inputs.values();
inputs.next();
inputs.next().value.onmidimessage = receiveMessage;
inputs.next().value.onmidimessage = receiveMessage;
// Send a message respectively, and see if it is loopbacked.
var outputs = a.outputs.values();
outputs.next();
outputs.next().value.send(noteOn);
outputs.next().value.send(noteOn);
};
output = a.outputs.values().next().value;
mockMIDIService.addInputPort(midi.mojom.PortState.CONNECTED);
mockMIDIService.addOutputPort(midi.mojom.PortState.CONNECTED);
mockMIDIService.addInputPort(midi.mojom.PortState.OPENED);
mockMIDIService.addOutputPort(midi.mojom.PortState.OPENED);
}).catch(e => assert_unreached(e));
});
}, "Test if newly connected ports work correctly");
</script>