Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../resources/js-test.js"></script> | |
| 5 <script src="../http/tests/resources/permissions-helper.js"></script> | |
| 6 </head> | |
| 7 <body> | |
| 8 <script> | |
| 9 | |
| 10 description("Test if newly connected ports work correctly."); | |
| 11 | |
| 12 window.jsTestIsAsync = true; | |
| 13 | |
| 14 var sysexHeader = [0xf0, 0x00, 0x02, 0x0d, 0x7f]; | |
| 15 var sysexFooter = [0xf7]; | |
| 16 var sysexPayloadToAddInputAsConnected = [0x00, 0x00]; | |
| 17 var sysexPayloadToAddOutputAsConnected = [0x00, 0x01]; | |
| 18 var sysexPayloadToAddInputAsOpened = [0x00, 0x02]; | |
| 19 var sysexPayloadToAddOutputAsOpened = [0x00, 0x03]; | |
| 20 var noteOn = [0x90, 0x45, 0x7f]; | |
| 21 | |
| 22 function createSysex(payload) { | |
| 23 return sysexHeader.concat(payload).concat(sysexFooter); | |
| 24 } | |
| 25 | |
| 26 var receivedMessages = 0; | |
| 27 | |
| 28 function receiveMessage(e) { | |
| 29 event = e; | |
| 30 shouldBe("event.data", "noteOn"); | |
| 31 if (++receivedMessages != 2) | |
| 32 return; | |
| 33 finishJSTest(); | |
| 34 } | |
| 35 | |
| 36 Promise.all([PermissionsHelper.setPermission('midi', 'granted'), | |
| 37 PermissionsHelper.setPermission('midi-sysex', 'granted')]).then(fun ction() { | |
| 38 return navigator.requestMIDIAccess({sysex: true}); | |
| 39 }).then(function(a) { | |
| 40 try { | |
|
yhirano
2016/11/14 04:32:55
No try-catch is needed: the exception should be ca
Takashi Toyoshima
2016/11/14 06:25:28
I just want to have a different catch for requestM
| |
| 41 var started = false; | |
| 42 a.onstatechange = function(e) { | |
| 43 // Wait until three outputs and three inputs appear. | |
| 44 if (a.inputs.size != 3 || a.outputs.size != 3 || started) | |
| 45 return; | |
| 46 started = true; | |
| 47 testPassed("Test devices are newly added correctly."); | |
| 48 | |
| 49 // Set an event handler respectively for newly connected ports. | |
| 50 var inputs = a.inputs.values(); | |
| 51 inputs.next(); | |
| 52 inputs.next().value.onmidimessage = receiveMessage; | |
| 53 inputs.next().value.onmidimessage = receiveMessage; | |
| 54 | |
| 55 // Send a message respectively, and see if it is loopbacked. | |
| 56 var outputs = a.outputs.values(); | |
| 57 outputs.next(); | |
| 58 outputs.next().value.send(noteOn); | |
| 59 outputs.next().value.send(noteOn); | |
| 60 }; | |
| 61 | |
| 62 output = a.outputs.values().next().value; | |
| 63 | |
| 64 // Send sysex messages to request dynamically adding mock devices. | |
| 65 output.send(createSysex(sysexPayloadToAddInputAsConnected)); | |
| 66 output.send(createSysex(sysexPayloadToAddOutputAsConnected)); | |
| 67 output.send(createSysex(sysexPayloadToAddInputAsOpened)); | |
| 68 output.send(createSysex(sysexPayloadToAddOutputAsOpened)); | |
| 69 } catch (e) { | |
| 70 testFailed("An unexpected exception is caught."); | |
| 71 } | |
| 72 }).catch(function () { | |
| 73 testFailed("requestMIDIAccess() return an error."); | |
|
yhirano
2016/11/14 04:32:55
It would be good to print the passed exception.
Takashi Toyoshima
2016/11/14 06:25:28
Done.
| |
| 74 finishJSTest(); | |
| 75 }); | |
| 76 | |
| 77 </script> | |
| 78 </body> | |
| 79 </html> | |
| OLD | NEW |