blob: 4bb6c88b809678a619bf05a56af80671ed0920a8 [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.open and MIDIPort.close.");
shouldBeDefined("PermissionsHelper.setPermission");
function runTests(port) {
return Promise.resolve().then(checkStateTransition.bind(undefined, {
port: port,
method: "close",
initialconnection: "closed",
finalconnection: "closed",
})).then(checkStateTransition.bind(undefined, {
port: port,
method: "open",
initialconnection: "closed",
finalconnection: "open",
})).then(checkStateTransition.bind(undefined, {
port: port,
method: "open",
initialconnection: "open",
finalconnection: "open",
})).then(checkStateTransition.bind(undefined, {
port: port,
method: "close",
initialconnection: "open",
finalconnection: "closed",
}));
}
function successAccessCallback(a) {
window.access = a;
testPassed("requestMIDIAccess() succeeded with access " + access + ".");
runTests(access.inputs.values().next().value)
.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 open() and close().
navigator.requestMIDIAccess().then(successAccessCallback, errorAccessCallback);
});
</script>
</body>
</html>