From d671049a1791631d8ba2f03c42100eae25416a90 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Thu, 11 Jun 2015 15:27:36 -0400 Subject: [PATCH] Fix and add unit tests. --- src/tilecache.js | 2 +- test/modules/events.js | 27 +++++++++++++++++++++++++++ test/modules/tilecache.js | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/tilecache.js b/src/tilecache.js index 85b51ebb..191bb52e 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -223,7 +223,7 @@ $.TileCache.prototype = /** @lends OpenSeadragon.TileCache.prototype */{ for ( var i = 0; i < this._tilesLoaded.length; ++i ) { tileRecord = this._tilesLoaded[ i ]; if ( tileRecord.tiledImage === tiledImage ) { - this._unloadTile(tileRecord.tile); + this._unloadTile(tileRecord); this._tilesLoaded.splice( i, 1 ); i--; } diff --git a/test/modules/events.js b/test/modules/events.js index b6838b40..62caa072 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -1040,4 +1040,31 @@ 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' ); + } ); + } )(); diff --git a/test/modules/tilecache.js b/test/modules/tilecache.js index afb0ca52..80bb44de 100644 --- a/test/modules/tilecache.js +++ b/test/modules/tilecache.js @@ -13,8 +13,15 @@ // ---------- asyncTest('basics', function() { - var fakeTiledImage0 = {}; - var fakeTiledImage1 = {}; + var fakeViewer = { + raiseEvent: function() {} + }; + var fakeTiledImage0 = { + viewer: fakeViewer + }; + var fakeTiledImage1 = { + viewer: fakeViewer + }; var fakeTile0 = { url: 'foo.jpg', @@ -58,7 +65,12 @@ // ---------- asyncTest('maxImageCacheCount', function() { - var fakeTiledImage0 = {}; + var fakeViewer = { + raiseEvent: function() {} + }; + var fakeTiledImage0 = { + viewer: fakeViewer + }; var fakeTile0 = { url: 'different.jpg',