summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/gamepad/timestamp-manual.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/gamepad/timestamp-manual.html
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/gamepad/timestamp-manual.html')
-rw-r--r--testing/web-platform/tests/gamepad/timestamp-manual.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/testing/web-platform/tests/gamepad/timestamp-manual.html b/testing/web-platform/tests/gamepad/timestamp-manual.html
new file mode 100644
index 0000000000..a2808dd0e0
--- /dev/null
+++ b/testing/web-platform/tests/gamepad/timestamp-manual.html
@@ -0,0 +1,58 @@
+<!doctype html>
+<html>
+<head>
+<title>Manual Gamepad timestamp tests</title>
+<link rel="help" href="https://w3c.github.io/gamepad/#dom-gamepad-timestamp">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+setup({explicit_timeout: true});
+
+function set_instructions(text) {
+ document.getElementById("instructions").textContent = text;
+}
+
+var index = -1;
+var lastTimestamp = performance.now();
+var id = -1;
+addEventListener("gamepadconnected", function (e) {
+ assert_equals(index, -1, "Too many connected events?");
+ index = e.gamepad.index;
+ assert_greater_than(e.gamepad.timestamp, lastTimestamp, "timestamp should be increasing");
+ lastTimestamp = e.gamepad.timestamp;
+ set_instructions("Found a gamepad. Now release the button you pressed and press it again.");
+ // There may not be a button pressed here, so handle it cleanly either way.
+ if (e.gamepad.buttons.some(function (b) { return b.pressed; })) {
+ id = setInterval(waitForButtonRelease, 15);
+ } else {
+ id = setInterval(waitForButtonPress, 15);
+ }
+});
+
+function waitForButtonRelease() {
+ var gamepad = navigator.getGamepads()[index];
+ assert_true(!!gamepad);
+ if (gamepad.buttons.every(function (b) { return !b.pressed; })) {
+ assert_greater_than(gamepad.timestamp, lastTimestamp, "timestamp should be increasing");
+ lastTimestamp = gamepad.timestamp;
+ clearInterval(id);
+ id = setInterval(waitForButtonPress, 15);
+ }
+}
+
+function waitForButtonPress() {
+ var gamepad = navigator.getGamepads()[index];
+ assert_true(!!gamepad);
+ if (gamepad.buttons.some(function (b) { return b.pressed; })) {
+ assert_greater_than(gamepad.timestamp, lastTimestamp, "timestamp should be increasing");
+ clearInterval(id);
+ done();
+ }
+}
+
+</script>
+</head>
+<body>
+<p id="instructions">This test requires a gamepad. Connect one and press any button to start the test.</p>
+</body>
+</html>