gecko-dev/testing/web-platform/tests/css/css-scroll-snap/scroll-margin.html
Kaan Alsan f507c70b61 Bug 1580857 [wpt PR 19027] - Update scroll-margin WPT to stop flakiness, a=testonly
Automatic update from web-platform-tests
Update scroll-margin WPT to stop flakiness

Updates test 'external/wpt/css/css-scroll-snap/scroll-margin.html' such
that the expected result is consistent. Originally the test's snap
areas were equally distant from the scroll position and therefore the
area chosen was not consistent.

Bug: 964239
Change-Id: I7e8b09719bd526c4e2fb7049131d585ef5e47d8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1799387
Reviewed-by: Yi Gu <yigu@chromium.org>
Commit-Queue: Kaan Alsan <alsan@google.com>
Cr-Commit-Position: refs/heads/master@{#698951}

--

wpt-commits: abf6c428d4efa39d5288be0337a26738946b28e4
wpt-pr: 19027
2019-09-26 20:26:03 +00:00

90 lines
2.6 KiB
HTML

<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-margin" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
position: absolute;
margin: 0px;
}
#scroller {
height: 500px;
width: 500px;
overflow: hidden;
scroll-snap-type: both mandatory;
}
#target {
width: 300px;
height: 300px;
background-color: blue;
}
#another-target {
width: 300px;
height: 300px;
top: 400px;
left: 400px;
background-color: blue;
scroll-snap-align: start;
}
</style>
<div id="scroller">
<div style="width: 2000px; height: 2000px;"></div>
<div id="target"></div>
<div id="another-target"></div>
</div>
<script>
test(() => {
target.style.scrollSnapAlign = "start";
target.style.scrollMargin = "100px";
target.style.left = "300px";
target.style.top = "300px";
scroller.scrollTo(0, 0);
// `target position (300px, 300px)` - `margin (100px, 100px)`.
assert_equals(scroller.scrollLeft, 200);
assert_equals(scroller.scrollTop, 200);
target.style.scrollSnapAlign = "end";
// `target position (300px, 300px)` + `target size (300px, 300px) +
// `margin (100px, 100px) - `scroller size (500px, 500px)`.
scroller.scrollTo(0, 0);
assert_equals(scroller.scrollLeft, 200);
assert_equals(scroller.scrollTop, 200);
}, "Snaps to the positions adjusted by scroll-margin");
test(() => {
target.style.left = "0px";
target.style.top = "0px";
target.style.scrollSnapAlign = "start";
// Since the target is at (0px, 0px) in the scroll port, the added margin
// should not be considered, and the snap points for this snap area should be
// the closest points in the scroll port (i.e x=0 or y=0).
target.style.scrollMargin = "200px";
// Distance from target without margin:
// `scroll position (150px, 150px)` - `target position (0px, 0px)`
// = (150px, 150px)
//
// Distance from target with margin:
// `scroll position (150px, 150px)` - [`target position (0px, 0px)` -
// `target margin (200px, 200px)`]
// = (350px, 350px)
//
// Distance from other target:
// `other target position (400px, 400px)` - `scroll position (150px, 150px)`
// = (250px, 250px)
//
// Therefore if the "out-of-scrollport" scroll-margin contributes to the
// calculation, then the other target would be snapped to. However if the
// scroll-margin is not considered, then the (0px, 0px) target should be
// snapped to.
scroller.scrollTo(150, 150);
assert_equals(scroller.scrollLeft, 0);
assert_equals(scroller.scrollTop, 0);
}, "scroll-margin doesn't contribute to the snap position of the element " +
"if it's outside of the scroll port");
</script>