summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webhid/resources/common.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/webhid/resources/common.js')
-rw-r--r--testing/web-platform/tests/webhid/resources/common.js18
1 files changed, 18 insertions, 0 deletions
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;
+ });
+}