Fix and add unit tests.

This commit is contained in:
Antoine Vandecreme 2015-06-11 15:27:36 -04:00
parent 9e1433dd66
commit d671049a17
3 changed files with 43 additions and 4 deletions

View File

@ -223,7 +223,7 @@ $.TileCache.prototype = /** @lends OpenSeadragon.TileCache.prototype */{
for ( var i = 0; i < this._tilesLoaded.length; ++i ) { for ( var i = 0; i < this._tilesLoaded.length; ++i ) {
tileRecord = this._tilesLoaded[ i ]; tileRecord = this._tilesLoaded[ i ];
if ( tileRecord.tiledImage === tiledImage ) { if ( tileRecord.tiledImage === tiledImage ) {
this._unloadTile(tileRecord.tile); this._unloadTile(tileRecord);
this._tilesLoaded.splice( i, 1 ); this._tilesLoaded.splice( i, 1 );
i--; i--;
} }

View File

@ -1040,4 +1040,31 @@
viewer.open( '/test/data/testpattern.dzi' ); viewer.open( '/test/data/testpattern.dzi' );
} ); } );
asyncTest( 'Viewer: tile-unloaded event.', function() {
var tiledImage;
var tile;
function tileLoaded( event ) {
viewer.removeHandler( 'tile-loaded', tileLoaded);
tiledImage = event.tiledImage;
tile = event.tile;
setTimeout(function() {
tiledImage.reset();
}, 0);
}
function tileUnloaded( event ) {
viewer.removeHandler( 'tile-unloaded', tileUnloaded );
equal( tile, event.tile,
"The unloaded tile should be the same than the loaded one." );
equal( tiledImage, event.tiledImage,
"The tiledImage of the unloaded tile should be the same than the one of the loaded one." );
start();
}
viewer.addHandler( 'tile-loaded', tileLoaded );
viewer.addHandler( 'tile-unloaded', tileUnloaded );
viewer.open( '/test/data/testpattern.dzi' );
} );
} )(); } )();

View File

@ -13,8 +13,15 @@
// ---------- // ----------
asyncTest('basics', function() { asyncTest('basics', function() {
var fakeTiledImage0 = {}; var fakeViewer = {
var fakeTiledImage1 = {}; raiseEvent: function() {}
};
var fakeTiledImage0 = {
viewer: fakeViewer
};
var fakeTiledImage1 = {
viewer: fakeViewer
};
var fakeTile0 = { var fakeTile0 = {
url: 'foo.jpg', url: 'foo.jpg',
@ -58,7 +65,12 @@
// ---------- // ----------
asyncTest('maxImageCacheCount', function() { asyncTest('maxImageCacheCount', function() {
var fakeTiledImage0 = {}; var fakeViewer = {
raiseEvent: function() {}
};
var fakeTiledImage0 = {
viewer: fakeViewer
};
var fakeTile0 = { var fakeTile0 = {
url: 'different.jpg', url: 'different.jpg',