OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 description("Tests navigator.requestMIDIAccess."); | 8 description("Tests navigator.requestMIDIAccess."); |
9 | 9 |
10 var access; | 10 var access; |
| 11 var input; |
11 var output; | 12 var output; |
| 13 |
| 14 function checkInputMap(inputs) { |
| 15 window.inputs = inputs; |
| 16 shouldBe("access.inputs.size", "1"); |
| 17 for (var input of inputs) { |
| 18 window.input = input; |
| 19 shouldBeEqualToString("input.id", "MockInputID"); |
| 20 shouldBeEqualToString("input.manufacturer", "MockInputManufacturer"); |
| 21 shouldBeEqualToString("input.name", "MockInputName"); |
| 22 shouldBeEqualToString("input.version", "MockInputVersion"); |
| 23 } |
| 24 for (var key of inputs.keys()) { |
| 25 window.inputKey = key; |
| 26 shouldBeEqualToString("inputKey", "MockInputID"); |
| 27 } |
| 28 for (var entry of inputs.entries()) { |
| 29 window.entry = entry; |
| 30 shouldBe("entry[0]", "inputKey"); |
| 31 shouldBe("entry[1]", "input"); |
| 32 } |
| 33 for (var input of inputs.values()) { |
| 34 window.inputValue = input; |
| 35 shouldBe("inputValue", "input"); |
| 36 } |
| 37 shouldBeTrue("inputs.has('MockInputID')"); |
| 38 shouldBeFalse("inputs.has('MockOutputID')"); |
| 39 shouldBe("inputs.get('MockInputID')", "input"); |
| 40 shouldBeUndefined("inputs.get('MockOutputID')"); |
| 41 } |
| 42 |
| 43 function checkOutputMap(outputs) { |
| 44 window.outputs = outputs; |
| 45 for (var output of outputs.values()) { |
| 46 window.output = output; |
| 47 shouldBeEqualToString("output.id", "MockOutputID"); |
| 48 shouldBeEqualToString("output.manufacturer", "MockOutputManufacturer"); |
| 49 shouldBeEqualToString("output.name", "MockOutputName"); |
| 50 shouldBeEqualToString("output.version", "MockOutputVersion"); |
| 51 } |
| 52 for (var key of outputs.keys()) { |
| 53 window.outputKey = key; |
| 54 shouldBeEqualToString("outputKey", "MockOutputID"); |
| 55 } |
| 56 for (var entry of outputs.entries()) { |
| 57 window.entry = entry; |
| 58 shouldBe("entry[0]", "outputKey"); |
| 59 shouldBe("entry[1]", "output"); |
| 60 } |
| 61 for (var output of outputs.values()) { |
| 62 window.outputValue = output; |
| 63 shouldBe("outputValue", "output"); |
| 64 } |
| 65 shouldBeTrue("outputs.has('MockOutputID')"); |
| 66 shouldBeFalse("outputs.has('MockInputID')"); |
| 67 shouldBe("outputs.get('MockOutputID')", "output"); |
| 68 shouldBeUndefined("outputs.get('MockInputID')"); |
| 69 } |
| 70 |
12 function successCallback1(a) { | 71 function successCallback1(a) { |
13 access = a; | 72 access = a; |
14 | 73 |
15 testPassed("requestMIDIAccess() succeeded with access " + access + "."); | 74 testPassed("requestMIDIAccess() succeeded with access " + access + "."); |
16 | 75 |
17 // Validate that we have one mock input and one mock output. | |
18 shouldBe("access.inputs().length", "1"); | |
19 shouldBe("access.outputs().length", "1"); | |
20 | |
21 // Validate the values of the attributes on the access. | 76 // Validate the values of the attributes on the access. |
22 shouldBeDefined("access.sysexEnabled"); | 77 shouldBeDefined("access.sysexEnabled"); |
23 shouldBeFalse("access.sysexEnabled"); | 78 shouldBeFalse("access.sysexEnabled"); |
24 | 79 |
25 var inputs = access.inputs(); | 80 checkInputMap(access.inputs); |
26 var outputs = access.outputs(); | 81 checkOutputMap(access.outputs); |
27 var input = inputs[0]; | |
28 output = outputs[0]; | |
29 | 82 |
30 // Validate the values of the attributes on the input and output. | 83 window.output = access.outputs[Symbol.iterator]().next().value; |
31 if (input.id == "MockInputID" && | |
32 input.manufacturer == "MockInputManufacturer" && | |
33 input.name == "MockInputName" && | |
34 input.version == "MockInputVersion") { | |
35 testPassed("input attributes are correct"); | |
36 } else { | |
37 testFailed("input attributes are not correct"); | |
38 } | |
39 | |
40 if (output.id == "MockOutputID" && | |
41 output.manufacturer == "MockOutputManufacturer" && | |
42 output.name == "MockOutputName" && | |
43 output.version == "MockOutputVersion") { | |
44 testPassed("output attributes are correct"); | |
45 } else { | |
46 testFailed("output attributes are not correct"); | |
47 } | |
48 | |
49 // Test sending of MIDI data with a Uint8Array. | 84 // Test sending of MIDI data with a Uint8Array. |
50 var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]); | 85 var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]); |
51 output.send(typedArrayData); | 86 output.send(typedArrayData); |
52 | 87 |
53 // Test sending of MIDI data with a regular Array. | 88 // Test sending of MIDI data with a regular Array. |
54 output.send([0x90, 0x45, 0x7f]); | 89 output.send([0x90, 0x45, 0x7f]); |
55 testPassed("a note on message is sent without timestamp"); | 90 testPassed("a note on message is sent without timestamp"); |
56 | 91 |
57 // Test sending of MIDI data with a regular Array giving an explicit timesta
mp. | 92 // Test sending of MIDI data with a regular Array giving an explicit timesta
mp. |
58 output.send([0x90, 0x45, 0x7f], performance.now()); | 93 output.send([0x90, 0x45, 0x7f], performance.now()); |
(...skipping 25 matching lines...) Expand all Loading... |
84 } | 119 } |
85 | 120 |
86 window.jsTestIsAsync = true; | 121 window.jsTestIsAsync = true; |
87 | 122 |
88 // Test basic access, with no System Exclusive. | 123 // Test basic access, with no System Exclusive. |
89 navigator.requestMIDIAccess().then(successCallback1, errorCallback1); | 124 navigator.requestMIDIAccess().then(successCallback1, errorCallback1); |
90 | 125 |
91 </script> | 126 </script> |
92 </body> | 127 </body> |
93 </html> | 128 </html> |
OLD | NEW |