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.initialconnection + " state."); | |
13 debug("- check initial state."); | |
14 window.port = options.port; | |
15 shouldBeEqualToString("port.connection", options.initialconnection); | |
16 var checkHandler = function(e) { | |
17 window.eventport = e.port; | |
18 testPassed("handler is called with port " + eventport + "."); | |
19 if (options.initialconnection == options.finalconnection) { | |
20 testFailed("onstatechange handler should not be called here."); | |
21 } | |
22 shouldBeEqualToString("eventport.id", options.port.id); | |
23 shouldBeEqualToString("eventport.connection", options.finalconnection); | |
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 }; | |
33 return port[options.method]().then(function(p) { | |
34 window.callbackport = p; | |
35 debug("- check callback arguments."); | |
36 testPassed("callback is called with port " + callbackport + "."); | |
37 shouldBeEqualToString("callbackport.id", options.port.id); | |
38 shouldBeEqualToString("callbackport.connection", options.finalconnection
); | |
39 debug("- check final state."); | |
40 shouldBeEqualToString("port.connection", options.finalconnection); | |
41 }, function(e) { | |
42 testFailed("error callback should not be called here."); | |
43 throw e; | |
44 }); | |
45 } | |
46 | |
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 | |
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 |