diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 4c4cf666..90311c80 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -49,6 +49,16 @@ function test(testName, expected) { }); } +function asyncTest(testName, expected) { + return QUnit.asyncTest(testName, function() { + var project = new Project(); + expected(function() { + project.remove(); + start(); + }); + }); +} + function compareNumbers(number1, number2, message) { equals(Format.number(number1, 2), Format.number(number2, 2), message); } diff --git a/test/resources/paper-js.gif b/test/resources/paper-js.gif new file mode 100644 index 00000000..e6775a4a Binary files /dev/null and b/test/resources/paper-js.gif differ diff --git a/test/tests/Raster.js b/test/tests/Raster.js index 6d540d49..4856669e 100644 --- a/test/tests/Raster.js +++ b/test/tests/Raster.js @@ -22,3 +22,48 @@ test('Create a raster without a source and set its size', function() { raster.size = [640, 480]; equals(raster.size.toString(), new Size(640, 480).toString(), true); }); + +asyncTest('Create a raster from a url', function(callback) { + var raster = new Raster('resources/paper-js.gif'); + raster.onLoad = function() { + equals(raster.size.toString(), new Size(146, 146).toString(), true); + callback(); + }; +}); + +asyncTest('Create a raster from a dom image', function(callback) { + var img = document.createElement('img'); + img.src = 'resources/paper-js.gif'; + document.body.appendChild(img); + DomEvent.add(img, { + load: function() { + var raster = new Raster(img); + equals(raster.size.toString(), new Size(146, 146).toString(), true); + document.body.removeChild(img); + callback(); + } + }); +}); + + +test('Create a raster from a canvas', function(callback) { + var canvas = CanvasProvider.getCanvas(30, 20); + var raster = new Raster(canvas); + equals(raster.size.toString(), new Size(30, 20).toString(), true); + CanvasProvider.release(canvas); +}); + +asyncTest('Create a raster from a dom id', function(callback) { + var img = document.createElement('img'); + img.src = 'resources/paper-js.gif'; + img.id = 'testimage'; + document.body.appendChild(img); + DomEvent.add(img, { + load: function() { + var raster = new Raster('testimage'); + equals(raster.size.toString(), new Size(146, 146).toString(), true); + document.body.removeChild(img); + callback(); + } + }); +}); \ No newline at end of file