Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-strokeText-invalid-maxWidth.js
1 descriptionQuiet("Series of tests to ensure that strokeText() does not display any text when maxWidth is invalid.");
2
3 var canvas = document.createElement('canvas');
4 var ctx = canvas.getContext('2d');
5 var canvasWidth = 100;
6 var canvasHeight = 50;
7 canvas.setWidth = canvasWidth;
8 canvas.setHeight = canvasHeight;
9
10
11 ctx.fillStyle = '#0f0';
12 ctx.fillRect(0, 0, canvasWidth, canvasHeight);
13 ctx.font = '35px Arial, sans-serif';
14
15 debug("Test canvas.strokeText() with maxWidth zero");
16 ctx.strokeStyle = '#f00';
17 ctx.strokeText("fail fail fail fail fail", 5, 35, 0);
18
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");
27     }
28 }
29
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);
35
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");
44     }
45 }
46