Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<head>
<title>Optimization of requestAnimationFrame callbacks that don't modify the DOM shouldn't break animations</title>
<link rel="author" title="Mukilan Thiyagarajan" href="mailto:mukilan@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="target">0</div>
</body>
<script>
"use strict";
async_test(function(test) {
const target = document.getElementById('target');
let frame = 0;
let restartTime;
const draw = test.step_func((t) => {
frame += 1;
if (frame < 11) {
// Don't mutate the DOM for 10 frames to meet the threshold for Servo's
// spurious frame optimization to kick in.
requestAnimationFrame(draw);
} else if (frame == 11) {
restartTime = t;
// Don't schedule next rAF so the compositor's tick is disabled.
// This is specific to Servo as the spurious frame detection at the
// time of this test was broken.
test.step_timeout(() => {
requestAnimationFrame(draw);
}, 0);
} else if (frame == 12) {
// Resume DOM updates without assuming a particular frame rate.
target.textContent = t;
requestAnimationFrame(draw);
} else {
assert_greater_than(Number(target.textContent), restartTime,
"A callback updated the DOM after restarting");
assert_greater_than(t, Number(target.textContent),
"Callbacks continue after updating the DOM");
test.done();
}
});
requestAnimationFrame(draw);
});
</script>