diff --git a/test/modules/events.js b/test/modules/events.js index 677e805f..0c5e5df9 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -968,4 +968,76 @@ viewer.open( '/test/data/testpattern.dzi' ); } ); + // tile-loaded event tests + asyncTest( 'Viewer: tile-loaded event without callback.', function () { + + function tileLoaded ( event ) { + viewer.removeHandler( 'tile-loaded', tileLoaded); + var tile = event.tile; + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + setTimeout(function() { + notOk( tile.loading, "The tile should not be marked as loading."); + ok( tile.loaded, "The tile should not be marked as loaded."); + start(); + }, 0); + } + + viewer.addHandler( 'tile-loaded', tileLoaded); + viewer.open( '/test/data/testpattern.dzi' ); + } ); + + asyncTest( 'Viewer: tile-loaded event with 1 callback.', function () { + + function tileLoaded ( event ) { + viewer.removeHandler( 'tile-loaded', tileLoaded); + var tile = event.tile; + var callback = event.getCompletionCallback(); + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + ok( callback, "The event should have a callback."); + setTimeout(function() { + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + callback(); + notOk( tile.loading, "The tile should not be marked as loading."); + ok( tile.loaded, "The tile should not be marked as loaded."); + start(); + }, 0); + } + + viewer.addHandler( 'tile-loaded', tileLoaded); + viewer.open( '/test/data/testpattern.dzi' ); + } ); + + asyncTest( 'Viewer: tile-loaded event with 2 callbacks.', function () { + + function tileLoaded ( event ) { + viewer.removeHandler( 'tile-loaded', tileLoaded); + var tile = event.tile; + var callback1 = event.getCompletionCallback(); + var callback2 = event.getCompletionCallback(); + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + setTimeout(function() { + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + callback1(); + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + setTimeout(function() { + ok( tile.loading, "The tile should be marked as loading."); + notOk( tile.loaded, "The tile should not be marked as loaded."); + callback2(); + notOk( tile.loading, "The tile should not be marked as loading."); + ok( tile.loaded, "The tile should not be marked as loaded."); + start(); + }, 0); + }, 0); + } + + viewer.addHandler( 'tile-loaded', tileLoaded); + viewer.open( '/test/data/testpattern.dzi' ); + } ); + } )();