Skip to content

Truly independent web browser

Tests/LibWeb: Import WPT tests for offsets of sticky positioned boxes

Andreas Kling37c1cde6f60c
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.txt
new file mode 100644
index 00000000000..1d8c5b7d86d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail .grid 1
+Fail .grid 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.txt
new file mode 100644
index 00000000000..1d8c5b7d86d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail .grid 1
+Fail .grid 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-bottom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-bottom.txt
new file mode 100644
index 00000000000..30ca414736f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-bottom.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Pass before reaching the sticking point the sticky box should not be offset
+Fail after reaching the sticking point the sticky box should be offset
+Fail the sticky box should not be pushed outside its containing block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-inflow-position.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-inflow-position.txt
new file mode 100644
index 00000000000..31605eff3b0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-inflow-position.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail sticky offset should not affect the position of other elements.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-left.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-left.txt
new file mode 100644
index 00000000000..30ca414736f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-left.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Pass before reaching the sticking point the sticky box should not be offset
+Fail after reaching the sticking point the sticky box should be offset
+Fail the sticky box should not be pushed outside its containing block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-margins.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-margins.txt
new file mode 100644
index 00000000000..eaaaede55f2
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-margins.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Pass Before sticking, the margin should be obeyed.
+Fail Whilst stuck, the margin is irrelevant.
+Fail The margin is taken into account when making sure the sticky element does not escape its container
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.txt
new file mode 100644
index 00000000000..16501993c03
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 5 tests
+
+2 Pass
+3 Fail
+Pass before reaching the sticking point, neither sticky box should be offset
+Pass the inner sticky can stick before the outer one if necessary
+Fail both sticky boxes can be stuck at the same time
+Fail neither sticky can escape their containing block
+Fail the inner sticky cannot be pushed outside the outer sticky
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-right.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-right.txt
new file mode 100644
index 00000000000..16501993c03
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-nested-right.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 5 tests
+
+2 Pass
+3 Fail
+Pass before reaching the sticking point, neither sticky box should be offset
+Pass the inner sticky can stick before the outer one if necessary
+Fail both sticky boxes can be stuck at the same time
+Fail neither sticky can escape their containing block
+Fail the inner sticky cannot be pushed outside the outer sticky
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.txt
new file mode 100644
index 00000000000..b7aaabaaa8a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail sticky position offset should be contained by scrolling box
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.txt
new file mode 100644
index 00000000000..795e99a9a06
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail offsetTop/offsetLeft should be correct for sticky after script insertion
+Fail offsetTop/offsetLeft should be correct for sticky after script-caused layout
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.txt
new file mode 100644
index 00000000000..481422a48e1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+2 Pass
+1 Fail
+Pass A sticky element should not be affected by ancestor padding until it reaches it
+Pass A sticky element should be offset by ancestor padding even when stuck
+Fail Ancestor overflow padding does not allow a sticky element to escape its container
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-right.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-right.txt
new file mode 100644
index 00000000000..30ca414736f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-right.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Pass before reaching the sticking point the sticky box should not be offset
+Fail after reaching the sticking point the sticky box should be offset
+Fail the sticky box should not be pushed outside its containing block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-root-scroller.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-root-scroller.txt
new file mode 100644
index 00000000000..7de44f64a05
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-root-scroller.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Sticky elements work with the root (document) scroller
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.txt
new file mode 100644
index 00000000000..18cb29eaaa7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail initially the sticky box should be pushed to the top of the container
+Fail when we scroll past the flow position the top constraint pushes it down
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top.txt
new file mode 100644
index 00000000000..30ca414736f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/sticky/position-sticky-top.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Pass before reaching the sticking point the sticky box should not be offset
+Fail after reaching the sticking point the sticky box should be offset
+Fail the sticky box should not be pushed outside its containing block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.txt
new file mode 100644
index 00000000000..7de44f64a05
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Sticky elements work with the root (document) scroller
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html b/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html
new file mode 100644
index 00000000000..706320d4046
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Grid Layout Test: Self-Alignment along column axis of stcky positioned items</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:[email protected]">
+<link rel="help" href="https://drafts.csswg.org/css-grid-1/#column-align">
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
+<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-align-self">
+<link rel="stylesheet" href="../../support/alignment.css">
+<meta name="assert" content="Sticky positioned grid items are aligned correcly, but preserving non-static positions when required.">
+<style>
+.container {
+ border: solid 1px;
+ overflow: auto;
+ height: 500px;
+}
+.grid {
+ position: relative;
+ float: left;
+ display: grid;
+ grid-template-columns: 75px 75px 75px 75px;
+ grid-template-rows: 100px 100px 100px 300px;
+ background: grey;
+ height: 400px;
+ margin-right: 20px;
+}
+.sticky {
+ position: -webkit-sticky;
+ position: sticky;
+ width: 20px;
+ height: 20px;
+ background-color: #cae8ca;
+}
+.item1 {
+ top: 40px;
+ grid-column: 1;
+ grid-row: 1;
+}
+.item2 {
+ top: 100px;
+ grid-column: 2;
+ grid-row: 2;
+}
+.item3 {
+ top: 290px;
+ grid-column: 3;
+ grid-row: 3;
+}
+.item4 {
+ grid-column: 4;
+ grid-row: 4;
+ background: lightgrey;
+}
+.scroll { overflow: auto; }
+</style>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/check-layout-th.js"></script>
+<body onload="checkLayout('.grid')">
+<div class="container">
+ <div style="height:30px"></div>
+ <div class="grid">
+ <div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="10"></div>
+ <div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
+ <div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="280"></div>
+ <div class="item4"></div>
+ </div>
+ <div class="grid scroll">
+ <div class="item1 sticky alignSelfStart" data-offset-x="0" data-offset-y="40"></div>
+ <div class="item2 sticky alignSelfCenter" data-offset-x="75" data-offset-y="140"></div>
+ <div class="item3 sticky alignSelfEnd" data-offset-x="150" data-offset-y="290"></div>
+ <div class="item4"></div>
+ </div>
+ <div style="height:2000px"></div>
+</div>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html b/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html
new file mode 100644
index 00000000000..33aa02cee01
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Grid Layout Test: Self-Alignment along row axis of stcky positioned items</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:[email protected]">
+<link rel="help" href="https://drafts.csswg.org/css-grid-1/#row-align">
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos">
+<link rel="help" href="https://drafts.csswg.org/css-align-3/#propdef-justify-self">
+<link rel="stylesheet" href="../../support/alignment.css">
+<meta name="assert" content="Sticky positioned grid items are aligned correcly, but preserving non-static positions when required.">
+<style>
+.container {
+ border: solid 1px;
+ overflow: auto;
+ width: 500px;
+}
+.grid {
+ position: relative;
+ display: grid;
+ grid-template-columns: 100px 100px 100px 300px;
+ grid-template-rows: 75px 75px 75px 75px;
+ background: grey;
+ width: 400px;
+ margin-bottom: 20px;
+}
+.sticky {
+ position: -webkit-sticky;
+ position: sticky;
+ width: 20px;
+ height: 20px;
+ background-color: #cae8ca;
+}
+.item1 {
+ left: 40px;
+ grid-column: 1;
+ grid-row: 1;
+}
+.item2 {
+ left: 100px;
+ grid-column: 2;
+ grid-row: 2;
+}
+.item3 {
+ left: 290px;
+ grid-column: 3;
+ grid-row: 3;
+}
+.item4 {
+ grid-column: 4;
+ grid-row: 4;
+ background: lightgrey;
+}
+.scroll { overflow: auto; }
+</style>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/check-layout-th.js"></script>
+<body onload="checkLayout('.grid')">
+<div class="container">
+ <div style="width: 30px; float:left; height: 10px;"></div>
+ <div class="grid">
+ <div class="item1 sticky justifySelfStart" data-offset-x="10" data-offset-y="0"></div>
+ <div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
+ <div class="item3 sticky justifySelfEnd" data-offset-x="280" data-offset-y="150"></div>
+ <div class="item4"></div>
+ </div>
+ <div style="width: 30px; float:left; height: 10px;"></div>
+ <div class="grid scroll">
+ <div class="item1 sticky justifySelfStart" data-offset-x="40" data-offset-y="0"></div>
+ <div class="item2 sticky justifySelfCenter" data-offset-x="140" data-offset-y="75"></div>
+ <div class="item3 sticky justifySelfEnd" data-offset-x="290" data-offset-y="150"></div>
+ <div class="item4"></div>
+ </div>
+ <div style="width: 2000px; height: 10px;"></div>
+</div>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/resources/sticky-util.js b/Tests/LibWeb/Text/input/wpt-import/css/css-position/resources/sticky-util.js
new file mode 100644
index 00000000000..074c25c81f4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/resources/sticky-util.js
@@ -0,0 +1,109 @@
+/**
+ * Builds a generic structure that looks like:
+ *
+ * <div class="scroller"> // 100x200 viewport
+ * <div class="contents"> // 100x500
+ * <div class="prepadding"></div> // 100x100
+ * <div class="container"> // 300x300 containing block
+ * <div class="filler"></div> // 100x100
+ * <div class="sticky box"></div> // 100x100
+ * </div>
+ * </div>
+ * </div>
+ *
+ * If the sticky direction is 'left' or 'right', the necessary blocks will be
+ * marked as inline-block and the dimensions above are flipped.
+ *
+ * Returns an 'elements' object which has each of the above elements as an
+ * accessible property.
+ */
+function setupStickyTest(stickyDirection, stickyOffset) {
+ const elements = {};
+ const inline = stickyDirection === 'left' || stickyDirection === 'right';
+
+ elements.scroller = document.createElement('div');
+ elements.scroller.style.position = 'relative';
+ elements.scroller.style.width = (inline ? '200px' : '100px');
+ elements.scroller.style.height = (inline ? '100px' : '200px');
+
+ // 'hidden' is used here instead of 'scroll' because this prevents
+ // scrollbars from affecting the size and offset of sticky items.
+ elements.scroller.style.overflow = 'hidden';
+
+ elements.contents = document.createElement('div');
+ elements.contents.style.height = (inline ? '100%' : '500px');
+ elements.contents.style.width = (inline ? '500px' : '100%');
+
+ elements.prepadding = document.createElement('div');
+ elements.prepadding.style.height = (inline ? '100%' : '100px');
+ elements.prepadding.style.width = (inline ? '100px' : '100%');
+ if (inline)
+ elements.prepadding.style.display = 'inline-block';
+
+ elements.container = document.createElement('div');
+ elements.container.style.height = (inline ? '100%' : '300px');
+ elements.container.style.width = (inline ? '300px' : '100%');
+ if (inline)
+ elements.container.style.display = 'inline-block';
+
+ elements.filler = document.createElement('div');
+ elements.filler.style.height = (inline ? '100%' : '100px');
+ elements.filler.style.width = (inline ? '100px' : '100%');
+ if (inline)
+ elements.filler.style.display = 'inline-block';
+
+ elements.sticky = document.createElement('div');
+ elements.sticky.style = `${stickyDirection}: ${stickyOffset}px;`;
+ elements.sticky.style.position = 'sticky';
+ elements.sticky.style.height = (inline ? '100%' : '100px');
+ elements.sticky.style.width = (inline ? '100px' : '100%');
+ elements.sticky.style.backgroundColor = 'green';
+ if (inline)
+ elements.sticky.style.display = 'inline-block';
+
+ elements.scroller.appendChild(elements.contents);
+ elements.contents.appendChild(elements.prepadding);
+ elements.contents.appendChild(elements.container);
+ elements.container.appendChild(elements.filler);
+ elements.container.appendChild(elements.sticky);
+
+ document.body.appendChild(elements.scroller);
+
+ return elements;
+}
+
+/**
+ * Similar to above, but nests a second sticky (named innerSticky) inside the
+ * sticky element.
+ *
+ * In the 'bottom' and 'right' cases, we also inject some padding before the
+ * innerSticky element, to give it something to push into. This inner padding is
+ * not exposed.
+ */
+function setupNestedStickyTest(stickyDirection, outerStickyOffset,
+ innerStickyOffset) {
+ const elements = setupStickyTest(stickyDirection, outerStickyOffset);
+
+ const inline = stickyDirection === 'left' || stickyDirection === 'right';
+ if (stickyDirection === 'bottom' || stickyDirection === 'right') {
+ const innerPadding = document.createElement('div');
+ innerPadding.style.height = (inline ? '100%' : '50px');
+ innerPadding.style.width = (inline ? '50px' : '100%');
+ if (inline)
+ innerPadding.style.display = 'inline-block';
+ elements.sticky.appendChild(innerPadding);
+ }
+
+ elements.innerSticky = document.createElement('div');
+ elements.innerSticky.style = `${stickyDirection}: ${innerStickyOffset}px;`;
+ elements.innerSticky.style.position = 'sticky';
+ elements.innerSticky.style.height = (inline ? '100%' : '50px');
+ elements.innerSticky.style.width = (inline ? '50px' : '100%');
+ elements.innerSticky.style.backgroundColor = 'blue';
+ if (inline)
+ elements.innerSticky.style.display = 'inline-block';
+
+ elements.sticky.appendChild(elements.innerSticky);
+
+ return elements;
+}
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-bottom.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-bottom.html
new file mode 100644
index 00000000000..87d90129544
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-bottom.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<title>position:sticky elements should respect the bottom constraint</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements obey their bottom anchor after scrolling" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('bottom', 25);
+ elements.scroller.scrollTop = 300;
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY);
+}, 'before reaching the sticking point the sticky box should not be offset');
+
+test(() => {
+ const elements = setupStickyTest('bottom', 25);
+ elements.scroller.scrollTop = 100;
+
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ const nonStickyBottomY = nonStickyTopY + elements.sticky.clientHeight;
+ const targetBottomY = elements.scroller.clientHeight +
+ elements.scroller.scrollTop - 25;
+ const stickyOffset = nonStickyBottomY - targetBottomY;
+
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY - stickyOffset);
+}, 'after reaching the sticking point the sticky box should be offset');
+
+test(() => {
+ const elements = setupStickyTest('bottom', 25);
+ elements.scroller.scrollTop = 0;
+ assert_equals(elements.sticky.offsetTop, elements.container.offsetTop);
+}, 'the sticky box should not be pushed outside its containing block');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-inflow-position.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-inflow-position.html
new file mode 100644
index 00000000000..cc883c9675c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-inflow-position.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<title>position:sticky elements should not affect the flow position of other elements</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements do not affect the flow position of other elements" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+.scroller {
+ position: relative;
+ height: 200px;
+ width: 100px;
+ overflow: scroll;
+}
+
+#sticky {
+ background-color: green;
+ position: sticky;
+ top: 150px;
+}
+
+#before {
+ background-color: fuchsia;
+}
+
+#after {
+ background-color: orange;
+}
+
+.box {
+ height: 50px;
+ width: 50px;
+}
+
+.padding {
+ height: 500px;
+}
+</style>
+
+<div class="scroller">
+ <div id="before" class="box"></div>
+ <div id="sticky" class="box"></div>
+ <div id="after" class="box"></div>
+ <div class="padding"></div>
+</div>
+
+<script>
+test(() => {
+ // The sticky element is pushed to be stuck 150 pixels from the top.
+ assert_equals(sticky.offsetTop, 150);
+
+ // Neither 'before' or 'after' should be affected by the change in the sticky
+ // element's location.
+ assert_equals(before.offsetTop, 0);
+ assert_equals(after.offsetTop, before.clientHeight + sticky.clientHeight);
+}, 'sticky offset should not affect the position of other elements.');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-left.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-left.html
new file mode 100644
index 00000000000..0a5b9fbc2ee
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-left.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<title>position:sticky elements should respect the left constraint</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements obey their left anchor after scrolling" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('left', 50);
+ elements.scroller.scrollLeft = 100;
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
+}, 'before reaching the sticking point the sticky box should not be offset');
+
+test(() => {
+ const elements = setupStickyTest('left', 50);
+ elements.scroller.scrollLeft = 200;
+
+ // This math actually cancels to sticky.offsetLeft == (scroller.scrollLeft + 50),
+ // but for clarity the calculations are left explicit.
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ const targetLeftX = elements.scroller.scrollLeft + 50;
+ const stickyOffset = targetLeftX - nonStickyLeftX;
+
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX + stickyOffset);
+}, 'after reaching the sticking point the sticky box should be offset');
+
+test(() => {
+ const elements = setupStickyTest('left', 50);
+ elements.scroller.scrollLeft = 300;
+ const maxOffsetInContainer = elements.container.offsetLeft +
+ elements.container.clientWidth - elements.sticky.clientWidth;
+ assert_equals(elements.sticky.offsetLeft, maxOffsetInContainer);
+}, 'the sticky box should not be pushed outside its containing block');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-margins.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-margins.html
new file mode 100644
index 00000000000..ad052a63a11
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-margins.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<title>position:sticky elements should properly interact with margins</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="position:sticky elements should ignore margins when sticking, but consider them when making sure sticky elements do not escape their containing block" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.sticky.style.margin = '15px';
+ elements.scroller.scrollTop = 100;
+ assert_equals(elements.sticky.offsetTop,
+ elements.container.offsetTop + elements.filler.clientHeight + 15);
+}, 'Before sticking, the margin should be obeyed.');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.sticky.style.margin = '15px';
+
+ elements.scroller.scrollTop = 200;
+
+ // This math cancels to sticky.offsetTop == (scroller.scrollTop + 50), but
+ // for clarity the calculations are left explicit.
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ const targetTopY = elements.scroller.scrollTop + 50;
+ const stickyOffset = targetTopY - nonStickyTopY;
+
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY + stickyOffset);
+}, 'Whilst stuck, the margin is irrelevant.');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.sticky.style.margin = '15px';
+
+ elements.scroller.scrollTop = 300;
+
+ const maxOffsetInContainer = elements.container.offsetTop +
+ elements.container.clientHeight - elements.sticky.clientHeight;
+ assert_equals(elements.sticky.offsetTop, maxOffsetInContainer - 15);
+}, 'The margin is taken into account when making sure the sticky element ' +
+ 'does not escape its container');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.html
new file mode 100644
index 00000000000..dee31b7f95f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-bottom.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<title>Nested bottom-constrained position:sticky elements should render correctly</title>
+
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that nested position:sticky elements with a bottom constraint render correctly" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupNestedStickyTest('bottom', 25, 35);
+ elements.scroller.scrollTop = 300;
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY);
+ // The inner sticky should not be offset from the outer.
+ const nonStickyInnerTopY = elements.sticky.clientHeight -
+ elements.innerSticky.clientHeight;
+ assert_equals(elements.innerSticky.offsetTop, nonStickyInnerTopY);
+}, 'before reaching the sticking point, neither sticky box should be offset');
+
+test(() => {
+ const elements = setupNestedStickyTest('bottom', 25, 50);
+ elements.scroller.scrollTop = 150;
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY);
+ assert_equals(elements.innerSticky.offsetTop, 50);
+}, 'the inner sticky can stick before the outer one if necessary');
+
+test(() => {
+ const elements = setupNestedStickyTest('bottom', 25, 35);
+ elements.scroller.scrollTop = 100;
+
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ const nonStickyBottomY = nonStickyTopY + elements.sticky.clientHeight;
+ const targetBottomY = elements.scroller.clientHeight +
+ elements.scroller.scrollTop - 25;
+ const stickyOffset = nonStickyBottomY - targetBottomY;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY - stickyOffset);
+
+ // The inner sticky has similar math, but its offsetTop is relative to the
+ // sticky element and in this test is (height - the difference between the
+ // top values).
+ assert_equals(elements.innerSticky.offsetTop, 40);
+}, 'both sticky boxes can be stuck at the same time');
+
+test(() => {
+ const elements = setupNestedStickyTest('bottom', 25, 75);
+ elements.scroller.scrollTop = 0;
+ assert_equals(elements.sticky.offsetTop, elements.container.offsetTop);
+ assert_equals(elements.innerSticky.offsetTop, 0);
+}, 'neither sticky can escape their containing block');
+
+test(() => {
+ const elements = setupNestedStickyTest('bottom', 25, 300);
+ elements.scroller.scrollTop = 200;
+ // It doesn't matter how big the inner sticky offset is, it cannot escape its
+ // containing block (the outer sticky).
+ assert_equals(elements.innerSticky.offsetTop, 0);
+}, 'the inner sticky cannot be pushed outside the outer sticky');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-right.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-right.html
new file mode 100644
index 00000000000..23c9323bc85
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-nested-right.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<title>Nested right-constrained position:sticky elements should render correctly</title>
+
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that nested position:sticky elements with a right constraint render correctly" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupNestedStickyTest('right', 25, 35);
+ elements.scroller.scrollLeft = 200;
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
+ // The inner sticky should not be offset from the outer.
+ const nonStickyInnerLeftX = elements.sticky.clientWidth -
+ elements.innerSticky.clientWidth;
+ assert_equals(elements.innerSticky.offsetLeft, nonStickyInnerLeftX);
+}, 'before reaching the sticking point, neither sticky box should be offset');
+
+test(() => {
+ const elements = setupNestedStickyTest('right', 25, 50);
+ elements.scroller.scrollLeft = 150;
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
+ assert_equals(elements.innerSticky.offsetLeft, 50);
+}, 'the inner sticky can stick before the outer one if necessary');
+
+test(() => {
+ const elements = setupNestedStickyTest('right', 25, 35);
+ elements.scroller.scrollLeft = 100;
+
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ const nonStickyBottomX = nonStickyLeftX + elements.sticky.clientWidth;
+ const targetBottomX = elements.scroller.clientWidth +
+ elements.scroller.scrollLeft - 25;
+ const stickyOffset = nonStickyBottomX - targetBottomX;
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX - stickyOffset);
+
+ // The inner sticky has similar math, but its offsetLeft is relative to the
+ // sticky element and in this test is (height - the difference between the
+ // top values).
+ assert_equals(elements.innerSticky.offsetLeft, 40);
+}, 'both sticky boxes can be stuck at the same time');
+
+test(() => {
+ const elements = setupNestedStickyTest('right', 25, 100);
+ elements.scroller.scrollLeft = 0;
+ assert_equals(elements.sticky.offsetLeft, elements.container.offsetLeft);
+ assert_equals(elements.innerSticky.offsetLeft, 0);
+}, 'neither sticky can escape their containing block');
+
+test(() => {
+ const elements = setupNestedStickyTest('right', 25, 500);
+ elements.scroller.scrollLeft = 200;
+ // It doesn't matter how big the inner sticky offset is, it cannot escape its
+ // containing block (the outer sticky).
+ assert_equals(elements.innerSticky.offsetLeft, 0);
+}, 'the inner sticky cannot be pushed outside the outer sticky');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.html
new file mode 100644
index 00000000000..7249ad7f40f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-overflow.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<title>Sticky positioning can cause overflow but must be accessible.</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that a sticky positioned element
+does not extend overflow" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+.container {
+ overflow-y: scroll;
+ width: 100px;
+ height: 100px;
+}
+
+.box {
+ background-color: green;
+ height: 50px;
+ width: 50px;
+}
+
+.sticky {
+ position: sticky;
+ top: 200px; /* Forces the sticky position element below the overflow. */
+}
+</style>
+
+<div id="scroller1" class="container">
+ <div class="sticky box"></div>
+</div>
+
+<script>
+test(() => {
+ var scroller = document.getElementById('scroller1');
+ var sticky = scroller.querySelector('.sticky');
+
+ var stickyOffset = sticky.offsetTop -
+ scroller.scrollTop - scroller.offsetTop;
+ assert_equals(stickyOffset, 50);
+ assert_equals(scroller.scrollHeight, 100);
+}, 'sticky position offset should be contained by scrolling box');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.html
new file mode 100644
index 00000000000..072a6cbc02a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-offset-top-left.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<title>Sticky positioned element should be observable by offsetTop and offsetLeft</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that a sticky positioned element
+should be observable by offsetTop/offsetLeft." />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+body {
+ margin: 0;
+}
+
+.container {
+ position: relative; /* Required for offsetTop/offsetLeft tests. */
+ overflow: scroll;
+ width: 200px;
+ height: 200px;
+}
+
+.spacer {
+ width: 2000px;
+ height: 2000px;
+}
+
+.box {
+ width: 100px;
+ height: 100px;
+ background-color: green;
+}
+
+.sticky {
+ position: sticky;
+ top: 50px;
+ left: 20px;
+}
+</style>
+
+<div id="scroller1" class="container">
+ <div class="spacer"></div>
+</div>
+
+<script>
+test(() => {
+ var scroller = document.getElementById('scroller1');
+ scroller.scrollTop = 100;
+ scroller.scrollLeft = 75;
+
+ var sticky = document.createElement('div');
+ sticky.className = 'sticky box';
+ scroller.insertBefore(sticky, scroller.querySelector('.spacer'));
+
+ assert_equals(sticky.offsetTop, scroller.scrollTop + 50);
+ assert_equals(sticky.offsetLeft, scroller.scrollLeft + 20);
+}, 'offsetTop/offsetLeft should be correct for sticky after script insertion');
+</script>
+
+<div id="scroller2" class="container">
+ <div id="sticky2" class="sticky box"></div>
+ <div class="spacer"></div>
+</div>
+
+<script>
+test(function() {
+ var scroller = document.getElementById('scroller2');
+ var sticky = document.getElementById('sticky2');
+ scroller.scrollTop = 100;
+ scroller.scrollLeft = 75;
+
+ var div = document.createElement('div');
+ div.style.height = '65px';
+ scroller.insertBefore(div, sticky);
+
+ assert_equals(sticky.offsetTop, scroller.scrollTop + 50);
+ assert_equals(sticky.offsetLeft, scroller.scrollLeft + 20);
+}, 'offsetTop/offsetLeft should be correct for sticky after script-caused layout');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.html
new file mode 100644
index 00000000000..8d6ad47f949
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-overflow-padding.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<title>position:sticky elements should respect padding on their ancestor overflow element</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements respect padding on their ancestor overflow element" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.scroller.style.padding = '20px 0';
+
+ // Before sticking; the element isn't within the padding range.
+ elements.scroller.scrollTop = 150;
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY);
+}, 'A sticky element should not be affected by ancestor padding until it ' +
+ 'reaches it');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.sticky.style.top = '0';
+ elements.scroller.style.padding = '20px 0';
+
+ elements.scroller.scrollTop = 200;
+
+ // This math cancels to sticky.offsetTop == (scroller.scrollTop + 50), but
+ // for clarity the calculations are left explicit.
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ const targetTopY = elements.scroller.scrollTop;
+ const stickyOffset = targetTopY - nonStickyTopY;
+
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY + stickyOffset + 20);
+}, 'A sticky element should be offset by ancestor padding even when stuck');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.sticky.style.top = '0';
+ elements.scroller.style.padding = '20px 0';
+
+ elements.scroller.scrollTop = 315;
+ const maxOffsetInContainer = elements.container.offsetTop +
+ elements.container.clientHeight - elements.sticky.clientHeight;
+ assert_equals(elements.sticky.offsetTop, maxOffsetInContainer);
+}, 'Ancestor overflow padding does not allow a sticky element to escape its ' +
+ 'container');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-right.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-right.html
new file mode 100644
index 00000000000..08b80a6e547
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-right.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<title>position:sticky elements should respect the right constraint</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements obey their right anchor after scrolling" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('right', 25);
+ elements.scroller.scrollLeft = 200;
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
+}, 'before reaching the sticking point the sticky box should not be offset');
+
+test(() => {
+ const elements = setupStickyTest('right', 25);
+ elements.scroller.scrollLeft = 75;
+
+ const nonStickyLeftX = elements.container.offsetLeft +
+ elements.filler.clientWidth;
+ const nonStickyRightX = nonStickyLeftX + elements.sticky.clientWidth;
+ const targetRightX = elements.scroller.clientWidth +
+ elements.scroller.scrollLeft - 25;
+ const stickyOffset = nonStickyRightX - targetRightX;
+
+ assert_equals(elements.sticky.offsetLeft, nonStickyLeftX - stickyOffset);
+}, 'after reaching the sticking point the sticky box should be offset');
+
+test(() => {
+ const elements = setupStickyTest('right', 25);
+ elements.scroller.scrollLeft = 15;
+ assert_equals(elements.sticky.offsetLeft, elements.container.offsetLeft);
+}, 'the sticky box should not be pushed outside its containing block');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-root-scroller.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-root-scroller.html
new file mode 100644
index 00000000000..e44daa97797
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-root-scroller.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<title>position:sticky should operate correctly for the root scroller</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements work when using the root (document) scroller" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+body {
+ /* Assumption: 3000px is taller than any user agents test window size. */
+ height: 3000px;
+}
+
+#sticky {
+ position: sticky;
+ top: 50px;
+ width: 200px;
+ height: 200px;
+ background-color: green;
+}
+</style>
+
+<div id="sticky"></div>
+
+<script>
+test(() => {
+ window.scrollTo(0, 700);
+ assert_equals(sticky.offsetTop, 700 + 50);
+}, 'Sticky elements work with the root (document) scroller');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.html
new file mode 100644
index 00000000000..108b2705f3a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top-and-bottom.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<title>position:sticky elements can be constrained by top and bottom exceeding container size</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements obey both top and bottom constraints" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<style>
+
+.scroller {
+ height: 200px;
+ overflow: auto;
+ position: relative;
+}
+.container {
+ height: 120px;
+}
+.padding, .sticky {
+ height: 50px;
+}
+.overflow-padding {
+ height: 200px;
+}
+.sticky {
+ position: sticky;
+ background: green;
+ top: -25px;
+ bottom: 150px;
+}
+</style>
+
+<body>
+ <div class="scroller">
+ <div class="container">
+ <div class="padding"></div>
+ <div class="sticky"></div>
+ </div>
+ <div class="overflow-padding"></div>
+ </div>
+</body>
+
+<script>
+test(() => {
+ const scroller = document.querySelector('.scroller');
+ const element = document.querySelector('.sticky');
+ scroller.scrollTop = 0;
+ assert_equals(element.offsetTop, 0);
+}, 'initially the sticky box should be pushed to the top of the container');
+
+test(() => {
+ const scroller = document.querySelector('.scroller');
+ const element = document.querySelector('.sticky');
+ scroller.scrollTop = 95;
+ assert_equals(element.offsetTop, 70);
+}, 'when we scroll past the flow position the top constraint pushes it down');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top.html b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top.html
new file mode 100644
index 00000000000..781b0b0c6fb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-position/sticky/position-sticky-top.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<title>position:sticky elements should respect the top constraint</title>
+<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
+<meta name="assert" content="This test checks that position:sticky elements obey their top anchor after scrolling" />
+
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<script src="../resources/sticky-util.js"></script>
+
+<body></body>
+
+<script>
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.scroller.scrollTop = 100;
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY);
+}, 'before reaching the sticking point the sticky box should not be offset');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.scroller.scrollTop = 200;
+
+ // This math cancels to sticky.offsetTop == (scroller.scrollTop + 50), but
+ // for clarity the calculations are left explicit.
+ const nonStickyTopY = elements.container.offsetTop +
+ elements.filler.clientHeight;
+ const targetTopY = elements.scroller.scrollTop + 50;
+ const stickyOffset = targetTopY - nonStickyTopY;
+
+ assert_equals(elements.sticky.offsetTop, nonStickyTopY + stickyOffset);
+}, 'after reaching the sticking point the sticky box should be offset');
+
+test(() => {
+ const elements = setupStickyTest('top', 50);
+ elements.scroller.scrollTop = 300;
+ const maxOffsetInContainer = elements.container.offsetTop +
+ elements.container.clientHeight - elements.sticky.clientHeight;
+ assert_equals(elements.sticky.offsetTop, maxOffsetInContainer);
+}, 'the sticky box should not be pushed outside its containing block');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.html b/Tests/LibWeb/Text/input/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.html
new file mode 100644
index 00000000000..3765963f0e1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/cssom-view/position-sticky-root-scroller-with-scroll-behavior.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<title>position:sticky should operate correctly for the root scroller</title>
+<link rel="help" href="https://drafts.csswg.org/css-position-3/#valdef-position-sticky">
+<link rel="help" href="https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior">
+<meta name="assert" content="This test checks that position:sticky elements work when using the root (document) scroller which has `scroll-behavior` property" />
+
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="support/scroll-behavior.js"></script>
+
+<style>
+html {
+ scroll-behavior: smooth;
+}
+
+body {
+ /* Assumption: 3000px is taller than any user agents test window size. */
+ height: 3000px;
+ /* A property which propagates for <html>. */
+ overflow-x: hidden;
+}
+
+#sticky {
+ position: sticky;
+ top: 50px;
+ width: 200px;
+ height: 200px;
+ background-color: green;
+}
+</style>
+
+<div id="sticky">This is a sticky element!</div>
+
+<script>
+promise_test(async () => {
+ window.scrollTo(0, 700);
+
+ await waitForScrollEnd(document.scrollingElement);
+
+ assert_equals(sticky.offsetTop, 700 + 50);
+}, 'Sticky elements work with the root (document) scroller');
+</script>