Skip to content

Truly independent web browser

LibWeb: Add test for select() focusing text controls

Andreas Kling78a10de66b2d
diff --git a/Tests/LibWeb/Text/expected/HTML/select-focuses-text-control.txt b/Tests/LibWeb/Text/expected/HTML/select-focuses-text-control.txt
new file mode 100644
index 00000000000..97d22c20449
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/select-focuses-text-control.txt
@@ -0,0 +1,12 @@
+empty-input: activeElement=BODY
+empty-input: selection=0-0
+filled-input: activeElement=BODY
+filled-input: selection=0-5
+textarea: activeElement=BODY
+textarea: selection=0-5
+scrollY: 0
+disabled-input: activeElement=BODY
+disabled-input: selection=0-8
+type-changing-input: activeElement=BODY
+type-changing-input: selection=0-4
+events:
diff --git a/Tests/LibWeb/Text/input/HTML/select-focuses-text-control.html b/Tests/LibWeb/Text/input/HTML/select-focuses-text-control.html
new file mode 100644
index 00000000000..50ac3c2a7e3
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/select-focuses-text-control.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<div style="height: 3000px"></div>
+<input id="empty-input">
+<input id="filled-input" value="hello">
+<textarea id="textarea">world</textarea>
+<input id="disabled-input" value="disabled" disabled>
+<input id="type-changing-input" value="text">
+<script>
+ test(() => {
+ const ids = ["empty-input", "filled-input", "textarea", "disabled-input", "type-changing-input"];
+ const log = [];
+ for (const id of ids) {
+ const element = document.getElementById(id);
+ element.addEventListener("focus", () => log.push(`focus ${id}`));
+ element.addEventListener("blur", () => log.push(`blur ${id}`));
+ }
+
+ const typeChangingInput = document.getElementById("type-changing-input");
+ typeChangingInput.addEventListener("focus", () => { typeChangingInput.type = "checkbox"; });
+
+ for (const id of ids) {
+ const element = document.getElementById(id);
+ element.select();
+ println(`${id}: activeElement=${document.activeElement.id || document.activeElement.nodeName}`);
+ println(`${id}: selection=${element.selectionStart}-${element.selectionEnd}`);
+ if (id === "textarea")
+ println(`scrollY: ${window.scrollY}`);
+ }
+
+ println(`events: ${log.join(", ")}`);
+ });
+</script>