Generalized test timeout code

This commit is contained in:
Ian Gilman 2013-05-10 11:53:49 -07:00
parent 457f908c06
commit b95d6540a1
2 changed files with 26 additions and 9 deletions

View File

@ -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);

View File

@ -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();
}
}
};
}
};