Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<!--
scrolling=no is just paranoia to ensure that we don't get invalidations
due to scrollbars
-->
<iframe scrolling="no" id="iframe"></iframe>
<!-- this contains the kTests array -->
<script src="animated_image_test_list.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
/*
* This test duplicates image/test/browser/browser_animated_css_image.js, so keep them in sync.
* This is because we need a browser-chrome test in order to test invalidation (the getSnapshot method there
* uses the same path as painting to the screen, whereas here we are doing a
* separate paint to a surface), but browser-chrome isn't run on android, so test_animated_css_image.html
* gets us android coverage.
*/
// We hit an optimized path in WebRender that doesn't cause a repaint on the
// main thread:
//
//
// So our assertions and polling need to be a bit weaker on WR.
const kUsingWebRender = SpecialPowers.DOMWindowUtils.layerManagerType.startsWith("WebRender");
let iframe = document.getElementById("iframe");
let blankSnapshot;
async function assertAnimates(html, getExpectedRepaintedElement) {
const kExpectEqual = true;
const kNumRetries = kUsingWebRender ? 600 : 30;
info("testing: " + html);
{
let load = new Promise(resolve => {
iframe.addEventListener("load", resolve, { once: true });
});
iframe.srcdoc = html;
await load;
}
// This ensures the MozAfterPaint events come through as expected.
await SimpleTest.promiseFocus(iframe.contentWindow);
let initial = await snapshotWindow(iframe.contentWindow);
let repaintedElement = getExpectedRepaintedElement(iframe.contentDocument);
if (!kUsingWebRender) {
// Ensure the painted state is clear before we start polling.
SpecialPowers.DOMWindowUtils.checkAndClearPaintedState(repaintedElement);
}
{
let [equal, s1 /* , s2, differentPixels, maxDiff */] = compareSnapshots(initial, blankSnapshot, kExpectEqual);
ok(!equal, "Initial snapshot shouldn't be blank");
info(s1);
}
let foundDifferent = false;
let foundInitialAgain = false;
for (let i = 0; i < kNumRetries; ++i) {
let current = await snapshotWindow(iframe.contentWindow);
let [equal, /* s1 */, s2 /* , differentPixels, maxDiff */ ] = compareSnapshots(initial, current, kExpectEqual);
if (!foundDifferent && !equal) {
ok(true, `Found different image after ${i} retries`);
ok(kUsingWebRender || SpecialPowers.DOMWindowUtils.checkAndClearPaintedState(repaintedElement), "Should've repainted the expected element");
info(s2);
foundDifferent = true;
}
// Ensure that we go back to the initial state (animated1.gif) is an
// infinite gif.
if (foundDifferent && equal) {
ok(true, `Found same image again after ${i} retries`);
ok(kUsingWebRender || SpecialPowers.DOMWindowUtils.checkAndClearPaintedState(repaintedElement), "Should've repainted the expected element");
foundInitialAgain = true;
break;
}
await new Promise(resolve => {
if (kUsingWebRender) {
requestAnimationFrame(() => {
requestAnimationFrame(resolve);
});
} else {
iframe.contentWindow.addEventListener("MozAfterPaint", resolve, { once: true });
}
});
}
ok(foundDifferent && foundInitialAgain, `Should've found a different snapshot and then an equal one, after ${kNumRetries} retries`);
}
onload = async function() {
// First snapshot the blank window.
blankSnapshot = await snapshotWindow(iframe.contentWindow);
// kTests is defined in the imported animated_image_test_list.js so it can
// be shared between tests.
// eslint-disable-next-line no-undef
for (let { html, element } of kTests)
await assertAnimates(html, element);
SimpleTest.finish();
}
</script>