Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../resources/js-test.js"></script> | |
|
tkent
2016/11/14 06:34:02
Do you have any reason to avoid testharness.js ?
Takashi Toyoshima
2016/11/14 07:53:43
Done.
| |
| 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) { | |
|
tkent
2016/11/14 06:34:02
Indentation is inconsistent. This |then| line and
Takashi Toyoshima
2016/11/14 07:53:43
Done.
| |
| 40 var started = false; | |
| 41 a.onstatechange = function(e) { | |
| 42 // Wait until three outputs and three inputs appear. | |
| 43 if (a.inputs.size != 3 || a.outputs.size != 3 || started) | |
| 44 return; | |
| 45 started = true; | |
| 46 testPassed("Test devices are newly added correctly."); | |
| 47 | |
| 48 // Set an event handler respectively for newly connected ports. | |
| 49 var inputs = a.inputs.values(); | |
| 50 inputs.next(); | |
| 51 inputs.next().value.onmidimessage = receiveMessage; | |
| 52 inputs.next().value.onmidimessage = receiveMessage; | |
| 53 | |
| 54 // Send a message respectively, and see if it is loopbacked. | |
| 55 var outputs = a.outputs.values(); | |
| 56 outputs.next(); | |
| 57 outputs.next().value.send(noteOn); | |
| 58 outputs.next().value.send(noteOn); | |
| 59 }; | |
| 60 | |
| 61 output = a.outputs.values().next().value; | |
| 62 | |
| 63 // Send sysex messages to request dynamically adding mock devices. | |
| 64 output.send(createSysex(sysexPayloadToAddInputAsConnected)); | |
| 65 output.send(createSysex(sysexPayloadToAddOutputAsConnected)); | |
| 66 output.send(createSysex(sysexPayloadToAddInputAsOpened)); | |
| 67 output.send(createSysex(sysexPayloadToAddOutputAsOpened)); | |
| 68 }).catch(function () { | |
| 69 testFailed("unexpected error: " + e); | |
| 70 finishJSTest(); | |
| 71 }); | |
| 72 | |
| 73 </script> | |
| 74 </body> | |
| 75 </html> | |
| OLD | NEW |