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 " + allowableDifference +
8 " of " + data0[i] + " but was " + data1[i]);
14 description("Test the default lineWidth is consistent.");
16 ctx = document.getElementById("canvas").getContext("2d");
18 ctx.strokeStyle = 'blue';
20 for (var j = 0; j < 3; ++j) {
22 for (var i = 0; i < 60; ++i) {
24 var y = j * 100 + 30 + (i % 15);
34 shouldBe("ctx.lineWidth", "1");
35 ctx.lineWidth = ctx.lineWidth;
36 shouldBe("ctx.lineWidth", "1");
38 shouldBe("ctx.lineWidth", "1");
40 shouldBe("ctx.lineWidth", "1");
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);