Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
<!doctype html>
<meta charset="utf-8">
<title>Content Visibility: stop ticking after relevancy updates</title>
<!--
Copied from testing/web-platform/tests/css/css-contain/content-visibility/content-visibility-auto-relevancy-updates.html
-->
<link rel="author" title="Frédéric Wang" href="mailto:fwang@igalia.com">
<meta name="assert" content="Verify relevancy is properly updated for content-visibility: auto elements and refresh driver stops ticking after such update.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#spacer {
height: 300vh;
}
#contentVisibilityAuto {
content-visibility: auto;
border: solid;
}
</style>
<div>
<div id="log"></div>
<div tabindex="1" id="spacer"></div>
<div tabindex="2" id="contentVisibilityAuto">
<span>Hello, World!</span>
</div>
</div>
<script>
function hasPendingTick() {
return SpecialPowers.wrap(window).windowUtils.refreshDriverHasPendingTick;
}
// See comment in layout/base/tests/test_bug1756118.html about why the timeouts
// etc.
async function expectTicksToStop() {
for (let i = 0; i < 100; i++) {
await new Promise(r => setTimeout(r, 8));
if(!hasPendingTick()) {
break;
}
}
assert_false(hasPendingTick(), "refresh driver should have eventually stopped ticking");
}
function tick() {
return new Promise(r => {
requestAnimationFrame(() => requestAnimationFrame(r));
});
}
function contentVisibilityAutoElementIsRelevant() {
// A content-visibility: auto element that is not relevant skips its contents,
// which do not contribute to the result of innerText.
return contentVisibilityAuto.innerText.length > 0;
}
function clearRelevancyReasons() {
window.scrollTo(0, 0);
spacer.focus({preventScroll: true});
window.getSelection().empty();
}
promise_test(async function(t) {
// Wait for page load.
await new Promise(resolve => { window.addEventListener("load", resolve); });
// Register cleanup method to reset relevancy.
t.add_cleanup(clearRelevancyReasons);
// Element should initially not be relevant and ticking should have stopped.
await SpecialPowers.pushPrefEnv({'set':
[['layout.keep_ticking_after_load_ms', 0]]});
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");
// Make element close to the viewport.
contentVisibilityAuto.firstElementChild.scrollIntoView();
await tick();
await expectTicksToStop();
assert_true(contentVisibilityAutoElementIsRelevant(), "close to viewport");
// Scroll away from the element again.
window.scrollTo(0, 0);
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "far from viewport");
}, "Relevancy updated after changing proximity to the viewport.");
promise_test(async function(t) {
// Register cleanup method to reset relevancy.
t.add_cleanup(clearRelevancyReasons);
// Element should initially not be relevant and no ticking be in progress.
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");
// Focus the element.
contentVisibilityAuto.focus({preventScroll: true});
await tick();
await expectTicksToStop();
assert_true(contentVisibilityAutoElementIsRelevant(), "focused");
// Unfocus the element again.
spacer.focus({preventScroll: true});
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "unfocused");
}, "Relevancy updated after being focused/unfocused.");
promise_test(async function(t) {
// Register cleanup method to reset relevancy.
t.add_cleanup(clearRelevancyReasons);
// Element should initially not be relevant and no ticking be in progress.
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");
// Select the contents of the element.
window.getSelection().selectAllChildren(contentVisibilityAuto);
await tick();
await expectTicksToStop();
assert_true(contentVisibilityAutoElementIsRelevant(), "selected");
// Unselect the contents of the element.
window.getSelection().empty();
await tick();
await expectTicksToStop();
assert_false(contentVisibilityAutoElementIsRelevant(), "unselected");
}, "Relevancy updated after being selected/unselected.");
</script>