summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/serial/resources/manual.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/serial/resources/manual.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/serial/resources/manual.js')
-rw-r--r--testing/web-platform/tests/serial/resources/manual.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/testing/web-platform/tests/serial/resources/manual.js b/testing/web-platform/tests/serial/resources/manual.js
new file mode 100644
index 0000000000..ac19136b35
--- /dev/null
+++ b/testing/web-platform/tests/serial/resources/manual.js
@@ -0,0 +1,38 @@
+let manualTestPort = null;
+
+navigator.serial.addEventListener('disconnect', (e) => {
+ if (e.target === manualTestPort) {
+ manualTestPort = null;
+ }
+})
+
+async function getPortForManualTest() {
+ if (manualTestPort) {
+ return manualTestPort;
+ }
+
+ const button = document.createElement('button');
+ button.textContent = 'Click to select a device';
+ button.style.display = 'block';
+ button.style.fontSize = '20px';
+ button.style.padding = '10px';
+
+ await new Promise((resolve) => {
+ button.onclick = () => {
+ document.body.removeChild(button);
+ resolve();
+ };
+ document.body.appendChild(button);
+ });
+
+ manualTestPort = await navigator.serial.requestPort({filters: []});
+ assert_true(manualTestPort instanceof SerialPort);
+
+ return manualTestPort;
+}
+
+function manual_serial_test(func, name, properties) {
+ promise_test(async (test) => {
+ await func(test, await getPortForManualTest());
+ }, name, properties);
+}