Skip to content

Truly independent web browser

LibWeb: Add keyboard activation coverage

Andreas Klingf85e82290676
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index df85ec06301..b6a8edca7fb 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1,4 +1,5 @@
[LoadFromHttpServer]
+Text/input/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.html
Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/
; These custom-element fixtures fetch a detached document by XHR.
Text/input/wpt-import/custom-elements/adopted-callback.html
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.txt
new file mode 100644
index 00000000000..f12aaa50599
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Button activation submits on keyup, but not if keydown is defaultPrevented
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.txt
new file mode 100644
index 00000000000..08ef893e9f6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 6 tests
+
+6 Pass
+Pass Dispatching untrusted keypress events to submit button should not cause click event
+Pass Dispatching untrusted keyup/keydown events to submit button should not cause click event
+Pass Dispatching untrusted keypress events to reset button should not cause click event
+Pass Dispatching untrusted keyup/keydown events to reset button should not cause click event
+Pass Dispatching untrusted keypress events to button button should not cause click event
+Pass Dispatching untrusted keyup/keydown events to button button should not cause click event
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.txt
new file mode 100644
index 00000000000..05c702c85af
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 4 tests
+
+4 Pass
+Pass Space key shouldn't active the checkbox when it's disabled by a keydown event listener
+Pass Space key shouldn't active the radio when it's disabled by a keydown event listener
+Pass Space key press shouldn't activate the disabled checkbox
+Pass Space key press shouldn't activate the disabled radio
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.txt
new file mode 100644
index 00000000000..21857906a01
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass Space key shouldn't active the checkbox when its default is prevented
+Pass Space key shouldn't active the radio when its default is prevented
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.txt
new file mode 100644
index 00000000000..3c48c197e80
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass Space key shouldn't active the checkbox when space key press is emulated by untrusted events
+Pass Space key shouldn't active the radio when space key press is emulated by untrusted events
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.txt
new file mode 100644
index 00000000000..4b42f12526b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.txt
@@ -0,0 +1,49 @@
+Harness status: OK
+
+Found 44 tests
+
+44 Pass
+Pass Dispatching untrusted keypress events to input button should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input button should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input checkbox should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input checkbox should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input color should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input color should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input date should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input date should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input datetime-local should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input datetime-local should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input email should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input email should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input file should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input file should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input hidden should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input hidden should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input image should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input image should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input month should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input month should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input number should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input number should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input password should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input password should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input radio should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input radio should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input range should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input range should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input reset should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input reset should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input search should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input search should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input submit should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input submit should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input tel should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input tel should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input text should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input text should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input time should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input time should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input url should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input url should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keypress events to input week should not cause submission, click, change, input, or focus events
+Pass Dispatching untrusted keyup/keydown events to input week should not cause submission, click, change, input, or focus events
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.txt
new file mode 100644
index 00000000000..fb8b4d4f9ac
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Details activation with space bar
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.txt
new file mode 100644
index 00000000000..3e89a61a3aa
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass Dispatching untrusted keypress events to summary should not cause click event
+Pass Dispatching untrusted keyup/keydown events to summary should not cause click event
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.html
new file mode 100644
index 00000000000..6b34de1d354
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-activate-keyup-prevented.html
@@ -0,0 +1,38 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Button activation submits on keyup, but not if keydown is defaultPrevented</title>
+<link rel=help href="https://bugzilla.mozilla.org/show_bug.cgi?id=1481400">
+<link rel=author href="mailto:[email protected]" title="Emilio Cobos Álvarez">
+<link rel=author href="https://mozilla.org" title="Mozilla">
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="../../../../resources/testdriver.js"></script>
+<script src="../../../../resources/testdriver-vendor.js"></script>
+<button>The button</button>
+<script>
+let button = document.querySelector("button");
+promise_test(async t => {
+ button.focus();
+ assert_equals(document.activeElement, button, "Button should be focused");
+ let clickPromise = new Promise(resolve => {
+ button.addEventListener("click", resolve, { once: true });
+ });
+
+ await test_driver.send_keys(button, " ");
+
+ await clickPromise;
+
+ assert_true(true, "Button should have activated");
+
+ document.addEventListener("keydown", t.step_func(function(e) {
+ e.preventDefault();
+ }));
+
+ button.addEventListener("click", t.unreached_func("button got incorrectly activated"));
+
+ await test_driver.send_keys(button, " ");
+
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ assert_true(true, "Button should not have activated");
+});
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.html
new file mode 100644
index 00000000000..619117854b2
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-button-element/button-untrusted-key-event.html
@@ -0,0 +1,112 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Forms</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<form id="input_form">
+ <button name="submitButton" type="submit">Submit</button>
+ <button name="resetButton" type="reset">Reset</button>
+ <button name="buttonButton" type="button">Button</button>
+</form>
+<script type="module">
+const form = document.querySelector("form");
+form.addEventListener("submit", (e) => {
+ e.preventDefault();
+ assert_true(false, 'form should not be submitted');
+});
+
+for (const button of document.querySelectorAll("button")) {
+ button.addEventListener("click", function(e) {
+ assert_true(false, `${button.type} button should not be clicked`);
+ });
+}
+
+// Create and append button elements
+for (const button of document.querySelectorAll("button")) {
+ test(() => {
+ // keyCode: Enter
+ button.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ button.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ button.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ button.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: " ",
+ })
+ );
+ }, `Dispatching untrusted keypress events to ${button.type} button should not cause click event`);
+
+ test(() => {
+ // keyCode: Enter
+ button.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 13,
+ })
+ );
+ button.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ button.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "Enter",
+ })
+ );
+ button.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ button.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 32,
+ })
+ );
+ button.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ button.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: " ",
+ })
+ );
+ button.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: " ",
+ })
+ );
+ }, `Dispatching untrusted keyup/keydown events to ${button.type} button should not cause click event`);
+}
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.html
new file mode 100644
index 00000000000..e1a38c5b246
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-being-disabled.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Tests active state of checkbox/radio when pressing space key but it's disabled by a keydown event listener</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="../../../../resources/testdriver.js"></script>
+<script src="../../../../resources/testdriver-actions.js"></script>
+<script src="../../../../resources/testdriver-vendor.js"></script>
+</head>
+<body>
+<input type="checkbox">
+<input type="radio">
+<script>
+const spaceKey = "\uE00D";
+
+function disableTarget(event) {
+ event.target.disabled = true;
+}
+
+// If a `keydown` event listener disables the event target, default event
+// handler in browser shouldn't activate the disabled element. Otherwise,
+// the browser loses a chance to inactivate the disabled element because
+// it won't get keyup events until it's enabled again.
+
+promise_test(async t => {
+ const checkbox = document.querySelector("input[type=checkbox]");
+ checkbox.focus();
+ checkbox.addEventListener("keydown", disableTarget);
+ await (new test_driver.Actions()).keyDown(spaceKey).send();
+ let released = false;
+ t.add_cleanup(async () => {
+ if (!released) {
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ }
+ checkbox.removeEventListener("keydown", disableTarget);
+ checkbox.remove();
+ });
+ test(() => {
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The checkbox shouldn't be activated"
+ );
+ }, "Space key press shouldn't activate the disabled checkbox");
+
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ released = true;
+
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The disabled checkbox should be inactivated even if activated accidentally"
+ );
+}, "Space key shouldn't active the checkbox when it's disabled by a keydown event listener");
+
+promise_test(async t => {
+ const radio = document.querySelector("input[type=radio]");
+ radio.focus();
+ radio.addEventListener("keydown", disableTarget);
+ await (new test_driver.Actions()).keyDown(spaceKey).send();
+ let released = false;
+ t.add_cleanup(async () => {
+ if (!released) {
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ }
+ radio.removeEventListener("keydown", disableTarget);
+ radio.disabled = false;
+ });
+ test(() => {
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The radio shouldn't be activated"
+ );
+ }, "Space key press shouldn't activate the disabled radio");
+
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ released = true;
+
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The disabled radio should be inactivated even if it's accidentally activated"
+ );
+}, "Space key shouldn't active the radio when it's disabled by a keydown event listener");
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.html
new file mode 100644
index 00000000000..f14ba05a385
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-prevented-default.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Tests active state of checkbox/radio when pressing space key but its default prevented</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="../../../../resources/testdriver.js"></script>
+<script src="../../../../resources/testdriver-actions.js"></script>
+<script src="../../../../resources/testdriver-vendor.js"></script>
+</head>
+<body>
+<input type="checkbox">
+<input type="radio">
+<script>
+const spaceKey = "\uE00D";
+
+function preventDefault(event) {
+ event.preventDefault();
+}
+
+promise_test(async t => {
+ const checkbox = document.querySelector("input[type=checkbox]");
+ checkbox.focus();
+ checkbox.addEventListener("keydown", preventDefault);
+ await (new test_driver.Actions()).keyDown(spaceKey).send();
+ t.add_cleanup(async () => {
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ checkbox.removeEventListener("keydown", preventDefault);
+ });
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The checkbox shouldn't be activated"
+ );
+}, "Space key shouldn't active the checkbox when its default is prevented");
+
+promise_test(async t => {
+ const radio = document.querySelector("input[type=radio]");
+ radio.focus();
+ radio.addEventListener("keydown", preventDefault);
+ await (new test_driver.Actions()).keyDown(spaceKey).send();
+ t.add_cleanup(async () => {
+ await (new test_driver.Actions()).keyUp(spaceKey).send();
+ radio.removeEventListener("keydown", preventDefault);
+ });
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The radio shouldn't be activated"
+ );
+}, "Space key shouldn't active the radio when its default is prevented");
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.html
new file mode 100644
index 00000000000..7e045269053
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/checkable-active-space-key-untrusted-event.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Tests active state of checkbox/radio when pressing space key emulated with untrusted key events</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+<input type="checkbox">
+<input type="radio">
+<script>
+function sendSpaceKeyEvent(eventType, target) {
+ const eventData = { keyCode: 32, which: 32, key: " ", code: "Space"};
+ const spaceKeyEvent = new KeyboardEvent(eventType, eventData);
+ target.dispatchEvent(spaceKeyEvent);
+}
+
+test(t => {
+ const checkbox = document.querySelector("input[type=checkbox]");
+ checkbox.focus();
+ sendSpaceKeyEvent("keydown", checkbox);
+ t.add_cleanup(() => {
+ sendSpaceKeyEvent("keyup", checkbox);
+ });
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The checkbox shouldn't be activated"
+ );
+}, "Space key shouldn't active the checkbox when space key press is emulated by untrusted events");
+
+test(t => {
+ const radio = document.querySelector("input[type=radio]");
+ radio.focus();
+ sendSpaceKeyEvent("keydown", radio);
+ t.add_cleanup(() => {
+ sendSpaceKeyEvent("keyup", radio);
+ });
+ assert_equals(
+ document.querySelector("input:active"),
+ null,
+ "The radio shouldn't be activated"
+ );
+}, "Space key shouldn't active the radio when space key press is emulated by untrusted events");
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.html
new file mode 100644
index 00000000000..9e0e0f123fe
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-untrusted-key-event.html
@@ -0,0 +1,225 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Forms</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<form id="input_form">
+ <fieldset>
+ <input type="radio" name="radio" value="1">
+ <input type="radio" name="radio" value="2">
+ </fieldset>
+</form>
+<script type="module">
+import inputTypes from "./input-types.js";
+
+const form = document.querySelector("form");
+form.addEventListener("submit", (e) => {
+ e.preventDefault();
+ assert_true(false, 'form should not be submitted');
+});
+
+const radioButton = document.querySelector("input[type=radio]");
+radioButton.addEventListener("click", function(e) {
+ assert_true(false, `input radio should not be clicked`);
+});
+radioButton.addEventListener("focus", function(e) {
+ assert_true(false, `input radio should not be focused on`);
+});
+radioButton.addEventListener("change", function(e) {
+ assert_true(false, `input radio should not be changed`);
+});
+radioButton.addEventListener("input", function(e) {
+ assert_true(false, `input radio should not have been inputted`);
+});
+
+// Create and append input elements
+for (const inputType of inputTypes) {
+ if (inputType == "radio") {
+ continue;
+ }
+
+ let input = document.createElement("input");
+ input.type = inputType;
+ form.appendChild(input);
+
+ input.addEventListener("click", function(e) {
+ assert_true(false, `input ${inputType} should not be clicked`);
+ });
+ input.addEventListener("focus", function(e) {
+ assert_true(false, `input ${inputType} should not be focused on`);
+ });
+ input.addEventListener("change", function(e) {
+ assert_true(false, `input ${inputType} should not be changed`);
+ });
+ input.addEventListener("input", function(e) {
+ assert_true(false, `input ${inputType} should not have been inputted`);
+ });
+}
+
+// Start tests
+for (const inputType of inputTypes) {
+ let input = document.querySelector(`input[type=${inputType}]`);
+
+ test(() => {
+ // keyCode: Enter
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: " ",
+ })
+ );
+
+ // keyCode: Tab
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 9,
+ })
+ );
+
+ // key: Tab
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: "Tab",
+ })
+ );
+
+ // keyCode: ArrowUp
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 38,
+ })
+ );
+
+ // key: ArrowUp
+ input.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: "ArrowUp",
+ })
+ );
+ }, `Dispatching untrusted keypress events to input ${inputType} should not cause submission, click, change, input, or focus events`);
+
+ test(() => {
+ // keyCode: Enter
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 13,
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "Enter",
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 32,
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: " ",
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: " ",
+ })
+ );
+
+ // keyCode: Tab
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 9,
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 9,
+ })
+ );
+
+ // key: Tab
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "Tab",
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: "Tab",
+ })
+ );
+
+ // keyCode: ArrowUp
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 38,
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 38,
+ })
+ );
+
+ // key: ArrowUp
+ input.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "ArrowUp",
+ })
+ );
+ input.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: "ArrowUp",
+ })
+ );
+ }, `Dispatching untrusted keyup/keydown events to input ${inputType} should not cause submission, click, change, input, or focus events`);
+}
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.html
new file mode 100644
index 00000000000..0c202a62723
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-details-element/details-keyboard-activation.html
@@ -0,0 +1,52 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Details activation with space bar</title>
+<link rel="author" href="mailto:[email protected]" title="Emilio Cobos Álvarez">
+<link rel="author" href="https://mozilla.org" title="Mozilla">
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1726454">
+<script src=../../../../resources/testharness.js></script>
+<script src=../../../../resources/testharnessreport.js></script>
+<script src="../../../../resources/testdriver.js"></script>
+<script src="../../../../resources/testdriver-actions.js"></script>
+<script src="../../../../resources/testdriver-vendor.js"></script>
+<style>
+:root {
+ scroll-behavior: instant;
+}
+.spacer {
+ height: 200vh;
+}
+</style>
+<details>
+ <summary>Activate me with the <kbd>Space</kbd> key</summary>
+ <p>Summary</p>
+</details>
+<div class="spacer"></div>
+<script>
+function tick() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+}
+
+promise_test(async t => {
+ const details = document.querySelector("details");
+ const summary = details.querySelector("summary");
+
+ summary.focus();
+ assert_equals(document.activeElement, summary, "Summary should be focusable");
+ assert_false(details.open, "Details should be closed");
+
+ const oldScrollY = window.scrollY;
+ assert_equals(oldScrollY, 0, "Should be at top");
+
+ window.addEventListener("scroll", t.unreached_func("Unexpected scroll event"));
+
+ await test_driver.send_keys(summary, " ");
+
+ assert_true(details.open, "Space bar on summary should open details");
+ assert_equals(window.scrollY, oldScrollY, "Scroll position shouldn't change");
+
+ await tick();
+
+ assert_equals(window.scrollY, oldScrollY, "Scroll position shouldn't change");
+});
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.html
new file mode 100644
index 00000000000..c2409f56e1b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-summary-element/summary-untrusted-key-event.html
@@ -0,0 +1,104 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Summary</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<details>
+ <summary>Summary</summary>
+ Details
+</details>
+<script type="module">
+const details = document.querySelector("details");
+details.addEventListener("toggle",
+ (e) => assert_true(false, 'details should not be toggled'));
+
+const summary = document.querySelector("summary");
+summary.addEventListener("click",
+ (e) => assert_true(false, `summary should not be clicked`));
+
+test(() => {
+ // keyCode: Enter
+ summary.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ summary.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ summary.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ summary.dispatchEvent(
+ new KeyboardEvent("keypress", {
+ key: " ",
+ })
+ );
+}, `Dispatching untrusted keypress events to summary should not cause click event`);
+
+test(() => {
+ // keyCode: Enter
+ summary.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 13,
+ })
+ );
+ summary.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 13,
+ })
+ );
+
+ // key: Enter
+ summary.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "Enter",
+ })
+ );
+ summary.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: "Enter",
+ })
+ );
+
+ // keyCode: Space
+ summary.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ keyCode: 32,
+ })
+ );
+ summary.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ keyCode: 32,
+ })
+ );
+
+ // key: Space
+ summary.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: " ",
+ })
+ );
+ summary.dispatchEvent(
+ new KeyboardEvent("keyup", {
+ key: " ",
+ })
+ );
+}, `Dispatching untrusted keyup/keydown events to summary should not cause click event`);
+</script>
+</body>
+</html>