Index: LayoutTests/webmidi/open_close.html |
diff --git a/LayoutTests/webmidi/open_close.html b/LayoutTests/webmidi/open_close.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e369ab88d2bd769b89bfe4e92b7e2f34ea4b9eb7 |
--- /dev/null |
+++ b/LayoutTests/webmidi/open_close.html |
@@ -0,0 +1,97 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script src="../resources/js-test.js"></script> |
+</head> |
+<body> |
+<script> |
+description("Tests MIDIPort.open and MIDIPort.close."); |
+ |
+function connectedPortCallback(port) { |
+ window.connectedPort = port; |
+ shouldBeEqualToString("connectedPort.state", "connected"); |
+} |
+ |
+function openedPortCallback(port) { |
+ window.openedPort = port; |
+ shouldBeEqualToString("openedPort.state", "opened"); |
+} |
+ |
+function errorPortCallback(error) { |
+ testFailed("open() or close() error callback should not be called here."); |
+ finishJSTest(); |
+} |
+ |
+function connectedPortHandler(e) { |
+ window.eventPort = e.port; |
+ shouldBeEqualToString("eventPort.state", "connected"); |
+} |
+ |
+function openedPortHandler(e) { |
+ window.eventPort = e.port; |
+ shouldBeEqualToString("eventPort.state", "opened"); |
+} |
+ |
+function errorPortHandler(e) { |
+ testFailed("onstatechange handler should not be called here."); |
+ finishJSTest(); |
+} |
+ |
+function finishOnConnected(port) { |
+ window.port = port; |
+ shouldBeEqualToString("port.state", "connected"); |
+ finishJSTest(); |
+} |
+ |
+function checkCloseOnOpened(port) { |
+ window.port = port; |
+ shouldBeEqualToString("port.state", "opened"); |
+ port.onstatechange = connectedPortHandler; |
+ port.close().then(finishOnConnected, errorPortCallback); |
+} |
+ |
+function checkOpenOnOpened(port) { |
+ window.port = port; |
+ shouldBeEqualToString("port.state", "opened"); |
+ port.onstatechange = errorPortHandler; |
+ port.open().then(checkCloseOnOpened, errorPortCallback); |
+} |
+ |
+function checkOpenOnConnected(port) { |
+ window.port = port; |
+ shouldBeEqualToString("port.state", "connected"); |
+ port.onstatechange = openedPortHandler; |
+ port.open().then(checkOpenOnOpened, errorPortCallback); |
+} |
+ |
+function checkCloseOnConnected(port) { |
+ window.port = port; |
+ shouldBeEqualToString("port.state", "connected"); |
+ port.onstatechange = errorPortHandler; |
+ port.close().then(checkOpenOnConnected, errorPortCallback); |
+} |
+ |
+function checkMIDIPortStateTransition(port) { |
+ 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
|
+} |
+ |
+function successAccessCallback(a) { |
+ window.access = a; |
+ testPassed("requestMIDIAccess() succeeded with access " + access + "."); |
+ |
+ 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.
|
+} |
+ |
+function errorAccessCallback(error) { |
+ testFailed("requestMIDIAccess() error callback should not be called when requesting basic access."); |
+ finishJSTest(); |
+} |
+ |
+window.jsTestIsAsync = true; |
+ |
+// Test MIDIPort state transition by open() and close(). |
+navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback); |
+ |
+</script> |
+</body> |
+</html> |