Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / canvas-path-with-inf-nan-dimensions.html
blob8d767fa0948947bf69930c75663eb4c994762316
1 <canvas width="200" height="200" id="canvas">FAIL: no canvas support</canvas>
2 <div id="log"></div>
3 <script>
4 if (window.testRunner)
5 testRunner.dumpAsText();
7 var canvas = document.getElementById("canvas").getContext("2d");
8 //four tests
9 // 1. Infinite dimensions to fillRect
10 canvas.fillStyle = "green";
11 canvas.fillRect(0, 0, 100, 100);
12 canvas.fillStyle = "red";
13 try {
14 canvas.fillRect(0, 0, Infinity, Infinity);
15 } catch (e) {
16 canvas.fillRect(0, 0, 100, 100);
19 // 2. Infinite dimensions to rect
20 canvas.fillStyle = "green";
21 canvas.fillRect(100, 0, 100, 100);
22 canvas.fillStyle = "red";
23 try {
24 canvas.rect(100, 0, Infinity, Infinity);
25 canvas.fill();
26 } catch (e) {
27 canvas.fillRect(100, 0, 100, 100);
30 // 3. Infinite argument to moveTo
31 canvas.translate(0, 100);
32 canvas.fillStyle = "red";
33 canvas.fillRect(0, 0, 100, 100);
34 canvas.fillStyle = "green";
35 try {
36 canvas.beginPath();
37 canvas.moveTo(Infinity, Infinity);
38 canvas.rect(0, 0, 100, 100);
39 canvas.fill();
40 } catch (e) {
41 alert(e);
44 // 4. Infinite argument to lineTo
45 canvas.translate(100, 0);
46 canvas.fillStyle = "red";
47 canvas.fillRect(0, 0, 100, 100);
48 canvas.fillStyle = "green";
49 try {
50 canvas.beginPath();
51 canvas.moveTo(0,0);
52 canvas.lineTo(100, 0);
53 canvas.lineTo(100, 100);
54 canvas.lineTo(0, 100);
55 canvas.lineTo(Infinity, 100);
56 canvas.fill();
57 } catch (e) {
60 function log(msg){
61 document.getElementById("log").innerHTML += msg + "<br/>";
64 function dataToArray(data) {
65 var result = new Array(data.length)
66 for (var i = 0; i < data.length; i++)
67 result[i] = data[i];
68 return result;
71 function getPixel(ctx, x, y) {
72 var data = ctx.getImageData(x,y,1,1);
73 if (!data) // getImageData failed, which should never happen
74 return [-1,-1,-1,-1];
75 return dataToArray(data.data);
78 function pixelShouldBe(ctx, x, y, colour) {
79 var ctxColour = getPixel(ctx, x, y);
80 var correct = true;
81 for (var i = 0; i < 4; i++)
82 if (colour[i] != ctxColour[i]) {
83 correct = false;
84 break;
86 if (correct)
87 log("PASS: pixel at ("+[x,y]+") was ["+colour+"]");
88 else
89 log("FAIL: pixel at ("+[x,y]+") was ["+ctxColour+"], expected ["+colour+"]");
92 var points = [25, 50, 75, 125, 150, 175];
93 for (var x = 0; x < points.length; x++) {
94 for (var y = 0; y < points.length; y++) {
95 pixelShouldBe(canvas, points[x], points[y], [0, 128, 0, 255]);
98 </script>