diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/webhid/resources | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webhid/resources')
-rw-r--r-- | testing/web-platform/tests/webhid/resources/automation.js | 42 | ||||
-rw-r--r-- | testing/web-platform/tests/webhid/resources/common.js | 18 |
2 files changed, 60 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webhid/resources/automation.js b/testing/web-platform/tests/webhid/resources/automation.js new file mode 100644 index 0000000000..f7477d1ecc --- /dev/null +++ b/testing/web-platform/tests/webhid/resources/automation.js @@ -0,0 +1,42 @@ +'use strict'; + +let fakeHidService = undefined; + +function hid_test(func, name, properties) { + promise_test(async (test) => { + assert_implements(navigator.hid, 'missing navigator.hid'); + if (fakeHidService === undefined) { + // Try loading a polyfill for the fake hid service. + if (isChromiumBased) { + const fakes = await import('/resources/chromium/fake-hid.js'); + fakeHidService = fakes.fakeHidService; + } + } + assert_implements( + fakeHidService, 'missing fakeHidService after initialization'); + + fakeHidService.start(); + try { + await func(test, fakeHidService); + } finally { + fakeHidService.stop(); + fakeHidService.reset(); + } + }, name, properties); +} + +function trustedClick() { + return new Promise(resolve => { + let button = document.createElement('button'); + button.textContent = 'click to continue test'; + button.style.display = 'block'; + button.style.fontSize = '20px'; + button.style.padding = '10px'; + button.onclick = () => { + document.body.removeChild(button); + resolve(); + }; + document.body.appendChild(button); + test_driver.click(button); + }); +} diff --git a/testing/web-platform/tests/webhid/resources/common.js b/testing/web-platform/tests/webhid/resources/common.js new file mode 100644 index 0000000000..1d0904af83 --- /dev/null +++ b/testing/web-platform/tests/webhid/resources/common.js @@ -0,0 +1,18 @@ +// Compare two DataViews byte-by-byte. +function compareDataViews(actual, expected) { + assert_true(actual instanceof DataView, 'actual is DataView'); + assert_true(expected instanceof DataView, 'expected is DataView'); + assert_equals(actual.byteLength, expected.byteLength, 'lengths equal'); + for (let i = 0; i < expected.byteLength; ++i) { + assert_equals( + actual.getUint8(i), expected.getUint8(i), `Mismatch at byte ${i}.`); + } +} + +// Returns a Promise that resolves once |device| receives an input report. +function oninputreport(device) { + assert_true(device instanceof HIDDevice); + return new Promise(resolve => { + device.oninputreport = resolve; + }); +} |