|
|
@ -7,7 +7,8 @@ var Canvas = require('../') |
|
|
|
, Image = Canvas.Image |
|
|
|
, assert = require('assert'); |
|
|
|
|
|
|
|
var png = __dirname + '/fixtures/clock.png'; |
|
|
|
var png_checkers = __dirname + '/fixtures/checkers.png'; |
|
|
|
var png_clock = __dirname + '/fixtures/clock.png'; |
|
|
|
|
|
|
|
describe('Image', function () { |
|
|
|
it('Image', function () { |
|
|
@ -23,18 +24,48 @@ describe('Image', function () { |
|
|
|
|
|
|
|
img.onload = function () { |
|
|
|
onloadCalled += 1; |
|
|
|
assert.strictEqual(img.src, png); |
|
|
|
assert.strictEqual(img.src, png_clock); |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png; |
|
|
|
img.src = png_clock; |
|
|
|
assert.strictEqual(1, onloadCalled); |
|
|
|
assert.strictEqual(img.src, png); |
|
|
|
assert.strictEqual(img.src, png_clock); |
|
|
|
|
|
|
|
assert.strictEqual(true, img.complete); |
|
|
|
assert.strictEqual(320, img.width); |
|
|
|
assert.strictEqual(320, img.height); |
|
|
|
}); |
|
|
|
|
|
|
|
it('test Image#onload multiple times', function() { |
|
|
|
var img = new Image |
|
|
|
, onloadCalled = 0; |
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
onloadCalled += 1; |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png_checkers; |
|
|
|
assert.equal(img.src, png_checkers); |
|
|
|
assert.strictEqual(true, img.complete); |
|
|
|
assert.strictEqual(2, img.width); |
|
|
|
assert.strictEqual(2, img.height); |
|
|
|
|
|
|
|
img.src = png_clock; |
|
|
|
assert.equal(img.src, png_clock); |
|
|
|
assert.strictEqual(true, img.complete); |
|
|
|
assert.strictEqual(320, img.width); |
|
|
|
assert.strictEqual(320, img.height); |
|
|
|
|
|
|
|
assert.equal(onloadCalled, 2); |
|
|
|
|
|
|
|
onloadCalled = 0; |
|
|
|
img.onload = function() { |
|
|
|
onloadCalled += 1; |
|
|
|
}; |
|
|
|
img.src = png_clock; |
|
|
|
assert.equal(onloadCalled, 1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Image#onerror', function () { |
|
|
|
var img = new Image |
|
|
|
, error |
|
|
@ -53,18 +84,48 @@ describe('Image', function () { |
|
|
|
}; |
|
|
|
|
|
|
|
try { |
|
|
|
img.src = png + 's'; |
|
|
|
img.src = png_clock + 's'; |
|
|
|
} catch (err) { |
|
|
|
assert.fail('error did not invoke onerror(): ' + err); |
|
|
|
} |
|
|
|
|
|
|
|
assert.strictEqual(1, onerrorCalled); |
|
|
|
assert.strictEqual(img.src, png + 's'); |
|
|
|
assert.strictEqual(img.src, png_clock + 's'); |
|
|
|
assert.strictEqual(false, img.complete); |
|
|
|
|
|
|
|
assert.ok(error instanceof Error, 'did not invoke onerror() with error'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('test Image#onerror multiple calls', function() { |
|
|
|
var img = new Image |
|
|
|
, onerrorCalled = 0; |
|
|
|
|
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
assert.fail('called onload'); |
|
|
|
}; |
|
|
|
|
|
|
|
img.onerror = function() { |
|
|
|
onerrorCalled += 1; |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png_clock + 's1'; |
|
|
|
assert.equal(img.src, png_clock + 's1'); |
|
|
|
|
|
|
|
img.src = png_clock + 's2'; |
|
|
|
assert.equal(img.src, png_clock + 's2'); |
|
|
|
|
|
|
|
assert.equal(onerrorCalled, 2); |
|
|
|
|
|
|
|
onerrorCalled = 0; |
|
|
|
img.onerror = function() { |
|
|
|
onerrorCalled += 1; |
|
|
|
}; |
|
|
|
img.src = png_clock + 's3'; |
|
|
|
assert.equal(img.src, png_clock + 's3'); |
|
|
|
assert.equal(onerrorCalled, 1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Image#{width,height}', function () { |
|
|
|
var img = new Image |
|
|
|
, onloadCalled = 0; |
|
|
@ -78,7 +139,7 @@ describe('Image', function () { |
|
|
|
assert.strictEqual(320, img.height); |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png; |
|
|
|
img.src = png_clock; |
|
|
|
assert.strictEqual(1, onloadCalled); |
|
|
|
assert.strictEqual(320, img.width); |
|
|
|
assert.strictEqual(320, img.height); |
|
|
|