| OLD | NEW |
| 1 <canvas width="200" height="200" id="canvas">FAIL: no canvas support</canvas> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <div id="log"></div> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <canvas width="200" height="200" id="canvas"></canvas> |
| 3 <script> | 4 <script> |
| 4 if (window.testRunner) | 5 test(function(t) { |
| 5 testRunner.dumpAsText(); | 6 var ctx = document.getElementById("canvas").getContext("2d"); |
| 6 | 7 |
| 7 var canvas = document.getElementById("canvas").getContext("2d"); | 8 // 1. Infinite dimensions to fillRect |
| 8 //four tests | 9 ctx.fillStyle = "green"; |
| 9 // 1. Infinite dimensions to fillRect | 10 ctx.fillRect(0, 0, 100, 100); |
| 10 canvas.fillStyle = "green"; | 11 ctx.fillStyle = "red"; |
| 11 canvas.fillRect(0, 0, 100, 100); | 12 ctx.fillRect(0, 0, Infinity, Infinity); |
| 12 canvas.fillStyle = "red"; | 13 |
| 13 try { | 14 // 2. Infinite dimensions to rect |
| 14 canvas.fillRect(0, 0, Infinity, Infinity); | 15 ctx.fillStyle = "green"; |
| 15 } catch (e) { | 16 ctx.fillRect(100, 0, 100, 100); |
| 16 canvas.fillRect(0, 0, 100, 100); | 17 ctx.fillStyle = "red"; |
| 17 } | 18 ctx.rect(100, 0, Infinity, Infinity); |
| 18 | 19 ctx.fill(); |
| 19 // 2. Infinite dimensions to rect | 20 |
| 20 canvas.fillStyle = "green"; | 21 // 3. Infinite argument to moveTo |
| 21 canvas.fillRect(100, 0, 100, 100); | 22 ctx.translate(0, 100); |
| 22 canvas.fillStyle = "red"; | 23 ctx.fillStyle = "red"; |
| 23 try { | 24 ctx.fillRect(0, 0, 100, 100); |
| 24 canvas.rect(100, 0, Infinity, Infinity); | 25 ctx.fillStyle = "green"; |
| 25 canvas.fill(); | 26 ctx.beginPath(); |
| 26 } catch (e) { | 27 ctx.moveTo(Infinity, Infinity); |
| 27 canvas.fillRect(100, 0, 100, 100); | 28 ctx.rect(0, 0, 100, 100); |
| 28 } | 29 ctx.fill(); |
| 29 | 30 |
| 30 // 3. Infinite argument to moveTo | 31 // 4. Infinite argument to lineTo |
| 31 canvas.translate(0, 100); | 32 ctx.translate(100, 0); |
| 32 canvas.fillStyle = "red"; | 33 ctx.fillStyle = "red"; |
| 33 canvas.fillRect(0, 0, 100, 100); | 34 ctx.fillRect(0, 0, 100, 100); |
| 34 canvas.fillStyle = "green"; | 35 ctx.fillStyle = "green"; |
| 35 try { | 36 ctx.beginPath(); |
| 36 canvas.beginPath(); | 37 ctx.moveTo(0,0); |
| 37 canvas.moveTo(Infinity, Infinity); | 38 ctx.lineTo(100, 0); |
| 38 canvas.rect(0, 0, 100, 100); | 39 ctx.lineTo(100, 100); |
| 39 canvas.fill(); | 40 ctx.lineTo(0, 100); |
| 40 } catch (e) { | 41 ctx.lineTo(Infinity, 100); |
| 41 alert(e); | 42 ctx.fill(); |
| 42 } | 43 |
| 43 | 44 var points = [25, 50, 75, 125, 150, 175]; |
| 44 // 4. Infinite argument to lineTo | 45 for (var x = 0; x < points.length; x++) |
| 45 canvas.translate(100, 0); | 46 for (var y = 0; y < points.length; y++) |
| 46 canvas.fillStyle = "red"; | 47 assert_array_equals(ctx.getImageData(points[x], points[y], 1, 1).dat
a, [0, 128, 0, 255]); |
| 47 canvas.fillRect(0, 0, 100, 100); | 48 }, 'Test canvas with infinity passed to fillRect, rect, moveTo and lineTo.'); |
| 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) { | |
| 58 } | |
| 59 | |
| 60 function log(msg){ | |
| 61 document.getElementById("log").innerHTML += msg + "<br/>"; | |
| 62 } | |
| 63 | |
| 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; | |
| 69 } | |
| 70 | |
| 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); | |
| 76 } | |
| 77 | |
| 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; | |
| 85 } | |
| 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+
"]"); | |
| 90 } | |
| 91 | |
| 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]); | |
| 96 } | |
| 97 } | |
| 98 </script> | 49 </script> |
| OLD | NEW |