| OLD | NEW |
| (Empty) |
| 1 description("Series of tests to ensure correct behaviour of canvas.strokeRect()"
); | |
| 2 var ctx = document.createElement('canvas').getContext('2d'); | |
| 3 | |
| 4 // stroke rect with solid green | |
| 5 debug("Test canvas.strokeRect() with solid green."); | |
| 6 ctx.beginPath(); | |
| 7 ctx.strokeStyle = 'green'; | |
| 8 ctx.lineWidth = 100; | |
| 9 ctx.strokeRect(50, 0, 100, 100); | |
| 10 | |
| 11 var imageData = ctx.getImageData(1, 1, 98, 98); | |
| 12 var imgdata = imageData.data; | |
| 13 shouldBe("imgdata[4]", "0"); | |
| 14 shouldBe("imgdata[5]", "128"); | |
| 15 shouldBe("imgdata[6]", "0"); | |
| 16 | |
| 17 ctx.clearRect(0, 0, 100, 100); | |
| 18 | |
| 19 // stroke rect with a pattern | |
| 20 debug("Test canvas.strokeRect() with a pattern."); | |
| 21 var canvas2 = document.createElement('canvas'); | |
| 22 canvas2.width = 100; | |
| 23 canvas2.height = 100; | |
| 24 var ctx2 = canvas2.getContext('2d'); | |
| 25 ctx2.fillStyle = 'green'; | |
| 26 ctx2.fillRect(0, 0, 100, 100); | |
| 27 var pattern = ctx.createPattern(canvas2, 'repeat'); | |
| 28 ctx.strokeStyle = 'pattern'; | |
| 29 ctx.lineWidth = 100; | |
| 30 ctx.strokeRect(50, 0, 100, 100); | |
| 31 | |
| 32 imageData = ctx.getImageData(1, 1, 98, 98); | |
| 33 imgdata = imageData.data; | |
| 34 shouldBe("imgdata[4]", "0"); | |
| 35 shouldBe("imgdata[5]", "128"); | |
| 36 shouldBe("imgdata[6]", "0"); | |
| 37 | |
| 38 ctx.clearRect(0, 0, 100, 100); | |
| 39 | |
| 40 // stroke rect with gradient | |
| 41 debug("Test canvas.strokeRect() with a gradient."); | |
| 42 var gradient = ctx.createLinearGradient(0, 0, 0, 100); | |
| 43 gradient.addColorStop(0, "green"); | |
| 44 gradient.addColorStop(1, "green"); | |
| 45 ctx.strokeStyle = 'gradient'; | |
| 46 ctx.lineWidth = 100; | |
| 47 ctx.strokeRect(50, 0, 100, 100); | |
| 48 | |
| 49 imageData = ctx.getImageData(1, 1, 98, 98); | |
| 50 imgdata = imageData.data; | |
| 51 shouldBe("imgdata[4]", "0"); | |
| 52 shouldBe("imgdata[5]", "128"); | |
| 53 shouldBe("imgdata[6]", "0"); | |
| 54 | |
| 55 ctx.clearRect(0, 0, 100, 100); | |
| 56 | |
| 57 // stroke rect with height = width = 0 and lineWidth = 2. | |
| 58 debug("Test canvas.strokeRect() with height = width = 0 and lineWidth = 2."); | |
| 59 ctx.strokeStyle = 'red'; | |
| 60 ctx.lineWidth = 2; | |
| 61 ctx.strokeRect(0, 0, 0, 0); | |
| 62 imageData = ctx.getImageData(0, 0, 1, 1); | |
| 63 imgdata = imageData.data; | |
| 64 shouldBe("imgdata[0]", "0"); | |
| 65 shouldBe("imgdata[1]", "0"); | |
| 66 shouldBe("imgdata[2]", "0"); | |
| 67 | |
| 68 // stroke rect with height = width = 0, lineWidth = 2, and shadow. | |
| 69 debug("Test canvas.strokeRect() with height = width = 0, lineWidth = 2, and shad
ow."); | |
| 70 ctx.shadowOffsetX = 5; | |
| 71 ctx.shadowOffsetY = 5; | |
| 72 ctx.shadowColor = 'blue'; | |
| 73 ctx.strokeStyle = 'red'; | |
| 74 ctx.lineWidth = 2; | |
| 75 ctx.strokeRect(0, 0, 0, 0); | |
| 76 imageData = ctx.getImageData(0, 0, 1, 1); | |
| 77 imgdata = imageData.data; | |
| 78 shouldBe("imgdata[0]", "0"); | |
| 79 shouldBe("imgdata[1]", "0"); | |
| 80 shouldBe("imgdata[2]", "0"); | |
| OLD | NEW |