summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webhid
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/webhid
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webhid')
-rw-r--r--testing/web-platform/tests/webhid/META.yml3
-rw-r--r--testing/web-platform/tests/webhid/idlharness.https.window.js20
-rw-r--r--testing/web-platform/tests/webhid/resources/automation.js42
-rw-r--r--testing/web-platform/tests/webhid/resources/common.js18
-rw-r--r--testing/web-platform/tests/webhid/unload-iframe.https.window.js22
5 files changed, 105 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webhid/META.yml b/testing/web-platform/tests/webhid/META.yml
new file mode 100644
index 0000000000..fbd7f7a58f
--- /dev/null
+++ b/testing/web-platform/tests/webhid/META.yml
@@ -0,0 +1,3 @@
+spec: https://wicg.github.io/webhid/
+suggested_reviewers:
+ - mattreynolds
diff --git a/testing/web-platform/tests/webhid/idlharness.https.window.js b/testing/web-platform/tests/webhid/idlharness.https.window.js
new file mode 100644
index 0000000000..bdc8419ba8
--- /dev/null
+++ b/testing/web-platform/tests/webhid/idlharness.https.window.js
@@ -0,0 +1,20 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+
+'use strict';
+
+// https://wicg.github.io/webhid/
+
+idl_test(
+ ['webhid'],
+ ['html', 'dom'],
+ idl_array => {
+ idl_array.add_objects({
+ HID: ['navigator.hid'],
+ Navigator: ['navigator'],
+ // TODO: HIDConnectionEvent
+ // TODO: HIDInputReportEvent
+ // TODO: HIDDevice
+ });
+ }
+);
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;
+ });
+}
diff --git a/testing/web-platform/tests/webhid/unload-iframe.https.window.js b/testing/web-platform/tests/webhid/unload-iframe.https.window.js
new file mode 100644
index 0000000000..2c0e2c1bb4
--- /dev/null
+++ b/testing/web-platform/tests/webhid/unload-iframe.https.window.js
@@ -0,0 +1,22 @@
+let frame;
+window.unloadChild = function() {
+ document.body.removeChild(frame);
+};
+
+promise_test(async t => {
+ frame = document.createElement('iframe');
+ frame.srcdoc = `<script>
+ navigator.hid.getDevices();
+ window.parent.unloadChild();
+ </script>`;
+ document.body.appendChild(frame);
+}, 'Unload child iframe with pending getDevices promise');
+
+promise_test(async t => {
+ frame = document.createElement('iframe');
+ frame.srcdoc = `<script>
+ navigator.hid.requestDevice({filters: []});
+ window.parent.unloadChild();
+ </script>`;
+ document.body.appendChild(frame);
+}, 'Unload child iframe with pending requestDevice promise');