summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webhid
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/webhid
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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/WEB_FEATURES.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
6 files changed, 108 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/WEB_FEATURES.yml b/testing/web-platform/tests/webhid/WEB_FEATURES.yml
new file mode 100644
index 0000000000..7453658f78
--- /dev/null
+++ b/testing/web-platform/tests/webhid/WEB_FEATURES.yml
@@ -0,0 +1,3 @@
+features:
+- name: webhid
+ files: "**"
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');