OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 </head> |
| 6 <body> |
| 7 <script> |
| 8 description("Tests MIDIPort.open and MIDIPort.close."); |
| 9 |
| 10 function checkStateTransition(options) { |
| 11 debug("Check state transition for " + options.method + " on " + |
| 12 options.initialstate + " state."); |
| 13 debug("- check initial state."); |
| 14 window.port = options.port; |
| 15 shouldBeEqualToString("port.state", options.initialstate); |
| 16 port.onstatechange = function(e) { |
| 17 debug("- check handler port."); |
| 18 window.eventport = e.port; |
| 19 testPassed("handler is called with port " + eventport + "."); |
| 20 if (options.initialstate == options.finalstate) { |
| 21 testFailed("onstatechange handler should not be called here."); |
| 22 } |
| 23 shouldBeEqualToString("eventport.id", options.port.id); |
| 24 shouldBeEqualToString("eventport.state", options.finalstate); |
| 25 }; |
| 26 return port[options.method]().then(function(p) { |
| 27 window.callbackport = p; |
| 28 debug("- check callback arguments."); |
| 29 testPassed("callback is called with port " + callbackport + "."); |
| 30 shouldBeEqualToString("callbackport.id", options.port.id); |
| 31 shouldBeEqualToString("callbackport.state", options.finalstate); |
| 32 debug("- check final state."); |
| 33 shouldBeEqualToString("port.state", options.finalstate); |
| 34 }, function(e) { |
| 35 testFailed("error callback should not be called here."); |
| 36 throw e; |
| 37 }); |
| 38 } |
| 39 |
| 40 function runTests(port) { |
| 41 return Promise.resolve().then(checkStateTransition.bind(undefined, { |
| 42 port: port, |
| 43 method: "close", |
| 44 initialstate: "connected", |
| 45 finalstate: "connected", |
| 46 })).then(checkStateTransition.bind(undefined, { |
| 47 port: port, |
| 48 method: "open", |
| 49 initialstate: "connected", |
| 50 finalstate: "opened", |
| 51 })).then(checkStateTransition.bind(undefined, { |
| 52 port: port, |
| 53 method: "open", |
| 54 initialstate: "opened", |
| 55 finalstate: "opened", |
| 56 })).then(checkStateTransition.bind(undefined, { |
| 57 port: port, |
| 58 method: "close", |
| 59 initialstate: "opened", |
| 60 finalstate: "connected", |
| 61 })); |
| 62 } |
| 63 |
| 64 function successAccessCallback(a) { |
| 65 window.access = a; |
| 66 testPassed("requestMIDIAccess() succeeded with access " + access + "."); |
| 67 |
| 68 runTests(access.inputs.values().next().value) |
| 69 .then(finishJSTest, finishJSTest); |
| 70 } |
| 71 |
| 72 function errorAccessCallback(error) { |
| 73 testFailed("requestMIDIAccess() error callback should not be called when req
uesting basic access."); |
| 74 finishJSTest(); |
| 75 } |
| 76 |
| 77 window.jsTestIsAsync = true; |
| 78 |
| 79 // Test MIDIPort state transition by open() and close(). |
| 80 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); |
| 81 |
| 82 </script> |
| 83 </body> |
| 84 </html> |
OLD | NEW |