mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-31 23:21:42 +03:00
Generalized test timeout code
This commit is contained in:
parent
457f908c06
commit
b95d6540a1
@ -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);
|
||||
|
23
test/util.js
23
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user