Skip to content

Truly independent web browser

LibWeb: Test caret-color: auto against the element's own color

Andreas Kling9c5194e52d3f
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/caret-color-auto-follows-own-color.txt b/Tests/LibWeb/Text/expected/css/style-engine/caret-color-auto-follows-own-color.txt
new file mode 100644
index 00000000000..82daaa68239
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/caret-color-auto-follows-own-color.txt
@@ -0,0 +1,9 @@
+row 0: color rgb(0, 128, 0), caret-color rgb(0, 128, 0)
+row 1: color rgb(0, 0, 255), caret-color rgb(0, 0, 255)
+row 2: color rgb(255, 0, 0), caret-color rgb(255, 0, 0)
+before: color rgb(0, 128, 0), caret-color rgb(0, 128, 0)
+before inheriting: color rgb(0, 128, 0), caret-color rgb(0, 128, 0)
+before owning: color rgb(1, 2, 3), caret-color rgb(1, 2, 3)
+after: color rgb(255, 0, 0), caret-color rgb(255, 0, 0)
+after inheriting: color rgb(255, 0, 0), caret-color rgb(255, 0, 0)
+after owning: color rgb(1, 2, 3), caret-color rgb(1, 2, 3)
diff --git a/Tests/LibWeb/Text/input/css/style-engine/caret-color-auto-follows-own-color.html b/Tests/LibWeb/Text/input/css/style-engine/caret-color-auto-follows-own-color.html
new file mode 100644
index 00000000000..d50ab87f96a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/caret-color-auto-follows-own-color.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<style>
+ #list > .row:first-child { color: rgb(0, 128, 0); }
+ #list > .row:nth-child(2) { color: rgb(0, 0, 255); }
+ #list > .row:last-child { color: rgb(255, 0, 0); }
+ .green { color: rgb(0, 128, 0); }
+ .red { color: rgb(255, 0, 0); }
+ .own { color: rgb(1, 2, 3); }
+</style>
+<div id="list"><div class="row">a</div><div class="row">b</div><div class="row">c</div></div>
+<div id="changing" class="green">d<span id="inheriting">e</span><span id="owning" class="own">f</span></div>
+<script>
+ function report(label, element) {
+ const style = getComputedStyle(element);
+ println(`${label}: color ${style.color}, caret-color ${style.caretColor}`);
+ }
+
+ test(() => {
+ // Alike siblings whose rules give each another color.
+ for (const [index, row] of [...document.querySelectorAll(".row")].entries())
+ report(`row ${index}`, row);
+
+ // A color that changes after the first style, with a child inheriting it and one declaring its own.
+ const changing = document.getElementById("changing");
+ report("before", changing);
+ report("before inheriting", document.getElementById("inheriting"));
+ report("before owning", document.getElementById("owning"));
+ changing.className = "red";
+ report("after", changing);
+ report("after inheriting", document.getElementById("inheriting"));
+ report("after owning", document.getElementById("owning"));
+ });
+</script>