Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-scroll-snap/snap-events/snap-events-with-disposed-pseudo-target.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Scroll Snap 2 Test: Snap Events with a disposed pseudo-element target.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/css/css-scroll-snap/snap-events/resources/common.js"></script>
<script src="/css/css-scroll-snap/snap-events/resources/user-scroll-common.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
</head>
<body>
<style>
.scroller {
overflow: scroll;
width: 200px;
height: 200px;
border: solid 1px black;
scroll-snap-type: y mandatory;
position: absolute;
}
.space {
height: 300vh;
width: 300vw;
position: absolute;
}
.scroller::before, .scroller::after {
scroll-snap-align: start;
height: 50px;
width: 50px;
display: block;
}
.scroller::before {
content: "before";
background-color: blue;
}
.scroller::after {
content: "after";
background-color: orange;
margin-top: 100px;
}
.scroller.no-after::after {
content: none;
}
</style>
<div class="scroller" id="scroller">
<div class="space"></div>
</div>
<script>
promise_test(async (t) => {
checkSnapEventSupport("scrollsnapchanging");
checkSnapEventSupport("scrollsnapchange");
await waitForCompositorCommit();
const targets = [];
for (const type of ["scrollsnapchanging", "scrollsnapchange"]) {
scroller.addEventListener(type, (evt) => {
targets.push(evt.snapTargetBlock, evt.snapTargetInline);
});
}
// On every frame, re-create ::after so that it is a snap area after
// that frame's layout, then dispose it again between frames with a
// style-only update. Snap targets resolved from compositor scroll
// state at the start of the next frame then refer to a disposed
// pseudo-element.
let running = true;
t.add_cleanup(() => { running = false; });
function toggle() {
if (!running) {
return;
}
scroller.classList.remove("no-after");
t.step_timeout(() => {
scroller.classList.add("no-after");
getComputedStyle(scroller).color;
}, 0);
requestAnimationFrame(toggle);
}
requestAnimationFrame(toggle);
const scrollend_promise = new Promise(resolve => {
scroller.addEventListener("scrollend", resolve, { once: true });
});
await snap_event_touch_scroll_helper(
{ x: scroller.clientWidth / 2, y: scroller.clientHeight / 2 },
{ x: scroller.clientWidth / 2, y: 0 });
await scrollend_promise;
for (let i = 0; i < 10; ++i) {
await new Promise(resolve => requestAnimationFrame(resolve));
}
running = false;
for (const target of targets) {
assert_true(target === null || target === scroller,
"snap target is null or the originating element");
}
}, "Snap events don't expose or crash on a snap target pseudo-element " +
"that was disposed since the last layout");
</script>
</body>
</html>