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 connectedPortCallback(port) { | |
11 window.connectedPort = port; | |
12 shouldBeEqualToString("connectedPort.state", "connected"); | |
13 } | |
14 | |
15 function openedPortCallback(port) { | |
16 window.openedPort = port; | |
17 shouldBeEqualToString("openedPort.state", "opened"); | |
18 } | |
19 | |
20 function errorPortCallback(error) { | |
21 testFailed("open() or close() error callback should not be called here."); | |
22 finishJSTest(); | |
23 } | |
24 | |
25 function connectedPortHandler(e) { | |
26 window.eventPort = e.port; | |
27 shouldBeEqualToString("eventPort.state", "connected"); | |
28 } | |
29 | |
30 function openedPortHandler(e) { | |
31 window.eventPort = e.port; | |
32 shouldBeEqualToString("eventPort.state", "opened"); | |
33 } | |
34 | |
35 function errorPortHandler(e) { | |
36 testFailed("onstatechange handler should not be called here."); | |
37 finishJSTest(); | |
38 } | |
39 | |
40 function finishOnConnected(port) { | |
41 window.port = port; | |
42 shouldBeEqualToString("port.state", "connected"); | |
43 finishJSTest(); | |
44 } | |
45 | |
46 function checkCloseOnOpened(port) { | |
47 window.port = port; | |
48 shouldBeEqualToString("port.state", "opened"); | |
49 port.onstatechange = connectedPortHandler; | |
50 port.close().then(finishOnConnected, errorPortCallback); | |
51 } | |
52 | |
53 function checkOpenOnOpened(port) { | |
54 window.port = port; | |
55 shouldBeEqualToString("port.state", "opened"); | |
56 port.onstatechange = errorPortHandler; | |
57 port.open().then(checkCloseOnOpened, errorPortCallback); | |
58 } | |
59 | |
60 function checkOpenOnConnected(port) { | |
61 window.port = port; | |
62 shouldBeEqualToString("port.state", "connected"); | |
63 port.onstatechange = openedPortHandler; | |
64 port.open().then(checkOpenOnOpened, errorPortCallback); | |
65 } | |
66 | |
67 function checkCloseOnConnected(port) { | |
68 window.port = port; | |
69 shouldBeEqualToString("port.state", "connected"); | |
70 port.onstatechange = errorPortHandler; | |
71 port.close().then(checkOpenOnConnected, errorPortCallback); | |
72 } | |
73 | |
74 function checkMIDIPortStateTransition(port) { | |
75 checkCloseOnConnected(port); | |
yhirano
2015/03/02 05:34:32
How about listing tests here?
return Promise.reso
Takashi Toyoshima
2015/03/02 15:44:44
that's nice idea, and I went more aggressively in
| |
76 } | |
77 | |
78 function successAccessCallback(a) { | |
79 window.access = a; | |
80 testPassed("requestMIDIAccess() succeeded with access " + access + "."); | |
81 | |
82 checkMIDIPortStateTransition(access.inputs.values().next().value); | |
yhirano
2015/03/02 05:34:32
If you return a promise from checkMIDIPortStateTra
Takashi Toyoshima
2015/03/02 15:44:44
Done.
| |
83 } | |
84 | |
85 function errorAccessCallback(error) { | |
86 testFailed("requestMIDIAccess() error callback should not be called when req uesting basic access."); | |
87 finishJSTest(); | |
88 } | |
89 | |
90 window.jsTestIsAsync = true; | |
91 | |
92 // Test MIDIPort state transition by open() and close(). | |
93 navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); | |
94 | |
95 </script> | |
96 </body> | |
97 </html> | |
OLD | NEW |