gecko-dev/testing/web-platform/tests/css/css-scroll-snap/snap-to-visible-areas-margin-x-axis.html
Kaan Alsan 41e7011cb8 Bug 1580772 [wpt PR 19007] - Update wpt scroll-to-visible-areas tests, a=testonly
Automatic update from web-platform-tests
Update wpt scroll-to-visible-areas tests

The original tests were based on an inaccurate understanding of
"visibility" for a snap area, where a snap area was considered to be
visible if it is in the viewport at the scroll location before the
snap. The definition of visibility per the specification is that a snap
area is visible if it would be in the viewport at its snap point.

See:
https://github.com/w3c/csswg-drafts/issues/2526#issuecomment-380371186

Also added tests for the consideration of scroll-margin when
calculating visibility as well.

Bug: 954851
Change-Id: Ic2ffef8d02fc5ea2439054b6ea5185bb66622d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1795308
Commit-Queue: Kaan Alsan <alsan@google.com>
Reviewed-by: Yi Gu <yigu@chromium.org>
Reviewed-by: Majid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696435}

--

wpt-commits: 224ecb27547a9b49b28b7ae06abc8bc09f4b91fc
wpt-pr: 19007
2019-09-18 23:38:11 +00:00

69 lines
1.5 KiB
HTML

<!DOCTYPE html>
<title>
Snap to an area where the element's scroll-margin is visible but not the
element itself (using x-axis snap type)
</title>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#snap-scope"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
position: absolute;
margin: 0px;
}
#scroller {
height: 600px;
width: 600px;
overflow: scroll;
scroll-snap-type: x mandatory;
}
#space {
width: 2000px;
height: 2000px;
}
.snap {
width: 200px;
height: 200px;
background-color: blue;
scroll-snap-align: start;
}
#left-visible {
left: 0px;
top: 0px;
}
#right-visible {
left: 800px;
top: 0px;
}
#middle-margin-visible {
left: 700px;
top: 800px;
/* 300px makes snap area visible with margin but non-visible without it */
scroll-margin-top: 300px;
}
</style>
<div id="scroller">
<div id="space"></div>
<div id="left-visible" class="snap"></div>
<div id="middle-margin-visible" class="snap"></div>
<div id="right-visible" class="snap"></div>
</div>
<script>
test(() => {
const scroller = document.getElementById("scroller");
scroller.scrollTo(0, 0);
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 0);
scroller.scrollTo(500, 0);
assert_equals(scroller.scrollLeft, 700);
assert_equals(scroller.scrollTop, 0);
}, 'Scroll margin should be considered when calculating snap area visibilty \
while snapping on the x-axis');
</script>