blob: 4400d04c40974c2c3d6b7add4090f05ac456e022 [file] [log] [blame]
<!DOCTYPE html><!-- webkit-test-runner [ IntersectionObserverEnabled=true ] -->
<html>
<body>
<pre id="log">This tests observing an element with an IntersectionObserver and removing the element from the document.
The element should become eligible for GC at some point.
</pre>
<script src="../resources/gc.js"></script>
<script>
let initialNodeCount;
function runTest()
{
if (!window.testRunner || !window.internals) {
log.textContent += 'FAIL - This test requires internals';
return;
}
testRunner.dumpAsText();
testRunner.waitUntilDone();
initialNodeCount = internals.referencingNodeCount(document);
const intersectionObservers = [];
for (let i = 0; i < 100; ++i)
intersectionObservers.push(createIntersectionObserver());
requestAnimationFrame(() => {
setTimeout(() => {
gc();
log.textContent += internals.referencingNodeCount(document) < initialNodeCount + intersectionObservers.length * 0.8 ? 'PASS' : 'FAIL - Less than 20% of nodes were collected.'
testRunner.notifyDone();
}, 0);
});
}
function createIntersectionObserver()
{
const element = document.createElement('div');
const intersectionObserver = new IntersectionObserver(() => { }).observe(element);
document.body.appendChild(element);
setTimeout(() => {
element.remove();
}, 0);
return intersectionObserver;
}
onload = runTest;
</script>
</body>
</html>