<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<img src="resources/animation.gif" id="img" />
<!-- To make this test able to pass in WK1, use this <div style="..."> to setAutodisplay:YES (rdar://42625657 has more details). -->
<div style="will-change: transform"></div>

<script>
description("This test ensures that animation play / pause state is updated when the page-wide 'animations disabled' flag changes.\n\n");
window.jsTestIsAsync = true;

var image = document.getElementById("img");
window.onload = async function() {
    if (!window.internals)
        return;
    internals.settings.setImageAnimationControlEnabled(true);

    debug("Pausing page-wide animation.");
    internals.setImageAnimationEnabled(false);
    await shouldBecomeEqual("internals.isImageAnimating(image)", "false");

    debug("Resuming page-wide image animation.");
    internals.setImageAnimationEnabled(true);
    await shouldBecomeEqual("internals.isImageAnimating(image)", "true");

    debug("Pausing GIF individually.");
    internals.pauseImageAnimation(image);
    await shouldBecomeEqual("internals.isImageAnimating(image)", "false");

    debug("Resuming page-wide image animation (this should cause the GIF to begin animating again, despite the fact it was previously paused individually).");
    internals.setImageAnimationEnabled(true);
    await shouldBecomeEqual("internals.isImageAnimating(image)", "true");

    internals.settings.setImageAnimationControlEnabled(false);
    internals.clearMemoryCache();
    finishJSTest();
};
</script>
</body>
</html>
