Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<title>View transitions: content-visibility:auto ancestor of a participant skips its contents again after the transition finishes</title>
<link rel="author" href="mailto:vmpstr@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#container { content-visibility: auto; }
#participant { width: 100px; height: 100px; view-transition-name: participant; }
::view-transition-group(*) { animation-duration: 0s; }
</style>
<script>
// Track #container's skipped state from the start. This listener is registered
// (in the capture phase on the document) before #container is parsed, so that
// no contentvisibilityautostatechange event can be missed.
let lastSkipped;
let pendingWait = null;
document.addEventListener("contentvisibilityautostatechange", e => {
if (e.target.id !== "container")
return;
lastSkipped = e.skipped;
if (pendingWait && pendingWait.skipped === e.skipped) {
pendingWait.resolve();
pendingWait = null;
}
}, { capture: true });
// Resolves once the most recent contentvisibilityautostatechange event for
// #container reported the given `skipped` value. Events with other values are
// ignored, since the order of intermediate states is not guaranteed. For
// example, the element may first report skipped=true before its first
// viewport intersection has been determined.
function waitForSkipped(skipped) {
if (lastSkipped === skipped)
return Promise.resolve();
return new Promise(resolve => { pendingWait = { skipped, resolve }; });
}
</script>
<div id="spacer"></div>
<div id="container"><div id="participant"></div></div>
<script>
promise_test(async () => {
assert_implements(document.startViewTransition, "Missing document.startViewTransition");
await waitForSkipped(false);
assert_true(participant.checkVisibility({ contentVisibilityAuto: true }),
"onscreen and not skipped before the transition");
// Move #container offscreen in the update callback. It stays relevant while
// #participant is captured in the transition.
const transition = document.startViewTransition(() => {
spacer.style.height = "3000px";
});
await transition.finished;
// #container is offscreen and no longer has a captured descendant.
await waitForSkipped(true);
assert_false(participant.checkVisibility({ contentVisibilityAuto: true }),
"skipped after the transition");
}, "content-visibility:auto ancestor is skipped again once the transition finishes");
</script>