Truly independent web browser
Tests/LibWeb: Import some CSS anchor positioning WPT tests
Andreas Klingb9c0edd7f374
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-004.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-004.txtnew file mode 100644index 00000000000..34a3d1c466e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-004.txt@@ -0,0 +1,38 @@+Harness status: OK++Found 32 tests++24 Pass+8 Fail+Pass .target 1+Pass .target 2+Pass .target 3+Pass .target 4+Pass .target 5+Pass .target 6+Pass .target 7+Pass .target 8+Pass .target 9+Pass .target 10+Pass .target 11+Pass .target 12+Pass .target 13+Pass .target 14+Pass .target 15+Pass .target 16+Pass .target 17+Pass .target 18+Pass .target 19+Pass .target 20+Pass .target 21+Pass .target 22+Pass .target 23+Pass .target 24+Fail .target 25+Fail .target 26+Fail .target 27+Fail .target 28+Fail .target 29+Fail .target 30+Fail .target 31+Fail .target 32\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.txtnew file mode 100644index 00000000000..504be14c6f7--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.txt@@ -0,0 +1,54 @@+Harness status: OK++Found 48 tests++32 Pass+16 Fail+Pass relpos htb-ltr/target/left: anchor(--a1 start)+Pass relpos htb-ltr/target/left: anchor(--a1 end)+Pass relpos htb-ltr/target/top: anchor(--a1 start)+Pass relpos htb-ltr/target/top: anchor(--a1 end)+Pass relpos htb-ltr/target htb-ltr/left: anchor(--a1 self-start)+Pass relpos htb-ltr/target htb-ltr/left: anchor(--a1 self-end)+Pass relpos htb-ltr/target htb-ltr/top: anchor(--a1 self-start)+Pass relpos htb-ltr/target htb-ltr/top: anchor(--a1 self-end)+Pass relpos htb-rtl/target/left: anchor(--a1 start)+Pass relpos htb-rtl/target/left: anchor(--a1 end)+Pass relpos htb-rtl/target/top: anchor(--a1 start)+Pass relpos htb-rtl/target/top: anchor(--a1 end)+Pass relpos htb-rtl/target htb-rtl/left: anchor(--a1 self-start)+Pass relpos htb-rtl/target htb-rtl/left: anchor(--a1 self-end)+Pass relpos htb-rtl/target htb-rtl/top: anchor(--a1 self-start)+Pass relpos htb-rtl/target htb-rtl/top: anchor(--a1 self-end)+Fail relpos vrl-ltr/target/left: anchor(--a1 start)+Fail relpos vrl-ltr/target/left: anchor(--a1 end)+Pass relpos vrl-ltr/target/top: anchor(--a1 start)+Pass relpos vrl-ltr/target/top: anchor(--a1 end)+Fail relpos vrl-ltr/target vrl-ltr/left: anchor(--a1 self-start)+Fail relpos vrl-ltr/target vrl-ltr/left: anchor(--a1 self-end)+Pass relpos vrl-ltr/target vrl-ltr/top: anchor(--a1 self-start)+Pass relpos vrl-ltr/target vrl-ltr/top: anchor(--a1 self-end)+Pass relpos vrl-rtl/target/left: anchor(--a1 start)+Pass relpos vrl-rtl/target/left: anchor(--a1 end)+Fail relpos vrl-rtl/target/top: anchor(--a1 start)+Fail relpos vrl-rtl/target/top: anchor(--a1 end)+Pass relpos vrl-rtl/target vrl-rtl/left: anchor(--a1 self-start)+Pass relpos vrl-rtl/target vrl-rtl/left: anchor(--a1 self-end)+Fail relpos vrl-rtl/target vrl-rtl/top: anchor(--a1 self-start)+Fail relpos vrl-rtl/target vrl-rtl/top: anchor(--a1 self-end)+Pass relpos vlr-ltr/target/left: anchor(--a1 start)+Pass relpos vlr-ltr/target/left: anchor(--a1 end)+Pass relpos vlr-ltr/target/top: anchor(--a1 start)+Pass relpos vlr-ltr/target/top: anchor(--a1 end)+Pass relpos vlr-ltr/target vlr-ltr/left: anchor(--a1 self-start)+Pass relpos vlr-ltr/target vlr-ltr/left: anchor(--a1 self-end)+Pass relpos vlr-ltr/target vlr-ltr/top: anchor(--a1 self-start)+Pass relpos vlr-ltr/target vlr-ltr/top: anchor(--a1 self-end)+Fail relpos vlr-rtl/target/left: anchor(--a1 start)+Fail relpos vlr-rtl/target/left: anchor(--a1 end)+Fail relpos vlr-rtl/target/top: anchor(--a1 start)+Fail relpos vlr-rtl/target/top: anchor(--a1 end)+Fail relpos vlr-rtl/target vlr-rtl/left: anchor(--a1 self-start)+Fail relpos vlr-rtl/target vlr-rtl/left: anchor(--a1 self-end)+Fail relpos vlr-rtl/target vlr-rtl/top: anchor(--a1 self-start)+Fail relpos vlr-rtl/target vlr-rtl/top: anchor(--a1 self-end)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-query-fallback.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-query-fallback.txtnew file mode 100644index 00000000000..0446c29a965--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-query-fallback.txt@@ -0,0 +1,22 @@+Harness status: OK++Found 16 tests++10 Pass+6 Fail+Pass .target 1+Fail .target 2+Pass .target 3+Pass .target 4+Pass .target 5+Pass .target 6+Pass .target 7+Pass .target 8+Pass .target 9+Fail .target 10+Pass .target 11+Pass .target 12+Fail .target 13+Fail .target 14+Fail .target 15+Fail .target 16\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-size-replaced-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-size-replaced-001.txtnew file mode 100644index 00000000000..f1242ca077b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-size-replaced-001.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++4 Pass+8 Fail+Fail .target 1+Fail .target 2+Pass .target 3+Pass .target 4+Fail .target 5+Fail .target 6+Fail .target 7+Fail .target 8+Pass .target 9+Pass .target 10+Fail .target 11+Fail .target 12\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-004.html b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-004.htmlnew file mode 100644index 00000000000..6f84333ce2a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-004.html@@ -0,0 +1,117 @@+<!DOCTYPE html>+<title>The `anchor()` function with percentages</title>+<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#anchor-pos">+<link rel="author" href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/check-layout-th.js"></script>+<script src="support/test-common.js"></script>+<style>+.relpos {+ position: relative;+ width: 200px;+ outline: 1px solid;+}+.vrl-rtl {+ writing-mode: vertical-rl;+ direction: rtl;+}+.spacer {+ background: yellow;+ width: 10px;+ height: 10px;+}+#anchor {+ anchor-name: --a1;+ margin: 20px;+ width: 100px;+ height: 200px;+ background: orange;+}+.target {+ position: absolute;+}+</style>+<body onload="checkLayoutForAnchorPos('.target')">+ <div class="relpos">+ <div class="spacer"></div>+ <div id="anchor"></div>++ <div class="target" style="left: anchor(--a1 0%)"+ data-offset-x="20"></div>+ <div class="target" style="left: anchor(--a1 20%)"+ data-offset-x="40"></div>+ <div class="target" style="left: anchor(--a1 50%)"+ data-offset-x="70"></div>+ <div class="target" style="left: anchor(--a1 center)"+ data-offset-x="70"></div>+ <div class="target" style="left: anchor(--a1 80%)"+ data-offset-x="100"></div>+ <div class="target" style="left: anchor(--a1 100%)"+ data-offset-x="120"></div>++ <div class="target" style="right: anchor(--a1 0%)"+ data-offset-x="20"></div>+ <div class="target" style="right: anchor(--a1 20%)"+ data-offset-x="40"></div>+ <div class="target" style="right: anchor(--a1 50%)"+ data-offset-x="70"></div>+ <div class="target" style="right: anchor(--a1 center)"+ data-offset-x="70"></div>+ <div class="target" style="right: anchor(--a1 80%)"+ data-offset-x="100"></div>+ <div class="target" style="right: anchor(--a1 100%)"+ data-offset-x="120"></div>++ <div class="target" style="top: anchor(--a1 0%)"+ data-offset-y="30"></div>+ <div class="target" style="top: anchor(--a1 20%)"+ data-offset-y="70"></div>+ <div class="target" style="top: anchor(--a1 50%)"+ data-offset-y="130"></div>+ <div class="target" style="top: anchor(--a1 center)"+ data-offset-y="130"></div>+ <div class="target" style="top: anchor(--a1 80%)"+ data-offset-y="190"></div>+ <div class="target" style="top: anchor(--a1 100%)"+ data-offset-y="230"></div>++ <div class="target" style="bottom: anchor(--a1 0%)"+ data-offset-y="30"></div>+ <div class="target" style="bottom: anchor(--a1 20%)"+ data-offset-y="70"></div>+ <div class="target" style="bottom: anchor(--a1 50%)"+ data-offset-y="130"></div>+ <div class="target" style="bottom: anchor(--a1 center)"+ data-offset-y="130"></div>+ <div class="target" style="bottom: anchor(--a1 80%)"+ data-offset-y="190"></div>+ <div class="target" style="bottom: anchor(--a1 100%)"+ data-offset-y="230"></div>+ </div>++ <div class="vrl-rtl relpos">+ <div class="spacer"></div>+ <div id="anchor"></div>++ <div class="target" style="left: anchor(--a1 0%)"+ data-offset-x="170"></div>+ <div class="target" style="left: anchor(--a1 100%)"+ data-offset-x="70"></div>++ <div class="target" style="right: anchor(--a1 0%)"+ data-offset-x="170"></div>+ <div class="target" style="right: anchor(--a1 100%)"+ data-offset-x="70"></div>++ <div class="target" style="top: anchor(--a1 0%)"+ data-offset-y="220"></div>+ <div class="target" style="top: anchor(--a1 100%)"+ data-offset-y="20"></div>++ <div class="target" style="bottom: anchor(--a1 0%)"+ data-offset-y="220"></div>+ <div class="target" style="bottom: anchor(--a1 100%)"+ data-offset-y="20"></div>+ </div>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.html b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.htmlnew file mode 100644index 00000000000..a4febced966--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-position-writing-modes-002.html@@ -0,0 +1,103 @@+<!DOCTYPE html>+<title>Tests logical `anchor` function for `writing-mode`/`direction`s</title>+<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#anchor-pos">+<link rel="author" href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<style>+.htb-ltr { writing-mode: horizontal-tb; direction: ltr; }+.htb-rtl { writing-mode: horizontal-tb; direction: rtl; }+.vlr-ltr { writing-mode: vertical-lr; direction: ltr; }+.vlr-rtl { writing-mode: vertical-lr; direction: rtl; }+.vrl-ltr { writing-mode: vertical-rl; direction: ltr; }+.vrl-rtl { writing-mode: vertical-rl; direction: rtl; }+.relpos {+ position: relative;+ outline: blue 1px solid;+}+.spacer {+ width: 10px;+ height: 10px;+ background: yellow;+}+.anchor {+ anchor-name: --a1;+ margin: 5px;+ width: 30px;+ height: 30px;+ background: orange;+}+.target {+ position: absolute;+ outline: 5px solid lime;+}+</style>+<body>+ <template id="template">+ <div class="relpos">+ <div class="spacer"></div>+ <div class="anchor"></div>+ </div>+ </template>+<script>+// Generate tests for all combinations.+// The first two entries are the side `start` and `end` should match in x-axis.+// The next two entries are the side `start` and `end` should match in y-axis.+const writingDirs = {+ 'htb-ltr':['l', 'r', 't', 'b'],+ 'htb-rtl':['r', 'l', 't', 'b'],+ 'vrl-ltr':['r', 'l', 't', 'b'],+ 'vrl-rtl':['r', 'l', 'b', 't'],+ 'vlr-ltr':['l', 'r', 't', 'b'],+ 'vlr-rtl':['l', 'r', 'b', 't'],+};+const container = document.body;+const cb_template = template.content.firstElementChild;+for (const [writingDir, matches] of Object.entries(writingDirs)) {+ const cb = cb_template.cloneNode(true);+ cb.classList.add(writingDir);+ createTarget(null, 'left: anchor(--a1 start)', matches[0], cb);+ createTarget(null, 'left: anchor(--a1 end)', matches[1], cb);+ createTarget(null, 'top: anchor(--a1 start)', matches[2], cb);+ createTarget(null, 'top: anchor(--a1 end)', matches[3], cb);+ createTarget(writingDir, 'left: anchor(--a1 self-start)', matches[0], cb);+ createTarget(writingDir, 'left: anchor(--a1 self-end)', matches[1], cb);+ createTarget(writingDir, 'top: anchor(--a1 self-start)', matches[2], cb);+ createTarget(writingDir, 'top: anchor(--a1 self-end)', matches[3], cb);+ container.appendChild(cb);+}++function createTarget(className, style, match, cb) {+ const target = document.createElement('div');+ target.classList.add('target');+ if (className)+ target.classList.add(className);+ target.style = style;+ target.dataset.name = style;+ target.dataset.match = match;+ cb.appendChild(target);+}++// Test all `.target`s.+for (const target of document.querySelectorAll('.target')) {+ const cb = target.parentElement;+ const anchor = cb.querySelector('.anchor');+ test(() => {+ switch (target.dataset.match) {+ case 'l':+ assert_equals(anchor.offsetLeft, target.offsetLeft);+ break;+ case 'r':+ assert_equals(anchor.offsetLeft + anchor.offsetWidth, target.offsetLeft);+ break;+ case 't':+ assert_equals(anchor.offsetTop, target.offsetTop);+ break;+ case 'b':+ assert_equals(anchor.offsetTop + anchor.offsetHeight, target.offsetTop);+ break;+ }+ }, `${cb.classList}/${target.classList}/${target.dataset.name}`);+}+</script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-query-fallback.html b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-query-fallback.htmlnew file mode 100644index 00000000000..412645183b0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-query-fallback.html@@ -0,0 +1,72 @@+<!DOCTYPE html>+<title>Tests the fallback value in anchor queries</title>+<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#anchor-pos">+<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#anchor-size">+<link rel="author" href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/check-layout-th.js"></script>+<script src="support/test-common.js"></script>+<style>+#container {+ position: relative;+ display: flex;+ flex-wrap: wrap;+ width: 300px;+}++.flex-item {+ width: 100px;+ height: 50px;+ flex: auto;+}++#a1 {+ anchor-name: --a1;+ background: orange;+}+#a2 {+ anchor-name: --a2;+ background: purple;+}++.target {+ position: absolute;+}+</style>++<body onload="checkLayoutForAnchorPos('.target')">+ <div id="container">+ <div class="flex-item" id="a1"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item"></div>+ <div class="flex-item" id="a2"></div>++ <!-- Fallback due to no valid anchor -->+ <div class="target" style="left: anchor(--inexist-anchor left, 50px)" data-offset-x="50"></div>+ <div class="target" style="width: anchor-size(--inexist-anchor width, 50px)" data-expected-width="50"></div>++ <!-- Fallback due to wrong axis for anchor() -->+ <div class="target" style="left: anchor(--a1 top, 50px)" data-offset-x="50"></div>+ <div class="target" style="left: anchor(--a1 bottom, 50px)" data-offset-x="50"></div>+ <div class="target" style="top: anchor(--a1 left, 50px)" data-offset-y="50"></div>+ <div class="target" style="top: anchor(--a1 right, 50px)" data-offset-y="50"></div>++ <!-- More complicated fallback values -->+ <div class="target" style="left: anchor(--inexist-anchor left, 50%)" data-offset-x="150"></div>+ <div class="target" style="left: anchor(--inexist-anchor left, calc(20% + 20px))" data-offset-x="80"></div>+ <div class="target" style="left: calc(anchor(--inexist-anchor left, calc(anchor(--inexist-anchor left, 20%) + 20px)) + 20px)" data-offset-x="100"></div>+ <div class="target" style="left: calc(anchor(--inexist-anchor left, calc(anchor-size(--inexist-anchor width, 20%) + 20px)) + 20px)" data-offset-x="100"></div>+ <div class="target" style="top: anchor(--a1 left, anchor(--a2 top))" data-offset-y="100"></div>+ <div class="target" style="top: anchor(--a1 left, calc((anchor(--a1 bottom) + anchor(--a2 top)) / 2))" data-offset-y="75"></div>+ <div class="target" style="width: anchor-size(--inexist-anchor width, 50%)" data-expected-width="150"></div>+ <div class="target" style="width: anchor-size(--inexist-anchor width, calc(20% + 20px))" data-expected-width="80"></div>+ <div class="target" style="height: anchor-size(--inexist-anchor height, anchor-size(--a1 width))" data-expected-height="100"></div>+ <div class="target" style="height: anchor-size(--inexist-anchor height, calc((anchor-size(--a1 width) + anchor-size(--a2 height)) / 2))" data-expected-height="75"></div>+ </div>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-size-replaced-001.html b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-size-replaced-001.htmlnew file mode 100644index 00000000000..6e25b5d846b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/anchor-size-replaced-001.html@@ -0,0 +1,75 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#propdef-anchor-name">+<link rel="author" href="mailto:[email protected]">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/check-layout-th.js"></script>+<script src="support/test-common.js"></script>+<style>+.container {+ position: relative;+ height: 10px;+}+.anchor1 {+ anchor-name: --a1;+ width: 5px;+ height: 24px;+ background: orange;+}+.target {+ position: absolute;+}+</style>+<body onload="checkLayoutForAnchorPos('.target')">+ <div class="container">+ <div class="anchor1"></div>++ <!-- Specifying the width or the height should scale uniformly. -->+ <img class="target" src="support/green-16x16.png"+ style="width: anchor-size(--a1 width)"+ data-expected-width=5 data-expected-height=5>+ <img class="target" src="support/green-16x16.png"+ style="height: anchor-size(--a1 width)"+ data-expected-width=5 data-expected-height=5>++ <!-- Smaller `min-width/height` than the natural size should be ignored. -->+ <img class="target" src="support/green-16x16.png"+ style="min-width: anchor-size(--a1 width)"+ data-expected-width=16 data-expected-height=16>+ <img class="target" src="support/green-16x16.png"+ style="min-height: anchor-size(--a1 width)"+ data-expected-width=16 data-expected-height=16>++ <!-- Larger `min-width/height` than the natural size should scale. -->+ <img class="target" src="support/green-16x16.png"+ style="min-width: anchor-size(--a1 height)"+ data-expected-width=24 data-expected-height=24>+ <img class="target" src="support/green-16x16.png"+ style="min-height: anchor-size(--a1 height)"+ data-expected-width=24 data-expected-height=24>++ <!-- Smaller `max-width/height` than the natural size should scale. -->+ <img class="target" src="support/green-16x16.png"+ style="max-width: anchor-size(--a1 width)"+ data-expected-width=5 data-expected-height=5>+ <img class="target" src="support/green-16x16.png"+ style="max-height: anchor-size(--a1 width)"+ data-expected-width=5 data-expected-height=5>++ <!-- Larger `min-width/height` than the natural size should be ignored. -->+ <img class="target" src="support/green-16x16.png"+ style="max-width: anchor-size(--a1 height)"+ data-expected-width=16 data-expected-height=16>+ <img class="target" src="support/green-16x16.png"+ style="max-height: anchor-size(--a1 height)"+ data-expected-width=16 data-expected-height=16>++ <!-- The `aspect-ratio` property should be honored. -->+ <img class="target" src="support/green-16x16.png"+ style="width: anchor-size(--a1 width); aspect-ratio: 0.5"+ data-expected-width=5 data-expected-height=10>+ <img class="target" src="support/green-16x16.png"+ style="height: anchor-size(--a1 width); aspect-ratio: 2"+ data-expected-width=10 data-expected-height=5>+ </div>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/support/green-16x16.png b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/support/green-16x16.pngnew file mode 100644index 00000000000..e19a3ffddd2Binary files /dev/null and b/Tests/LibWeb/Text/input/wpt-import/css/css-anchor-position/support/green-16x16.png differ