OLD | NEW |
---|---|
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) { | 1 function checkStateTransition(options) { |
11 debug("Check state transition for " + options.method + " on " + | 2 debug("Check state transition for " + options.method + " on " + |
12 options.initialconnection + " state."); | 3 options.initialconnection + " state."); |
13 debug("- check initial state."); | 4 debug("- check initial state."); |
14 window.port = options.port; | 5 window.port = options.port; |
15 shouldBeEqualToString("port.connection", options.initialconnection); | 6 shouldBeEqualToString("port.connection", options.initialconnection); |
16 var checkHandler = function(e) { | 7 var checkHandler = function(e) { |
17 window.eventport = e.port; | 8 window.eventport = e.port; |
18 testPassed("handler is called with port " + eventport + "."); | 9 testPassed("handler is called with port " + eventport + "."); |
19 if (options.initialconnection == options.finalconnection) { | 10 if (options.initialconnection == options.finalconnection) { |
20 testFailed("onstatechange handler should not be called here."); | 11 testFailed("onstatechange handler should not be called here."); |
21 } | 12 } |
22 shouldBeEqualToString("eventport.id", options.port.id); | 13 shouldBeEqualToString("eventport.id", options.port.id); |
23 shouldBeEqualToString("eventport.connection", options.finalconnection); | 14 shouldBeEqualToString("eventport.connection", options.finalconnection); |
24 }; | 15 }; |
25 port.onstatechange = function(e) { | 16 port.onstatechange = function(e) { |
26 debug("- check port handler."); | 17 debug("- check port handler."); |
27 checkHandler(e); | 18 checkHandler(e); |
28 }; | 19 }; |
29 access.onstatechange = function(e) { | 20 access.onstatechange = function(e) { |
30 debug("- check access handler."); | 21 debug("- check access handler."); |
31 checkHandler(e); | 22 checkHandler(e); |
32 }; | 23 }; |
24 if (options.method == "send") { | |
25 port.send([]); | |
26 } | |
27 if (options.method == "midimessage") { | |
yhirano
2015/04/02 02:15:10
[optional] How about naming this as "setonmidimess
Takashi Toyoshima
2015/04/02 04:03:20
Done.
| |
28 port.onmidimessage = function() {}; | |
29 } | |
30 if (options.method == "send" || options.method == "midimessage") { | |
31 // Following tests expect an implicit open finishes synchronously. | |
32 // But it will be asynchronous in the future. | |
33 debug("- check final state."); | |
34 shouldBeEqualToString("port.connection", options.finalconnection); | |
35 return Promise.resolve(); | |
36 } | |
37 // |method| is expected to be "open" or "close". | |
33 return port[options.method]().then(function(p) { | 38 return port[options.method]().then(function(p) { |
34 window.callbackport = p; | 39 window.callbackport = p; |
35 debug("- check callback arguments."); | 40 debug("- check callback arguments."); |
36 testPassed("callback is called with port " + callbackport + "."); | 41 testPassed("callback is called with port " + callbackport + "."); |
37 shouldBeEqualToString("callbackport.id", options.port.id); | 42 shouldBeEqualToString("callbackport.id", options.port.id); |
38 shouldBeEqualToString("callbackport.connection", options.finalconnection ); | 43 shouldBeEqualToString("callbackport.connection", options.finalconnection ); |
39 debug("- check final state."); | 44 debug("- check final state."); |
40 shouldBeEqualToString("port.connection", options.finalconnection); | 45 shouldBeEqualToString("port.connection", options.finalconnection); |
41 }, function(e) { | 46 }, function(e) { |
42 testFailed("error callback should not be called here."); | 47 testFailed("error callback should not be called here."); |
43 throw e; | 48 throw e; |
44 }); | 49 }); |
45 } | 50 } |
46 | 51 |
47 function runTests(port) { | |
48 return Promise.resolve().then(checkStateTransition.bind(undefined, { | |
49 port: port, | |
50 method: "close", | |
51 initialconnection: "closed", | |
52 finalconnection: "closed", | |
53 })).then(checkStateTransition.bind(undefined, { | |
54 port: port, | |
55 method: "open", | |
56 initialconnection: "closed", | |
57 finalconnection: "open", | |
58 })).then(checkStateTransition.bind(undefined, { | |
59 port: port, | |
60 method: "open", | |
61 initialconnection: "open", | |
62 finalconnection: "open", | |
63 })).then(checkStateTransition.bind(undefined, { | |
64 port: port, | |
65 method: "close", | |
66 initialconnection: "open", | |
67 finalconnection: "closed", | |
68 })); | |
69 } | |
70 | 52 |
71 function successAccessCallback(a) { | |
72 window.access = a; | |
73 testPassed("requestMIDIAccess() succeeded with access " + access + "."); | |
74 | |
75 runTests(access.inputs.values().next().value) | |
76 .then(finishJSTest, finishJSTest); | |
77 } | |
78 | |
79 function errorAccessCallback(error) { | |
80 testFailed("requestMIDIAccess() error callback should not be called when req uesting basic access."); | |
81 finishJSTest(); | |
82 } | |
83 | |
84 window.jsTestIsAsync = true; | |
85 | |
86 // Test MIDIPort state transition by open() and close(). | |
87 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); | |
88 | |
89 </script> | |
90 </body> | |
91 </html> | |
OLD | NEW |