do not set background or overlay image if the load fails. (#3003)

This commit is contained in:
Andrea Bogazzi 2016-05-23 14:53:09 +02:00
parent 1843581488
commit dd3e6a81e2
2 changed files with 13 additions and 1 deletions

View file

@ -398,7 +398,7 @@
__setBgOverlayImage: function(property, image, callback, options) {
if (typeof image === 'string') {
fabric.util.loadImage(image, function(img) {
this[property] = new fabric.Image(img, options);
img && (this[property] = new fabric.Image(img, options));
callback && callback(img);
}, this, options && options.crossOrigin);
}

View file

@ -1217,6 +1217,18 @@
});
});
//how to test with an exception?
/*asyncTest('options in setBackgroundImage from invalid URL', function() {
canvas.backgroundImage = null;
canvas.setBackgroundImage(IMG_SRC + '_not_exist', function() {
equal(canvas.backgroundImage, null);
start();
}, {
left: 50,
originX: 'right'
});
});*/
asyncTest('options in setBackgroundImage from image instance', function() {
createImageObject(function(imageInstance) {
canvas.setBackgroundImage(imageInstance, function() {