diff --git a/src/canvasdrawer.js b/src/canvasdrawer.js index c013b0bc..67ff6ec8 100644 --- a/src/canvasdrawer.js +++ b/src/canvasdrawer.js @@ -479,24 +479,9 @@ class CanvasDrawer extends $.DrawerBase{ this._drawDebugInfo( tiledImage, lastDrawn ); // Fire tiled-image-drawn event. - if( this.viewer ){ - /** - * Raised when a tiled image is drawn to the canvas. Used internally for testing. - * The update-viewport event is preferred if you want to know when a frame has been drawn. - * - * @event tiled-image-drawn - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. - * @property {Array} tiles - An array of Tile objects that were drawn. - * @property {?Object} userData - Arbitrary subscriber-defined object. - */ - this.viewer.raiseEvent( 'tiled-image-drawn', { - tiledImage: tiledImage, - tiles: lastDrawn, - }); - } + + this._raiseTiledImageDrawnEvent(tiledImage, lastDrawn); + } /** diff --git a/src/drawerbase.js b/src/drawerbase.js index ec0d52cd..864ba699 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -252,6 +252,33 @@ $.DrawerBase = class DrawerBase{ return new OpenSeadragon.Point( Math.round(viewportSize.x * pixelDensityRatio), Math.round(viewportSize.y * pixelDensityRatio)); } + /** + * Called by implementations to fire the tiled-image-drawn event (used by tests) + * @private + */ + _raiseTiledImageDrawnEvent(tiledImage, tiles){ + if(!this.viewer) { + return; + } + + /** + * Raised when a tiled image is drawn to the canvas. Used internally for testing. + * The update-viewport event is preferred if you want to know when a frame has been drawn. + * + * @event tiled-image-drawn + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. + * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. + * @property {Array} tiles - An array of Tile objects that were drawn. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.viewer.raiseEvent( 'tiled-image-drawn', { + tiledImage: tiledImage, + tiles: tiles, + }); + } + }; }( OpenSeadragon )); diff --git a/src/webgldrawer.js b/src/webgldrawer.js index 3a50d5f8..9c436837 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -352,25 +352,7 @@ gl.clear(gl.COLOR_BUFFER_BIT); // clear the back buffer } - // Fire tiled-image-drawn event. This is used for the tests - if( this.viewer ){ - /** - * Raised when a tiled image is drawn to the canvas. Used internally for testing. - * The update-viewport event is preferred if you want to know when a frame has been drawn. - * - * @event tiled-image-drawn - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. - * @property {Array} tiles - An array of Tile objects that were drawn. - * @property {?Object} userData - Arbitrary subscriber-defined object. - */ - this.viewer.raiseEvent( 'tiled-image-drawn', { - tiledImage: tiledImage, - tiles: tilesToDraw.map(info => info.tile), - }); - } + this._raiseTiledImageDrawnEvent(tiledImage, tilesToDraw.map(info=>info.tile)); }); diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index b2af3066..bc950c49 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -13,7 +13,8 @@ viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', - springStiffness: 100 // Faster animation = faster tests + springStiffness: 100, // Faster animation = faster tests + drawer: 'canvas', // always use canvas drawer for these tests }); }, afterEach: function() { @@ -132,8 +133,7 @@ QUnit.test('update', function(assert) { var done = assert.async(); var handlerCount = 0; - var testTileDrawingEvent = viewer.drawer.getType() === 'canvas'; - let expectedHandlers = testTileDrawingEvent ? 4 : 3; + let expectedHandlers = 4; viewer.addHandler('open', function(event) { var image = viewer.world.getItemAt(0); @@ -162,17 +162,17 @@ assert.ok(event.tile, 'update-tile event includes tile'); }); - if(testTileDrawingEvent){ - viewer.addHandler('tile-drawing', function tileDrawingHandler(event) { - viewer.removeHandler('tile-drawing', tileDrawingHandler); - handlerCount++; - assert.equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); - assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - assert.ok(event.tile, 'tile-drawing event includes a tile'); - assert.ok(event.context, 'tile-drawing event includes a context'); - assert.ok(event.rendered, 'tile-drawing event includes a rendered'); - }); - } + + viewer.addHandler('tile-drawing', function tileDrawingHandler(event) { + viewer.removeHandler('tile-drawing', tileDrawingHandler); + handlerCount++; + assert.equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'tile-drawing event includes a tile'); + assert.ok(event.context, 'tile-drawing event includes a context'); + assert.ok(event.rendered, 'tile-drawing event includes a rendered'); + }); + viewer.addHandler('tiled-image-drawn', function tileDrawnHandler(event) {