From 7e39a528c03708bcf762ab55069937b7f00bf44f Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Thu, 4 Jun 2015 09:47:50 -0400 Subject: [PATCH] Add tests for tile-loaded event. --- test/modules/events.js | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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' ); + } ); + } )();