blob: 5e2f1880f48bf45a64ae103d3983431507d57edf [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../http/tests/resources/permissions-helper.js"></script>
</head>
<body>
<script>
description("Test if midimessage event handler work.");
shouldBeDefined("navigator.requestMIDIAccess");
window.jsTestIsAsync = true;
testData = [
// Complete messages.
[0x80, 0x00, 0x00],
[0x90, 0x00, 0x00],
[0xa0, 0x00, 0x00],
[0xb0, 0x00, 0x00],
[0xc0, 0x00],
[0xd0, 0x00],
[0xe0, 0x00, 0x00],
// Real-Time messages.
[0xf8],
[0xfa],
[0xfb],
[0xfc],
[0xfe],
[0xff],
// Sysex messages.
[0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7],
[0xf0, 0xf8, 0xf7],
];
receiveCount = 0;
function verifyData(e) {
debug("receiving data " + receiveCount + ": " + e.data);
expected = testData[receiveCount];
actual = e.data;
shouldBe("actual", "expected");
midiMessageEvent = e;
receiveCount++;
if (receiveCount == testData.length)
e.target.resolve();
}
function test(useAddEventListener) {
return new Promise(function(resolve, reject) {
debug("running test with useAddEventListener = " + useAddEventListener);
navigator.requestMIDIAccess({sysex: true}).then(function (a) {
receiveCount = 0;
var input = a.inputs.values().next().value;
input.resolve = resolve;
input.reject = reject;
if (useAddEventListener) {
input.addEventListener('midimessage', verifyData);
} else {
input.onmidimessage = verifyData;
}
var output = a.outputs.values().next().value;
for (var i = 0; i < testData.length; ++i)
output.send(testData[i]);
}, function () {
testFailed("requestMIDIAccess() return an error.");
reject();
});
});
}
Promise.all([PermissionsHelper.setPermission('midi', 'granted'),
PermissionsHelper.setPermission('midi-sysex', 'granted')]).then(function() {
test(false).then(test.bind(null, true)).then(finishJSTest, finishJSTest);
});
</script>
</body>
</html>