From b7c78812c5859faa0d0d87951d47f5eedaaae39f Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 18 Nov 2014 15:45:03 -0800 Subject: [PATCH 01/12] Items added with addTiledImage are now added in correct sequence --- src/viewer.js | 126 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 50 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index e5269a8b..eeee5fbf 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -207,6 +207,7 @@ $.Viewer = function( options ) { this._sequenceIndex = 0; this._firstOpen = true; this._updateRequestId = null; + this._loadQueue = []; this.currentOverlays = []; //Inherit some behaviors and properties @@ -1260,12 +1261,22 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, $.console.assert(options, "[Viewer.addTiledImage] options is required"); $.console.assert(options.tileSource, "[Viewer.addTiledImage] options.tileSource is required"); - var _this = this, - tileSource = options.tileSource; + var _this = this; this._hideMessage(); + var myQueueItem = { + options: options + }; + function raiseAddItemFailed( event ) { + for (var i = 0; i < _this._loadQueue; i++) { + if (_this._loadQueue[i] === myQueueItem) { + _this._loadQueue.splice(i, 1); + break; + } + } + /** * Raised when an error occurs while adding a item. * @event add-item-failed @@ -1284,7 +1295,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } } - getTileSourceImplementation( this, tileSource, function( tileSource ) { + this._loadQueue.push(myQueueItem); + + getTileSourceImplementation( this, options.tileSource, function( tileSource ) { if ( tileSource instanceof Array ) { raiseAddItemFailed({ @@ -1295,59 +1308,72 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, return; } - var tiledImage = new $.TiledImage({ - viewer: _this, - source: tileSource, - viewport: _this.viewport, - drawer: _this.drawer, - tileCache: _this.tileCache, - imageLoader: _this.imageLoader, - x: options.x, - y: options.y, - width: options.width, - height: options.height, - imageLoaderLimit: _this.imageLoaderLimit, - minZoomImageRatio: _this.minZoomImageRatio, - wrapHorizontal: _this.wrapHorizontal, - wrapVertical: _this.wrapVertical, - immediateRender: _this.immediateRender, - blendTime: _this.blendTime, - alwaysBlend: _this.alwaysBlend, - minPixelRatio: _this.minPixelRatio, - debugMode: _this.debugMode, - debugGridColor: _this.debugGridColor - }); + myQueueItem.tileSource = tileSource; - _this.world.addItem( tiledImage, { - index: options.index - }); + // add everybody at the front of the queue that's ready to go + var queueItem, tiledImage, optionsClone; + while (_this._loadQueue.length) { + queueItem = _this._loadQueue[0]; + if (!queueItem.tileSource) { + break; + } - if (_this.collectionMode) { - _this.world.arrange({ - rows: _this.collectionRows, - layout: _this.collectionLayout, - tileSize: _this.collectionTileSize, - tileMargin: _this.collectionTileMargin - }); - } + _this._loadQueue.splice(0, 1); - if (_this.world.getItemCount() === 1 && !_this.preserveViewport) { - _this.viewport.goHome(true); - } - - if (_this.navigator) { - var optionsClone = $.extend({}, options, { - originalTiledImage: tiledImage, - tileSource: tileSource + tiledImage = new $.TiledImage({ + viewer: _this, + source: queueItem.tileSource, + viewport: _this.viewport, + drawer: _this.drawer, + tileCache: _this.tileCache, + imageLoader: _this.imageLoader, + x: queueItem.options.x, + y: queueItem.options.y, + width: queueItem.options.width, + height: queueItem.options.height, + imageLoaderLimit: _this.imageLoaderLimit, + minZoomImageRatio: _this.minZoomImageRatio, + wrapHorizontal: _this.wrapHorizontal, + wrapVertical: _this.wrapVertical, + immediateRender: _this.immediateRender, + blendTime: _this.blendTime, + alwaysBlend: _this.alwaysBlend, + minPixelRatio: _this.minPixelRatio, + debugMode: _this.debugMode, + debugGridColor: _this.debugGridColor }); - _this.navigator.addTiledImage(optionsClone); - } - - if (options.success) { - options.success({ - item: tiledImage + _this.world.addItem( tiledImage, { + index: queueItem.options.index }); + + if (_this.collectionMode) { + _this.world.arrange({ + rows: _this.collectionRows, + layout: _this.collectionLayout, + tileSize: _this.collectionTileSize, + tileMargin: _this.collectionTileMargin + }); + } + + if (_this.world.getItemCount() === 1 && !_this.preserveViewport) { + _this.viewport.goHome(true); + } + + if (_this.navigator) { + optionsClone = $.extend({}, queueItem.options, { + originalTiledImage: tiledImage, + tileSource: queueItem.tileSource + }); + + _this.navigator.addTiledImage(optionsClone); + } + + if (queueItem.options.success) { + queueItem.options.success({ + item: tiledImage + }); + } } }, function( event ) { event.options = options; From 613e03d4131bcecf1a51fcb6edd13a8682c39113 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 18 Nov 2014 16:28:08 -0800 Subject: [PATCH 02/12] Drawer tests; multi-image test --- test/modules/drawer.js | 51 +++++++++++++++++++++++++++++++++++++ test/{ => modules}/world.js | 0 test/multi-image.js | 23 ++++++++++++++++- test/test.html | 3 ++- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/modules/drawer.js rename test/{ => modules}/world.js (100%) diff --git a/test/modules/drawer.js b/test/modules/drawer.js new file mode 100644 index 00000000..694c6f3d --- /dev/null +++ b/test/modules/drawer.js @@ -0,0 +1,51 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('Drawer', { + setup: function () { + var example = $('
').appendTo("#qunit-fixture"); + + testLog.reset(); + + viewer = OpenSeadragon({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }); + }, + teardown: function () { + if (viewer && viewer.close) { + viewer.close(); + } + + viewer = null; + } + }); + + // ---------- + asyncTest('basics', function() { + ok(viewer.drawer, 'Drawer exists'); + equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); + equal(viewer.drawer.getOpacity(), 1, 'starts with full opacity'); + viewer.drawer.setOpacity(0.4); + equal(viewer.drawer.getOpacity(), 0.4, 'setting opacity works'); + start(); + }); + + // ---------- + asyncTest('tile-drawing event', function() { + viewer.addHandler('tile-drawing', function handler(event) { + viewer.removeHandler('tile-drawing', handler); + equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); + ok(event.tile, 'tile-drawing event includes a tile'); + ok(event.context, 'tile-drawing event includes a context'); + ok(event.rendered, 'tile-drawing event includes a rendered'); + start(); + }); + + viewer.open('/test/data/testpattern.dzi'); + }); + +})(); diff --git a/test/world.js b/test/modules/world.js similarity index 100% rename from test/world.js rename to test/modules/world.js diff --git a/test/multi-image.js b/test/multi-image.js index f67f5a37..c875757c 100644 --- a/test/multi-image.js +++ b/test/multi-image.js @@ -118,8 +118,8 @@ viewer.open( '/test/data/testpattern.dzi' ); }); + // ---------- asyncTest( 'Sequences as items', function() { - var options = { tileSource: [{ type: 'legacy-image-pyramid', @@ -154,4 +154,25 @@ viewer.open( '/test/data/testpattern.dzi' ); }); + // ---------- + asyncTest('items are added in order', function() { + viewer.addHandler('open', function(event) { + equal(viewer.world.getItemAt(0).getContentSize().y, 2000, 'first image is tall'); + equal(viewer.world.getItemAt(0).getBounds().width, 4, 'first image has 4 width'); + equal(viewer.world.getItemAt(1).getContentSize().x, 2000, 'second image is wide'); + equal(viewer.world.getItemAt(1).getBounds().width, 2, 'second image has 2 width'); + start(); + }); + + viewer.open([ + { + tileSource: '/test/data/tall.dzi', + width: 4 + }, { + tileSource: '/test/data/wide.dzi', + width: 2 + } + ]); + }); + })(); diff --git a/test/test.html b/test/test.html index 54b5de05..acff4452 100644 --- a/test/test.html +++ b/test/test.html @@ -31,7 +31,8 @@ - + + From 3449ba19616f37499c5c5965046af049aab987f0 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 18 Nov 2014 17:12:15 -0800 Subject: [PATCH 03/12] tiledImage tests --- src/drawer.js | 6 ++++-- src/tiledimage.js | 19 ------------------- test/test.html | 1 + 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 969c0e06..6099dd06 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -129,8 +129,10 @@ $.Drawer = function( options ) { * @memberof OpenSeadragon.Viewer * @type {object} * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.Tile} tile - * @property {?Object} userData - 'context', 'tile' and 'rendered'. + * @property {OpenSeadragon.Tile} tile - The Tile being drawn. + * @property {OpenSeadragon.Tile} context - The HTML canvas context being drawn into. + * @property {OpenSeadragon.Tile} rendered - The HTML canvas context containing the tile imagery. + * @property {?Object} userData - Arbitrary subscriber-defined object. */ _this.viewer.raiseEvent('tile-drawing', args); } diff --git a/src/tiledimage.js b/src/tiledimage.js index 7e0ee5ee..dc4f6c29 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -868,25 +868,6 @@ function drawTiles( tiledImage, lastDrawn ){ position, tileSource; - // We need a callback to give image manipulation a chance to happen - var drawingHandler = function(args) { - if (tiledImage.viewer) { - /** - * This event is fired just before the tile is drawn giving the application a chance to alter the image. - * - * NOTE: This event is only fired when the tiledImage is using a . - * - * @event tile-drawing - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.Tile} tile - * @property {?Object} userData - 'context', 'tile' and 'rendered'. - */ - tiledImage.viewer.raiseEvent('tile-drawing', args); - } - }; - for ( i = lastDrawn.length - 1; i >= 0; i-- ) { tile = lastDrawn[ i ]; tiledImage._drawer.drawTile( tile ); diff --git a/test/test.html b/test/test.html index acff4452..5e4c617d 100644 --- a/test/test.html +++ b/test/test.html @@ -33,6 +33,7 @@ + From 2508dd35f54dc5b588b759b174a609ccc25e0c7f Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 19 Nov 2014 09:28:09 -0800 Subject: [PATCH 04/12] tiledImage tests for real --- test/modules/tiledimage.js | 141 +++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/modules/tiledimage.js diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js new file mode 100644 index 00000000..72f9a728 --- /dev/null +++ b/test/modules/tiledimage.js @@ -0,0 +1,141 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('TiledImage', { + setup: function () { + var example = $('
').appendTo("#qunit-fixture"); + + testLog.reset(); + + viewer = OpenSeadragon({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }); + }, + teardown: function () { + if (viewer && viewer.close) { + viewer.close(); + } + + viewer = null; + } + }); + + // ---------- + var checkBounds = function(image, expected, message) { + var bounds = image.getBounds(); + equal(bounds.x, expected.x, message + ' x'); + equal(bounds.y, expected.y, message + ' y'); + equal(bounds.width, expected.width, message + ' width'); + equal(bounds.height, expected.height, message + ' height'); + }; + + // ---------- + asyncTest('metrics', function() { + var handlerCount = 0; + + viewer.addHandler('open', function(event) { + var image = viewer.world.getItemAt(0); + var contentSize = image.getContentSize(); + equal(contentSize.x, 500, 'contentSize.x'); + equal(contentSize.y, 2000, 'contentSize.y'); + + checkBounds(image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); + + image.addHandler('bounds-change', function boundsChangeHandler(event) { + image.removeHandler('bounds-change', boundsChangeHandler); + handlerCount++; + }); + + image.setPosition(new OpenSeadragon.Point(7, 8)); + checkBounds(image, new OpenSeadragon.Rect(7, 8, 10, 40), 'bounds after position'); + + image.setWidth(5); + checkBounds(image, new OpenSeadragon.Rect(7, 8, 5, 20), 'bounds after width'); + + image.setHeight(4); + checkBounds(image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width'); + + equal(handlerCount, 1, 'correct number of handlers called'); + start(); + }); + + viewer.open({ + tileSource: '/test/data/tall.dzi', + x: 5, + y: 6, + width: 10 + }); + }); + + // ---------- + asyncTest('update', function() { + var handlerCount = 0; + + viewer.addHandler('open', function(event) { + var image = viewer.world.getItemAt(0); + equal(image.needsUpdate(), true, 'needs update after open'); + + viewer.addHandler('update-level', function updateLevelHandler(event) { + viewer.removeHandler('update-level', updateLevelHandler); + handlerCount++; + equal(event.eventSource, viewer, 'sender of update-level event was viewer'); + ok('havedrawn' in event, 'update-level event includes havedrawn'); + ok('level' in event, 'update-level event includes level'); + ok('opacity' in event, 'update-level event includes opacity'); + ok('visibility' in event, 'update-level event includes visibility'); + ok('topleft' in event, 'update-level event includes topleft'); + ok('bottomright' in event, 'update-level event includes bottomright'); + ok('currenttime' in event, 'update-level event includes currenttime'); + ok('best' in event, 'update-level event includes best'); + }); + + viewer.addHandler('update-tile', function updateTileHandler(event) { + viewer.removeHandler('update-tile', updateTileHandler); + handlerCount++; + equal(event.eventSource, viewer, 'sender of update-tile event was viewer'); + ok(event.tile, 'update-tile event includes tile'); + }); + + viewer.addHandler('tile-drawn', function tileDrawnHandler(event) { + viewer.removeHandler('tile-drawn', tileDrawnHandler); + handlerCount++; + equal(event.eventSource, viewer, 'sender of tile-drawn event was viewer'); + ok(event.tile, 'tile-drawn event includes tile'); + + equal(handlerCount, 3, 'correct number of handlers called'); + start(); + }); + + image.update(); + }); + + viewer.open('/test/data/testpattern.dzi'); + }); + + // ---------- + asyncTest('reset', function() { + viewer.addHandler('tile-drawn', function updateHandler() { + viewer.removeHandler('tile-drawn', updateHandler); + ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); + viewer.world.getItemAt(0).reset(); + equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); + + viewer.addHandler('tile-drawn', function updateHandler2() { + viewer.removeHandler('tile-drawn', updateHandler2); + ok(viewer.tileCache.numTilesLoaded() > 0, 'more tiles load'); + viewer.world.getItemAt(0).destroy(); + equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after destroy'); + start(); + }); + }); + + equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); + + viewer.open('/test/data/testpattern.dzi'); + }); + +})(); From e465c24f2bf32363dd196f9cca2db229f105f77b Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 19 Nov 2014 16:46:05 -0800 Subject: [PATCH 05/12] Support for generating code coverage reports --- .gitignore | 2 ++ Gruntfile.js | 32 ++++++++++++++++--- README.md | 6 ++++ package.json | 4 +-- test/coverage.html | 76 ++++++++++++++++++++++++++++++++++++++++++++++ test/navigator.js | 6 ---- 6 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 test/coverage.html diff --git a/.gitignore b/.gitignore index 588aee54..3ebd08b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules build/ sftp-config.json +coverage/ +temp/ diff --git a/Gruntfile.js b/Gruntfile.js index 7500d85c..f774df6f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,5 @@ +/* global module */ + module.exports = function(grunt) { // ---------- @@ -5,7 +7,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-jshint"); grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.loadNpmTasks("grunt-contrib-qunit"); + grunt.loadNpmTasks("grunt-qunit-istanbul"); grunt.loadNpmTasks("grunt-contrib-connect"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-clean"); @@ -72,6 +74,7 @@ module.exports = function(grunt) { clean: { build: ["build"], package: [packageDir], + coverage: ["coverage"], release: { src: [releaseRoot], options: { @@ -137,10 +140,26 @@ module.exports = function(grunt) { } }, qunit: { + normal: { + options: { + urls: [ "http://localhost:8000/test/test.html" ] + } + }, + coverage: { + options: { + urls: [ "http://localhost:8000/test/coverage.html" ], + coverage: { + src: ['src/*.js'], + htmlReport: 'coverage/html/', + instrumentedFiles: 'temp/', + baseUrl: '.', + disposeCollector: true + } + } + }, all: { options: { - timeout: 10000, - urls: [ "http://localhost:8000/test/test.html" ] + timeout: 10000 } } }, @@ -248,7 +267,12 @@ module.exports = function(grunt) { // ---------- // Test task. // Builds and runs unit tests. - grunt.registerTask("test", ["build", "connect", "qunit"]); + grunt.registerTask("test", ["build", "connect", "qunit:normal"]); + + // ---------- + // Coverage task. + // Outputs unit test code coverage report. + grunt.registerTask("coverage", ["clean:coverage", "connect", "qunit:coverage"]); // ---------- // Package task. diff --git a/README.md b/README.md index 71fafeca..75fc5c92 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,12 @@ and open `http://localhost:8000/test/test.html` in your browser. Another good page, if you want to interactively test out your changes, is `http://localhost:8000/test/demo/basic.html`. +You can also get a report of the tests' code coverage: + + grunt coverage + +The report shows up at `coverage/html/index.html` viewable in a browser. + ### Contributing OpenSeadragon is truly a community project; we welcome your involvement! diff --git a/package.json b/package.json index 486d8743..2b102600 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "grunt-git-describe": "^2.3.2", "grunt-contrib-uglify": "^0.4.0", "grunt-contrib-watch": "^0.6.1", - "grunt-contrib-qunit": "^0.5.1", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-compress": "^0.9.1", "grunt-contrib-connect": "^0.7.1", - "qunitjs": "^1.14.0" + "qunitjs": "^1.14.0", + "grunt-qunit-istanbul": "^0.4.5" }, "scripts": { "test": "grunt test" diff --git a/test/coverage.html b/test/coverage.html new file mode 100644 index 00000000..ee23c1c5 --- /dev/null +++ b/test/coverage.html @@ -0,0 +1,76 @@ + + + + + OpenSeadragon QUnit + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/navigator.js b/test/navigator.js index f4f9b856..8c5aeb27 100644 --- a/test/navigator.js +++ b/test/navigator.js @@ -1,7 +1,5 @@ /* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal */ -QUnit.config.autostart = false; - (function () { var debug = false, viewer, @@ -31,10 +29,6 @@ QUnit.config.autostart = false; } }); - $(document).ready(function () { - start(); - }); - var resetTestVariables = function () { if (viewer) { viewer.close(); From cf0059daa5ac5dde245d4f72dfc978a8982f2b97 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 19 Nov 2014 16:52:33 -0800 Subject: [PATCH 06/12] Reorganized test folder --- test/coverage.html | 28 ++++++++++++------------- test/{ => helpers}/legacy.mouse.shim.js | 0 test/{ => helpers}/test.css | 0 test/{ => helpers}/test.js | 0 test/{ => modules}/basic.js | 0 test/{ => modules}/controls.js | 0 test/{ => modules}/multi-image.js | 0 test/{ => modules}/navigator.js | 0 test/{ => modules}/overlays.js | 0 test/{ => modules}/polyfills.js | 0 test/{ => modules}/strings.js | 0 test/{ => modules}/units.js | 0 test/{ => modules}/utils.js | 0 test/test.html | 28 ++++++++++++------------- 14 files changed, 28 insertions(+), 28 deletions(-) rename test/{ => helpers}/legacy.mouse.shim.js (100%) rename test/{ => helpers}/test.css (100%) rename test/{ => helpers}/test.js (100%) rename test/{ => modules}/basic.js (100%) rename test/{ => modules}/controls.js (100%) rename test/{ => modules}/multi-image.js (100%) rename test/{ => modules}/navigator.js (100%) rename test/{ => modules}/overlays.js (100%) rename test/{ => modules}/polyfills.js (100%) rename test/{ => modules}/strings.js (100%) rename test/{ => modules}/units.js (100%) rename test/{ => modules}/utils.js (100%) diff --git a/test/coverage.html b/test/coverage.html index ee23c1c5..07ab4d7f 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -5,7 +5,7 @@ OpenSeadragon QUnit - +
@@ -49,28 +49,28 @@ - - + + - - - - - - - - - - + + + + + + + + + + - + diff --git a/test/legacy.mouse.shim.js b/test/helpers/legacy.mouse.shim.js similarity index 100% rename from test/legacy.mouse.shim.js rename to test/helpers/legacy.mouse.shim.js diff --git a/test/test.css b/test/helpers/test.css similarity index 100% rename from test/test.css rename to test/helpers/test.css diff --git a/test/test.js b/test/helpers/test.js similarity index 100% rename from test/test.js rename to test/helpers/test.js diff --git a/test/basic.js b/test/modules/basic.js similarity index 100% rename from test/basic.js rename to test/modules/basic.js diff --git a/test/controls.js b/test/modules/controls.js similarity index 100% rename from test/controls.js rename to test/modules/controls.js diff --git a/test/multi-image.js b/test/modules/multi-image.js similarity index 100% rename from test/multi-image.js rename to test/modules/multi-image.js diff --git a/test/navigator.js b/test/modules/navigator.js similarity index 100% rename from test/navigator.js rename to test/modules/navigator.js diff --git a/test/overlays.js b/test/modules/overlays.js similarity index 100% rename from test/overlays.js rename to test/modules/overlays.js diff --git a/test/polyfills.js b/test/modules/polyfills.js similarity index 100% rename from test/polyfills.js rename to test/modules/polyfills.js diff --git a/test/strings.js b/test/modules/strings.js similarity index 100% rename from test/strings.js rename to test/modules/strings.js diff --git a/test/units.js b/test/modules/units.js similarity index 100% rename from test/units.js rename to test/modules/units.js diff --git a/test/utils.js b/test/modules/utils.js similarity index 100% rename from test/utils.js rename to test/modules/utils.js diff --git a/test/test.html b/test/test.html index 5e4c617d..48773e1a 100644 --- a/test/test.html +++ b/test/test.html @@ -5,7 +5,7 @@ OpenSeadragon QUnit - +
@@ -15,27 +15,27 @@ - - + + - - - - - - - - - - + + + + + + + + + + - + From 78e44d487bea76624bc23df40242be3390c99ce2 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 11:51:24 -0800 Subject: [PATCH 07/12] TileCache tests --- src/tilecache.js | 2 +- test/coverage.html | 1 + test/{ => modules}/events.js | 0 test/{ => modules}/formats.js | 0 test/modules/tilecache.js | 111 ++++++++++++++++++++++++++++++++++ test/test.html | 1 + 6 files changed, 114 insertions(+), 1 deletion(-) rename test/{ => modules}/events.js (100%) rename test/{ => modules}/formats.js (100%) create mode 100644 test/modules/tilecache.js diff --git a/src/tilecache.js b/src/tilecache.js index a643ae49..45344a05 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -155,7 +155,7 @@ $.TileCache.prototype = /** @lends OpenSeadragon.TileCache.prototype */{ // Note that just because we're unloading a tile doesn't necessarily mean // we're unloading an image. With repeated calls it should sort itself out, though. - if ( this._imagesLoadedCount >= this._maxImageCacheCount ) { + if ( this._imagesLoadedCount > this._maxImageCacheCount ) { var worstTile = null; var worstTileIndex = -1; var prevTile, worstTime, worstLevel, prevTime, prevLevel, prevTileRecord; diff --git a/test/coverage.html b/test/coverage.html index 07ab4d7f..97e1a0c9 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -69,6 +69,7 @@ + diff --git a/test/events.js b/test/modules/events.js similarity index 100% rename from test/events.js rename to test/modules/events.js diff --git a/test/formats.js b/test/modules/formats.js similarity index 100% rename from test/formats.js rename to test/modules/formats.js diff --git a/test/modules/tilecache.js b/test/modules/tilecache.js new file mode 100644 index 00000000..afb0ca52 --- /dev/null +++ b/test/modules/tilecache.js @@ -0,0 +1,111 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + + // ---------- + module('TileCache', { + setup: function () { + testLog.reset(); + }, + teardown: function () { + } + }); + + // ---------- + asyncTest('basics', function() { + var fakeTiledImage0 = {}; + var fakeTiledImage1 = {}; + + var fakeTile0 = { + url: 'foo.jpg', + image: {}, + unload: function() {} + }; + + var fakeTile1 = { + url: 'foo.jpg', + image: {}, + unload: function() {} + }; + + var cache = new OpenSeadragon.TileCache(); + equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + + cache.cacheTile({ + tile: fakeTile0, + tiledImage: fakeTiledImage0 + }); + + equal(cache.numTilesLoaded(), 1, 'tile count after cache'); + + cache.cacheTile({ + tile: fakeTile1, + tiledImage: fakeTiledImage1 + }); + + equal(cache.numTilesLoaded(), 2, 'tile count after second cache'); + + cache.clearTilesFor(fakeTiledImage0); + + equal(cache.numTilesLoaded(), 1, 'tile count after first clear'); + + cache.clearTilesFor(fakeTiledImage1); + + equal(cache.numTilesLoaded(), 0, 'tile count after second clear'); + + start(); + }); + + // ---------- + asyncTest('maxImageCacheCount', function() { + var fakeTiledImage0 = {}; + + var fakeTile0 = { + url: 'different.jpg', + image: {}, + unload: function() {} + }; + + var fakeTile1 = { + url: 'same.jpg', + image: {}, + unload: function() {} + }; + + var fakeTile2 = { + url: 'same.jpg', + image: {}, + unload: function() {} + }; + + var cache = new OpenSeadragon.TileCache({ + maxImageCacheCount: 1 + }); + + equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + + cache.cacheTile({ + tile: fakeTile0, + tiledImage: fakeTiledImage0 + }); + + equal(cache.numTilesLoaded(), 1, 'tile count after add'); + + cache.cacheTile({ + tile: fakeTile1, + tiledImage: fakeTiledImage0 + }); + + equal(cache.numTilesLoaded(), 1, 'tile count after add of second image'); + + cache.cacheTile({ + tile: fakeTile2, + tiledImage: fakeTiledImage0 + }); + + equal(cache.numTilesLoaded(), 2, 'tile count after additional same image'); + + start(); + }); + +})(); diff --git a/test/test.html b/test/test.html index 48773e1a..c74148ba 100644 --- a/test/test.html +++ b/test/test.html @@ -34,6 +34,7 @@ + From 632f09caa2ecdfa0a09d681cb7e82edce9ff15d0 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 14:25:17 -0800 Subject: [PATCH 08/12] More drawer tests --- test/demo/collections/main.js | 6 +-- test/helpers/test.js | 19 +++++++- test/modules/drawer.js | 88 ++++++++++++++++++++++++++++++++--- 3 files changed, 102 insertions(+), 11 deletions(-) diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index d1f9c652..a9f02b8c 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -6,7 +6,7 @@ init: function() { var self = this; - var testInitialOpen = false; + var testInitialOpen = true; var testOverlays = false; var testMargins = false; var testNavigator = false; @@ -16,8 +16,8 @@ // debugMode: true, zoomPerScroll: 1.02, showNavigator: testNavigator, - sequenceMode: true, - showReferenceStrip: true, + // sequenceMode: true, + // showReferenceStrip: true, // referenceStripScroll: 'vertical', navPrevNextWrap: false, preserveViewport: false, diff --git a/test/helpers/test.js b/test/helpers/test.js index 68010ef4..389c4763 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -50,6 +50,7 @@ .simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', event ); }, + // ---------- initializeTestDOM: function () { $( "#qunit-fixture" ) .append( '
' ) @@ -57,14 +58,17 @@ .append( '
' ); }, + // ---------- equalsWithVariance: function ( value1, value2, variance ) { return Math.abs( value1 - value2 ) <= variance; }, + // ---------- assessNumericValue: function ( value1, value2, variance, message ) { ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance ); }, + // ---------- timeWatcher: function ( time ) { time = time || 2000; var finished = false; @@ -85,8 +89,21 @@ } } }; - } + }, + // ---------- + spyOnce: function(obj, functionName, callback) { + var original = obj[functionName]; + obj[functionName] = function() { + obj[functionName] = original; + var result = callback.apply(this, arguments); + if (result === undefined) { + result = original.apply(this, arguments); + } + + return result; + }; + } }; /* diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 694c6f3d..64028637 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -8,12 +8,6 @@ var example = $('
').appendTo("#qunit-fixture"); testLog.reset(); - - viewer = OpenSeadragon({ - id: 'example', - prefixUrl: '/build/openseadragon/images/', - springStiffness: 100 // Faster animation = faster tests - }); }, teardown: function () { if (viewer && viewer.close) { @@ -24,8 +18,44 @@ } }); + // ---------- + var createViewer = function(options) { + options = options || {}; + viewer = OpenSeadragon(OpenSeadragon.extend({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }, options)); + }; + + // ---------- + var testDeprecation = function(obj0, member0, obj1, member1) { + var called = false; + var errored = false; + + if (obj1 && member1) { + Util.spyOnce(obj1, member1, function() { + called = true; + return false; + }); + } else { + called = true; + } + + Util.spyOnce(OpenSeadragon.console, 'error', function(message) { + if (/deprecated/.test(message)) { + errored = true; + } + }); + + obj0[member0](); + equal(called, true, 'called through for ' + member0); + equal(errored, true, 'errored for ' + member0); + }; + // ---------- asyncTest('basics', function() { + createViewer(); ok(viewer.drawer, 'Drawer exists'); equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); equal(viewer.drawer.getOpacity(), 1, 'starts with full opacity'); @@ -36,6 +66,10 @@ // ---------- asyncTest('tile-drawing event', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi' + }); + viewer.addHandler('tile-drawing', function handler(event) { viewer.removeHandler('tile-drawing', handler); equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); @@ -44,8 +78,48 @@ ok(event.rendered, 'tile-drawing event includes a rendered'); start(); }); + }); - viewer.open('/test/data/testpattern.dzi'); + // ---------- + asyncTest('rotation', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi' + }); + + viewer.addHandler('open', function handler(event) { + viewer.viewport.setRotation(30); + Util.spyOnce(viewer.drawer.context, 'rotate', function() { + ok(true, 'drawing with new rotation'); + start(); + }); + }); + }); + + // ---------- + asyncTest('debug', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi', + debugMode: true + }); + + Util.spyOnce(viewer.drawer, 'drawDebugInfo', function() { + ok(true, 'drawDebugInfo is called'); + start(); + }); + }); + + // ---------- + asyncTest('deprecations', function() { + createViewer(); + testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + testDeprecation(viewer.drawer, 'needsUpdate'); + testDeprecation(viewer.drawer, 'numTilesLoaded'); + testDeprecation(viewer.drawer, 'reset'); + testDeprecation(viewer.drawer, 'update'); + start(); }); })(); From 78f65152bcb2f4fe630799d6f650839ac98d64fc Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 14:50:07 -0800 Subject: [PATCH 09/12] Fixed: overlays were appearing under the canvas --- src/viewer.js | 9 ++++++--- test/demo/collections/index.html | 4 ---- test/demo/collections/main.js | 13 ++++++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index eeee5fbf..b7879013 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -229,7 +229,6 @@ $.Viewer = function( options ) { this.element = this.element || document.getElementById( this.id ); this.canvas = $.makeNeutralElement( "div" ); this.keyboardCommandArea = $.makeNeutralElement( "textarea" ); - this.overlaysContainer = $.makeNeutralElement( "div" ); this.canvas.className = "openseadragon-canvas"; (function( style ){ @@ -268,7 +267,6 @@ $.Viewer = function( options ) { this.container.insertBefore( this.canvas, this.container.firstChild ); this.container.insertBefore( this.keyboardCommandArea, this.container.firstChild ); this.element.appendChild( this.container ); - this.canvas.appendChild( this.overlaysContainer ); //Used for toggling between fullscreen and default container size //TODO: these can be closure private and shared across Viewer @@ -454,6 +452,10 @@ $.Viewer = function( options ) { debugGridColor: this.debugGridColor }); + // Overlay container + this.overlaysContainer = $.makeNeutralElement( "div" ); + this.canvas.appendChild( this.overlaysContainer ); + // Now that we have a drawer, see if it supports rotate. If not we need to remove the rotate buttons if (!this.drawer.canRotate()) { // Disable/remove the rotate left/right buttons since they aren't supported @@ -689,7 +691,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, _this.addTiledImage(options); - // For backwards compatibility. TODO: deprecate. + // TODO: now that options has other things besides tileSource, the overlays + // should probably be at the options level, not the tileSource level. if (options.tileSource.overlays) { for (var i = 0; i < options.tileSource.overlays.length; i++) { _this.addOverlay(options.tileSource.overlays[i]); diff --git a/test/demo/collections/index.html b/test/demo/collections/index.html index c9fd0b3c..b6aca4a1 100644 --- a/test/demo/collections/index.html +++ b/test/demo/collections/index.html @@ -19,10 +19,6 @@ background-color: rgba(255, 0, 0, 0.3); } - #overlay1 { - z-index: 10; - } - diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index a9f02b8c..155634e0 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -7,7 +7,7 @@ var self = this; var testInitialOpen = true; - var testOverlays = false; + var testOverlays = true; var testMargins = false; var testNavigator = false; var margins; @@ -54,7 +54,7 @@ config.overlays = [ { id: "overlay1", - x: 0, + x: 2, y: 0, width: 0.25, height: 0.25 @@ -92,7 +92,14 @@ if (testInitialOpen) { this.viewer.addHandler( "open", function() { - // console.log(self.viewer.viewport.contentSize); + // setTimeout(function() { + // // console.log(self.viewer.viewport.contentSize); + // var $el = $('#overlay1').click(function() { + // console.log('foo'); + // }); + + // console.log($el.length, $el.css('background')); + // }, 1000); }); } From 68fbdc7bebe5dcd988ab93738bc76db8c4bc4539 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 15:33:13 -0800 Subject: [PATCH 10/12] * Overlays appear in the DOM immediately on open or addOverlay (#507) --- changelog.txt | 1 + src/viewer.js | 29 +++++++++++++++++------------ test/demo/collections/main.js | 8 -------- test/modules/overlays.js | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/changelog.txt b/changelog.txt index 547646c4..028c3300 100644 --- a/changelog.txt +++ b/changelog.txt @@ -37,6 +37,7 @@ OPENSEADRAGON CHANGELOG * Viewport.open supports positioning config properties * Margins option to push the home region in from the edges of the Viewer (#505) * Rect and Point toString() functions are now consistent: rounding values to nearest hundredth +* Overlays appear in the DOM immediately on open or addOverlay (#507) 1.2.0: (in progress) diff --git a/src/viewer.js b/src/viewer.js index b7879013..2f1684de 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -622,6 +622,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, _this.currentOverlays[ i ] = getOverlayObject( _this, _this.overlays[ i ] ); } + _this._drawOverlays(); + /** * Raised when the viewer has opened and loaded one or more TileSources. * @@ -1776,8 +1778,11 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, // they're trying to add a duplicate overlay return this; } - this.currentOverlays.push( getOverlayObject( this, options ) ); - THIS[ this.hash ].forceRedraw = true; + + var overlay = getOverlayObject( this, options); + this.currentOverlays.push(overlay); + overlay.drawHTML( this.overlaysContainer, this.viewport ); + /** * Raised when an overlay is added to the viewer (see {@link OpenSeadragon.Viewer#addOverlay}). * @@ -1984,8 +1989,16 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, default: return this.gestureSettingsUnknown; } - } + }, + // private + _drawOverlays: function() { + var i, + length = this.currentOverlays.length; + for ( i = 0; i < length; i++ ) { + this.currentOverlays[ i ].drawHTML( this.overlaysContainer, this.viewport ); + } + } }); @@ -2143,14 +2156,6 @@ function getOverlayIndex( overlays, element ) { return -1; } -function drawOverlays( viewport, overlays, container ) { - var i, - length = overlays.length; - for ( i = 0; i < length; i++ ) { - overlays[ i ].drawHTML( container, viewport ); - } -} - /////////////////////////////////////////////////////////////////////////////// // Schedulers provide the general engine for animation /////////////////////////////////////////////////////////////////////////////// @@ -2674,7 +2679,7 @@ function updateOnce( viewer ) { if ( animated || THIS[ viewer.hash ].forceRedraw || viewer.world.needsUpdate() ) { updateWorld( viewer ); - drawOverlays( viewer.viewport, viewer.currentOverlays, viewer.overlaysContainer ); + viewer._drawOverlays(); if( viewer.navigator ){ viewer.navigator.update( viewer.viewport ); } diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 155634e0..669d4fdb 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -92,14 +92,6 @@ if (testInitialOpen) { this.viewer.addHandler( "open", function() { - // setTimeout(function() { - // // console.log(self.viewer.viewport.contentSize); - // var $el = $('#overlay1').click(function() { - // console.log('foo'); - // }); - - // console.log($el.length, $el.css('background')); - // }, 1000); }); } diff --git a/test/modules/overlays.js b/test/modules/overlays.js index 223f99de..9fdfdb2e 100644 --- a/test/modules/overlays.js +++ b/test/modules/overlays.js @@ -1,4 +1,4 @@ -/* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal */ +/* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal, testLog */ ( function() { var viewer; @@ -532,4 +532,35 @@ } ); + // ---------- + asyncTest('overlays appear immediately', function() { + equal($('#immediate-overlay0').length, 0, 'overlay 0 does not exist'); + equal($('#immediate-overlay1').length, 0, 'overlay 1 does not exist'); + + viewer = OpenSeadragon( { + id: 'example-overlays', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/testpattern.dzi', + springStiffness: 100, // Faster animation = faster tests + overlays: [ { + x: 0, + y: 0, + id: "immediate-overlay0" + } ] + } ); + + viewer.addHandler('open', function() { + equal($('#immediate-overlay0').length, 1, 'overlay 0 exists'); + + viewer.addOverlay( { + x: 0, + y: 0, + id: "immediate-overlay1" + } ); + + equal($('#immediate-overlay1').length, 1, 'overlay 1 exists'); + start(); + }); + }); + } )( ); From 36831d34346fd271db42b88ad60faccdf4732e2d Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 16:02:02 -0800 Subject: [PATCH 11/12] Testing deprecations --- src/drawer.js | 21 +++++++------ test/coverage.html | 2 ++ test/helpers/test.js | 25 +++++++++++++++ test/modules/drawer.js | 41 +++++-------------------- test/modules/referencestrip.js | 46 ++++++++++++++++++++++++++++ test/modules/tilesourcecollection.js | 20 ++++++++++++ test/test.html | 2 ++ 7 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 test/modules/referencestrip.js create mode 100644 test/modules/tilesourcecollection.js diff --git a/src/drawer.js b/src/drawer.js index 6099dd06..804f0693 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -129,9 +129,9 @@ $.Drawer = function( options ) { * @memberof OpenSeadragon.Viewer * @type {object} * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.Tile} tile - The Tile being drawn. - * @property {OpenSeadragon.Tile} context - The HTML canvas context being drawn into. - * @property {OpenSeadragon.Tile} rendered - The HTML canvas context containing the tile imagery. + * @property {OpenSeadragon.Tile} tile - The Tile being drawn. + * @property {OpenSeadragon.Tile} context - The HTML canvas context being drawn into. + * @property {OpenSeadragon.Tile} rendered - The HTML canvas context containing the tile imagery. * @property {?Object} userData - Arbitrary subscriber-defined object. */ _this.viewer.raiseEvent('tile-drawing', args); @@ -189,25 +189,28 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{ // deprecated needsUpdate: function() { - $.console.error( "[Drawer.needsUpdate] this function is deprecated." ); - return false; + $.console.error( "[Drawer.needsUpdate] this function is deprecated. Use World.needsUpdate instead." ); + return this.viewer.world.needsUpdate(); }, // deprecated numTilesLoaded: function() { - $.console.error( "[Drawer.numTilesLoaded] this function is deprecated." ); - return 0; + $.console.error( "[Drawer.numTilesLoaded] this function is deprecated. Use TileCache.numTilesLoaded instead." ); + return this.viewer.tileCache.numTilesLoaded(); }, // deprecated reset: function() { - $.console.error( "[Drawer.reset] this function is deprecated." ); + $.console.error( "[Drawer.reset] this function is deprecated. Use World.resetItems instead." ); + this.viewer.world.resetItems(); return this; }, // deprecated update: function() { - $.console.error( "[Drawer.update] this function is deprecated." ); + $.console.error( "[Drawer.update] this function is deprecated. Use Drawer.clear and World.update instead." ); + this.clear(); + this.viewer.world.update(); return this; }, diff --git a/test/coverage.html b/test/coverage.html index 97e1a0c9..c55fd31f 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -70,6 +70,8 @@ + + diff --git a/test/helpers/test.js b/test/helpers/test.js index 389c4763..54a28412 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -103,6 +103,31 @@ return result; }; + }, + + // ---------- + testDeprecation: function(obj0, member0, obj1, member1) { + var called = false; + var errored = false; + + if (obj1 && member1) { + this.spyOnce(obj1, member1, function() { + called = true; + return false; + }); + } else { + called = true; + } + + this.spyOnce(OpenSeadragon.console, 'error', function(message) { + if (/deprecated/.test(message)) { + errored = true; + } + }); + + obj0[member0](); + equal(called, true, 'called through for ' + member0); + equal(errored, true, 'errored for ' + member0); } }; diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 64028637..e024c72e 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -28,31 +28,6 @@ }, options)); }; - // ---------- - var testDeprecation = function(obj0, member0, obj1, member1) { - var called = false; - var errored = false; - - if (obj1 && member1) { - Util.spyOnce(obj1, member1, function() { - called = true; - return false; - }); - } else { - called = true; - } - - Util.spyOnce(OpenSeadragon.console, 'error', function(message) { - if (/deprecated/.test(message)) { - errored = true; - } - }); - - obj0[member0](); - equal(called, true, 'called through for ' + member0); - equal(errored, true, 'errored for ' + member0); - }; - // ---------- asyncTest('basics', function() { createViewer(); @@ -111,14 +86,14 @@ // ---------- asyncTest('deprecations', function() { createViewer(); - testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); - testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); - testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); - testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); - testDeprecation(viewer.drawer, 'needsUpdate'); - testDeprecation(viewer.drawer, 'numTilesLoaded'); - testDeprecation(viewer.drawer, 'reset'); - testDeprecation(viewer.drawer, 'update'); + Util.testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + Util.testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + Util.testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + Util.testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + Util.testDeprecation(viewer.drawer, 'needsUpdate', viewer.world, 'needsUpdate'); + Util.testDeprecation(viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); + Util.testDeprecation(viewer.drawer, 'reset', viewer.world, 'resetItems'); + Util.testDeprecation(viewer.drawer, 'update', viewer.world, 'update'); start(); }); diff --git a/test/modules/referencestrip.js b/test/modules/referencestrip.js new file mode 100644 index 00000000..45130070 --- /dev/null +++ b/test/modules/referencestrip.js @@ -0,0 +1,46 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('ReferenceStrip', { + setup: function () { + var example = $('
').appendTo("#qunit-fixture"); + + testLog.reset(); + }, + teardown: function () { + if (viewer && viewer.close) { + viewer.close(); + } + + viewer = null; + } + }); + + // ---------- + var createViewer = function(options) { + options = options || {}; + viewer = OpenSeadragon(OpenSeadragon.extend({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }, options)); + }; + + // ---------- + asyncTest('basics', function() { + createViewer({ + sequenceMode: true, + showReferenceStrip: true, + tileSources: [ + '/test/data/tall.dzi', + '/test/data/wide.dzi', + ] + }); + + ok(viewer.referenceStrip, 'referenceStrip exists'); + start(); + }); + +})(); diff --git a/test/modules/tilesourcecollection.js b/test/modules/tilesourcecollection.js new file mode 100644 index 00000000..a9bbf79e --- /dev/null +++ b/test/modules/tilesourcecollection.js @@ -0,0 +1,20 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('TileSourceCollection', { + setup: function () { + testLog.reset(); + }, + teardown: function () { + } + }); + + // ---------- + asyncTest('deprecation', function() { + Util.testDeprecation(OpenSeadragon, 'TileSourceCollection'); + start(); + }); + +})(); diff --git a/test/test.html b/test/test.html index c74148ba..65f0d5b3 100644 --- a/test/test.html +++ b/test/test.html @@ -35,6 +35,8 @@ + + From 2336b8161876f9e1ca2ac4bbbb4bce953329354e Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 16:41:43 -0800 Subject: [PATCH 12/12] TiledImage update events now include which tiled image --- src/tiledimage.js | 6 ++++++ test/modules/tiledimage.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/tiledimage.js b/src/tiledimage.js index dc4f6c29..40726dbd 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -438,6 +438,7 @@ function updateLevel( tiledImage, haveDrawn, drawLevel, level, levelOpacity, lev * @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 {Object} havedrawn * @property {Object} level * @property {Object} opacity @@ -449,6 +450,7 @@ function updateLevel( tiledImage, haveDrawn, drawLevel, level, levelOpacity, lev * @property {?Object} userData - Arbitrary subscriber-defined object. */ tiledImage.viewer.raiseEvent( 'update-level', { + tiledImage: tiledImage, havedrawn: haveDrawn, level: level, opacity: levelOpacity, @@ -519,10 +521,12 @@ function updateTile( tiledImage, drawLevel, haveDrawn, x, y, level, levelOpacity * @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 {OpenSeadragon.Tile} tile * @property {?Object} userData - Arbitrary subscriber-defined object. */ tiledImage.viewer.raiseEvent( 'update-tile', { + tiledImage: tiledImage, tile: tile }); } @@ -889,10 +893,12 @@ function drawTiles( tiledImage, lastDrawn ){ * @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 {OpenSeadragon.Tile} tile * @property {?Object} userData - Arbitrary subscriber-defined object. */ tiledImage.viewer.raiseEvent( 'tile-drawn', { + tiledImage: tiledImage, tile: tile }); } diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index 72f9a728..186d6686 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -83,6 +83,7 @@ viewer.removeHandler('update-level', updateLevelHandler); handlerCount++; equal(event.eventSource, viewer, 'sender of update-level event was viewer'); + equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); ok('havedrawn' in event, 'update-level event includes havedrawn'); ok('level' in event, 'update-level event includes level'); ok('opacity' in event, 'update-level event includes opacity'); @@ -97,6 +98,7 @@ viewer.removeHandler('update-tile', updateTileHandler); handlerCount++; equal(event.eventSource, viewer, 'sender of update-tile event was viewer'); + equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); ok(event.tile, 'update-tile event includes tile'); }); @@ -104,6 +106,7 @@ viewer.removeHandler('tile-drawn', tileDrawnHandler); handlerCount++; equal(event.eventSource, viewer, 'sender of tile-drawn event was viewer'); + equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); ok(event.tile, 'tile-drawn event includes tile'); equal(handlerCount, 3, 'correct number of handlers called');