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