Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
async function createFrameWithArmedTimers() {
const frame = document.createElement("iframe");
frame.srcdoc = "child document";
document.body.append(frame);
await new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));
frame.contentWindow.internals.armCompositorAnimationTimersForTesting();
return frame;
}
function armedTimers(frameInternals) {
return frameInternals.dumpCompositorAnimations().split("\n").filter(line => line.endsWith("timer armed"));
}
asyncTest(async done => {
const navigatedFrame = await createFrameWithArmedTimers();
println(`timers armed before navigation: [${armedTimers(navigatedFrame.contentWindow.internals).join(", ")}]`);
const navigatedInternals = navigatedFrame.contentWindow.internals;
navigatedFrame.srcdoc = "replacement";
await new Promise(resolve => navigatedFrame.addEventListener("load", resolve, { once: true }));
println(`timers armed after navigation: [${armedTimers(navigatedInternals).join(", ")}]`);
const removedFrame = await createFrameWithArmedTimers();
println(`timers armed before destruction: [${armedTimers(removedFrame.contentWindow.internals).join(", ")}]`);
const removedInternals = removedFrame.contentWindow.internals;
removedFrame.remove();
// Child destruction unloads the document through the UI process, so the timers stop
// asynchronously rather than within one task.
while (armedTimers(removedInternals).length)
await new Promise(resolve => setTimeout(resolve, 0));
println(`timers armed after destruction: [${armedTimers(removedInternals).join(", ")}]`);
done();
});
</script>