<p>Tests for image elements firing their load events even when they're not in the document.</p>
<pre id="console"></pre>

<script src="../../resources/js-test-pre.js"></script>
<script>
function $(id)
{
    return document.getElementById(id);
}

function log(s)
{
    $("console").appendChild(document.createTextNode(s + "\n"));
}

var imageCount = 0;

function createImage()
{
    ++imageCount;
    var image = new Image;
    image.src = "resources/apple.gif";
    image.onload = function () {
        log("PASS: loaded");
        --imageCount;
        if (imageCount)
            return;
        if (window.testRunner)
            testRunner.notifyDone();
    };
}

(function () {
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    var image = new Image;
    image.src = "resources/apple.gif";
    image.onload = function () { // Wait for the image to load so subsequent loads will be synchronous.
        for (var i = 0; i < 10; ++i)
            createImage();
        gc();
    }
})();
</script>
