Skip to content

Truly independent web browser

1.8 KB
Raw Blame
<!DOCTYPE html>
<html class="reftest-wait">
<link rel="match" href="../expected/green-100x100-ref.html">
<style>
    body {
        margin: 0;
    }
    img {
        display: block;
        width: 100px;
        height: 100px;
    }
</style>
<img id="target" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cimage href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAD0lEQVR4nGNgaGBAIOI4ANA0CAF5jtVRAAAAAElFTkSuQmCC' width='100' height='100'/%3E%3C/svg%3E">
<script>
    const target = document.getElementById("target");
    const checkCanvas = document.createElement("canvas");
    checkCanvas.width = 1;
    checkCanvas.height = 1;
    const checkContext = checkCanvas.getContext("2d");

    // The outer SVG's load event can fire before its embedded PNG finishes decoding.
    // Wait for the image contents rather than assuming a fixed delay is long enough.
    const waitForInnerImage = () => {
        checkContext.clearRect(0, 0, 1, 1);
        checkContext.drawImage(target, 0, 0, 1, 1);
        if (Array.from(checkContext.getImageData(0, 0, 1, 1).data).join(",") !== "0,128,0,255") {
            requestAnimationFrame(waitForInnerImage);
            return;
        }
        requestAnimationFrame(() => {
            requestAnimationFrame(() => {
                if (window.internals)
                    internals.signalTestIsDone("PASS");
                else
                    document.documentElement.classList.remove("reftest-wait");
            });
        });
    };
    const finish = () => {
        requestAnimationFrame(() => {
            requestAnimationFrame(waitForInnerImage);
        });
    };
    if (target.complete)
        finish();
    else
        target.addEventListener("load", finish, { once: true });
</script>
</html>