OLD | NEW |
(Empty) | |
| 1 description("Series of tests to ensure correct behaviour when canvas size is ext
remely large."); |
| 2 var canvas = document.createElement('canvas') |
| 3 var ctx = canvas.getContext('2d'); |
| 4 |
| 5 // WebIDL defines width and height as int. 2147483647 is int max. |
| 6 var extremelyLargeNumber = 2147483647; |
| 7 canvas.width = extremelyLargeNumber; |
| 8 canvas.height = extremelyLargeNumber; |
| 9 |
| 10 debug("check for crash on extremely large canvas size."); |
| 11 useCanvasContext(ctx); |
| 12 var imageData = ctx.getImageData(1, 1, 98, 98); |
| 13 var imgdata = imageData.data; |
| 14 // Blink returns zero color if the image buffer does not exist. |
| 15 shouldBe("imgdata[4]", "0"); |
| 16 shouldBe("imgdata[5]", "0"); |
| 17 shouldBe("imgdata[6]", "0"); |
| 18 |
| 19 debug("check for crash after resetting to the same size."); |
| 20 canvas.width = extremelyLargeNumber; |
| 21 useCanvasContext(ctx); |
| 22 imageData = ctx.getImageData(1, 1, 98, 98); |
| 23 imgdata = imageData.data; |
| 24 shouldBe("imgdata[4]", "0"); |
| 25 shouldBe("imgdata[5]", "0"); |
| 26 shouldBe("imgdata[6]", "0"); |
| 27 |
| 28 // googol is parsed to 0. |
| 29 var googol = Math.pow(10, 100); |
| 30 debug("check for crash after resizing to googol."); |
| 31 canvas.width = googol; |
| 32 canvas.height = googol; |
| 33 useCanvasContext(ctx); |
| 34 imageData = ctx.getImageData(1, 1, 98, 98); |
| 35 imgdata = imageData.data; |
| 36 shouldBe("imgdata[4]", "0"); |
| 37 shouldBe("imgdata[5]", "0"); |
| 38 shouldBe("imgdata[6]", "0"); |
| 39 |
| 40 debug("check for crash after resetting to the same size."); |
| 41 canvas.width = googol; |
| 42 useCanvasContext(ctx); |
| 43 imageData = ctx.getImageData(1, 1, 98, 98); |
| 44 imgdata = imageData.data; |
| 45 shouldBe("imgdata[4]", "0"); |
| 46 shouldBe("imgdata[5]", "0"); |
| 47 shouldBe("imgdata[6]", "0"); |
| 48 |
| 49 debug("check again for crash on extremely large canvas size."); |
| 50 canvas.width = extremelyLargeNumber; |
| 51 canvas.height = extremelyLargeNumber; |
| 52 useCanvasContext(ctx); |
| 53 imageData = ctx.getImageData(1, 1, 98, 98); |
| 54 imgdata = imageData.data; |
| 55 shouldBe("imgdata[4]", "0"); |
| 56 shouldBe("imgdata[5]", "0"); |
| 57 shouldBe("imgdata[6]", "0"); |
| 58 |
| 59 function useCanvasContext(ctx) { |
| 60 ctx.fillStyle = 'green'; |
| 61 ctx.fillRect(0, 0, 100, 100); |
| 62 for(var i = 0; i < 100; i++) { |
| 63 // This API tries to create an image buffer if the image buffer is not c
reated. |
| 64 ctx.getImageData(1, 1, 1, 1); |
| 65 } |
| 66 ctx.beginPath(); |
| 67 ctx.rect(0,0,100,100); |
| 68 ctx.save(); |
| 69 ctx.fillStyle = 'red'; |
| 70 ctx.fillRect(0, 0, 100, 100); |
| 71 ctx.restore(); |
| 72 ctx.fillStyle = 'green'; |
| 73 ctx.fill(); |
| 74 } |
| 75 |
| 76 debug("after resizing to normal size, the canvas must be in a valid state."); |
| 77 canvas.width = 100; |
| 78 canvas.height = 100; |
| 79 ctx.fillStyle = 'blue'; |
| 80 ctx.fillRect(0, 0, 100, 100); |
| 81 imageData = ctx.getImageData(1, 1, 98, 98); |
| 82 imgdata = imageData.data; |
| 83 shouldBe("imgdata[4]", "0"); |
| 84 shouldBe("imgdata[5]", "0"); |
| 85 shouldBe("imgdata[6]", "255"); |
OLD | NEW |