4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"../http/tests/resources/permissions-helper.js"></script>
10 description("Test if midimessage event handler work.");
12 shouldBeDefined("navigator.requestMIDIAccess");
14 window
.jsTestIsAsync
= true;
26 // Real-Time messages.
35 [0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7],
41 function verifyData(e
) {
42 debug("receiving data " + receiveCount
+ ": " + e
.data
);
43 expected
= testData
[receiveCount
];
45 shouldBe("actual", "expected");
47 if (receiveCount
== testData
.length
)
51 function test(useAddEventListener
) {
52 return new Promise(function(resolve
, reject
) {
53 debug("running test with useAddEventListener = " + useAddEventListener
);
54 navigator
.requestMIDIAccess({sysex
: true}).then(function (a
) {
56 var input
= a
.inputs
.values().next().value
;
57 input
.resolve
= resolve
;
58 input
.reject
= reject
;
59 if (useAddEventListener
) {
60 input
.addEventListener('midimessage', verifyData
);
62 input
.onmidimessage
= verifyData
;
64 var output
= a
.outputs
.values().next().value
;
65 for (var i
= 0; i
< testData
.length
; ++i
)
66 output
.send(testData
[i
]);
68 testFailed("requestMIDIAccess() return an error.");
74 PermissionsHelper
.setPermission('midi-sysex', 'granted').then(function() {
75 test(false).then(test
.bind(null, true)).then(finishJSTest
, finishJSTest
);