1 descriptionQuiet("Series of tests to ensure that strokeText() does not display any text when maxWidth is invalid.");
3 var canvas = document.createElement('canvas');
4 var ctx = canvas.getContext('2d');
7 canvas.setWidth = canvasWidth;
8 canvas.setHeight = canvasHeight;
11 ctx.fillStyle = '#0f0';
12 ctx.fillRect(0, 0, canvasWidth, canvasHeight);
13 ctx.font = '35px Arial, sans-serif';
15 debug("Test canvas.strokeText() with maxWidth zero");
16 ctx.strokeStyle = '#f00';
17 ctx.strokeText("fail fail fail fail fail", 5, 35, 0);
19 var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
20 var w = imageData.width, h = imageData.height, d = imageData.data;
21 for (var i = 0; i < h; ++i) {
22 for (var j = 0; j < w; ++j) {
23 if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0");
24 if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255");
25 if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0");
26 if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");
30 ctx.fillStyle = '#0f0';
31 ctx.fillRect(0, 0, canvasWidth, canvasHeight);
32 debug("Test canvas.strokeText() with maxWidth -1");
33 ctx.strokeStyle = '#f00';
34 ctx.strokeText("fail fail fail fail fail", 5, 35, -1);
36 var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
37 var w = imageData.width, h = imageData.height, d = imageData.data;
38 for (var i = 0; i < h; ++i) {
39 for (var j = 0; j < w; ++j) {
40 if (d[4 * (w * i + j) + 0] != 0) shouldBe("d[4 * (w * i + j) + 0]", "0");
41 if (d[4 * (w * i + j) + 1] != 255) shouldBe("d[4 * (w * i + j) + 1]", "255");
42 if (d[4 * (w * i + j) + 2] != 0) shouldBe("d[4 * (w * i + j) + 2]", "0");
43 if (d[4 * (w * i + j) + 3] != 255) shouldBe("d[4 * (w * i + j) + 3]", "255");