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 MIDIPort.open and MIDIPort.close."); | 8 description("Tests MIDIPort.open and MIDIPort.close."); |
9 | 9 |
10 function checkStateTransition(options) { | 10 function checkStateTransition(options) { |
11 debug("Check state transition for " + options.method + " on " + | 11 debug("Check state transition for " + options.method + " on " + |
12 options.initialconnection + " state."); | 12 options.initialconnection + " state."); |
13 debug("- check initial state."); | 13 debug("- check initial state."); |
14 window.port = options.port; | 14 window.port = options.port; |
15 shouldBeEqualToString("port.connection", options.initialconnection); | 15 shouldBeEqualToString("port.connection", options.initialconnection); |
16 port.onstatechange = function(e) { | 16 var checkHandler = function(e) { |
17 debug("- check handler port."); | |
18 window.eventport = e.port; | 17 window.eventport = e.port; |
19 testPassed("handler is called with port " + eventport + "."); | 18 testPassed("handler is called with port " + eventport + "."); |
20 if (options.initialconnection == options.finalconnection) { | 19 if (options.initialconnection == options.finalconnection) { |
21 testFailed("onstatechange handler should not be called here."); | 20 testFailed("onstatechange handler should not be called here."); |
22 } | 21 } |
23 shouldBeEqualToString("eventport.id", options.port.id); | 22 shouldBeEqualToString("eventport.id", options.port.id); |
24 shouldBeEqualToString("eventport.connection", options.finalconnection); | 23 shouldBeEqualToString("eventport.connection", options.finalconnection); |
25 }; | 24 }; |
| 25 port.onstatechange = function(e) { |
| 26 debug("- check port handler."); |
| 27 checkHandler(e); |
| 28 }; |
| 29 access.onstatechange = function(e) { |
| 30 debug("- check access handler."); |
| 31 checkHandler(e); |
| 32 }; |
26 return port[options.method]().then(function(p) { | 33 return port[options.method]().then(function(p) { |
27 window.callbackport = p; | 34 window.callbackport = p; |
28 debug("- check callback arguments."); | 35 debug("- check callback arguments."); |
29 testPassed("callback is called with port " + callbackport + "."); | 36 testPassed("callback is called with port " + callbackport + "."); |
30 shouldBeEqualToString("callbackport.id", options.port.id); | 37 shouldBeEqualToString("callbackport.id", options.port.id); |
31 shouldBeEqualToString("callbackport.connection", options.finalconnection
); | 38 shouldBeEqualToString("callbackport.connection", options.finalconnection
); |
32 debug("- check final state."); | 39 debug("- check final state."); |
33 shouldBeEqualToString("port.connection", options.finalconnection); | 40 shouldBeEqualToString("port.connection", options.finalconnection); |
34 }, function(e) { | 41 }, function(e) { |
35 testFailed("error callback should not be called here."); | 42 testFailed("error callback should not be called here."); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 82 } |
76 | 83 |
77 window.jsTestIsAsync = true; | 84 window.jsTestIsAsync = true; |
78 | 85 |
79 // Test MIDIPort state transition by open() and close(). | 86 // Test MIDIPort state transition by open() and close(). |
80 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); | 87 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); |
81 | 88 |
82 </script> | 89 </script> |
83 </body> | 90 </body> |
84 </html> | 91 </html> |
OLD | NEW |