Add raster constructor tests, add async test helper function and test image.

This commit is contained in:
Jonathan Puckey 2013-03-17 18:13:55 +01:00
parent 0d3f746c10
commit 9865d7bdd5
3 changed files with 55 additions and 0 deletions

View file

@ -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);
}

BIN
test/resources/paper-js.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -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();
}
});
});