forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageUtils.test.js
More file actions
87 lines (48 loc) · 1.74 KB
/
ImageUtils.test.js
File metadata and controls
87 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
QUnit.module( "ImageLoader", {
beforeEach: function() {
THREE.Cache.clear();
}
});
var good_url = '../../examples/textures/sprite.png';
var bad_url = 'url_not_found';
QUnit.test( "test load handler", function( assert ) {
var done = assert.async();
new THREE.TextureLoader().load(good_url, function ( tex ) {
assert.success( "load handler should be called" );
assert.ok( tex, "texture is defined" );
assert.ok( tex.image, "texture.image is defined" );
done();
}, undefined, function () {
assert.fail( "error handler should not be called" );
done();
});
});
QUnit.test( "test error handler", function( assert ) {
var done = assert.async();
new THREE.TextureLoader().load(bad_url, function () {
assert.fail( "load handler should not be called" );
done();
},
undefined,
function ( event ) {
assert.success( "error handler should be called" );
assert.ok( event.type === 'error', "should have error event" );
done();
});
});
QUnit.test( "test cached texture", function( assert ) {
var done = assert.async();
var rtex1 = new THREE.TextureLoader().load(good_url, function ( tex1 ) {
assert.ok( rtex1.image !== undefined, "texture 1 image is loaded" );
assert.equal( rtex1, tex1, "texture 1 callback is equal to return" );
var rtex2 = new THREE.TextureLoader().load(good_url, function ( tex2 ) {
assert.ok( rtex2 !== undefined, "cached callback is async" );
assert.ok( rtex2.image !== undefined, "texture 2 image is loaded" );
assert.equal( rtex2, tex2, "texture 2 callback is equal to return" );
done();
});
assert.ok( rtex2, "texture 2 return is defined" );
});
assert.ok( rtex1, "texture 1 return is defined" );
assert.ok( rtex1.image === undefined, "texture 1 image is not loaded" );
});