Skip to content

Truly independent web browser

LibWeb: Test :focus-visible as a focused element's editability changes

Andreas Klingf657e6b0f236
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/focus-visible-as-editability-changes.txt b/Tests/LibWeb/Text/expected/css/style-engine/focus-visible-as-editability-changes.txt
new file mode 100644
index 00000000000..e54c47fe2b7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/focus-visible-as-editability-changes.txt
@@ -0,0 +1,12 @@
+Focused with a pointer: focused true, matches false, rgb(0, 0, 0)
+Ancestor made editable: focused true, matches true, rgb(0, 0, 0)
+Ancestor no longer editable: focused true, matches false, rgb(0, 0, 0)
+Made an editing host: focused true, matches true, rgb(0, 0, 0)
+No longer an editing host: focused true, matches false, rgb(0, 0, 0)
+designMode on: focused false, matches false, rgb(1, 2, 3)
+designMode off: focused false, matches false, rgb(1, 2, 3)
+Moved into an editing host: focused false, matches false, rgb(1, 2, 3)
+Moved out of it: focused false, matches false, rgb(1, 2, 3)
+Checkbox focused with a pointer: focused true, matches false, rgb(0, 0, 0)
+Became a text field: focused true, matches true, rgb(0, 0, 0)
+Became a checkbox: focused true, matches false, rgb(0, 0, 0)
diff --git a/Tests/LibWeb/Text/input/css/style-engine/focus-visible-as-editability-changes.html b/Tests/LibWeb/Text/input/css/style-engine/focus-visible-as-editability-changes.html
new file mode 100644
index 00000000000..005b2af9e46
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/focus-visible-as-editability-changes.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<style>
+ :focus-visible {
+ color: rgb(1, 2, 3);
+ }
+ div,
+ input {
+ display: block;
+ width: 100px;
+ height: 20px;
+ }
+</style>
+<div id="ancestor"><div id="focusable" tabindex="0"></div></div>
+<input id="input" type="checkbox">
+<div id="editable" contenteditable></div>
+<script src="../../include.js"></script>
+<script>
+ test(() => {
+ const element = id => document.getElementById(id);
+
+ function focusWithPointer(target) {
+ const rect = target.getBoundingClientRect();
+ internals.mouseDown(rect.x + rect.width / 2, rect.y + rect.height / 2);
+ internals.mouseUp(rect.x + rect.width / 2, rect.y + rect.height / 2);
+ }
+
+ function report(label, target) {
+ println(`${label}: focused ${document.activeElement === target}, matches ${target.matches(":focus-visible")}, ${getComputedStyle(target).color}`);
+ }
+
+ const focusable = element("focusable");
+ focusWithPointer(focusable);
+ report("Focused with a pointer", focusable);
+ element("ancestor").setAttribute("contenteditable", "");
+ report("Ancestor made editable", focusable);
+ element("ancestor").removeAttribute("contenteditable");
+ report("Ancestor no longer editable", focusable);
+ focusable.setAttribute("contenteditable", "");
+ report("Made an editing host", focusable);
+ focusable.removeAttribute("contenteditable");
+ report("No longer an editing host", focusable);
+ document.designMode = "on";
+ report("designMode on", focusable);
+ document.designMode = "off";
+ report("designMode off", focusable);
+ element("editable").moveBefore(focusable, null);
+ report("Moved into an editing host", focusable);
+ element("ancestor").moveBefore(focusable, null);
+ report("Moved out of it", focusable);
+
+ const input = element("input");
+ focusWithPointer(input);
+ report("Checkbox focused with a pointer", input);
+ input.type = "text";
+ report("Became a text field", input);
+ input.type = "checkbox";
+ report("Became a checkbox", input);
+ });
+</script>