diff options
Diffstat (limited to 'testing/web-platform/tests/serial/resources/manual.js')
-rw-r--r-- | testing/web-platform/tests/serial/resources/manual.js | 38 |
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); +} |