| OLD | NEW |
| (Empty) |
| 1 // Compare sections of a <canvas> to assert they are identical, or nearly so. | |
| 2 function compareRows(ctx, y0, y1, width, height, allowableDifference) { | |
| 3 var data0 = ctx.getImageData(0, y0, width, height).data; | |
| 4 var data1 = ctx.getImageData(0, y1, width, height).data; | |
| 5 for (var i = 0, il = data0.length; i < il; ++i) { | |
| 6 if (Math.abs(data0[i] - data1[i]) > allowableDifference) { | |
| 7 testFailed("Pixel at " + i + " should be within " + allowableDiffere
nce + | |
| 8 " of " + data0[i] + " but was " + data1[i]); | |
| 9 break; | |
| 10 } | |
| 11 } | |
| 12 } | |
| 13 | |
| 14 description("Test the default lineWidth is consistent."); | |
| 15 | |
| 16 ctx = document.getElementById("canvas").getContext("2d"); | |
| 17 | |
| 18 ctx.strokeStyle = 'blue'; | |
| 19 | |
| 20 for (var j = 0; j < 3; ++j) { | |
| 21 ctx.beginPath(); | |
| 22 for (var i = 0; i < 60; ++i) { | |
| 23 var x = i * 10; | |
| 24 var y = j * 100 + 30 + (i % 15); | |
| 25 if (i == 0) { | |
| 26 ctx.moveTo(x, y); | |
| 27 } else { | |
| 28 ctx.lineTo(x, y); | |
| 29 } | |
| 30 } | |
| 31 ctx.stroke(); | |
| 32 | |
| 33 if (j == 0) { | |
| 34 shouldBe("ctx.lineWidth", "1"); | |
| 35 ctx.lineWidth = ctx.lineWidth; | |
| 36 shouldBe("ctx.lineWidth", "1"); | |
| 37 } else { | |
| 38 shouldBe("ctx.lineWidth", "1"); | |
| 39 ctx.lineWidth = 1; | |
| 40 shouldBe("ctx.lineWidth", "1"); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 // Make sure that all rows are nearly identical. | |
| 45 // (Tiny variations are OK.) | |
| 46 compareRows(ctx, 0, 100, 600, 100, 1); | |
| 47 compareRows(ctx, 0, 200, 600, 100, 1); | |
| OLD | NEW |