1 function checkStateTransition(options) {
2 debug("Check state transition for " + options.method + " on " +
3 options.initialconnection + " state.");
4 debug("- check initial state.");
5 window.port = options.port;
6 shouldBeEqualToString("port.connection", options.initialconnection);
7 var checkHandler = function(e) {
8 window.eventport = e.port;
9 testPassed("handler is called with port " + eventport + ".");
10 if (options.initialconnection == options.finalconnection) {
11 testFailed("onstatechange handler should not be called here.");
13 shouldBeEqualToString("eventport.id", options.port.id);
14 shouldBeEqualToString("eventport.connection", options.finalconnection);
16 port.onstatechange = function(e) {
17 debug("- check port handler.");
20 access.onstatechange = function(e) {
21 debug("- check access handler.");
24 if (options.method == "send") {
27 if (options.method == "setonmidimessage") {
28 port.onmidimessage = function() {};
30 if (options.method == "addeventlistener") {
31 port.addEventListener("midimessage", function() {});
33 if (options.method == "send" || options.method == "setonmidimessage" ||
34 options.method == "addeventlistener") {
35 // Following tests expect an implicit open finishes synchronously.
36 // But it will be asynchronous in the future.
37 debug("- check final state.");
38 shouldBeEqualToString("port.connection", options.finalconnection);
39 return Promise.resolve();
41 // |method| is expected to be "open" or "close".
42 return port[options.method]().then(function(p) {
43 window.callbackport = p;
44 debug("- check callback arguments.");
45 testPassed("callback is called with port " + callbackport + ".");
46 shouldBeEqualToString("callbackport.id", options.port.id);
47 shouldBeEqualToString("callbackport.connection", options.finalconnection);
48 debug("- check final state.");
49 shouldBeEqualToString("port.connection", options.finalconnection);
51 testFailed("error callback should not be called here.");