chromium/third_party/blink/web_tests/fast/canvas-api/drawImage-with-broken-image.html

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>

<script>

// Create an image with invalid data.
var invalidImage = new Image();
invalidImage.src = 'resources/shadow-offset.js';

var ctx = document.createElement("canvas").getContext('2d');
function draw() {
    // null and undefined images should throw TypeError
    assert_throws_js(TypeError, function() {
      ctx.drawImage(null, 0, 0);
    });
    assert_throws_js(TypeError, function() {
      ctx.drawImage(null, 0, 0, 20, 20);
    });
    assert_throws_js(TypeError, function() {
      ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20);
    });
    assert_throws_js(TypeError, function() {
      ctx.drawImage(undefined, 0, 0);
    });
    assert_throws_js(TypeError, function() {
      ctx.drawImage(undefined, 0, 0, 20, 20);
    });
    assert_throws_js(TypeError, function() {
      ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20);
    });

    // broken images should throw InvalidStateError
    assert_throws_dom("INVALID_STATE_ERR", function() {
      ctx.drawImage(invalidImage, 0, 0);
    });
    assert_throws_dom("INVALID_STATE_ERR", function() {
      ctx.drawImage(invalidImage, 0, 0, 20, 20);
    });
    assert_throws_dom("INVALID_STATE_ERR", function() {
      ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20);
    });
    assert_throws_dom("INVALID_STATE_ERR", function() {
      ctx.drawImage(invalidImage, 0, 0, 0, 20);
    });
    assert_throws_dom("INVALID_STATE_ERR", function() {
      ctx.drawImage(invalidImage, 0, 0, 0, 20, 0, 0, 20, 20);
    });
}

async_test(t => {
        invalidImage.onerror = function() {
            t.step(draw);
            t.done();
        }
}, "This test checks behavior of Canvas::drawImage with a broken source image.");
</script>
</body>
</html>