summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html')
-rw-r--r--testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html b/testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html
new file mode 100644
index 0000000000..5fdedf753d
--- /dev/null
+++ b/testing/web-platform/tests/css/cssom-view/scrollIntoView-scrollPadding.html
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<title>CSSOM View - scrollIntoView considers scroll-padding</title>
+<meta charset="utf-8">
+<link rel="author" title="Sandra Sun" href="mailto:sunyunjia@chromium.org">
+<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview">
+<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-padding">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<style>
+#scroller {
+ width: 200px;
+ height: 200px;
+ overflow: scroll;
+ scroll-padding-top: 4px;
+ scroll-padding-right: 8px;
+ scroll-padding-bottom: 12px;
+ scroll-padding-left: 16px;
+}
+#content {
+ width: 500px;
+ height: 500px;
+}
+#target {
+ position: relative;
+ left: 200px;
+ top: 200px;
+ width: 100px;
+ height: 100px;
+ background-color: lightgreen;
+}
+</style>
+
+<div id="scroller">
+ <div id="content">
+ <div id="target"></div>
+ </div>
+</div>
+<div id="log"></div>
+
+<script>
+var target = document.getElementById("target");
+var scroller = document.getElementById("scroller");
+var expectedXLeft = 200 - 16;
+var expectedXRight = 200 - scroller.clientWidth + 8 + target.clientWidth;
+var expectedXCenter = 200 - (16 + scroller.clientWidth - 8) / 2 +
+ target.clientWidth / 2;
+
+var expectedYTop = 200 - 4;
+var expectedYBottom = 200 - scroller.clientHeight + 12 + target.clientHeight;
+var expectedYCenter = 200 - (4 + scroller.clientHeight - 12) / 2 +
+ target.clientHeight / 2;
+
+// This formats dict as a string suitable as test name.
+// format_value() is provided by testharness.js,
+// which also preserves sign for -0.
+function format_dict(dict) {
+ const props = [];
+ for (let prop in dict) {
+ props.push(`${prop}: ${format_value(dict[prop])}`);
+ }
+ return `{${props.join(", ")}}`;
+}
+
+[
+ [{block: "center", inline: "center"}, expectedXCenter, expectedYCenter],
+ [{block: "start", inline: "start"}, expectedXLeft, expectedYTop],
+ [{block: "end", inline: "end"}, expectedXRight, expectedYBottom],
+].forEach(([input, expectedX, expectedY]) => {
+ test(() => {
+ scroller.scrollTo(0, 0);
+ target.scrollIntoView(input);
+ assert_approx_equals(scroller.scrollLeft, expectedX, 0.5, "scrollX");
+ assert_approx_equals(scroller.scrollTop, expectedY, 0.5, "scrollY");
+ }, `scrollIntoView(${format_dict(input)})`);
+})
+</script> \ No newline at end of file