Skip to content

Truly independent web browser

Tests/LibWeb: Test main thread keys after one with nothing to scroll

Andreas Kling3e712218fd19
diff --git a/Tests/LibWeb/Text/expected/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.txt b/Tests/LibWeb/Text/expected/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.txt
new file mode 100644
index 00000000000..4cd715cd5a0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.txt
@@ -0,0 +1,2 @@
+keys the page heard of: ArrowUp, ArrowDown
+main thread offset: 0
diff --git a/Tests/LibWeb/Text/input/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.html b/Tests/LibWeb/Text/input/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.html
new file mode 100644
index 00000000000..453d78f6160
--- /dev/null
+++ b/Tests/LibWeb/Text/input/async-scrolling/key-on-the-main-thread-after-a-key-with-nothing-to-scroll.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 5000px;
+ }
+</style>
+<script>
+ // A blocking listener leaves keys to the main thread, which may handle several together once a task ends. A key at
+ // the end of the scroll range goes nowhere, and takes nothing away from the key after it.
+ promiseTest(async () => {
+ const keys = [];
+ addEventListener("keydown", () => {});
+ document.addEventListener("keyup", event => keys.push(event.key));
+ await animationFrame();
+ await animationFrame();
+ internals.synchronizeCompositor();
+
+ internals.sendKeyThroughUIProcess("Up");
+ internals.sendKeyThroughUIProcess("Down");
+ const waitUntil = performance.now() + 100;
+ while (performance.now() < waitUntil) {
+ // Stay in this task, so that the main thread handles the keys together.
+ }
+
+ // NB: This only gives up on what never comes, so the time limit can't fail a slow machine's run of a fixed engine.
+ const giveUpAt = performance.now() + 5000;
+ while ((keys.length < 2 || window.scrollY !== 100) && performance.now() < giveUpAt) await animationFrame();
+ println(`keys the page heard of: ${keys.join(", ")}`);
+ println(`main thread offset: ${window.scrollY}`);
+ });
+</script>