diff --git a/test/canvas.test.js b/test/canvas.test.js index 2719615..918f043 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -303,5 +303,39 @@ module.exports = { assert.ok(!err); assert.ok(0 == str.indexOf('data:image/png;base64,')); }); + }, + + 'test Context2d#getImageData()': function(assert){ + var canvas = new Canvas(3, 6) + , ctx = canvas.getContext('2d'); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0,0,1,6); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(1,0,1,6); + + ctx.fillStyle = '#00f'; + ctx.fillRect(2,0,1,6); + + var imageData = ctx.getImageData(0,0,3,6); + assert.equal(3, imageData.width); + assert.equal(6, imageData.height); + assert.equal(3 * 6 * 4, imageData.data.length); + + assert.equal(255, imageData.data[0]); + assert.equal(0, imageData.data[1]); + assert.equal(0, imageData.data[2]); + assert.equal(255, imageData.data[3]); + + assert.equal(0, imageData.data[4]); + assert.equal(255, imageData.data[5]); + assert.equal(0, imageData.data[6]); + assert.equal(255, imageData.data[7]); + + assert.equal(0, imageData.data[8]); + assert.equal(0, imageData.data[9]); + assert.equal(255, imageData.data[10]); + assert.equal(255, imageData.data[11]); } } \ No newline at end of file