blob: b5dbecaa006bb2736ce5c415a5edb41bfea28b07 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../http/tests/resources/permissions-helper.js"></script>
<script src="state-check-utils.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/media/midi/midi_service.mojom.js"></script>
<script src="../http/tests/webmidi/mock-midiservice.js"></script>
</head>
<body>
<script>
description("Tests MIDIPort implicit open.");
shouldBeDefined("PermissionsHelper.setPermission");
function resetInputDevice(port) {
debug("- reset input device");
// Reset event handlers so that close() does not cause check failures.
port.onstatechange = null;
access.onstatechange = null;
return port.close();
}
function successAccessCallback(a) {
window.access = a;
testPassed("requestMIDIAccess() succeeded with access " + access + ".");
var inputPort = access.inputs.values().next().value;
var outputPort = access.outputs.values().next().value;
checkStateTransition({
port: inputPort,
method: "setonmidimessage",
initialconnection: "closed",
finalconnection: "open" }
).then(resetInputDevice.bind(undefined, inputPort
)).then(checkStateTransition.bind(undefined, {
port: inputPort,
method: "addeventlistener",
initialconnection: "closed",
finalconnection: "open" }
)).then(checkStateTransition.bind(undefined, {
port: outputPort,
method: "send",
initialconnection: "closed",
finalconnection: "open" }
)).then(finishJSTest, finishJSTest);
}
function errorAccessCallback(error) {
testFailed("requestMIDIAccess() error callback should not be called when requesting basic access.");
finishJSTest();
}
window.jsTestIsAsync = true;
// Set default permission behavior that grants non-sysex requests.
PermissionsHelper.setPermission('midi', 'granted').then(function() {
// Test MIDIPort state transition by send() and onmidimessage handler.
navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback);
});
</script>
</body>
</html>