Move open-failed error message to the handler, adjust test for the new message style. Add 'numberOfHandlers()' method for events.

This commit is contained in:
Jirka 2022-04-15 10:32:08 +02:00
parent 1ec4d71db0
commit ec430779f4
4 changed files with 48 additions and 4 deletions

View File

@ -122,6 +122,18 @@ $.EventSource.prototype = {
}
},
/**
* Get the amount of handlers registered for a given event.
* @param {String} eventName - Name of event to inspect.
* @return {number} amount of events
*/
numberOfHandlers: function (eventName) {
var events = this.events[ eventName ];
if ( !events ) {
return 0;
}
return events.length;
},
/**
* Remove all event handlers for a given event type. If no type is given all

View File

@ -529,7 +529,7 @@ $.TileSource.prototype = {
exception rather than the second one raised when we try to access xhr.status
*/
try {
msg = "HTTP " + xhr.status + " attempting to load TileSource";
msg = "HTTP " + xhr.status + " attempting to load TileSource: " + url;
} catch ( e ) {
var formattedExc;
if ( typeof ( exc ) === "undefined" || !exc.toString ) {
@ -538,9 +538,11 @@ $.TileSource.prototype = {
formattedExc = exc.toString();
}
msg = formattedExc + " attempting to load TileSource";
msg = formattedExc + " attempting to load TileSource: " + url;
}
$.console.error(msg);
/***
* Raised when an error occurs loading a TileSource.
*

View File

@ -58,8 +58,8 @@
assert.equal($(".openseadragon-message").length, 1, "Open failures should display a message");
assert.ok(testLog.error.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
"AJAX failures should be logged to the console");
assert.ok(testLog.error.contains('["HTTP 404 attempting to load TileSource: /test/data/not-a-real-file"]'),
"'open-failed' fired after AJAX error handler prints error to the console.'");
done();
});

View File

@ -1152,6 +1152,36 @@
});
// ----------
QUnit.test( 'Viewer: event count test with \'tile-drawing\'', function (assert) {
var done = assert.async();
assert.ok(viewer.numberOfHandlers('tile-drawing') === 0,
"'tile-drawing' event is empty by default.");
var tileDrawing = function ( event ) {
viewer.removeHandler( 'tile-drawing', tileDrawing );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 0,
"'tile-drawing' deleted: count is 0.");
viewer.close();
done();
};
var tileDrawingDummy = function ( event ) {};
viewer.addHandler( 'tile-drawing', tileDrawing );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 1,
"'tile-drawing' event set to 1.");
viewer.addHandler( 'tile-drawing', tileDrawingDummy );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 2,
"'tile-drawing' event set to 2.");
viewer.removeHandler( 'tile-drawing', tileDrawingDummy );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 1,
"'tile-drawing' deleted once: count is 1.");
viewer.open( '/test/data/testpattern.dzi' );
} );
QUnit.test( 'Viewer: tile-drawing event', function (assert) {
var done = assert.async();
var tileDrawing = function ( event ) {