4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"../http/tests/resources/permissions-helper.js"></script>
10 description("Test if various kinds of MIDI messages can be validated.");
12 shouldBeDefined("navigator.requestMIDIAccess");
14 window
.jsTestIsAsync
= true;
16 PermissionsHelper
.setPermission('midi-sysex', 'granted').then(function() {
17 return navigator
.requestMIDIAccess({sysex
: true});
19 output
= a
.outputs
.values().next().value
;
22 output
.send([0xff, 0x90, 0x00, 0x00, 0x90, 0x07, 0x00]);
24 // Running status is not allowed in Web MIDI API.
25 shouldThrow('output.send([0x00, 0x01])');
27 // Unexpected End of Sysex.
28 shouldThrow('output.send([0xf7])');
30 // Unexpected reserved status bytes.
31 shouldThrow('output.send([0xf4])');
32 shouldThrow('output.send([0xf5])');
33 shouldThrow('output.send([0xf9])');
34 shouldThrow('output.send([0xfd])');
36 // Incomplete channel messages.
37 shouldThrow('output.send([0x80])');
38 shouldThrow('output.send([0x80, 0x00])');
39 shouldThrow('output.send([0x90])');
40 shouldThrow('output.send([0x90, 0x00])');
41 shouldThrow('output.send([0xa0])');
42 shouldThrow('output.send([0xa0, 0x00])');
43 shouldThrow('output.send([0xb0])');
44 shouldThrow('output.send([0xb0, 0x00])');
45 shouldThrow('output.send([0xc0])');
46 shouldThrow('output.send([0xd0])');
47 shouldThrow('output.send([0xe0])');
48 shouldThrow('output.send([0xe0, 0x00])');
50 // Incomplete system messages.
51 shouldThrow('output.send([0xf1])');
52 shouldThrow('output.send([0xf2])');
53 shouldThrow('output.send([0xf2, 0x00])');
54 shouldThrow('output.send([0xf3])');
56 // Invalid data bytes.
57 shouldThrow('output.send([0x80, 0x80, 0x00])');
58 shouldThrow('output.send([0x80, 0x00, 0x80])');
61 output
.send([0x80, 0x00, 0x00]);
62 output
.send([0x90, 0x00, 0x00]);
63 output
.send([0xa0, 0x00, 0x00]);
64 output
.send([0xb0, 0x00, 0x00]);
65 output
.send([0xc0, 0x00]);
66 output
.send([0xd0, 0x00]);
67 output
.send([0xe0, 0x00, 0x00]);
69 // Real-Time messages.
77 // Valid messages with Real-Time messages.
78 output
.send([0x90, 0xff, 0xff, 0x00, 0xff, 0x01, 0xff, 0x80, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff]);
81 output
.send([0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7]);
82 output
.send([0xf0, 0xf8, 0xf7, 0xff]);
83 shouldThrow('output.send([0xf0, 0x80, 0xf7])');
84 shouldThrow('output.send([0xf0, 0xf0, 0xf7])');
85 shouldThrow('output.send([0xf0, 0xff, 0xf7, 0xf7])');
87 // Reserved status bytes.
88 shouldThrow('output.send([0xf4, 0x80, 0x00, 0x00])');
89 shouldThrow('output.send([0x80, 0xf4, 0x00, 0x00])');
90 shouldThrow('output.send([0x80, 0x00, 0xf4, 0x00])');
91 shouldThrow('output.send([0x80, 0x00, 0x00, 0xf4])');
92 shouldThrow('output.send([0xf0, 0xff, 0xf4, 0xf7])');
94 // Invalid timestamps.
95 shouldThrow('output.send([], NaN)');
96 shouldThrow('output.send([], Infinity)');
97 shouldThrow('output.send(new Uint8Array(), NaN)');
98 shouldThrow('output.send(new Uint8Array(), Infinity)');
101 }).catch(function () {
102 testFailed("requestMIDIAccess() return an error.");