chromium/third_party/blink/web_tests/fast/dom/gc-image-element-2.html

<p>Tests for image elements firing their load events even when they're not in the document. Should say "onload fired" ten times, and then "PASS".</p>
<pre id="console"></pre>

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

var imageCount = 0;
var finished = false;

function createImage() {
    return new Promise(function(resolve, reject) {
        ++imageCount;
        var image = new Image;
        image.src = "resources/apple.gif";
        image.onload = function () {
            gc();

            --imageCount;
            if (!imageCount) {
                finished = true;
            }
            resolve();
        };
        image = null;
    });
}

function load() {
    var imagePromises = [];
    for (var i = 0; i < 10; ++i) {
        imagePromises.push(createImage());
    }
    return Promise.all(imagePromises);
}

async_test(function(t) {
    load().then(function() {
        assert_true(finished);
        t.done();  // Indicate that the async test is done
    });
})
</script>