chromium/third_party/blink/web_tests/fast/canvas-api/painting-on-bad-canvas.html

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

<canvas id="mycanvas"><button id="button"></button></canvas>
<script>
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
var button = document.getElementById('button');
button.focus();

function testAPICalls() {
    ctx.beginPath();
    ctx.rect(0, 0, 10, 10);
    ctx.fill();
    ctx.stroke();
    ctx.drawFocusIfNeeded(button);
    ctx.isPointInPath(0,0);
    ctx.isPointInStroke(0,0);
    ctx.clearRect(0, 0, 5, 5);
    ctx.fillRect(0, 0, 5, 5);
    ctx.strokeRect(0, 0, 5, 5);
    data = ctx.createImageData(5, 5);
    ctx.putImageData(data, 0, 0);
    ctx.font = "20px arial";
    ctx.fillText("Test", 20, 20);
    ctx.strokeText("Test", 20, 20);
    ctx.measureText("Test");
    ctx.clip();
    ctx.drawImage(canvas, 0, 0);
    ctx.getImageData(0, 0, 5, 5);
    canvas.toDataURL();
}

test(function(){

    // First pass: normal conditions
    testAPICalls();

    // Test a canvas so large that it has no chance of successful allocating a backing
    canvas.width = 10000000;
    canvas.height = 10000000;
    testAPICalls();

    // Test a canvas that is valid, but detached from the DOM
    canvas.width = 100;
    canvas.height = 100;
    canvas.remove();
    testAPICalls();

}, "Verify that canvas API calls on a canvas with no backing or no visibility do not crash or throw exceptions.");
</script>