Reviewers: yhirano,
Message:
ptal
Description:
Web MIDI API: update open() and close() implementation
Update the implementation algorithm to conform the latest WD,
http://www.w3.org/TR/2015/WD-webmidi-20150317/.
BUG=462183
Please review this at
https://codereview.chromium.org/1041213004/
Base URL:
https://chromium.googlesource.com/chromium/blink.git@midi_wd
Affected files (+36, -24 lines):
M LayoutTests/webmidi/open_close.html
M LayoutTests/webmidi/open_close-expected.txt
M Source/modules/webmidi/MIDIPort.cpp
Index: LayoutTests/webmidi/open_close-expected.txt
diff --git a/LayoutTests/webmidi/open_close-expected.txt
b/LayoutTests/webmidi/open_close-expected.txt
index
a72d5578a3d2f476f70a67bbc6ef4e374527aa2b..56337609a98edcebb3f51dc79bb82288fd700c01
100644
--- a/LayoutTests/webmidi/open_close-expected.txt
+++ b/LayoutTests/webmidi/open_close-expected.txt
@@ -16,7 +16,11 @@ PASS port.connection is "closed"
Check state transition for open on closed state.
- check initial state.
PASS port.connection is "closed"
-- check handler port.
+- check port handler.
+PASS handler is called with port [object MIDIInput].
+PASS
eventport.id is "MockInputID"
+PASS eventport.connection is "open"
+- check access handler.
PASS handler is called with port [object MIDIInput].
PASS
eventport.id is "MockInputID"
PASS eventport.connection is "open"
@@ -38,7 +42,11 @@ PASS port.connection is "open"
Check state transition for close on open state.
- check initial state.
PASS port.connection is "open"
-- check handler port.
+- check port handler.
+PASS handler is called with port [object MIDIInput].
+PASS
eventport.id is "MockInputID"
+PASS eventport.connection is "closed"
+- check access handler.
PASS handler is called with port [object MIDIInput].
PASS
eventport.id is "MockInputID"
PASS eventport.connection is "closed"
Index: LayoutTests/webmidi/open_close.html
diff --git a/LayoutTests/webmidi/open_close.html
b/LayoutTests/webmidi/open_close.html
index
8f6bcb405d0b51b8a41b37dc0e6ae31997a50f1f..98b414bfbe4d44e6266ee6437d18e17bc796f2f2
100644
--- a/LayoutTests/webmidi/open_close.html
+++ b/LayoutTests/webmidi/open_close.html
@@ -13,8 +13,7 @@ function checkStateTransition(options) {
debug("- check initial state.");
window.port = options.port;
shouldBeEqualToString("port.connection", options.initialconnection);
- port.onstatechange = function(e) {
- debug("- check handler port.");
+ checkHandler = function(e) {
window.eventport = e.port;
testPassed("handler is called with port " + eventport + ".");
if (options.initialconnection == options.finalconnection) {
@@ -23,6 +22,14 @@ function checkStateTransition(options) {
shouldBeEqualToString("
eventport.id",
options.port.id);
shouldBeEqualToString("eventport.connection",
options.finalconnection);
};
+ port.onstatechange = function(e) {
+ debug("- check port handler.");
+ checkHandler(e);
+ };
+ access.onstatechange = function(e) {
+ debug("- check access handler.");
+ checkHandler(e);
+ };
return port[options.method]().then(function(p) {
window.callbackport = p;
debug("- check callback arguments.");
Index: Source/modules/webmidi/MIDIPort.cpp
diff --git a/Source/modules/webmidi/MIDIPort.cpp
b/Source/modules/webmidi/MIDIPort.cpp
index
20824dcf3820de76b078dbf5f85535599665bfa1..02d17fe7dd054500d262c5bc7b1c7e3813ce1f43
100644
--- a/Source/modules/webmidi/MIDIPort.cpp
+++ b/Source/modules/webmidi/MIDIPort.cpp
@@ -104,34 +104,30 @@ String MIDIPort::type() const
ScriptPromise MIDIPort::open(ScriptState* scriptState)
{
- // FIXME: Implement the latest open() algorithm.
- switch (m_state) {
- case PortState::MIDIPortStateDisconnected:
- return reject(scriptState, InvalidStateError, "The port has been
disconnected.");
- case PortState::MIDIPortStateConnected:
- // FIXME: Add blink API to perform a real open operation.
- setStates(m_state, MIDIPortConnectionStateOpen);
- return accept(scriptState);
- default:
- ASSERT_NOT_REACHED();
+ if (m_connection == MIDIPortConnectionStateClosed) {
+ switch (m_state) {
+ case PortState::MIDIPortStateDisconnected:
+ setStates(m_state, MIDIPortConnectionStatePending);
+ break;
+ case PortState::MIDIPortStateConnected:
+ // FIXME: Add blink API to perform a real open and close
operation.
+ setStates(m_state, MIDIPortConnectionStateOpen);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
}
- return reject(scriptState, InvalidStateError, "The port is in unknown
state.");
+ return accept(scriptState);
}
ScriptPromise MIDIPort::close(ScriptState* scriptState)
{
- // FIXME: Implement the latest close() algorithm.
- switch (m_state) {
- case PortState::MIDIPortStateDisconnected:
- return reject(scriptState, InvalidStateError, "The port has been
disconnected.");
- case PortState::MIDIPortStateConnected:
+ if (m_connection != MIDIPortConnectionStateClosed) {
+ // FIXME: Do clear() operation on MIDIOutput.
// FIXME: Add blink API to perform a real close operation.
setStates(m_state, MIDIPortConnectionStateClosed);
- return accept(scriptState);
- default:
- ASSERT_NOT_REACHED();
}
- return reject(scriptState, InvalidStateError, "The port is in unknown
state.");
+ return accept(scriptState);
}
void MIDIPort::setState(PortState state)
@@ -167,6 +163,7 @@ void MIDIPort::setStates(PortState state,
MIDIPortConnectionState connection)
m_state = state;
m_connection = connection;
dispatchEvent(MIDIConnectionEvent::create(this));
+ m_access->dispatchEvent(MIDIConnectionEvent::create(this));
}
} // namespace blink