diff --git a/test/dzi-jsonp.js b/test/dzi-jsonp.js index dca069d5..08b7da22 100644 --- a/test/dzi-jsonp.js +++ b/test/dzi-jsonp.js @@ -7,6 +7,8 @@ // ---------- asyncTest('Open', function() { $(document).ready(function() { + var timeWatcher = Util.timeWatcher(); + viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -19,21 +21,13 @@ viewer.removeHandler('open', openHandler); ok(true, 'Open event was sent'); viewer.drawer.viewer = viewer; - - timeout = setTimeout(function() { - viewer.removeHandler('tile-drawn', tileDrawnHandler); - ok(false, 'taking too long'); - start(); - }, 2000); - viewer.addHandler('tile-drawn', tileDrawnHandler); }; var tileDrawnHandler = function(eventSender, eventData) { viewer.removeHandler('tile-drawn', tileDrawnHandler); ok(true, 'A tile has been drawn'); - clearTimeout(timeout); - start(); + timeWatcher.done(); }; viewer.addHandler('open', openHandler); diff --git a/test/util.js b/test/util.js index a426bd52..382e7032 100644 --- a/test/util.js +++ b/test/util.js @@ -26,6 +26,29 @@ .simulate('mouseover', event) .simulate('mousedown', event) .simulate('mouseup', event); + }, + + // ---------- + timeWatcher: function(time) { + time = time || 2000; + var finished = false; + + setTimeout(function() { + if (!finished) { + finished = true; + ok(false, 'finishes in ' + time + 'ms'); + start(); + } + }, time); + + return { + done: function() { + if (!finished) { + finished = true; + start(); + } + } + }; } };