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) { | |
yhirano
2015/03/03 11:18:31
Throwing from this function has no effect: You can
Takashi Toyoshima
2015/03/03 13:18:38
Oh, nice catch.
But, I guess your suggesting appro
| |
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 throw options; | |
23 } | |
24 shouldBeEqualToString("eventport.id", options.port.id); | |
25 shouldBeEqualToString("eventport.state", options.finalstate); | |
26 }; | |
27 return port[options.method]().then(function(p) { | |
28 window.callbackport = p; | |
29 debug("- check callback arguments."); | |
30 testPassed("callback is called with port " + callbackport + "."); | |
31 shouldBeEqualToString("callbackport.id", options.port.id); | |
32 shouldBeEqualToString("callbackport.state", options.finalstate); | |
33 debug("- check final state."); | |
34 shouldBeEqualToString("port.state", options.finalstate); | |
35 }, function(e) { | |
36 testFailed("error callback should not be called here."); | |
37 throw e; | |
38 }); | |
39 } | |
40 | |
41 function runTests(port) { | |
42 return Promise.resolve().then(checkStateTransition.bind(undefined, { | |
43 port: port, | |
44 method: "close", | |
45 initialstate: "connected", | |
46 finalstate: "connected", | |
47 })).then(checkStateTransition.bind(undefined, { | |
48 port: port, | |
49 method: "open", | |
50 initialstate: "connected", | |
51 finalstate: "opened", | |
52 })).then(checkStateTransition.bind(undefined, { | |
53 port: port, | |
54 method: "open", | |
55 initialstate: "opened", | |
56 finalstate: "opened", | |
57 })).then(checkStateTransition.bind(undefined, { | |
58 port: port, | |
59 method: "close", | |
60 initialstate: "opened", | |
61 finalstate: "connected", | |
62 })); | |
63 } | |
64 | |
65 function successAccessCallback(a) { | |
66 window.access = a; | |
67 testPassed("requestMIDIAccess() succeeded with access " + access + "."); | |
68 | |
69 runTests(access.inputs.values().next().value) | |
70 .then(finishJSTest, finishJSTest); | |
71 } | |
72 | |
73 function errorAccessCallback(error) { | |
74 testFailed("requestMIDIAccess() error callback should not be called when req uesting basic access."); | |
75 finishJSTest(); | |
76 } | |
77 | |
78 window.jsTestIsAsync = true; | |
79 | |
80 // Test MIDIPort state transition by open() and close(). | |
81 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); | |
82 | |
83 </script> | |
84 </body> | |
85 </html> | |
OLD | NEW |