summaryrefslogtreecommitdiffstats
path: root/dom/midi/tests/test_midi_device_connect_disconnect.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/midi/tests/test_midi_device_connect_disconnect.html
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/midi/tests/test_midi_device_connect_disconnect.html')
-rw-r--r--dom/midi/tests/test_midi_device_connect_disconnect.html54
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/midi/tests/test_midi_device_connect_disconnect.html b/dom/midi/tests/test_midi_device_connect_disconnect.html
new file mode 100644
index 0000000000..9b5143921d
--- /dev/null
+++ b/dom/midi/tests/test_midi_device_connect_disconnect.html
@@ -0,0 +1,54 @@
+<html>
+ <head>
+ <title>WebMIDI Listener Test</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+ <script type="application/javascript" src="MIDITestUtils.js"></script>
+ </head>
+
+ <body onload="runTests()">
+ <script class="testbody" type="application/javascript">
+ SimpleTest.waitForExplicitFinish();
+
+ async function runTests() {
+ await MIDITestUtils.permissionSetup(true);
+ let output;
+
+ let midi_access;
+ try {
+ midi_access = await navigator.requestMIDIAccess({ "sysex": false });
+ ok(true, "MIDI Access Request successful");
+ } catch (e) {
+ ok(false, "MIDI Access Request failed!");
+ SimpleTest.finish();
+ return;
+ }
+ is(midi_access.sysexEnabled, false, "Sysex should be false");
+ output = midi_access.outputs.get(MIDITestUtils.outputInfo.id);
+ let statePromiseRes;
+ let statePromise = new Promise((res) => { statePromiseRes = res; });
+ await output.open();
+ let stateChangeHandler = (event) => {
+ if (event.port == output) {
+ return;
+ }
+ statePromiseRes(event.port);
+ };
+ midi_access.addEventListener("statechange", stateChangeHandler);
+ // Send command to connect new port.
+ output.send([0x90, 0x01, 0x00]);
+ let p = await statePromise;
+ is(p.state, "connected", "Device " + p.name + " connected");
+
+ // Rebuild our promise, we'll need to await another one.
+ statePromise = new Promise((res) => { statePromiseRes = res; });
+ output.send([0x90, 0x02, 0x00]);
+ p = await statePromise;
+ is(p.state, "disconnected", "Device " + p.name + " disconnected");
+ midi_access.removeEventListener("statechange", stateChangeHandler);
+ SimpleTest.finish();
+ }
+ </script>
+ </body>
+</html>