summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/painting-on-bad-canvas.html
blob: 8044178c7e45f99a0744399d30b478a0388a9a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<canvas id="mycanvas"><button id="button"></button></canvas>
<script src="../../resources/js-test.js"></script>
<script>
description("This tests verifies that canvas API calls on a canvas with no backing or no visibility do not crash or throw exceptions.");

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

var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
var button = document.getElementById('button');
button.focus();

function testAPICalls() {
    try {
        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);
        ctx.scrollPathIntoView();
        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();
    } catch(err) {
        testFailed("Unexpected exception.");
    }
}

// First pass: normal conditions
testAPICalls();

// Test a zero size canvas
canvas.width = 0;
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();

</script>