diff --git a/.gitignore b/.gitignore index 282b4dc1..2b037d24 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ node_modules build/ sftp-config.json coverage/ -temp/ +instrumented/ .idea /nbproject/private/ .directory diff --git a/Gruntfile.js b/Gruntfile.js index 77d48789..1658f83f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,18 +1,20 @@ /* global module */ module.exports = function(grunt) { + var dateFormat = require('dateformat'); // ---------- grunt.loadNpmTasks("grunt-contrib-compress"); grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.loadNpmTasks("grunt-qunit-istanbul"); + grunt.loadNpmTasks("grunt-contrib-qunit"); grunt.loadNpmTasks("grunt-contrib-connect"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-eslint"); grunt.loadNpmTasks("grunt-git-describe"); grunt.loadNpmTasks('grunt-text-replace'); + grunt.loadNpmTasks('grunt-istanbul'); // ---------- var packageJson = grunt.file.readJSON("package.json"), @@ -21,6 +23,7 @@ module.exports = function(grunt) { packageDirName = "openseadragon-bin-" + packageJson.version, packageDir = "build/" + packageDirName + "/", releaseRoot = "../site-build/built-openseadragon/", + coverageDir = 'coverage/' + dateFormat(new Date(), 'yyyymmdd-HHMMss'), sources = [ "src/openseadragon.js", "src/fullscreen.js", @@ -83,7 +86,7 @@ module.exports = function(grunt) { clean: { build: ["build"], package: [packageDir], - coverage: ["coverage"], + coverage: ["instrumented"], release: { src: [releaseRoot], options: { @@ -154,7 +157,8 @@ module.exports = function(grunt) { qunit: { normal: { options: { - urls: [ "http://localhost:8000/test/test.html" ] + urls: [ "http://localhost:8000/test/test.html" ], + timeout: 10000 } }, coverage: { @@ -162,11 +166,13 @@ module.exports = function(grunt) { urls: [ "http://localhost:8000/test/coverage.html" ], coverage: { src: ['src/*.js'], - htmlReport: 'coverage/html/', - instrumentedFiles: 'temp/', + htmlReport: coverageDir + '/html/', + instrumentedFiles: 'instrumented/src/', baseUrl: '.', disposeCollector: true - } + }, + inject: 'test/helpers/phantom-bridge.js', + timeout: 10000 } }, all: { @@ -199,7 +205,38 @@ module.exports = function(grunt) { }, build: {} }, - gitInfo: "unknown" + gitInfo: "unknown", + instrument: { + files: sources, + options: { + lazy: false, + basePath: 'instrumented/' + } + }, + reloadTasks: { + rootPath: "instrumented/src/" + }, + storeCoverage: { + options: { + dir: coverageDir, + 'include-all-sources': true + } + }, + makeReport: { + src: "coverage/**/*.json", + options: { + type: [ "lcov", "html" ], + dir: coverageDir, + print: "detail" + } + } + }); + + grunt.event.on("qunit.coverage", function(coverage) { + var reportPath = coverageDir + "/coverage.json"; + + // Create the coverage file + grunt.file.write(reportPath, JSON.stringify(coverage)); }); // ---------- @@ -287,7 +324,7 @@ module.exports = function(grunt) { // ---------- // Coverage task. // Outputs unit test code coverage report. - grunt.registerTask("coverage", ["clean:coverage", "connect", "qunit:coverage"]); + grunt.registerTask("coverage", ["clean:coverage", "instrument", "connect", "qunit:coverage", "makeReport"]); // ---------- // Package task. diff --git a/changelog.txt b/changelog.txt index 9b8ac00b..0d2a7464 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,11 @@ OPENSEADRAGON CHANGELOG * BREAKING CHANGE: Viewer's canvas-double-click event is now fired before it initiates the zoom (#1288) * You can now prevent canvas-double-click events from zooming on a per-event basis (#1288) +* Fixed: Opacity 0 images were causing unnecessary redraws (#1319) +* The "page" event is now fired after the page index has been updated (#1330) +* Added option pixelsPerArrowPress that sets the speed of arrow keys (#1364) +* Improved IIIF options.maxLevel calculation (#1401) +* Added canvas-key events, along with the ability to cancel key actions (#1414) 2.3.1: diff --git a/package.json b/package.json index 457edf01..efc0ed5f 100644 --- a/package.json +++ b/package.json @@ -2,31 +2,45 @@ "name": "openseadragon", "version": "2.3.1", "description": "Provides a smooth, zoomable user interface for HTML/Javascript.", - "keywords": ["image", "zoom", "pan", "openseadragon", "seadragon", "deepzoom", "dzi", "iiif", "osm", "tms"], + "keywords": [ + "image", + "zoom", + "pan", + "openseadragon", + "seadragon", + "deepzoom", + "dzi", + "iiif", + "osm", + "tms" + ], "homepage": "http://openseadragon.github.io/", "bugs": { "url": "https://github.com/openseadragon/openseadragon/issues" }, "license": "BSD-3-Clause", - "files": ["build/openseadragon/"], + "files": [ + "build/openseadragon/" + ], "main": "build/openseadragon/openseadragon.js", "repository": { - "type" : "git", - "url" : "https://github.com/openseadragon/openseadragon.git" + "type": "git", + "url": "https://github.com/openseadragon/openseadragon.git" }, "devDependencies": { - "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.7.0", + "grunt": "^1.0.1", + "grunt-contrib-clean": "^1.1.0", "grunt-contrib-compress": "^1.4.3", "grunt-contrib-concat": "^1.0.1", - "grunt-contrib-connect": "^0.11.2", - "grunt-contrib-uglify": "^2.0.0", - "grunt-contrib-watch": "^0.6.1", - "grunt-git-describe": "^2.3.2", + "grunt-contrib-connect": "^1.0.2", + "grunt-contrib-qunit": "^2.0.0", + "grunt-contrib-uglify": "^3.2.1", + "grunt-contrib-watch": "^1.0.0", "grunt-eslint": "^19.0.0", - "grunt-qunit-istanbul": "^0.6.0", + "grunt-git-describe": "^2.3.2", + "grunt-istanbul": "^0.8.0", "grunt-text-replace": "^0.4.0", - "qunitjs": "^1.20.0" + "qunitjs": "2.4.1" }, "scripts": { "test": "grunt test", diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 0af45c8b..c80a3f2d 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -127,7 +127,8 @@ $.IIIFTileSource = function( options ){ if (!this.scale_factors) { options.maxLevel = Number(Math.ceil(Math.log(Math.max(this.width, this.height), 2))); } else { - options.maxLevel = Math.floor(Math.pow(Math.max.apply(null, this.scale_factors), 0.5)); + var maxScaleFactor = Math.max.apply(null, this.scale_factors); + options.maxLevel = Math.round(Math.log(maxScaleFactor) * Math.LOG2E); } } diff --git a/src/openseadragon.js b/src/openseadragon.js index de88f717..fd3fe809 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -266,6 +266,9 @@ * @property {Number} [pixelsPerWheelLine=40] * For pixel-resolution scrolling devices, the number of pixels equal to one scroll line. * + * @property {Number} [pixelsPerArrowPress=40] + * The number of pixels viewport moves when an arrow key is pressed. + * * @property {Number} [visibilityRatio=0.5] * The percentage ( as a number from 0 to 1 ) of the source image which * must be kept within the viewport. If the image is dragged beyond that @@ -1088,6 +1091,7 @@ function OpenSeadragon( options ){ smoothTileEdgesMinZoom: 1.1, //-> higher than maxZoomPixelRatio disables it iOSDevice: isIOSDevice(), pixelsPerWheelLine: 40, + pixelsPerArrowPress: 40, autoResize: true, preserveImageSizeOnResize: false, // requires autoResize=true minScrollDeltaTime: 50, diff --git a/src/tiledimage.js b/src/tiledimage.js index bfc67fc8..aa4ca876 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -35,8 +35,8 @@ (function( $ ){ /** - * You shouldn't have to create a TiledImage directly; use {@link OpenSeadragon.Viewer#open} - * or {@link OpenSeadragon.Viewer#addTiledImage} instead. + * You shouldn't have to create a TiledImage instance directly; get it asynchronously by + * using {@link OpenSeadragon.Viewer#open} or {@link OpenSeadragon.Viewer#addTiledImage} instead. * @class TiledImage * @memberof OpenSeadragon * @extends OpenSeadragon.EventSource diff --git a/src/viewer.js b/src/viewer.js index dc1d7438..bffb18ad 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -481,6 +481,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, /** * Open tiled images into the viewer, closing any others. + * To get the TiledImage instance created by open, add an event listener for + * {@link OpenSeadragon.Viewer.html#.event:open}, which when fired can be used to get access + * to the instance, i.e., viewer.world.getItemAt(0). * @function * @param {Array|String|Object|Function} tileSources - This can be a TiledImage * specifier, a TileSource specifier, or an array of either. A TiledImage specifier @@ -1263,7 +1266,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * requests. * @param {Function} [options.success] A function that gets called when the image is * successfully added. It's passed the event object which contains a single property: - * "item", the resulting TiledImage. + * "item", which is the resulting instance of TiledImage. * @param {Function} [options.error] A function that gets called if the image is * unable to be added. It's passed the error event object, which contains "message" * and "source" properties. @@ -1832,6 +1835,16 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ goToPage: function( page ){ if( this.tileSources && page >= 0 && page < this.tileSources.length ){ + this._sequenceIndex = page; + + this._updateSequenceButtons( page ); + + this.open( this.tileSources[ page ] ); + + if( this.referenceStrip ){ + this.referenceStrip.setFocus( page ); + } + /** * Raised when the page is changed on a viewer configured with multiple image sources (see {@link OpenSeadragon.Viewer#goToPage}). * @@ -1843,16 +1856,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @property {?Object} userData - Arbitrary subscriber-defined object. */ this.raiseEvent( 'page', { page: page } ); - - this._sequenceIndex = page; - - this._updateSequenceButtons( page ); - - this.open( this.tileSources[ page ] ); - - if( this.referenceStrip ){ - this.referenceStrip.setFocus( page ); - } } return this; @@ -2474,31 +2477,62 @@ function onBlur(){ } function onCanvasKeyDown( event ) { - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + var canvasKeyDownEventArgs = { + originalEvent: event.originalEvent, + preventDefaultAction: event.preventDefaultAction, + preventVerticalPan: event.preventVerticalPan, + preventHorizontalPan: event.preventHorizontalPan + }; + + /** + * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-key + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default keyboard behaviour. Default: false. + * @property {Boolean} preventVerticalPan - Set to true to prevent keyboard vertical panning. Default: false. + * @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + + this.raiseEvent('canvas-key', canvasKeyDownEventArgs); + + if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ case 38://up arrow - if ( event.shift ) { + if (!canvasKeyDownEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(1.1); - } else { - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -40))); + } else { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -this.pixelsPerArrowPress))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 40://down arrow - if ( event.shift ) { + if (!canvasKeyDownEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(0.9); - } else { - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, 40))); + } else { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, this.pixelsPerArrowPress))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 37://left arrow - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyDownEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-this.pixelsPerArrowPress, 0))); + this.viewport.applyConstraints(); + } return false; case 39://right arrow - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyDownEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(this.pixelsPerArrowPress, 0))); + this.viewport.applyConstraints(); + } return false; default: //console.log( 'navigator keycode %s', event.keyCode ); @@ -2508,9 +2542,18 @@ function onCanvasKeyDown( event ) { return true; } } - function onCanvasKeyPress( event ) { - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + var canvasKeyPressEventArgs = { + originalEvent: event.originalEvent, + preventDefaultAction: event.preventDefaultAction, + preventVerticalPan: event.preventVerticalPan, + preventHorizontalPan: event.preventHorizontalPan + }; + + // This event is documented in onCanvasKeyDown + this.raiseEvent('canvas-key', canvasKeyPressEventArgs); + + if ( !canvasKeyPressEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ case 43://=|+ case 61://=|+ @@ -2527,29 +2570,37 @@ function onCanvasKeyPress( event ) { return false; case 119://w case 87://W - if ( event.shift ) { - this.viewport.zoomBy(1.1); - } else { - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -40))); - } - this.viewport.applyConstraints(); - return false; + if (!canvasKeyPressEventArgs.preventVerticalPan) { + if ( event.shift ) { + this.viewport.zoomBy(1.1); + } else { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -40))); + } + this.viewport.applyConstraints(); + } + return false; case 115://s case 83://S - if ( event.shift ) { + if (!canvasKeyPressEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(0.9); - } else { + } else { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, 40))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 97://a - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyPressEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); + this.viewport.applyConstraints(); + } return false; case 100://d - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyPressEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); + this.viewport.applyConstraints(); + } return false; default: //console.log( 'navigator keycode %s', event.keyCode ); diff --git a/test/coverage.html b/test/coverage.html index 36e2e056..e2abc706 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -21,40 +21,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/data/iiif_2_0_tiled_sf1/0,0,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/0,0,256,256/256,/0/default.jpg new file mode 100644 index 00000000..a29c5568 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/0,0,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/0,256,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/0,256,256,256/256,/0/default.jpg new file mode 100644 index 00000000..cb38ba74 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/0,256,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/0,512,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/0,512,256,256/256,/0/default.jpg new file mode 100644 index 00000000..0b44da15 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/0,512,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/0,768,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/0,768,256,256/256,/0/default.jpg new file mode 100644 index 00000000..8cf078fa Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/0,768,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/256,0,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/256,0,256,256/256,/0/default.jpg new file mode 100644 index 00000000..36ecb717 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/256,0,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/256,256,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/256,256,256,256/256,/0/default.jpg new file mode 100644 index 00000000..b57469a8 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/256,256,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/256,512,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/256,512,256,256/256,/0/default.jpg new file mode 100644 index 00000000..7fd76a78 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/256,512,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/256,768,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/256,768,256,256/256,/0/default.jpg new file mode 100644 index 00000000..cf96a405 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/256,768,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/512,0,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/512,0,256,256/256,/0/default.jpg new file mode 100644 index 00000000..ca605428 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/512,0,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/512,256,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/512,256,256,256/256,/0/default.jpg new file mode 100644 index 00000000..41dd14bb Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/512,256,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/512,512,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/512,512,256,256/256,/0/default.jpg new file mode 100644 index 00000000..1b42d53c Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/512,512,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/512,768,256,256/256,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/512,768,256,256/256,/0/default.jpg new file mode 100644 index 00000000..b3e0f5cb Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/512,768,256,256/256,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/768,0,7,256/7,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/768,0,7,256/7,/0/default.jpg new file mode 100644 index 00000000..7f08427a Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/768,0,7,256/7,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/768,256,7,256/7,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/768,256,7,256/7,/0/default.jpg new file mode 100644 index 00000000..b21f307b Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/768,256,7,256/7,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/768,512,7,256/7,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/768,512,7,256/7,/0/default.jpg new file mode 100644 index 00000000..4a92be8c Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/768,512,7,256/7,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/768,768,7,256/7,/0/default.jpg b/test/data/iiif_2_0_tiled_sf1/768,768,7,256/7,/0/default.jpg new file mode 100644 index 00000000..f167fa29 Binary files /dev/null and b/test/data/iiif_2_0_tiled_sf1/768,768,7,256/7,/0/default.jpg differ diff --git a/test/data/iiif_2_0_tiled_sf1/info.json b/test/data/iiif_2_0_tiled_sf1/info.json new file mode 100644 index 00000000..1507348d --- /dev/null +++ b/test/data/iiif_2_0_tiled_sf1/info.json @@ -0,0 +1,31 @@ +{ + "@context": "http://iiif.io/api/image/2/context.json", + "@id": "http://localhost:8000/test/data/iiif_2_0_tiled_sf1", + "protocol": "http://iiif.io/api/image", + "height": 1024, + "width": 775, + "tiles": [ + { + "width": 256, + "scaleFactors": [ + 1 + ] + } + ], + "profile": [ + "http://iiif.io/api/image/2/level1.json", + { + "qualities": [ + "native", + "bitonal", + "grey", + "color" + ], + "formats": [ + "jpg", + "png", + "gif" + ] + } + ] +} diff --git a/test/demo/iiif-tiled-sf1.html b/test/demo/iiif-tiled-sf1.html new file mode 100644 index 00000000..d1931e44 --- /dev/null +++ b/test/demo/iiif-tiled-sf1.html @@ -0,0 +1,34 @@ + + + + OpenSeadragon Demo - IIIF Tiled scaleFactors [1] + + + + + +
+

Default OpenSeadragon viewer from IIIF Tile Source.

+

This is for testing the support for scaleFactors [1]

+
+
+ + + diff --git a/test/helpers/phantom-bridge.js b/test/helpers/phantom-bridge.js new file mode 100644 index 00000000..ed5b84ad --- /dev/null +++ b/test/helpers/phantom-bridge.js @@ -0,0 +1,73 @@ +/* + * grunt-contrib-qunit + * http://gruntjs.com/ + * + * Copyright (c) 2016 "Cowboy" Ben Alman, contributors + * Licensed under the MIT license. + */ + +/*global QUnit:true, alert:true*/ +(function (factory) { + if (typeof define === 'function' && define.amd) { + require(['qunit'], factory); + } else { + factory(QUnit); + } +}(function(QUnit) { + 'use strict'; + + // Don't re-order tests. + QUnit.config.reorder = false; + + // Send messages to the parent PhantomJS process via alert! Good times!! + function sendMessage() { + var args = [].slice.call(arguments); + alert(JSON.stringify(args)); + } + + // These methods connect QUnit to PhantomJS. + QUnit.log(function(obj) { + // What is this I don’t even + if (obj.message === '[object Object], undefined:undefined') { return; } + + // Parse some stuff before sending it. + var actual, expected; + if (!obj.result) { + // Dumping large objects can be very slow, and the dump isn't used for + // passing tests, so only dump if the test failed. + actual = QUnit.dump.parse(obj.actual); + expected = QUnit.dump.parse(obj.expected); + } + // Send it. + sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source, obj.todo); + }); + + QUnit.testStart(function(obj) { + sendMessage('qunit.testStart', obj.name); + }); + + QUnit.testDone(function(obj) { + sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.runtime, obj.skipped, obj.todo); + }); + + QUnit.moduleStart(function(obj) { + sendMessage('qunit.moduleStart', obj.name); + }); + + QUnit.moduleDone(function(obj) { + sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total); + }); + + QUnit.begin(function() { + sendMessage('qunit.begin'); + }); + + QUnit.done(function(obj) { + // send coverage data if available + if ( window.__coverage__ ) { + sendMessage( "qunit.coverage", window.__coverage__ ); + } + + sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime); + }); +})); diff --git a/test/helpers/test.js b/test/helpers/test.js index 3dbb5468..8e7685d8 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util */ +/* global $, Util */ (function () { @@ -64,38 +64,39 @@ }, // ---------- - assessNumericValue: function ( value1, value2, variance, message ) { - ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance ); + assessNumericValue: function ( assert, value1, value2, variance, message ) { + assert.ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance ); }, // ---------- - assertPointsEquals: function (pointA, pointB, precision, message) { - Util.assessNumericValue(pointA.x, pointB.x, precision, message + " x: "); - Util.assessNumericValue(pointA.y, pointB.y, precision, message + " y: "); + assertPointsEquals: function (assert, pointA, pointB, precision, message) { + Util.assessNumericValue(assert, pointA.x, pointB.x, precision, message + " x: "); + Util.assessNumericValue(assert, pointA.y, pointB.y, precision, message + " y: "); }, // ---------- - assertRectangleEquals: function (rectA, rectB, precision, message) { - Util.assessNumericValue(rectA.x, rectB.x, precision, message + " x: "); - Util.assessNumericValue(rectA.y, rectB.y, precision, message + " y: "); - Util.assessNumericValue(rectA.width, rectB.width, precision, + assertRectangleEquals: function (assert, rectA, rectB, precision, message) { + Util.assessNumericValue(assert, rectA.x, rectB.x, precision, message + " x: "); + Util.assessNumericValue(assert, rectA.y, rectB.y, precision, message + " y: "); + Util.assessNumericValue(assert, rectA.width, rectB.width, precision, message + " width: "); - Util.assessNumericValue(rectA.height, rectB.height, precision, + Util.assessNumericValue(assert, rectA.height, rectB.height, precision, message + " height: "); - Util.assessNumericValue(rectA.degrees, rectB.degrees, precision, + Util.assessNumericValue(assert, rectA.degrees, rectB.degrees, precision, message + " degrees: "); }, // ---------- - timeWatcher: function ( time ) { + timeWatcher: function ( assert, time ) { + var done = assert.async(); time = time || 2000; var finished = false; setTimeout( function () { if ( !finished ) { finished = true; - ok( false, 'finishes in ' + time + 'ms' ); - start(); + assert.ok( false, 'finishes in ' + time + 'ms' ); + done(); } }, time ); @@ -103,7 +104,7 @@ done: function () { if ( !finished ) { finished = true; - start(); + done(); } } }; @@ -118,13 +119,12 @@ if (result === undefined) { result = original.apply(this, arguments); } - return result; }; }, // ---------- - testDeprecation: function(obj0, member0, obj1, member1) { + testDeprecation: function(assert, obj0, member0, obj1, member1) { var called = false; var errored = false; @@ -144,8 +144,8 @@ }); obj0[member0](); - equal(called, true, 'called through for ' + member0); - equal(errored, true, 'errored for ' + member0); + assert.equal(called, true, 'called through for ' + member0); + assert.equal(errored, true, 'errored for ' + member0); } }; diff --git a/test/modules/ajax-tiles.js b/test/modules/ajax-tiles.js index 646e80b8..a77dfed8 100644 --- a/test/modules/ajax-tiles.js +++ b/test/modules/ajax-tiles.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, start, $, ok, equal, deepEqual, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer; @@ -36,8 +36,8 @@ }, }; - module('AJAX-Tiles', { - setup: function() { + QUnit.module('AJAX-Tiles', { + beforeEach: function() { $('
').appendTo('#qunit-fixture'); testLog.reset(); @@ -52,7 +52,7 @@ } }); }, - teardown: function() { + afterEach: function() { if (viewer && viewer.close) { viewer.close(); } @@ -61,25 +61,27 @@ } }); - asyncTest('tile-loaded event includes AJAX request object', function() { + QUnit.test('tile-loaded event includes AJAX request object', function(assert) { + var done = assert.async(); var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); - ok(evt.tileRequest, 'Event includes tileRequest property'); - equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); - start(); + assert.ok(evt.tileRequest, 'Event includes tileRequest property'); + assert.equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); viewer.open(customTileSource); }); - asyncTest('withCredentials is set in tile AJAX requests', function() { + QUnit.test('withCredentials is set in tile AJAX requests', function(assert) { + var done = assert.async(); var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); - ok(evt.tileRequest, 'Event includes tileRequest property'); - equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); - equal(evt.tileRequest.withCredentials, true, 'withCredentials is set in tile request'); - start(); + assert.ok(evt.tileRequest, 'Event includes tileRequest property'); + assert.equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); + assert.equal(evt.tileRequest.withCredentials, true, 'withCredentials is set in tile request'); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); @@ -89,7 +91,8 @@ }); }); - asyncTest('tile-load-failed event includes AJAX request object', function() { + QUnit.test('tile-load-failed event includes AJAX request object', function(assert) { + var done = assert.async(); // Create a tile source that points to a broken URL var brokenTileSource = OpenSeadragon.extend({}, customTileSource, { getTileUrl: function () { @@ -99,31 +102,32 @@ var tileLoadFailed = function tileLoadFailed(evt) { viewer.removeHandler('tile-load-failed', tileLoadFailed); - ok(evt.tileRequest, 'Event includes tileRequest property'); - equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); - start(); + assert.ok(evt.tileRequest, 'Event includes tileRequest property'); + assert.equal(evt.tileRequest.readyState, XMLHttpRequest.DONE, 'tileRequest is in completed state'); + done(); }; viewer.addHandler('tile-load-failed', tileLoadFailed); viewer.open(brokenTileSource); }); - asyncTest('Headers can be set per-tile', function() { + QUnit.test('Headers can be set per-tile', function(assert) { + var done = assert.async(); var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); var tile = evt.tile; - ok(tile, 'tile property exists on event'); - ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); - equal(tile.ajaxHeaders.Range, getTileRangeHeader(tile.level, tile.x, tile.y), 'Tile has correct range header.'); - start(); + assert.ok(tile, 'tile property exists on event'); + assert.ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); + assert.equal(tile.ajaxHeaders.Range, getTileRangeHeader(tile.level, tile.x, tile.y), 'Tile has correct range header.'); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); - viewer.open(customTileSource); }); - asyncTest('Headers are propagated correctly', function() { + QUnit.test('Headers are propagated correctly', function(assert) { + var done = assert.async(); // Create a tile source that sets a static header for tiles var staticHeaderTileSource = OpenSeadragon.extend({}, customTileSource, { getTileAjaxHeaders: function() { @@ -142,13 +146,13 @@ var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); var tile = evt.tile; - ok(tile, 'tile property exists on event'); - ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); - deepEqual( + assert.ok(tile, 'tile property exists on event'); + assert.ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); + assert.deepEqual( tile.ajaxHeaders, expectedHeaders, 'Tile headers include headers set on Viewer and TiledImage' ); - start(); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); @@ -161,7 +165,8 @@ }); }); - asyncTest('Viewer headers are overwritten by TiledImage', function() { + QUnit.test('Viewer headers are overwritten by TiledImage', function(assert) { + var done = assert.async(); // Create a tile source that sets a static header for tiles var staticHeaderTileSource = OpenSeadragon.extend({}, customTileSource, { getTileAjaxHeaders: function() { @@ -180,13 +185,13 @@ var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); var tile = evt.tile; - ok(tile, 'tile property exists on event'); - ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); - deepEqual( + assert.ok(tile, 'tile property exists on event'); + assert.ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); + assert.deepEqual( tile.ajaxHeaders, expectedHeaders, 'TiledImage header overwrites viewer header' ); - start(); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); @@ -200,7 +205,8 @@ }); }); - asyncTest('TiledImage headers are overwritten by Tile', function() { + QUnit.test('TiledImage headers are overwritten by Tile', function(assert) { + var done = assert.async(); var expectedHeaders = { 'X-Viewer-Header': 'ViewerHeaderValue', @@ -211,13 +217,13 @@ var tileLoaded = function tileLoaded(evt) { viewer.removeHandler('tile-loaded', tileLoaded); var tile = evt.tile; - ok(tile, 'tile property exists on event'); - ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); - deepEqual( + assert.ok(tile, 'tile property exists on event'); + assert.ok(tile.ajaxHeaders, 'Tile has ajaxHeaders property'); + assert.deepEqual( tile.ajaxHeaders, expectedHeaders, 'Tile header overwrites TiledImage header' ); - start(); + done(); }; viewer.addHandler('tile-loaded', tileLoaded); diff --git a/test/modules/basic.js b/test/modules/basic.js index 4cecce2a..257246db 100644 --- a/test/modules/basic.js +++ b/test/modules/basic.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, Util, testLog */ (function() { var viewer; - module('Basic', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('Basic', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -25,57 +25,59 @@ }); // ---------- - asyncTest('Open', function() { - ok(viewer, 'Viewer exists'); + QUnit.test('Open', function(assert) { + var done = assert.async(); + assert.ok(viewer, 'Viewer exists'); var openHandler = function(event) { viewer.removeHandler('open', openHandler); - ok(true, 'Open event was sent'); - ok(event, 'Handler received event data'); - equal(event.eventSource, viewer, 'Sender of open event was viewer'); - ok(viewer.viewport, 'Viewport exists'); - ok(viewer.source, 'source exists'); - ok(viewer._updateRequestId, 'timer is on'); - start(); + assert.ok(true, 'Open event was sent'); + assert.ok(event, 'Handler received event data'); + assert.equal(event.eventSource, viewer, 'Sender of open event was viewer'); + assert.ok(viewer.viewport, 'Viewport exists'); + assert.ok(viewer.source, 'source exists'); + assert.ok(viewer._updateRequestId, 'timer is on'); + done(); }; viewer.addHandler('open', openHandler); viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('Open Error Handling', function() { - ok(viewer, 'Viewer exists'); + QUnit.test('Open Error Handling', function(assert) { + var done = assert.async(); + assert.ok(viewer, 'Viewer exists'); viewer.addHandler('open', function(event) { - ok(false, "The open event should not fire for failed opens"); - start(); + assert.ok(false, "The open event should not fire for failed opens"); + done(); }); viewer.addHandler('open-failed', function(event) { - ok(true, "The open-failed event should be fired when the source 404s"); + assert.ok(true, "The open-failed event should be fired when the source 404s"); - equal($(".openseadragon-message").length, 1, "Open failures should display a message"); + assert.equal($(".openseadragon-message").length, 1, "Open failures should display a message"); - ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'), + assert.ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'), "AJAX failures should be logged to the console"); - start(); + done(); }); viewer.open('/test/data/not-a-real-file'); }); - // ---------- - asyncTest('Zoom', function() { + QUnit.test('Zoom', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; - equal(viewport.getZoom(), 1, 'We start out unzoomed'); + assert.equal(viewport.getZoom(), 1, 'We start out unzoomed'); var zoomHandler = function() { viewer.removeHandler('animation-finish', zoomHandler); - equal(viewport.getZoom(), 2, 'Zoomed correctly'); - start(); + assert.equal(viewport.getZoom(), 2, 'Zoomed correctly'); + done(); }; viewer.addHandler('animation-finish', zoomHandler); @@ -84,20 +86,20 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('Pan', function() { + QUnit.test('Pan', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport, center = viewport.getCenter(); - ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned'); + assert.ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned'); var panHandler = function() { viewer.removeHandler('animation-finish', panHandler); center = viewport.getCenter(); - Util.assessNumericValue(center.x, 0.1, 0.00001, 'panned horizontally'); - Util.assessNumericValue(center.y, 0.1, 0.00001, 'panned vertically'); - start(); + Util.assessNumericValue(assert, center.x, 0.1, 0.00001, 'panned horizontally'); + Util.assessNumericValue(assert, center.y, 0.1, 0.00001, 'panned vertically'); + done(); }; viewer.addHandler('animation-finish', panHandler); @@ -107,9 +109,9 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('Home', function() { - // Test setup: + QUnit.test('Home', function(assert) { + var done = assert.async(); + // Test beforeEach: function opener() { var viewport = viewer.viewport; viewport.panTo(new OpenSeadragon.Point(0.1, 0.1)); @@ -122,15 +124,15 @@ viewer.removeHandler('animation-finish', stage1); - ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned'); - notEqual(viewport.getZoom(), 1, 'We start out zoomed'); + assert.ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned'); + assert.notEqual(viewport.getZoom(), 1, 'We start out zoomed'); var homeHandler = function() { viewer.removeHandler('animation-finish', homeHandler); center = viewport.getCenter(); - ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned'); - equal(viewport.getZoom(), 1, 'We end up unzoomed'); - start(); + assert.ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned'); + assert.equal(viewport.getZoom(), 1, 'We end up unzoomed'); + done(); }; viewer.addHandler('animation-finish', homeHandler); @@ -143,21 +145,21 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('Click', function() { + QUnit.test('Click', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport, center = viewport.getCenter(); - ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned'); - equal(viewport.getZoom(), 1, 'We start out unzoomed'); + assert.ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned'); + assert.equal(viewport.getZoom(), 1, 'We start out unzoomed'); var clickHandler = function() { viewer.removeHandler('animation-finish', clickHandler); center = viewport.getCenter(); - ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly'); - equal(viewport.getZoom(), 2, 'Zoomed correctly'); - start(); + assert.ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly'); + assert.equal(viewport.getZoom(), 2, 'Zoomed correctly'); + done(); }; viewer.addHandler('animation-finish', clickHandler); @@ -174,39 +176,39 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('FullPage', function() { + QUnit.test('FullPage', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { - ok(!viewer.isFullPage(), 'Started out not fullpage'); - ok(!$(viewer.element).hasClass('fullpage'), + assert.ok(!viewer.isFullPage(), 'Started out not fullpage'); + assert.ok(!$(viewer.element).hasClass('fullpage'), 'No fullpage class on div'); var checkEnteringPreFullPage = function(event) { viewer.removeHandler('pre-full-page', checkEnteringPreFullPage); - ok(event.fullPage, 'Switching to fullpage'); - ok(!viewer.isFullPage(), 'Not yet fullpage'); + assert.ok(event.fullPage, 'Switching to fullpage'); + assert.ok(!viewer.isFullPage(), 'Not yet fullpage'); }; var checkEnteringFullPage = function(event) { viewer.removeHandler('full-page', checkEnteringFullPage); - ok(event.fullPage, 'Switched to fullpage'); - ok(viewer.isFullPage(), 'Enabled fullpage'); - ok($(viewer.element).hasClass('fullpage'), + assert.ok(event.fullPage, 'Switched to fullpage'); + assert.ok(viewer.isFullPage(), 'Enabled fullpage'); + assert.ok($(viewer.element).hasClass('fullpage'), 'Fullpage class added to div'); var checkExitingPreFullPage = function(event) { viewer.removeHandler('pre-full-page', checkExitingPreFullPage); - ok(!event.fullPage, 'Exiting fullpage'); - ok(viewer.isFullPage(), 'Still fullpage'); + assert.ok(!event.fullPage, 'Exiting fullpage'); + assert.ok(viewer.isFullPage(), 'Still fullpage'); }; var checkExitingFullPage = function(event) { viewer.removeHandler('full-page', checkExitingFullPage); - ok(!event.fullPage, 'Exiting fullpage'); - ok(!viewer.isFullPage(), 'Disabled fullpage'); - ok(!$(viewer.element).hasClass('fullpage'), + assert.ok(!event.fullPage, 'Exiting fullpage'); + assert.ok(!viewer.isFullPage(), 'Disabled fullpage'); + assert.ok(!$(viewer.element).hasClass('fullpage'), 'Fullpage class removed from div'); - start(); + done(); }; viewer.addHandler("pre-full-page", checkExitingPreFullPage); @@ -221,30 +223,30 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('FullScreen', function() { - + QUnit.test('FullScreen', function(assert) { + var done = assert.async(); if (!OpenSeadragon.supportsFullScreen) { - expect(0); - start(); + assert.expect(0); + done(); return; } viewer.addHandler("open", function () { - ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen'); + assert.ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen'); var checkEnteringPreFullScreen = function(event) { viewer.removeHandler('pre-full-screen', checkEnteringPreFullScreen); - ok(event.fullScreen, 'Switching to fullscreen'); - ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen'); + assert.ok(event.fullScreen, 'Switching to fullscreen'); + assert.ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen'); }; // The fullscreen mode is always denied during tests so we are // exiting directly. var checkExitingFullScreen = function(event) { viewer.removeHandler('full-screen', checkExitingFullScreen); - ok(!event.fullScreen, 'Exiting fullscreen'); - ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen'); - start(); + assert.ok(!event.fullScreen, 'Exiting fullscreen'); + assert.ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen'); + done(); }; viewer.addHandler("pre-full-screen", checkEnteringPreFullScreen); viewer.addHandler("full-screen", checkExitingFullScreen); @@ -254,16 +256,16 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('Close', function() { + QUnit.test('Close', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { var closeHandler = function() { viewer.removeHandler('close', closeHandler); - ok(!viewer.source, 'no source'); - ok(true, 'Close event was sent'); + assert.ok(!viewer.source, 'no source'); + assert.ok(true, 'Close event was sent'); setTimeout(function() { - ok(!viewer._updateRequestId, 'timer is off'); - start(); + assert.ok(!viewer._updateRequestId, 'timer is off'); + done(); }, 100); }; @@ -273,11 +275,11 @@ viewer.open('/test/data/testpattern.dzi'); }); - // ---------- - asyncTest('Destroy', function() { + QUnit.test('Destroy', function(assert) { + var done = assert.async(); viewer.addHandler("open", function () { // Check that the DOM has been modified - notEqual(0, $('#example').children().length); + assert.notEqual(0, $('#example').children().length); var closeCalled = false; var closeHandler = function() { @@ -289,14 +291,14 @@ viewer.destroy(); // Check that the DOM has been cleaned up - equal(0, $('#example').children().length); - equal(null, viewer.canvas); - equal(null, viewer.keyboardCommandArea); - equal(null, viewer.container); - equal(null, viewer.element); - equal(true, closeCalled); + assert.equal(0, $('#example').children().length); + assert.equal(null, viewer.canvas); + assert.equal(null, viewer.keyboardCommandArea); + assert.equal(null, viewer.container); + assert.equal(null, viewer.element); + assert.equal(true, closeCalled); viewer = null; - start(); + done(); }); viewer.open('/test/data/testpattern.dzi'); }); @@ -319,8 +321,8 @@ img.src = corsImg; } - asyncTest( 'CrossOriginPolicyMissing', function () { - + QUnit.test( 'CrossOriginPolicyMissing', function (assert) { + var done = assert.async(); viewer.crossOriginPolicy = false; viewer.smoothTileEdgesMinZoom = Infinity; viewer.open( { @@ -332,19 +334,19 @@ } ] } ); viewer.addOnceHandler('tile-drawn', function() { - ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + assert.ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), "Canvas should be tainted."); - start(); + done(); }); } ); - asyncTest( 'CrossOriginPolicyAnonymous', function () { - + QUnit.test( 'CrossOriginPolicyAnonymous', function (assert) { + var done = assert.async(); browserSupportsImgCrossOrigin(function(supported) { if (!supported) { - expect(0); - start(); + assert.expect(0); + done(); } else { viewer.crossOriginPolicy = 'Anonymous'; viewer.open( { @@ -356,21 +358,21 @@ } ] } ); viewer.addOnceHandler('tile-drawn', function() { - ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + assert.ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), "Canvas should not be tainted."); - start(); + done(); }); } }); } ); - asyncTest( 'CrossOriginPolicyOption', function () { - + QUnit.test( 'CrossOriginPolicyOption', function (assert) { + var done = assert.async(); browserSupportsImgCrossOrigin(function(supported) { if (!supported) { - expect(0); - start(); + assert.expect(0); + done(); } else { viewer.crossOriginPolicy = "Anonymous"; viewer.smoothTileEdgesMinZoom = Infinity; @@ -386,20 +388,21 @@ crossOriginPolicy : false } ); viewer.addOnceHandler('tile-drawn', function() { - ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + assert.ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), "Canvas should be tainted."); - start(); + done(); }); } }); } ); - asyncTest( 'CrossOriginPolicyTileSource', function () { + QUnit.test( 'CrossOriginPolicyTileSource', function (assert) { + var done = assert.async(); browserSupportsImgCrossOrigin(function(supported) { if (!supported) { - expect(0); - start(); + assert.expect(0); + done(); } else { viewer.crossOriginPolicy = false; viewer.smoothTileEdgesMinZoom = Infinity; @@ -415,9 +418,9 @@ } } ); viewer.addOnceHandler('tile-drawn', function() { - ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), + assert.ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas), "Canvas should not be tainted."); - start(); + done(); }); } }); @@ -425,8 +428,9 @@ } ); - asyncTest('SetDebugMode', function() { - ok(viewer, 'Viewer exists'); + QUnit.test('SetDebugMode', function(assert) { + var done = assert.async(); + assert.ok(viewer, 'Viewer exists'); var checkImageTilesDebugState = function (expectedState) { @@ -443,15 +447,15 @@ //Ensure we start with debug mode turned off viewer.setDebugMode(false); - ok(checkImageTilesDebugState(false), "All image tiles have debug mode turned off."); - ok(!viewer.debugMode, "Viewer debug mode is turned off."); + assert.ok(checkImageTilesDebugState(false), "All image tiles have debug mode turned off."); + assert.ok(!viewer.debugMode, "Viewer debug mode is turned off."); //Turn debug mode on and check that the Viewer and all tiled images are in debug mode. viewer.setDebugMode(true); - ok(checkImageTilesDebugState(true), "All image tiles have debug mode turned on."); - ok(viewer.debugMode, "Viewer debug mode is turned on."); + assert.ok(checkImageTilesDebugState(true), "All image tiles have debug mode turned on."); + assert.ok(viewer.debugMode, "Viewer debug mode is turned on."); - start(); + done(); }; viewer.addHandler('open', openHandler); @@ -460,11 +464,11 @@ //Version numbers are injected by the build process, so skip version tests if we are only running code coverage if(!window.isCoverageTest ){ - test('version object', function() { - equal(typeof OpenSeadragon.version.versionStr, "string", "versionStr should be a string"); - ok(OpenSeadragon.version.major >= 0, "major should be a positive number"); - ok(OpenSeadragon.version.minor >= 0, "minor should be a positive number"); - ok(OpenSeadragon.version.revision >= 0, "revision should be a positive number"); + QUnit.test('version object', function(assert) { + assert.equal(typeof OpenSeadragon.version.versionStr, "string", "versionStr should be a string"); + assert.ok(OpenSeadragon.version.major >= 0, "major should be a positive number"); + assert.ok(OpenSeadragon.version.minor >= 0, "minor should be a positive number"); + assert.ok(OpenSeadragon.version.revision >= 0, "revision should be a positive number"); }); } })(); diff --git a/test/modules/controls.js b/test/modules/controls.js index 640b2402..57d827c9 100644 --- a/test/modules/controls.js +++ b/test/modules/controls.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function () { var viewer; - module('Controls', { - setup: function () { - var example = $('
') + QUnit.module('Controls', { + beforeEach: function () { + $('
') .css({ width: 1000, height: 1000 @@ -15,7 +15,7 @@ testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -24,16 +24,16 @@ } }); - asyncTest('ZoomControlOff', function () { - + QUnit.test('ZoomControlOff', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(!viewer.showZoomControl, 'showZoomControl should be off'); - ok(!viewer.zoomInButton, "zoomIn button should be null"); - ok(!viewer.zoomOutButton, "zoomOut button should be null"); + assert.ok(!viewer.showZoomControl, 'showZoomControl should be off'); + assert.ok(!viewer.zoomInButton, "zoomIn button should be null"); + assert.ok(!viewer.zoomOutButton, "zoomOut button should be null"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -46,29 +46,29 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('ZoomControlOn', function () { - + QUnit.test('ZoomControlOn', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(viewer.showZoomControl, 'showZoomControl should be on'); - ok(!!viewer.zoomInButton, "zoomIn button should not be null"); - ok(!!viewer.zoomOutButton, "zoomOut button should not be null"); - notEqual(viewer.buttons.buttons.indexOf(viewer.zoomInButton), -1, + assert.ok(viewer.showZoomControl, 'showZoomControl should be on'); + assert.ok(!!viewer.zoomInButton, "zoomIn button should not be null"); + assert.ok(!!viewer.zoomOutButton, "zoomOut button should not be null"); + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.zoomInButton), -1, "The zoomIn button should be present"); - notEqual(viewer.buttons.buttons.indexOf(viewer.zoomOutButton), -1, + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.zoomOutButton), -1, "The zoomOut button should be present"); var oldZoom = viewer.viewport.getZoom(); viewer.zoomInButton.onClick(); var newZoom = viewer.viewport.getZoom(); - ok(oldZoom < newZoom, "OSD should have zoomed in."); + assert.ok(oldZoom < newZoom, "OSD should have zoomed in."); oldZoom = newZoom; viewer.zoomOutButton.onClick(); newZoom = viewer.viewport.getZoom(); - ok(oldZoom > newZoom, "OSD should have zoomed out."); + assert.ok(oldZoom > newZoom, "OSD should have zoomed out."); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -81,15 +81,15 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('HomeControlOff', function () { - + QUnit.test('HomeControlOff', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(!viewer.showHomeControl, 'showHomeControl should be off'); - ok(!viewer.homeButton, "Home button should be null"); + assert.ok(!viewer.showHomeControl, 'showHomeControl should be off'); + assert.ok(!viewer.homeButton, "Home button should be null"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -102,32 +102,32 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('HomeControlOn', function () { - + QUnit.test('HomeControlOn', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(viewer.showHomeControl, 'showHomeControl should be on'); - ok(!!viewer.homeButton, "Home button should not be null"); - notEqual(viewer.buttons.buttons.indexOf(viewer.homeButton), -1, + assert.ok(viewer.showHomeControl, 'showHomeControl should be on'); + assert.ok(!!viewer.homeButton, "Home button should not be null"); + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.homeButton), -1, "The home button should be present"); viewer.viewport.zoomBy(1.1); var bounds = viewer.viewport.getBounds(); var homeBounds = viewer.viewport.getHomeBounds(); - ok(bounds.x !== homeBounds.x || + assert.ok(bounds.x !== homeBounds.x || bounds.y !== homeBounds.y || bounds.width !== homeBounds.width || bounds.height !== homeBounds.height, "OSD should not be at home."); viewer.homeButton.onRelease(); bounds = viewer.viewport.getBounds(); - ok(bounds.x === homeBounds.x && + assert.ok(bounds.x === homeBounds.x && bounds.y === homeBounds.y && bounds.width === homeBounds.width && bounds.height === homeBounds.height, "OSD should have get home."); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -140,15 +140,15 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('FullPageControlOff', function () { - + QUnit.test('FullPageControlOff', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(!viewer.showFullPageControl, 'showFullPageControl should be off'); - ok(!viewer.fullPageButton, "FullPage button should be null"); + assert.ok(!viewer.showFullPageControl, 'showFullPageControl should be off'); + assert.ok(!viewer.fullPageButton, "FullPage button should be null"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -161,23 +161,23 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('FullPageControlOn', function () { - + QUnit.test('FullPageControlOn', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(viewer.showHomeControl, 'showFullPageControl should be on'); - ok(!!viewer.fullPageButton, "FullPage button should not be null"); - notEqual(viewer.buttons.buttons.indexOf(viewer.fullPageButton), -1, + assert.ok(viewer.showHomeControl, 'showFullPageControl should be on'); + assert.ok(!!viewer.fullPageButton, "FullPage button should not be null"); + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.fullPageButton), -1, "The full page button should be present"); - ok(!viewer.isFullPage(), "OSD should not be in full page."); + assert.ok(!viewer.isFullPage(), "OSD should not be in full page."); viewer.fullPageButton.onRelease(); - ok(viewer.isFullPage(), "OSD should be in full page."); + assert.ok(viewer.isFullPage(), "OSD should be in full page."); viewer.fullPageButton.onRelease(); - ok(!viewer.isFullPage(), "OSD should not be in full page."); + assert.ok(!viewer.isFullPage(), "OSD should not be in full page."); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -190,19 +190,19 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('RotateControlOff', function () { - + QUnit.test('RotateControlOff', function (assert) { + var done = assert.async(); var openHandler = function (event) { viewer.removeHandler('open', openHandler); - ok(true, 'Open event was sent'); - ok(viewer.drawer, 'Drawer exists'); - ok(viewer.drawer.canRotate(), 'drawer.canRotate needs to be true'); - ok(!viewer.showRotationControl, 'showRotationControl should be off'); - ok(!viewer.rotateLeftButton, "rotateLeft button should be null"); - ok(!viewer.rotateRightButton, "rotateRight button should be null"); + assert.ok(true, 'Open event was sent'); + assert.ok(viewer.drawer, 'Drawer exists'); + assert.ok(viewer.drawer.canRotate(), 'drawer.canRotate needs to be true'); + assert.ok(!viewer.showRotationControl, 'showRotationControl should be off'); + assert.ok(!viewer.rotateLeftButton, "rotateLeft button should be null"); + assert.ok(!viewer.rotateRightButton, "rotateRight button should be null"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -215,29 +215,29 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('RotateControlOn', function () { - + QUnit.test('RotateControlOn', function (assert) { + var done = assert.async(); var openHandler = function (event) { viewer.removeHandler('open', openHandler); - ok(true, 'Open event was sent'); - ok(viewer.drawer, 'Drawer exists'); - ok(viewer.drawer.canRotate(), 'drawer.canRotate needs to be true'); - ok(viewer.showRotationControl, 'showRotationControl should be true'); - notEqual(viewer.buttons.buttons.indexOf(viewer.rotateLeftButton), -1, + assert.ok(true, 'Open event was sent'); + assert.ok(viewer.drawer, 'Drawer exists'); + assert.ok(viewer.drawer.canRotate(), 'drawer.canRotate needs to be true'); + assert.ok(viewer.showRotationControl, 'showRotationControl should be true'); + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.rotateLeftButton), -1, "rotateLeft should be found"); - notEqual(viewer.buttons.buttons.indexOf(viewer.rotateRightButton), -1, + assert.notEqual(viewer.buttons.buttons.indexOf(viewer.rotateRightButton), -1, "rotateRight should be found"); // Now simulate the left/right button clicks. // TODO: re-factor simulateViewerClickWithDrag so it'll accept any element, and use that. - equal(viewer.viewport.degrees, 0, "Image should start at 0 degrees rotation"); + assert.equal(viewer.viewport.degrees, 0, "Image should start at 0 degrees rotation"); viewer.rotateLeftButton.onRelease(); - equal(viewer.viewport.degrees, 270, "Image should be 270 degrees rotation (left)"); + assert.equal(viewer.viewport.degrees, 270, "Image should be 270 degrees rotation (left)"); viewer.rotateRightButton.onRelease(); - equal(viewer.viewport.degrees, 0, "Image should be 270 degrees rotation (right)"); + assert.equal(viewer.viewport.degrees, 0, "Image should be 270 degrees rotation (right)"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -250,16 +250,16 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('SequenceControlOff', function () { - + QUnit.test('SequenceControlOff', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(!viewer.showSequenceControl, 'showSequenceControl should be off'); - ok(!viewer.previousButton, "Previous button should be null"); - ok(!viewer.nextButton, "Next button should be null"); + assert.ok(!viewer.showSequenceControl, 'showSequenceControl should be off'); + assert.ok(!viewer.previousButton, "Previous button should be null"); + assert.ok(!viewer.nextButton, "Next button should be null"); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -276,47 +276,47 @@ viewer.addHandler('open', openHandler); }); - asyncTest('SequenceControlOnPrevNextWrapOff', function () { - + QUnit.test('SequenceControlOnPrevNextWrapOff', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(viewer.showSequenceControl, 'showSequenceControl should be on'); - ok(!!viewer.previousButton, "Previous button should not be null"); - ok(!!viewer.nextButton, "Next button should not be null"); - notEqual(viewer.paging.buttons.indexOf(viewer.previousButton), -1, + assert.ok(viewer.showSequenceControl, 'showSequenceControl should be on'); + assert.ok(!!viewer.previousButton, "Previous button should not be null"); + assert.ok(!!viewer.nextButton, "Next button should not be null"); + assert.notEqual(viewer.paging.buttons.indexOf(viewer.previousButton), -1, "The previous button should be present"); - notEqual(viewer.paging.buttons.indexOf(viewer.nextButton), -1, + assert.notEqual(viewer.paging.buttons.indexOf(viewer.nextButton), -1, "The next button should be present"); - equal(viewer.currentPage(), 0, "OSD should open on first page."); - ok(viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 0, "OSD should open on first page."); + assert.ok(viewer.previousButton.element.disabled, "Previous should be disabled on first page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on first page."); viewer.nextButton.onRelease(); - equal(viewer.currentPage(), 1, "OSD should be on second page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 1, "OSD should be on second page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on second page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on second page."); viewer.nextButton.onRelease(); - equal(viewer.currentPage(), 2, "OSD should be on third page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 2, "OSD should be on third page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on third page."); - ok(viewer.nextButton.element.disabled, + assert.ok(viewer.nextButton.element.disabled, "Next should be disabled on third page."); viewer.previousButton.onRelease(); - equal(viewer.currentPage(), 1, "OSD should be on second page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 1, "OSD should be on second page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on second page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on second page."); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ @@ -335,40 +335,40 @@ viewer.addHandler('open', openHandler); }); - asyncTest('SequenceControlOnPrevNextWrapOn', function () { - + QUnit.test('SequenceControlOnPrevNextWrapOn', function (assert) { + var done = assert.async(); var openHandler = function () { viewer.removeHandler('open', openHandler); - ok(viewer.showSequenceControl, 'showSequenceControl should be on'); - ok(!!viewer.previousButton, "Previous button should not be null"); - ok(!!viewer.nextButton, "Next button should not be null"); - notEqual(viewer.paging.buttons.indexOf(viewer.previousButton), -1, + assert.ok(viewer.showSequenceControl, 'showSequenceControl should be on'); + assert.ok(!!viewer.previousButton, "Previous button should not be null"); + assert.ok(!!viewer.nextButton, "Next button should not be null"); + assert.notEqual(viewer.paging.buttons.indexOf(viewer.previousButton), -1, "The previous button should be present"); - notEqual(viewer.paging.buttons.indexOf(viewer.nextButton), -1, + assert.notEqual(viewer.paging.buttons.indexOf(viewer.nextButton), -1, "The next button should be present"); - equal(viewer.currentPage(), 0, "OSD should open on first page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 0, "OSD should open on first page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on first page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on first page."); viewer.previousButton.onRelease(); - equal(viewer.currentPage(), 2, "OSD should be on third page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 2, "OSD should be on third page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on third page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on third page."); viewer.nextButton.onRelease(); - equal(viewer.currentPage(), 0, "OSD should be on first page."); - ok(!viewer.previousButton.element.disabled, + assert.equal(viewer.currentPage(), 0, "OSD should be on first page."); + assert.ok(!viewer.previousButton.element.disabled, "Previous should be enabled on first page."); - ok(!viewer.nextButton.element.disabled, + assert.ok(!viewer.nextButton.element.disabled, "Next should be enabled on first page."); viewer.close(); - start(); + done(); }; viewer = OpenSeadragon({ diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 4016ebfd..ba53ba2d 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -1,15 +1,15 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, Util, testLog */ (function() { var viewer; - module('Drawer', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('Drawer', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -29,15 +29,17 @@ }; // ---------- - asyncTest('basics', function() { + QUnit.test('basics', function(assert) { + var done = assert.async(); createViewer(); - ok(viewer.drawer, 'Drawer exists'); - equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); - start(); + assert.ok(viewer.drawer, 'Drawer exists'); + assert.equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); + done(); }); // ---------- - asyncTest('rotation', function() { + QUnit.test('rotation', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi' }); @@ -45,27 +47,29 @@ viewer.addHandler('open', function handler(event) { viewer.viewport.setRotation(30); Util.spyOnce(viewer.drawer.context, 'rotate', function() { - ok(true, 'drawing with new rotation'); - start(); + assert.ok(true, 'drawing with new rotation'); + done(); }); }); }); // ---------- - asyncTest('debug', function() { + QUnit.test('debug', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi', debugMode: true }); Util.spyOnce(viewer.drawer, 'drawDebugInfo', function() { - ok(true, 'drawDebugInfo is called'); - start(); + assert.ok(true, 'drawDebugInfo is called'); + done(); }); }); // ---------- - asyncTest('sketchCanvas', function() { + QUnit.test('sketchCanvas', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi' }); @@ -73,9 +77,9 @@ viewer.addHandler('tile-drawn', function noOpacityHandler() { viewer.removeHandler('tile-drawn', noOpacityHandler); - equal(drawer.sketchCanvas, null, + assert.equal(drawer.sketchCanvas, null, 'The sketch canvas should be null if no decimal opacity is used.'); - equal(drawer.sketchContext, null, + assert.equal(drawer.sketchContext, null, 'The sketch context should be null if no decimal opacity is used.'); testOpacityDecimal(); }); @@ -95,32 +99,34 @@ return; } viewer.removeHandler('tile-drawn', opacityDecimalHandler); - notEqual(drawer.sketchCanvas, null, + assert.notEqual(drawer.sketchCanvas, null, 'The sketch canvas should not be null once a decimal opacity has been used.'); - notEqual(drawer.sketchContext, null, + assert.notEqual(drawer.sketchContext, null, 'The sketch context should not be null once a decimal opacity has been used.'); - start(); + done(); }); } }); // ---------- - asyncTest('deprecations', function() { + QUnit.test('deprecations', function(assert) { + var done = assert.async(); + createViewer({ tileSources: '/test/data/testpattern.dzi' }); viewer.world.addHandler('add-item', function() { - 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, 'needsDraw'); - Util.testDeprecation(viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); - Util.testDeprecation(viewer.drawer, 'reset', viewer.world, 'resetItems'); - Util.testDeprecation(viewer.drawer, 'update', viewer.world, 'draw'); - Util.testDeprecation(viewer.drawer, 'setOpacity', viewer.world.getItemAt(0), 'setOpacity'); - Util.testDeprecation(viewer.drawer, 'getOpacity', viewer.world.getItemAt(0), 'getOpacity'); - start(); + Util.testDeprecation(assert, viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + Util.testDeprecation(assert, viewer.drawer, 'needsUpdate', viewer.world, 'needsDraw'); + Util.testDeprecation(assert, viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); + Util.testDeprecation(assert, viewer.drawer, 'reset', viewer.world, 'resetItems'); + Util.testDeprecation(assert, viewer.drawer, 'update', viewer.world, 'draw'); + Util.testDeprecation(assert, viewer.drawer, 'setOpacity', viewer.world.getItemAt(0), 'setOpacity'); + Util.testDeprecation(assert, viewer.drawer, 'getOpacity', viewer.world.getItemAt(0), 'getOpacity'); + done(); }); }); diff --git a/test/modules/dzitilesource.js b/test/modules/dzitilesource.js index 25b0c265..8c6360c9 100644 --- a/test/modules/dzitilesource.js +++ b/test/modules/dzitilesource.js @@ -1,42 +1,48 @@ - -/*global module:true, test:true, equal:true, OpenSeadragon:true*/ +/* global QUnit, testLog */ (function() { - module('DziTileSource', { - setup: function() { + QUnit.module('DziTileSource', { + beforeEach: function() { testLog.reset(); } }); - function testImplicitTilesUrl(dziUrl, expected, msg) { + function testImplicitTilesUrl(assert, dziUrl, expected, msg) { var source = new OpenSeadragon.DziTileSource(); var options = source.configure({ Image: {Size: {Width:0, Height: 0}} }, dziUrl); - equal(options.tilesUrl, expected, msg); + assert.equal(options.tilesUrl, expected, msg); } - test('test implicit tilesUrl guessed from dzi url', function() { + QUnit.test('test implicit tilesUrl guessed from dzi url', function(assert) { testImplicitTilesUrl( + assert, '/path/my.dzi', '/path/my_files/', 'dzi extension should be stripped'); testImplicitTilesUrl( + assert, '/path/my', '/path/my_files/', 'no extension should still produce _files path'); testImplicitTilesUrl( + assert, '/my/', '/my_files/', 'no extension with trailing slash should preserve slash'); testImplicitTilesUrl( + assert, 'my.xml', 'my_files/', 'relative link should stay the same'); testImplicitTilesUrl( + assert, '/p/foo.dzi?a=1&b=2', '/p/foo_files/', 'querystring in dzi url should be ignored after slashes'); testImplicitTilesUrl( + assert, '/iiipsrv?DeepZoom=/path/my.dzi', '/iiipsrv?DeepZoom=/path/my_files/', 'querystring in dzi url should not be ignored before slashes'); testImplicitTilesUrl( + assert, '/fcg-bin/iipsrv.fcgi?Deepzoom=123test.tif.dzi', '/fcg-bin/iipsrv.fcgi?Deepzoom=123test.tif_files/', 'filename in querystring does not have to contain slash'); }); diff --git a/test/modules/events.js b/test/modules/events.js index af226a44..849e86f9 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, TouchUtil, Util, testLog */ +/* global QUnit, $, TouchUtil, Util, testLog */ (function () { var viewer; - module( 'Events', { - setup: function () { - var example = $( '
' ).appendTo( "#qunit-fixture" ); + QUnit.module( 'Events', { + beforeEach: function () { + $( '
' ).appendTo( "#qunit-fixture" ); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests } ); }, - teardown: function () { + afterEach: function () { if ( viewer && viewer.close ) { viewer.close(); } @@ -25,12 +25,12 @@ } ); // ---------- - asyncTest( 'MouseTracker: mouse gestures', function () { + QUnit.test( 'MouseTracker: mouse gestures', function (assert) { + var done = assert.async(); var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), simEvent = {}, offset = $canvas.offset(), tracker = viewer.innerTracker, - intervalId, origEnterHandler, origExitHandler, origPressHandler, @@ -278,58 +278,58 @@ var assessGestureExpectations = function (expected) { var pointersList = tracker.getActivePointersListByType('mouse'); if ('enterCount' in expected) { - equal( enterCount, expected.enterCount, expected.description + 'enterHandler event count matches expected (' + expected.enterCount + ')' ); + assert.equal( enterCount, expected.enterCount, expected.description + 'enterHandler event count matches expected (' + expected.enterCount + ')' ); } if ('exitCount' in expected) { - equal( exitCount, expected.exitCount, expected.description + 'exitHandler event count matches expected (' + expected.exitCount + ')' ); + assert.equal( exitCount, expected.exitCount, expected.description + 'exitHandler event count matches expected (' + expected.exitCount + ')' ); } if ('pressCount' in expected) { - equal( pressCount, expected.pressCount, expected.description + 'pressHandler event count matches expected (' + expected.pressCount + ')' ); + assert.equal( pressCount, expected.pressCount, expected.description + 'pressHandler event count matches expected (' + expected.pressCount + ')' ); } if ('releaseCount' in expected) { - equal( releaseCount, expected.releaseCount, expected.description + 'releaseHandler event count matches expected (' + expected.releaseCount + ')' ); + assert.equal( releaseCount, expected.releaseCount, expected.description + 'releaseHandler event count matches expected (' + expected.releaseCount + ')' ); } if ('rightPressCount' in expected) { - equal( rightPressCount, expected.rightPressCount, expected.description + 'nonPrimaryPressHandler event count (secondary/right button) matches expected (' + expected.rightPressCount + ')' ); + assert.equal( rightPressCount, expected.rightPressCount, expected.description + 'nonPrimaryPressHandler event count (secondary/right button) matches expected (' + expected.rightPressCount + ')' ); } if ('rightReleaseCount' in expected) { - equal( rightReleaseCount, expected.rightReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (secondary/right button) matches expected (' + expected.rightReleaseCount + ')' ); + assert.equal( rightReleaseCount, expected.rightReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (secondary/right button) matches expected (' + expected.rightReleaseCount + ')' ); } if ('middlePressCount' in expected) { - equal( middlePressCount, expected.middlePressCount, expected.description + 'nonPrimaryPressHandler event count (aux/middle button) matches expected (' + expected.middlePressCount + ')' ); + assert.equal( middlePressCount, expected.middlePressCount, expected.description + 'nonPrimaryPressHandler event count (aux/middle button) matches expected (' + expected.middlePressCount + ')' ); } if ('middleReleaseCount' in expected) { - equal( middleReleaseCount, expected.middleReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (aux/middle button) matches expected (' + expected.middleReleaseCount + ')' ); + assert.equal( middleReleaseCount, expected.middleReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (aux/middle button) matches expected (' + expected.middleReleaseCount + ')' ); } if ('moveCount' in expected) { - equal( moveCount, expected.moveCount, expected.description + 'moveHandler event count matches expected (' + expected.moveCount + ')' ); + assert.equal( moveCount, expected.moveCount, expected.description + 'moveHandler event count matches expected (' + expected.moveCount + ')' ); } if ('clickCount' in expected) { - equal( clickCount, expected.clickCount, expected.description + 'clickHandler event count matches expected (' + expected.clickCount + ')' ); + assert.equal( clickCount, expected.clickCount, expected.description + 'clickHandler event count matches expected (' + expected.clickCount + ')' ); } if ('dblClickCount' in expected) { - equal( dblClickCount, expected.dblClickCount, expected.description + 'dblClickHandler event count matches expected (' + expected.dblClickCount + ')' ); + assert.equal( dblClickCount, expected.dblClickCount, expected.description + 'dblClickHandler event count matches expected (' + expected.dblClickCount + ')' ); } if ('dragCount' in expected) { - equal( dragCount, expected.dragCount, expected.description + 'dragHandler event count matches expected (' + expected.dragCount + ')' ); + assert.equal( dragCount, expected.dragCount, expected.description + 'dragHandler event count matches expected (' + expected.dragCount + ')' ); } if ('dragEndCount' in expected) { - equal( dragEndCount, expected.dragEndCount, expected.description + 'dragEndHandler event count matches expected (' + expected.dragEndCount + ')' ); + assert.equal( dragEndCount, expected.dragEndCount, expected.description + 'dragEndHandler event count matches expected (' + expected.dragEndCount + ')' ); } if ('insideElementPressed' in expected) { - equal( insideElementPressed, expected.insideElementPressed, expected.description + 'releaseHandler event.insideElementPressed matches expected (' + expected.insideElementPressed + ')' ); + assert.equal( insideElementPressed, expected.insideElementPressed, expected.description + 'releaseHandler event.insideElementPressed matches expected (' + expected.insideElementPressed + ')' ); } if ('insideElementReleased' in expected) { - equal( insideElementReleased, expected.insideElementReleased, expected.description + 'releaseHandler event.insideElementReleased matches expected (' + expected.insideElementReleased + ')' ); + assert.equal( insideElementReleased, expected.insideElementReleased, expected.description + 'releaseHandler event.insideElementReleased matches expected (' + expected.insideElementReleased + ')' ); } if ('contacts' in expected) { - equal( pointersList.contacts, expected.contacts, expected.description + 'Remaining pointer contact count matches expected (' + expected.contacts + ')' ); + assert.equal( pointersList.contacts, expected.contacts, expected.description + 'Remaining pointer contact count matches expected (' + expected.contacts + ')' ); } if ('trackedPointers' in expected) { - equal( pointersList.getLength(), expected.trackedPointers, expected.description + 'Remaining tracked pointer count matches expected (' + expected.trackedPointers + ')' ); + assert.equal( pointersList.getLength(), expected.trackedPointers, expected.description + 'Remaining tracked pointer count matches expected (' + expected.trackedPointers + ')' ); } if ('quickClick' in expected) { - equal( quickClick, expected.quickClick, expected.description + 'clickHandler event.quick matches expected (' + expected.quickClick + ')' ); + assert.equal( quickClick, expected.quickClick, expected.description + 'clickHandler event.quick matches expected (' + expected.quickClick + ')' ); } if ('speed' in expected) { Util.assessNumericValue(expected.speed, speed, 1.0, expected.description + 'Drag speed '); @@ -340,8 +340,6 @@ }; var onOpen = function ( event ) { - var timeStart, - timeElapsed; viewer.removeHandler( 'open', onOpen ); @@ -670,7 +668,7 @@ unhookViewerHandlers(); viewer.close(); - start(); + done(); }; viewer.addHandler( 'open', onOpen ); @@ -679,7 +677,8 @@ // ---------- if ('TouchEvent' in window) { - asyncTest( 'MouseTracker: touch events', function () { + QUnit.test( 'MouseTracker: touch events', function (assert) { + var done = assert.async(); var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), tracker = viewer.innerTracker, touches; @@ -692,13 +691,13 @@ var assessTouchExpectations = function ( expected ) { var pointersList = tracker.getActivePointersListByType( 'touch' ); if ('captureCount' in expected) { - equal( pointersList.captureCount, expected.captureCount, expected.description + 'Pointer capture count matches expected (' + expected.captureCount + ')' ); + assert.equal( pointersList.captureCount, expected.captureCount, expected.description + 'Pointer capture count matches expected (' + expected.captureCount + ')' ); } if ('contacts' in expected) { - equal( pointersList.contacts, expected.contacts, expected.description + 'Pointer contact count matches expected (' + expected.contacts + ')' ); + assert.equal( pointersList.contacts, expected.contacts, expected.description + 'Pointer contact count matches expected (' + expected.contacts + ')' ); } if ('trackedPointers' in expected) { - equal( pointersList.getLength(), expected.trackedPointers, expected.description + 'Tracked pointer count matches expected (' + expected.trackedPointers + ')' ); + assert.equal( pointersList.getLength(), expected.trackedPointers, expected.description + 'Tracked pointer count matches expected (' + expected.trackedPointers + ')' ); } }; @@ -745,7 +744,7 @@ TouchUtil.resetTracker( tracker ); viewer.close(); - start(); + done(); }; viewer.addHandler( 'open', onOpen ); @@ -754,7 +753,8 @@ } // ---------- - asyncTest('Viewer: preventDefaultAction', function() { + QUnit.test('Viewer: preventDefaultAction', function(assert) { + var done = assert.async(); var $canvas = $(viewer.element).find('.openseadragon-canvas') .not('.navigator .openseadragon-canvas'); var tracker = viewer.innerTracker; @@ -805,9 +805,9 @@ var zoom = viewer.viewport.getZoom(); var bounds = viewer.viewport.getBounds(); - Util.assessNumericValue(zoom, originalZoom, epsilon, + Util.assessNumericValue(assert, zoom, originalZoom, epsilon, "Zoom should be prevented"); - Util.assertRectangleEquals(bounds, originalBounds, epsilon, + Util.assertRectangleEquals(assert, bounds, originalBounds, epsilon, 'Pan should be prevented'); tracker.clickHandler = origClickHandler; @@ -815,18 +815,19 @@ simulateClickAndDrag(); - var zoom = viewer.viewport.getZoom(); - var bounds = viewer.viewport.getBounds(); - Util.assessNumericValue(zoom, 0.002, epsilon, + zoom = viewer.viewport.getZoom(); + bounds = viewer.viewport.getBounds(); + Util.assessNumericValue(assert, zoom, 0.002, epsilon, "Zoom should not be prevented"); Util.assertRectangleEquals( + assert, new OpenSeadragon.Rect(-249.5, -0.25, 500, 0.5), bounds, epsilon, 'Pan should not be prevented'); viewer.close(); - start(); + done(); }; viewer.addHandler('open', onOpen); @@ -834,7 +835,8 @@ }); // ---------- - asyncTest('Viewer: preventDefaultAction in dblClickHandler', function() { + QUnit.test('Viewer: preventDefaultAction in dblClickHandler', function(assert) { + var done = assert.async(); var tracker = viewer.innerTracker; var epsilon = 0.0000001; @@ -863,7 +865,7 @@ simulateDblTap(); var zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(originalZoom, zoom, epsilon, + Util.assessNumericValue(assert, originalZoom, zoom, epsilon, "Zoom on double tap should be prevented"); // Reset event handler to original @@ -872,19 +874,19 @@ simulateDblTap(); originalZoom = originalZoom * viewer.zoomPerClick; - var zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(originalZoom, zoom, epsilon, + zoom = viewer.viewport.getZoom(); + Util.assessNumericValue(assert, originalZoom, zoom, epsilon, "Zoom on double tap should not be prevented"); var dblClickHandler = function(event) { event.preventDefaultAction = true; - } + }; viewer.addHandler('canvas-double-click', dblClickHandler); - var zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(originalZoom, zoom, epsilon, + zoom = viewer.viewport.getZoom(); + Util.assessNumericValue(assert, originalZoom, zoom, epsilon, "Zoom on double tap should be prevented"); // Remove custom event handler @@ -893,13 +895,13 @@ simulateDblTap(); originalZoom = originalZoom * viewer.zoomPerClick; - var zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(originalZoom, zoom, epsilon, + zoom = viewer.viewport.getZoom(); + Util.assessNumericValue(assert, originalZoom, zoom, epsilon, "Zoom on double tap should not be prevented"); TouchUtil.resetTracker(tracker); viewer.close(); - start(); + done(); }; viewer.addHandler('open', onOpen); @@ -907,7 +909,8 @@ }); // ---------- - asyncTest( 'EventSource/MouseTracker/Viewer: event.originalEvent event.userData canvas-drag canvas-drag-end canvas-release canvas-click', function () { + QUnit.test( 'EventSource/MouseTracker/Viewer: event.originalEvent event.userData canvas-drag canvas-drag-end canvas-release canvas-click', function (assert) { + var done = assert.async(); var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), mouseTracker = null, userData = { item1: 'Test user data', item2: Math.random() }, @@ -1055,18 +1058,18 @@ viewer.removeHandler( 'canvas-release', onEventSourceRelease ); viewer.removeHandler( 'canvas-click', onEventSourceClick ); - equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); - equal( dragEndsHandledEventSource, dragEndsExpected, "'canvas-drag-end' event count matches expected (" + dragEndsExpected + ")" ); - equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); - equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); - equal( originalEventsPassedViewer, eventsHandledViewer, "Original event received count matches expected (" + eventsHandledViewer + ")" ); + assert.equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); + assert.equal( dragEndsHandledEventSource, dragEndsExpected, "'canvas-drag-end' event count matches expected (" + dragEndsExpected + ")" ); + assert.equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); + assert.equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); + assert.equal( originalEventsPassedViewer, eventsHandledViewer, "Original event received count matches expected (" + eventsHandledViewer + ")" ); - equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" ); - equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); - deepEqual( event.userData, originalUserData, 'MouseTracker userData was untouched' ); + assert.equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" ); + assert.equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); + assert.deepEqual( event.userData, originalUserData, 'MouseTracker userData was untouched' ); viewer.close(); - start(); + done(); }; viewer.addHandler( 'open', onOpen ); @@ -1074,16 +1077,17 @@ } ); // ---------- - asyncTest( 'EventSource: addHandler without userData', function () { + QUnit.test( 'EventSource: addHandler without userData', function (assert) { + var done = assert.async(); var openHandler = function ( event ) { viewer.removeHandler( 'open', openHandler ); - ok( event, 'Event handler received event data' ); + assert.ok( event, 'Event handler received event data' ); if ( event ) { - strictEqual( event.eventSource, viewer, 'eventSource sent, eventSource is viewer' ); - strictEqual( event.userData, null, 'User data defaulted to null' ); + assert.strictEqual( event.eventSource, viewer, 'eventSource sent, eventSource is viewer' ); + assert.strictEqual( event.userData, null, 'User data defaulted to null' ); } viewer.close(); - start(); + done(); }; viewer.addHandler( 'open', openHandler ); @@ -1091,19 +1095,20 @@ } ); // ---------- - asyncTest( 'EventSource: addHandler with userData', function () { + QUnit.test( 'EventSource: addHandler with userData', function (assert) { + var done = assert.async(); var userData = { item1: 'Test user data', item2: Math.random() }, originalUserData = { item1: userData.item1, item2: userData.item2 }; var openHandler = function ( event ) { viewer.removeHandler( 'open', openHandler ); - ok( event, 'Event handler received event data' ); - ok( event && event.userData, 'Event handler received user data' ); + assert.ok( event, 'Event handler received event data' ); + assert.ok( event && event.userData, 'Event handler received user data' ); if ( event && event.userData ) { - deepEqual( event.userData, originalUserData, 'User data was untouched' ); + assert.deepEqual( event.userData, originalUserData, 'User data was untouched' ); } viewer.close(); - start(); + done(); }; viewer.addHandler( 'open', openHandler, userData ); @@ -1111,7 +1116,7 @@ } ); // ---------- - test('EventSource: addOnceHandler', function() { + QUnit.test('EventSource: addOnceHandler', function(assert) { var eventSource = new OpenSeadragon.EventSource(); var userData = 'data'; var eventData = { @@ -1120,23 +1125,23 @@ var handlerCalledCount = 0; eventSource.addOnceHandler('test-event', function(event) { handlerCalledCount++; - strictEqual(event.foo, eventData.foo, + assert.strictEqual(event.foo, eventData.foo, 'Event data should be transmitted to the event.'); - strictEqual(event.userData, userData, + assert.strictEqual(event.userData, userData, 'User data should be transmitted to the event.'); }, userData); - strictEqual(0, handlerCalledCount, + assert.strictEqual(0, handlerCalledCount, 'Handler should not have been called yet.'); eventSource.raiseEvent('test-event', eventData); - strictEqual(1, handlerCalledCount, + assert.strictEqual(1, handlerCalledCount, 'Handler should have been called once.'); eventSource.raiseEvent('test-event', eventData); - strictEqual(1, handlerCalledCount, + assert.strictEqual(1, handlerCalledCount, 'Handler should still have been called once.'); }); // ---------- - test('EventSource: addOnceHandler 2 times', function() { + QUnit.test('EventSource: addOnceHandler 2 times', function(assert) { var eventSource = new OpenSeadragon.EventSource(); var userData = 'data'; var eventData = { @@ -1145,37 +1150,38 @@ var handlerCalledCount = 0; eventSource.addOnceHandler('test-event', function(event) { handlerCalledCount++; - strictEqual(event.foo, eventData.foo, + assert.strictEqual(event.foo, eventData.foo, 'Event data should be transmitted to the event.'); - strictEqual(event.userData, userData, + assert.strictEqual(event.userData, userData, 'User data should be transmitted to the event.'); }, userData, 2); - strictEqual(0, handlerCalledCount, + assert.strictEqual(0, handlerCalledCount, 'Handler should not have been called yet.'); eventSource.raiseEvent('test-event', eventData); - strictEqual(1, handlerCalledCount, + assert.strictEqual(1, handlerCalledCount, 'Handler should have been called once.'); eventSource.raiseEvent('test-event', eventData); - strictEqual(2, handlerCalledCount, + assert.strictEqual(2, handlerCalledCount, 'Handler should have been called twice.'); eventSource.raiseEvent('test-event', eventData); - strictEqual(2, handlerCalledCount, + assert.strictEqual(2, handlerCalledCount, 'Handler should still have been called twice.'); }); // ---------- - asyncTest( 'Viewer: tile-drawing event', function () { + QUnit.test( 'Viewer: tile-drawing event', function (assert) { + var done = assert.async(); var tileDrawing = function ( event ) { viewer.removeHandler( 'tile-drawing', tileDrawing ); - ok( event, 'Event handler should be invoked' ); + assert.ok( event, 'Event handler should be invoked' ); if ( event ) { // Make sure we have the expected elements set - ok(event.context, "Context should be set"); - ok(event.tile, "Tile should be set"); - ok(event.rendered, "Rendered should be set"); + assert.ok(event.context, "Context should be set"); + assert.ok(event.tile, "Tile should be set"); + assert.ok(event.rendered, "Rendered should be set"); } viewer.close(); - start(); + done(); }; viewer.addHandler( 'tile-drawing', tileDrawing ); @@ -1183,17 +1189,17 @@ } ); // tile-loaded event tests - asyncTest( 'Viewer: tile-loaded event without callback.', function () { - + QUnit.test( 'Viewer: tile-loaded event without callback.', function (assert) { + var done = assert.async(); function tileLoaded ( event ) { viewer.removeHandler( 'tile-loaded', tileLoaded); var tile = event.tile; - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); setTimeout(function() { - notOk( tile.loading, "The tile should not be marked as loading."); - ok( tile.loaded, "The tile should be marked as loaded."); - start(); + assert.notOk( tile.loading, "The tile should not be marked as loading."); + assert.ok( tile.loaded, "The tile should be marked as loaded."); + done(); }, 0); } @@ -1201,22 +1207,22 @@ viewer.open( '/test/data/testpattern.dzi' ); } ); - asyncTest( 'Viewer: tile-loaded event with 1 callback.', function () { - + QUnit.test( 'Viewer: tile-loaded event with 1 callback.', function (assert) { + var done = assert.async(); function tileLoaded ( event ) { viewer.removeHandler( 'tile-loaded', tileLoaded); var tile = event.tile; var callback = event.getCompletionCallback(); - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); - ok( callback, "The event should have a callback."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( callback, "The event should have a callback."); setTimeout(function() { - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); callback(); - notOk( tile.loading, "The tile should not be marked as loading."); - ok( tile.loaded, "The tile should be marked as loaded."); - start(); + assert.notOk( tile.loading, "The tile should not be marked as loading."); + assert.ok( tile.loaded, "The tile should be marked as loaded."); + done(); }, 0); } @@ -1224,28 +1230,28 @@ viewer.open( '/test/data/testpattern.dzi' ); } ); - asyncTest( 'Viewer: tile-loaded event with 2 callbacks.', function () { - + QUnit.test( 'Viewer: tile-loaded event with 2 callbacks.', function (assert) { + var done = assert.async(); function tileLoaded ( event ) { viewer.removeHandler( 'tile-loaded', tileLoaded); var tile = event.tile; var callback1 = event.getCompletionCallback(); var callback2 = event.getCompletionCallback(); - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); setTimeout(function() { - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); callback1(); - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); setTimeout(function() { - ok( tile.loading, "The tile should be marked as loading."); - notOk( tile.loaded, "The tile should not be marked as loaded."); + assert.ok( tile.loading, "The tile should be marked as loading."); + assert.notOk( tile.loaded, "The tile should not be marked as loaded."); callback2(); - notOk( tile.loading, "The tile should not be marked as loading."); - ok( tile.loaded, "The tile should be marked as loaded."); - start(); + assert.notOk( tile.loading, "The tile should not be marked as loading."); + assert.ok( tile.loaded, "The tile should be marked as loaded."); + done(); }, 0); }, 0); } @@ -1254,9 +1260,10 @@ viewer.open( '/test/data/testpattern.dzi' ); } ); - asyncTest( 'Viewer: tile-unloaded event.', function() { + QUnit.test( 'Viewer: tile-unloaded event.', function(assert) { var tiledImage; var tile; + var done = assert.async(); function tileLoaded( event ) { viewer.removeHandler( 'tile-loaded', tileLoaded); @@ -1269,11 +1276,11 @@ function tileUnloaded( event ) { viewer.removeHandler( 'tile-unloaded', tileUnloaded ); - equal( tile, event.tile, + assert.equal( tile, event.tile, "The unloaded tile should be the same than the loaded one." ); - equal( tiledImage, event.tiledImage, + assert.equal( tiledImage, event.tiledImage, "The tiledImage of the unloaded tile should be the same than the one of the loaded one." ); - start(); + done(); } viewer.addHandler( 'tile-loaded', tileLoaded ); diff --git a/test/modules/formats.js b/test/modules/formats.js index c3a6c850..b14a5680 100644 --- a/test/modules/formats.js +++ b/test/modules/formats.js @@ -1,10 +1,12 @@ +/* global QUnit, Util */ + (function() { // This module tests whether our various file formats can be opened. // TODO: Add more file formats (with corresponding test data). - module('Formats', { - setup: function () { + QUnit.module('Formats', { + beforeEach: function () { var example = document.createElement("div"); example.id = "example"; document.getElementById("qunit-fixture").appendChild(example); @@ -14,113 +16,115 @@ var viewer = null; // ---------- - var testOpenUrl = function(relativeUrl) { - testOpen('/test/data/' + relativeUrl); + var testOpenUrl = function(relativeUrl, assert) { + testOpen('/test/data/' + relativeUrl, assert); }; - var testOpen = function(tileSource) { - $(document).ready(function() { - var timeWatcher = Util.timeWatcher(7000); + var testOpen = function(tileSource, assert) { + var timeWatcher = Util.timeWatcher(assert, 7000); - viewer = OpenSeadragon({ - id: 'example', - prefixUrl: '/build/openseadragon/images/', - tileSources: tileSource - }); - - ok(viewer, 'Viewer exists'); - - var openHandler = function(event) { - viewer.removeHandler('open', openHandler); - ok(true, 'Open event was sent'); - viewer.addHandler('tile-drawn', tileDrawnHandler); - }; - - var tileDrawnHandler = function(event) { - viewer.removeHandler('tile-drawn', tileDrawnHandler); - ok(true, 'A tile has been drawn'); - viewer.addHandler('close', closeHandler); - viewer.close(); - }; - - var closeHandler = function(event) { - viewer.removeHandler('close', closeHandler); - $('#example').empty(); - ok(true, 'Close event was sent'); - timeWatcher.done(); - }; - - viewer.addHandler('open', openHandler); + viewer = OpenSeadragon({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: tileSource }); + + assert.ok(viewer, 'Viewer exists'); + + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + assert.ok(true, 'Open event was sent'); + viewer.addHandler('tile-drawn', tileDrawnHandler); + }; + + var tileDrawnHandler = function(event) { + viewer.removeHandler('tile-drawn', tileDrawnHandler); + assert.ok(true, 'A tile has been drawn'); + viewer.addHandler('close', closeHandler); + viewer.close(); + }; + + var closeHandler = function(event) { + viewer.removeHandler('close', closeHandler); + $('#example').empty(); + assert.ok(true, 'Close event was sent'); + timeWatcher.done(); + }; + viewer.addHandler('open', openHandler); }; // ---------- - asyncTest('DZI', function() { - testOpenUrl('testpattern.dzi'); + QUnit.test('DZI', function(assert) { + testOpenUrl('testpattern.dzi', assert); }); // ---------- - asyncTest('DZI JSONp', function() { - testOpenUrl('testpattern.js'); + QUnit.test('DZI JSONp', function(assert) { + testOpenUrl('testpattern.js', assert); }); // ---------- - asyncTest('DZI XML', function() { - testOpenUrl('testpattern.xml'); + QUnit.test('DZI XML', function(assert) { + testOpenUrl('testpattern.xml', assert); }); // ---------- - asyncTest('DZI XML with query parameter', function() { - testOpenUrl('testpattern.xml?param=value'); + QUnit.test('DZI XML with query parameter', function(assert) { + testOpenUrl('testpattern.xml?param=value', assert); }); // ---------- - asyncTest('IIIF 1.0 JSON', function() { - testOpenUrl('iiif_1_0_files/info.json'); + QUnit.test('IIIF 1.0 JSON', function(assert) { + testOpenUrl('iiif_1_0_files/info.json', assert); }); // ---------- - asyncTest('IIIF 1.0 XML', function() { - testOpenUrl('iiif_1_0_files/info.xml'); + QUnit.test('IIIF 1.0 XML', function(assert) { + testOpenUrl('iiif_1_0_files/info.xml', assert); }); // ---------- - asyncTest('IIIF 1.1 JSON', function() { - testOpenUrl('iiif_1_1_tiled/info.json'); + QUnit.test('IIIF 1.1 JSON', function(assert) { + testOpenUrl('iiif_1_1_tiled/info.json', assert); }); // ---------- - asyncTest('IIIF No Tiles, Less than 256', function() { - testOpenUrl('iiif_1_1_no_tiles_255/info.json'); + QUnit.test('IIIF No Tiles, Less than 256', function(assert) { + testOpenUrl('iiif_1_1_no_tiles_255/info.json', assert); }); // ---------- - asyncTest('IIIF No Tiles, Bet. 256 and 512', function() { - testOpenUrl('iiif_1_1_no_tiles_384/info.json'); + QUnit.test('IIIF No Tiles, Bet. 256 and 512', function(assert) { + testOpenUrl('iiif_1_1_no_tiles_384/info.json', assert); }); // ---------- - asyncTest('IIIF No Tiles, Bet. 512 and 1024', function() { - testOpenUrl('iiif_1_1_no_tiles_768/info.json'); + QUnit.test('IIIF No Tiles, Bet. 512 and 1024', function(assert) { + testOpenUrl('iiif_1_1_no_tiles_768/info.json', assert); }); // ---------- - asyncTest('IIIF No Tiles, Larger than 1024', function() { - testOpenUrl('iiif_1_1_no_tiles_1048/info.json'); + QUnit.test('IIIF No Tiles, Larger than 1024', function(assert) { + testOpenUrl('iiif_1_1_no_tiles_1048/info.json', assert); }); // ---------- - asyncTest('IIIF 2.0 JSON', function() { - testOpenUrl('iiif_2_0_tiled/info.json'); + QUnit.test('IIIF 2.0 JSON', function(assert) { + testOpenUrl('iiif_2_0_tiled/info.json', assert); }); // ---------- - asyncTest('IIIF 2.0 JSON, sizes array only', function() { - testOpenUrl('iiif_2_0_sizes/info.json'); + QUnit.test('IIIF 2.0 JSON scaleFactors [1]', function(assert) { + testOpenUrl('iiif_2_0_tiled_sf1/info.json', assert); }); // ---------- - asyncTest('IIIF 2.0 JSON String', function() { + QUnit.test('IIIF 2.0 JSON, sizes array only', function(assert) { + testOpenUrl('iiif_2_0_sizes/info.json', assert); + }); + + // ---------- + QUnit.test('IIIF 2.0 JSON String', function(assert) { testOpen( '{' + ' "@context": "http://iiif.io/api/image/2/context.json",' + @@ -144,58 +148,58 @@ ' ]' + ' }' + ' ]' + - '}'); + '}', assert); }); // ---------- - asyncTest('ImageTileSource', function () { + QUnit.test('ImageTileSource', function(assert) { testOpen({ type: "image", url: "/test/data/A.png" - }); + }, assert); }); // ---------- - asyncTest('Zoomify', function () { + QUnit.test('Zoomify', function(assert) { testOpen({ - type: "zoomifytileservice", + type: "zoomifytileservice", tileSize: 256, width: 1000, height: 1000, tilesUrl: "/test/data/zoomify/" - }); - }); - - + }, assert); + }); + + // ---------- - asyncTest('Legacy Image Pyramid', function() { + QUnit.test('Legacy Image Pyramid', function(assert) { // Although it is using image paths that happen to be in IIIF format, this is not a IIIFTileSource. // The url values are opaque, just image locations. - // When emulating a legacy pyramid, IIIFTileSource calls functions from LegacyTileSource, so this + // When emulating a legacy pyramid, IIIFTileSource calls functions from LegacyTileSource, so this // adds a test for the legacy functionality too. testOpen({ type: 'legacy-image-pyramid', - levels:[{ + levels: [{ url: '/test/data/iiif_2_0_sizes/full/400,/0/default.jpg', height: 291, width: 400 - },{ + }, { url: '/test/data/iiif_2_0_sizes/full/800,/0/default.jpg', height: 582, width: 800 - },{ + }, { url: '/test/data/iiif_2_0_sizes/full/1600,/0/default.jpg', height: 1164, width: 1600 - },{ + }, { url: '/test/data/iiif_2_0_sizes/full/3200,/0/default.jpg', height: 2328, width: 3200 - },{ + }, { url: '/test/data/iiif_2_0_sizes/full/6976,/0/default.jpg', height: 5074, width: 6976 }] - }); + }, assert); }); })(); diff --git a/test/modules/imageloader.js b/test/modules/imageloader.js index 1750ea73..1e201b10 100644 --- a/test/modules/imageloader.js +++ b/test/modules/imageloader.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer, @@ -8,13 +8,13 @@ springStiffness: 100 // Faster animation = faster tests }; - module('ImageLoader', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('ImageLoader', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -25,19 +25,19 @@ // ---------- - test('Default timeout', function() { + QUnit.test('Default timeout', function(assert) { var actual, expected = OpenSeadragon.DEFAULT_SETTINGS.timeout, message, options = OpenSeadragon.extend(true, baseOptions, { imageLoaderLimit: 1 - }), + }), viewer = OpenSeadragon(options), imageLoader = viewer.imageLoader; message = 'ImageLoader timeout should be set to the default value of ' + expected + ' when none is specified'; actual = imageLoader.timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); // Manually seize the ImageLoader imageLoader.jobsInProgress = imageLoader.jobLimit; @@ -51,12 +51,12 @@ message = 'ImageJob should inherit the ImageLoader timeout value'; actual = imageLoader.jobQueue.shift().timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); }); // ---------- - - test('Configure timeout', function() { + + QUnit.test('Configure timeout', function(assert) { var actual, expected = 123456, message, @@ -69,7 +69,7 @@ message = 'ImageLoader timeout should be configurable'; actual = imageLoader.timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); imageLoader.jobsInProgress = imageLoader.jobLimit; imageLoader.addJob({ @@ -82,7 +82,7 @@ message = 'ImageJob should inherit the ImageLoader timeout value'; actual = imageLoader.jobQueue.shift().timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); }); })(); diff --git a/test/modules/multi-image.js b/test/modules/multi-image.js index 1dc9cbca..8fab4eee 100644 --- a/test/modules/multi-image.js +++ b/test/modules/multi-image.js @@ -1,10 +1,10 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, expect */ +/* global QUnit, $,testLog */ ( function() { var viewer; - module( 'Multi-Image', { - setup: function() { + QUnit.module( 'Multi-Image', { + beforeEach: function() { $( '
' ).appendTo( "#qunit-fixture" ); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function() { + afterEach: function() { if ( viewer && viewer.close ) { viewer.close(); } @@ -26,10 +26,11 @@ } ); // ---------- - asyncTest( 'Multi-image operations', function() { - expect( 24 ); + QUnit.test( 'Multi-image operations', function(assert) { + var done = assert.async(); + assert.expect( 24 ); viewer.addHandler( "open", function( ) { - equal( 1, viewer.world.getItemCount( ), + assert.equal( 1, viewer.world.getItemCount( ), "One item should be present after opening." ); var options = { tileSource: { @@ -45,41 +46,41 @@ viewer.world.addHandler( "add-item", function addFirstItemHandler( event ) { viewer.world.removeHandler( "add-item", addFirstItemHandler ); var item1 = event.item; - equal( viewer.world.getItemCount( ), 2, + assert.equal( viewer.world.getItemCount( ), 2, "2 items should be present after adding a item." ); - equal( viewer.world.getIndexOfItem( item1 ), 1, + assert.equal( viewer.world.getIndexOfItem( item1 ), 1, "The first added item should have a index of 1" ); - equal( viewer.world.getItemAt( 1 ), item1, + assert.equal( viewer.world.getItemAt( 1 ), item1, "The item at index 1 should be the first added item." ); viewer.addTiledImage( options ); viewer.world.addHandler( "add-item", function addSecondItemHandler( event ) { viewer.world.removeHandler( "add-item", addSecondItemHandler ); var item2 = event.item; - equal( viewer.world.getItemCount( ), 3, + assert.equal( viewer.world.getItemCount( ), 3, "3 items should be present after adding a second item." ); - equal( viewer.world.getIndexOfItem( item2 ), 2, + assert.equal( viewer.world.getIndexOfItem( item2 ), 2, "If not specified, a item should be added with the highest index." ); - equal( viewer.world.getItemAt( 2 ), item2, + assert.equal( viewer.world.getItemAt( 2 ), item2, "The item at index 2 should be the second added item." ); viewer.world.addHandler( "item-index-change", function itemIndexChangedHandler( event ) { viewer.world.removeHandler( "item-index-change", itemIndexChangedHandler ); - equal( event.item, item2, + assert.equal( event.item, item2, "The item which changed index should be item2" ); - equal( event.previousIndex, 2, "Previous index should be 2." ); - equal( event.newIndex, 1, "New index should be 1." ); + assert.equal( event.previousIndex, 2, "Previous index should be 2." ); + assert.equal( event.newIndex, 1, "New index should be 1." ); }); viewer.world.setItemIndex( item2, 1 ); - equal( viewer.world.getIndexOfItem( item2 ), 1, + assert.equal( viewer.world.getIndexOfItem( item2 ), 1, "Item2 index should be 1 after setItemIndex." ); - equal( viewer.world.getIndexOfItem( item1 ), 2, + assert.equal( viewer.world.getIndexOfItem( item1 ), 2, "Item1 index should be 2 after setItemIndex." ); - equal( viewer.world.getItemAt( 1 ), item2, + assert.equal( viewer.world.getItemAt( 1 ), item2, "The item at index 1 should be item2." ); - equal( viewer.world.getItemAt( 2 ), item1, + assert.equal( viewer.world.getItemAt( 2 ), item1, "The item at index 2 should be item1." ); options.index = 2; @@ -88,11 +89,11 @@ viewer.world.addHandler( "add-item", function addThirdItemHandler( event ) { viewer.world.removeHandler( "add-item", addThirdItemHandler ); var item3 = event.item; - equal( viewer.world.getItemCount( ), 4, + assert.equal( viewer.world.getItemCount( ), 4, "4 items should be present after adding a third item." ); - equal( viewer.world.getIndexOfItem( item3 ), 2, + assert.equal( viewer.world.getIndexOfItem( item3 ), 2, "Item 3 should be added with index 2." ); - equal( viewer.world.getIndexOfItem( item2 ), 1, + assert.equal( viewer.world.getIndexOfItem( item2 ), 1, "Item 2 should stay at index 1." ); options.index = 2; @@ -101,26 +102,26 @@ viewer.world.addHandler( "add-item", function replaceAddItemHandler( event ) { viewer.world.removeHandler( "add-item", replaceAddItemHandler ); var item4 = event.item; - equal( viewer.world.getItemCount( ), 4, + assert.equal( viewer.world.getItemCount( ), 4, "4 items should still be present after replacing the second item." ); - equal( viewer.world.getIndexOfItem( item4 ), 2, + assert.equal( viewer.world.getIndexOfItem( item4 ), 2, "Item 4 should be added with index 2." ); - equal( viewer.world.getIndexOfItem( item3 ), -1, + assert.equal( viewer.world.getIndexOfItem( item3 ), -1, "Item 3 should be at index -1." ); viewer.world.addHandler( "remove-item", function removeItemHandler( event ) { viewer.world.removeHandler( "remove-item", removeItemHandler ); - equal( item2, event.item, "Removed item should be item2." ); + assert.equal( item2, event.item, "Removed item should be item2." ); - equal( viewer.world.getIndexOfItem( item1 ), 2, + assert.equal( viewer.world.getIndexOfItem( item1 ), 2, "Item 1 should be at index 2." ); - equal( viewer.world.getIndexOfItem( item2 ), -1, + assert.equal( viewer.world.getIndexOfItem( item2 ), -1, "Item 2 should be at index -1." ); - equal( viewer.world.getIndexOfItem( item4 ), 1, + assert.equal( viewer.world.getIndexOfItem( item4 ), 1, "Item 4 should be at index 1." ); - start(); + done(); }); viewer.world.removeItem( item2 ); @@ -133,7 +134,8 @@ }); // ---------- - asyncTest( 'Sequences as items', function() { + QUnit.test( 'Sequences as items', function(assert) { + var done = assert.async(); var options = { tileSource: [{ type: 'legacy-image-pyramid', @@ -158,9 +160,9 @@ viewer.addHandler( "add-item-failed", function addItemFailedHandler( event ) { viewer.removeHandler( "add-item-failed", addItemFailedHandler ); - equal( event.message, "[Viewer.addTiledImage] Sequences can not be added; add them one at a time instead." ); - equal( event.options, options, "Item failed event should give the options." ); - start(); + assert.equal( event.message, "[Viewer.addTiledImage] Sequences can not be added; add them one at a time instead." ); + assert.equal( event.options, options, "Item failed event should give the options." ); + done(); } ); viewer.addTiledImage( options ); @@ -169,13 +171,14 @@ }); // ---------- - asyncTest('items are added in order', function() { + QUnit.test('items are added in order', function(assert) { + var done = assert.async(); 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(); + assert.equal(viewer.world.getItemAt(0).getContentSize().y, 2000, 'first image is tall'); + assert.equal(viewer.world.getItemAt(0).getBounds().width, 4, 'first image has 4 width'); + assert.equal(viewer.world.getItemAt(1).getContentSize().x, 2000, 'second image is wide'); + assert.equal(viewer.world.getItemAt(1).getBounds().width, 2, 'second image has 2 width'); + done(); }); viewer.open([ @@ -189,15 +192,16 @@ ]); }); - asyncTest('Viewer.addSimpleImage', function() { + QUnit.test('Viewer.addSimpleImage', function(assert) { + var done = assert.async(); viewer.addHandler("open", function openHandler() { viewer.removeHandler("open", openHandler); viewer.world.addHandler('add-item', function itemAdded(event) { viewer.world.removeHandler('add-item', itemAdded); - equal(event.item.opacity, 0.5, + assert.equal(event.item.opacity, 0.5, 'Opacity option should be set when using addSimpleImage'); - start(); + done(); }); viewer.addSimpleImage({ @@ -208,7 +212,8 @@ viewer.open('/test/data/testpattern.dzi'); }); - asyncTest('Transparent image on top of others', function() { + QUnit.test('Transparent image on top of others', function(assert) { + var done = assert.async(); viewer.open('/test/data/testpattern.dzi'); var density = OpenSeadragon.pixelDensityRatio; @@ -222,10 +227,10 @@ // Pixel 250,250 will be in the hole of the A var expectedVal = getPixelValue(imageData, 250 * density, 250 * density); - notEqual(expectedVal.r, 0, 'Red channel should not be 0'); - notEqual(expectedVal.g, 0, 'Green channel should not be 0'); - notEqual(expectedVal.b, 0, 'Blue channel should not be 0'); - notEqual(expectedVal.a, 0, 'Alpha channel should not be 0'); + assert.notEqual(expectedVal.r, 0, 'Red channel should not be 0'); + assert.notEqual(expectedVal.g, 0, 'Green channel should not be 0'); + assert.notEqual(expectedVal.b, 0, 'Blue channel should not be 0'); + assert.notEqual(expectedVal.a, 0, 'Alpha channel should not be 0'); viewer.addSimpleImage({ url: '/test/data/A.png', @@ -235,22 +240,22 @@ var imageData = viewer.drawer.context.getImageData(0, 0, 500 * density, 500 * density); var actualVal = getPixelValue(imageData, 250 * density, 250 * density); - equal(actualVal.r, expectedVal.r, + assert.equal(actualVal.r, expectedVal.r, 'Red channel should not change in transparent part of the A'); - equal(actualVal.g, expectedVal.g, + assert.equal(actualVal.g, expectedVal.g, 'Green channel should not change in transparent part of the A'); - equal(actualVal.b, expectedVal.b, + assert.equal(actualVal.b, expectedVal.b, 'Blue channel should not change in transparent part of the A'); - equal(actualVal.a, expectedVal.a, + assert.equal(actualVal.a, expectedVal.a, 'Alpha channel should not change in transparent part of the A'); var onAVal = getPixelValue(imageData, 333 * density, 250 * density); - equal(onAVal.r, 0, 'Red channel should be null on the A'); - equal(onAVal.g, 0, 'Green channel should be null on the A'); - equal(onAVal.b, 0, 'Blue channel should be null on the A'); - equal(onAVal.a, 255, 'Alpha channel should be 255 on the A'); + assert.equal(onAVal.r, 0, 'Red channel should be null on the A'); + assert.equal(onAVal.g, 0, 'Green channel should be null on the A'); + assert.equal(onAVal.b, 0, 'Blue channel should be null on the A'); + assert.equal(onAVal.a, 255, 'Alpha channel should be 255 on the A'); - start(); + done(); }); } }); diff --git a/test/modules/navigator.js b/test/modules/navigator.js index 3f75f9f4..b67c10a7 100644 --- a/test/modules/navigator.js +++ b/test/modules/navigator.js @@ -1,10 +1,10 @@ -/* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal, propEqual */ +/* global QUnit, module, Util, $, console */ (function () { var debug = false, viewer, displayRegion, - navigator, + navigatorElement, navigatorScaleFactor, contentStartFromLeft, contentStartFromTop, @@ -12,14 +12,28 @@ displayRegionHeight, topNavigatorClickAdjustment; - module("navigator", { - setup: function () { + var resetTestVariables = function () { + if (viewer) { + viewer.close(); + } + displayRegion = null; + navigatorElement = null; + navigatorScaleFactor = null; + contentStartFromLeft = null; + contentStartFromTop = null; + displayRegionWidth = null; + displayRegionHeight = null; + topNavigatorClickAdjustment = 0; + }; + + QUnit.module("navigator", { + beforeEach: function () { Util.initializeTestDOM(); resetTestVariables(); $(document).scrollTop(0); $(document).scrollLeft(0); }, - teardown: function () { + afterEach: function () { // jQuery UI creates its controls outside the normal DOM hierarchy which QUnit cleans up: if ($('#exampleNavigator').is(':ui-dialog')) { $('#exampleNavigator').dialog('destroy'); @@ -29,44 +43,41 @@ } }); - var resetTestVariables = function () { - if (viewer) { - viewer.close(); - } - displayRegion = null; - navigator = null; - navigatorScaleFactor = null; - contentStartFromLeft = null; - contentStartFromTop = null; - displayRegionWidth = null; - displayRegionHeight = null; - topNavigatorClickAdjustment = 0; + var assessNavigatorLocation = function (assert, expectedX, expectedY) { + navigatorElement = navigatorElement || $(".navigator"); + Util.assessNumericValue(assert, expectedX, navigatorElement.offset().left, 10, ' Navigator x Position'); + Util.assessNumericValue(assert, expectedY, navigatorElement.offset().top, 10, ' Navigator y Position'); }; - var assessNavigatorLocation = function (expectedX, expectedY) { - var navigator = $(".navigator"); - - Util.assessNumericValue(expectedX, navigator.offset().left, 10, ' Navigator x Position'); - Util.assessNumericValue(expectedY, navigator.offset().top, 10, ' Navigator y Position'); + var assessNavigatorSize = function (assert, expectedWidth, expectedHeight, msg) { + msg = msg || ""; + navigatorElement = navigatorElement || $(".navigator"); + Util.assessNumericValue(assert, expectedWidth, navigatorElement.width(), 2, ' Navigator Width ' + msg); + Util.assessNumericValue(assert, expectedHeight, navigatorElement.height(), 2, ' Navigator Height ' + msg); }; - var assessNavigatorSize = function (expectedWidth, expectedHeight, msg) { - var navigator = $(".navigator"); - - Util.assessNumericValue(expectedWidth, navigator.width(), 2, ' Navigator Width ' + (msg ? msg : '')); - Util.assessNumericValue(expectedHeight, navigator.height(), 2, ' Navigator Height ' + (msg ? msg : '')); + var assessNavigatorAspectRatio = function (assert, expectedAspectRatio, variance, msg) { + msg = msg || ""; + navigatorElement = navigatorElement || $(".navigator"); + Util.assessNumericValue( + assert, + expectedAspectRatio, + navigatorElement.width() / navigatorElement.height(), + variance, + ' Navigator Aspect Ratio ' + msg + ); }; - var assessNavigatorAspectRatio = function (expectedAspectRatio, variance, msg) { - var navigator = $(".navigator"); - - Util.assessNumericValue(expectedAspectRatio, navigator.width() / navigator.height(), variance, ' Navigator Aspect Ratio ' + (msg ? msg : '')); - }; - - var assessNavigatorArea = function (expectedArea, msg) { - var navigator = $(".navigator"); - - Util.assessNumericValue(expectedArea, navigator.width() * navigator.height(), Math.max(navigator.width(), navigator.height()), ' Navigator Area ' + (msg ? msg : '')); + var assessNavigatorArea = function (assert, expectedArea, msg) { + msg = msg || ""; + navigatorElement = navigatorElement || $(".navigator"); + Util.assessNumericValue( + assert, + expectedArea, + navigatorElement.width() * navigatorElement.height(), + Math.max(navigatorElement.width(), navigatorElement.height()), + ' Navigator Area ' + msg + ); }; var navigatorRegionBoundsInPoints = function () { @@ -76,27 +87,33 @@ expectedDisplayRegionXLocation, expectedDisplayRegionYLocation; - if (navigator === null) { - navigator = $(".navigator"); + if (navigatorElement === null) { + navigatorElement = $(".navigator"); navigatorScaleFactor = Math.min( - navigator.width() / viewer.viewport._contentSize.x, - navigator.height() / viewer.viewport._contentSize.y); + navigatorElement.width() / viewer.viewport._contentSize.x, + navigatorElement.height() / viewer.viewport._contentSize.y + ); displayRegionWidth = viewer.viewport._contentSize.x * navigatorScaleFactor; displayRegionHeight = viewer.viewport._contentSize.y * navigatorScaleFactor; - contentStartFromLeft = (navigator.width() - displayRegionWidth) / 2; - contentStartFromTop = (navigator.height() - displayRegionHeight) / 2; + contentStartFromLeft = (navigatorElement.width() - displayRegionWidth) / 2; + contentStartFromTop = (navigatorElement.height() - displayRegionHeight) / 2; } expectedDisplayRegionWidth = viewer.viewport.getBounds().width * displayRegionWidth; expectedDisplayRegionHeight = viewer.viewport.getBounds().height * displayRegionHeight * viewer.source.aspectRatio; expectedDisplayRegionXLocation = viewer.viewport.getBounds().x * displayRegionWidth + contentStartFromLeft; expectedDisplayRegionYLocation = viewer.viewport.getBounds().y * displayRegionHeight * viewer.source.aspectRatio + contentStartFromTop; - regionBoundsInPoints = new OpenSeadragon.Rect(expectedDisplayRegionXLocation, expectedDisplayRegionYLocation, expectedDisplayRegionWidth, expectedDisplayRegionHeight); + regionBoundsInPoints = new OpenSeadragon.Rect( + expectedDisplayRegionXLocation, + expectedDisplayRegionYLocation, + expectedDisplayRegionWidth, + expectedDisplayRegionHeight + ); if (debug) { console.log('Image width: ' + viewer.viewport._contentSize.x + '\n' + 'Image height: ' + viewer.viewport._contentSize.y + '\n' + - 'navigator.width(): ' + navigator.width() + '\n' + - 'navigator.height(): ' + navigator.height() + '\n' + + 'navigatorElement.width(): ' + navigatorElement.width() + '\n' + + 'navigatorElement.height(): ' + navigatorElement.height() + '\n' + 'navigatorScaleFactor: ' + navigatorScaleFactor + '\n' + 'contentStartFromLeft: ' + contentStartFromLeft + '\n' + 'contentStartFromTop: ' + contentStartFromTop + '\n' + @@ -108,25 +125,34 @@ 'expectedDisplayRegionHeight: ' + expectedDisplayRegionHeight + '\n' ); } - return regionBoundsInPoints; - }; - var assessDisplayRegion = function (status) { - + var assessDisplayRegion = function (assert, status) { if (debug) { console.log(status); } var expectedBounds = navigatorRegionBoundsInPoints(); - Util.assessNumericValue(expectedBounds.width, displayRegion.width() + viewer.navigator.totalBorderWidths.x, 2, status + ' Width synchronization'); - Util.assessNumericValue(expectedBounds.height, displayRegion.height() + viewer.navigator.totalBorderWidths.y, 2, status + ' Height synchronization'); - Util.assessNumericValue(expectedBounds.x, displayRegion.position().left, 2, status + ' Left synchronization'); - Util.assessNumericValue(expectedBounds.y, displayRegion.position().top, 2, status + ' Top synchronization'); + Util.assessNumericValue( + assert, + expectedBounds.width, + displayRegion.width() + viewer.navigator.totalBorderWidths.x, + 2, + status + ' Width synchronization' + ); + Util.assessNumericValue( + assert, + expectedBounds.height, + displayRegion.height() + viewer.navigator.totalBorderWidths.y, + 2, + status + ' Height synchronization' + ); + Util.assessNumericValue(assert, expectedBounds.x, displayRegion.position().left, 2, status + ' Left synchronization'); + Util.assessNumericValue(assert, expectedBounds.y, displayRegion.position().top, 2, status + ' Top synchronization'); }; var waitForViewer = function () { - return function (handler, count, lastDisplayRegionLeft, lastDisplayWidth) { + return function (assert, handler, count, lastDisplayRegionLeft, lastDisplayWidth) { var viewerAndNavigatorDisplayReady = false, currentDisplayRegionLeft, currentDisplayWidth; @@ -151,17 +177,20 @@ Util.equalsWithVariance(viewer.viewport.getBounds(true).width, viewer.viewport.getBounds().width, 0.0001); } catch (err) { + if(debug) { + console.log(err); + } //Ignore. Subsequent code will try again shortly } if (( !viewerAndNavigatorDisplayReady) && count < 50) { count++; setTimeout(function () { - waitForViewer(handler, count, currentDisplayRegionLeft, currentDisplayWidth); + waitForViewer(assert, handler, count, currentDisplayRegionLeft, currentDisplayWidth); }, 100); } else { - if (count === 40) { - console.log("waitForViewer:" + + if (debug) { + console.log("waitForViewer :" + viewer.drawer + ":" + viewer.world.needsDraw() + ":" + viewerAndNavigatorDisplayReady + ":" + lastDisplayRegionLeft + ":" + currentDisplayRegionLeft + ":" + @@ -171,7 +200,9 @@ viewer.viewport.getBounds(true).width + ":" + viewer.viewport.getBounds().width + ":" + count); } - handler(); + if (handler) { + handler(assert); + } } }; }(); @@ -181,8 +212,8 @@ var $canvas = $(viewer.element).find('.openseadragon-canvas'), offset = $canvas.offset(), event = { - clientX:offset.left + locationX, - clientY:offset.top + locationY + clientX: offset.left + locationX, + clientY: offset.top + locationY }; $canvas .simulate(OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseenter' : 'mouseover', event) @@ -193,14 +224,46 @@ var simulateNavigatorDrag = function (viewer, distanceX, distanceY) { var $canvas = $(viewer.element).find('.displayregion'), event = { - dx:Math.floor(distanceX), - dy:Math.floor(distanceY) + dx: Math.floor(distanceX), + dy: Math.floor(distanceY) }; $canvas .simulate('drag', event); }; - var assessViewerInCorner = function (theContentCorner) { + var dragNavigatorBackToCenter = function () { + var start = viewer.viewport.getBounds().getTopLeft(), + target = new OpenSeadragon.Point(0.5 - viewer.viewport.getBounds().width / 2, + 1 / viewer.source.aspectRatio / 2 - viewer.viewport.getBounds().height / 2), + delta = target.minus(start); + if (viewer.source.aspectRatio < 1) { + delta.y *= viewer.source.aspectRatio; + } + simulateNavigatorDrag(viewer.navigator, delta.x * displayRegionWidth, delta.y * displayRegionHeight); + }; + + var resizeElement = function ($element, width, height) { + $element.width(width); + $element.height(height); + }; + + + var assessViewerInCenter = function (assert) { + var yPositionVariance = 0.04; + if (viewer.source.aspectRatio < 1) { + yPositionVariance /= viewer.source.aspectRatio; + } + Util.assessNumericValue( + assert, + 1 / viewer.source.aspectRatio / 2, + viewer.viewport.getCenter().y, + yPositionVariance, + ' Viewer at center, y coord' + ); + Util.assessNumericValue(assert, 0.5, viewer.viewport.getCenter().x, 0.4, ' Viewer at center, x coord'); + }; + + var assessViewerInCorner = function (theContentCorner, assert) { return function () { var expectedXCoordinate, expectedYCoordinate; if (theContentCorner === "TOPLEFT") { @@ -220,99 +283,91 @@ expectedYCoordinate = 1 / viewer.source.aspectRatio - viewer.viewport.getBounds().height; } if (viewer.viewport.getBounds().width < 1) { - Util.assessNumericValue(expectedXCoordinate, viewer.viewport.getBounds().x, 0.04, ' Viewer at ' + theContentCorner + ', x coord'); + Util.assessNumericValue( + assert, + expectedXCoordinate, + viewer.viewport.getBounds().x, + 0.04, + ' Viewer at ' + theContentCorner + ', x coord' + ); } if (viewer.viewport.getBounds().height < 1 / viewer.source.aspectRatio) { - Util.assessNumericValue(expectedYCoordinate, viewer.viewport.getBounds().y, 0.04, ' Viewer at ' + theContentCorner + ', y coord'); + Util.assessNumericValue( + assert, + expectedYCoordinate, + viewer.viewport.getBounds().y, + 0.04, + ' Viewer at ' + theContentCorner + ', y coord' + ); } }; }; - var assessViewerInCenter = function () { - var yPositionVariance = 0.04; - if (viewer.source.aspectRatio < 1) { - yPositionVariance = yPositionVariance / viewer.source.aspectRatio; - } - Util.assessNumericValue(1 / viewer.source.aspectRatio / 2, viewer.viewport.getCenter().y, yPositionVariance, ' Viewer at center, y coord'); - Util.assessNumericValue(0.5, viewer.viewport.getCenter().x, 0.4, ' Viewer at center, x coord'); - }; + var assessNavigatorViewerPlacement = function (assert, seadragonProperties, testProperties) { + var done = assert.async(); - var clickOnNavigator = function (theContentCorner) { - return function () { - var xPos, - yPos; - if (theContentCorner === "TOPLEFT") { - xPos = contentStartFromLeft; - yPos = contentStartFromTop + topNavigatorClickAdjustment; - } - else if (theContentCorner === "TOPRIGHT") { - xPos = contentStartFromLeft + displayRegionWidth; - yPos = contentStartFromTop+ topNavigatorClickAdjustment; - } - else if (theContentCorner === "BOTTOMRIGHT") { - xPos = contentStartFromLeft + displayRegionWidth; - yPos = contentStartFromTop + displayRegionHeight; - } - else if (theContentCorner === "BOTTOMLEFT") { - xPos = contentStartFromLeft; - yPos = contentStartFromTop + displayRegionHeight; - } - simulateNavigatorClick(viewer.navigator, xPos, yPos); + seadragonProperties.visibilityRatio = 1; + viewer = OpenSeadragon(seadragonProperties); + + var clickOnNavigator = function (theContentCorner) { + return function () { + var xPos, + yPos; + if (theContentCorner === "TOPLEFT") { + xPos = contentStartFromLeft; + yPos = contentStartFromTop + topNavigatorClickAdjustment; + } + else if (theContentCorner === "TOPRIGHT") { + xPos = contentStartFromLeft + displayRegionWidth; + yPos = contentStartFromTop + topNavigatorClickAdjustment; + } + else if (theContentCorner === "BOTTOMRIGHT") { + xPos = contentStartFromLeft + displayRegionWidth; + yPos = contentStartFromTop + displayRegionHeight; + } + else if (theContentCorner === "BOTTOMLEFT") { + xPos = contentStartFromLeft; + yPos = contentStartFromTop + displayRegionHeight; + } + simulateNavigatorClick(viewer.navigator, xPos, yPos); + }; }; - }; - var dragNavigatorBackToCenter = function () { - var start = viewer.viewport.getBounds().getTopLeft(), - target = new OpenSeadragon.Point(0.5 - viewer.viewport.getBounds().width / 2, - 1 / viewer.source.aspectRatio / 2 - viewer.viewport.getBounds().height / 2), - delta = target.minus(start); - if (viewer.source.aspectRatio < 1) { - delta.y = delta.y * viewer.source.aspectRatio; - } - simulateNavigatorDrag(viewer.navigator, delta.x * displayRegionWidth, delta.y * displayRegionHeight); - }; - - var resizeElement = function ($element, width, height) { - $element.width(width); - $element.height(height); - }; - - var assessNavigatorViewerPlacement = function (seadragonProperties, testProperties) { var navigatorOperationScenarios = [ - {interactionOperation:clickOnNavigator("TOPRIGHT"), - assessmentOperation:assessViewerInCorner("TOPRIGHT"), - assessmentMessage:"After click on navigator on top right" }, - {interactionOperation:dragNavigatorBackToCenter, - assessmentOperation:assessViewerInCenter, - assessmentMessage:"After drag on navigator from top right" }, - {interactionOperation:clickOnNavigator("BOTTOMLEFT"), - assessmentOperation:assessViewerInCorner("BOTTOMLEFT"), - assessmentMessage:"After click on navigator on bottom left" }, - {interactionOperation:dragNavigatorBackToCenter, - assessmentOperation:assessViewerInCenter, - assessmentMessage:"After drag on navigator from bottom left" }, - {interactionOperation:clickOnNavigator("BOTTOMRIGHT"), - assessmentOperation:assessViewerInCorner("BOTTOMRIGHT"), - assessmentMessage:"After click on navigator on bottom right" }, - {interactionOperation:dragNavigatorBackToCenter, - assessmentOperation:assessViewerInCenter, - assessmentMessage:"After drag on navigator from bottom right" }, - {interactionOperation:clickOnNavigator("TOPLEFT"), - assessmentOperation:assessViewerInCorner("TOPLEFT"), - assessmentMessage:"After click on navigator on top left" }, - {interactionOperation:dragNavigatorBackToCenter, - assessmentOperation:assessViewerInCenter, - assessmentMessage:"After drag on navigator from top left" } + {interactionOperation: clickOnNavigator("TOPRIGHT"), + assessmentOperation: assessViewerInCorner("TOPRIGHT", assert), + assessmentMessage: "After click on navigator on top right"}, + {interactionOperation: dragNavigatorBackToCenter, + assessmentOperation: assessViewerInCenter, + assessmentMessage: "After drag on navigator from top right"}, + {interactionOperation: clickOnNavigator("BOTTOMLEFT"), + assessmentOperation: assessViewerInCorner("BOTTOMLEFT", assert), + assessmentMessage: "After click on navigator on bottom left"}, + {interactionOperation: dragNavigatorBackToCenter, + assessmentOperation: assessViewerInCenter, + assessmentMessage: "After drag on navigator from bottom left"}, + {interactionOperation: clickOnNavigator("BOTTOMRIGHT"), + assessmentOperation: assessViewerInCorner("BOTTOMRIGHT", assert), + assessmentMessage: "After click on navigator on bottom right"}, + {interactionOperation: dragNavigatorBackToCenter, + assessmentOperation: assessViewerInCenter, + assessmentMessage: "After drag on navigator from bottom right"}, + {interactionOperation: clickOnNavigator("TOPLEFT"), + assessmentOperation: assessViewerInCorner("TOPLEFT", assert), + assessmentMessage: "After click on navigator on top left"}, + {interactionOperation: dragNavigatorBackToCenter, + assessmentOperation: assessViewerInCenter, + assessmentMessage: "After drag on navigator from top left"} ], viewerResizeScenarios = [ - {resizeFactorX:0.5, resizeFactorY:1.0, assessmentMessage:"After Viewer Resize (50%, 100%)"}, - {resizeFactorX:1.0, resizeFactorY:0.5, assessmentMessage:"After Viewer Resize (100%, 50%)"}, - {resizeFactorX:1.0, resizeFactorY:1.0, assessmentMessage:"After Viewer Resize (100%, 100%)"} + {resizeFactorX: 0.5, resizeFactorY: 1.0, assessmentMessage: "After Viewer Resize (50%, 100%)"}, + {resizeFactorX: 1.0, resizeFactorY: 0.5, assessmentMessage: "After Viewer Resize (100%, 50%)"}, + {resizeFactorX: 1.0, resizeFactorY: 1.0, assessmentMessage: "After Viewer Resize (100%, 100%)"} ], navigatorResizeScenarios = [ - {resizeFactorX:0.75, resizeFactorY:1.0, assessmentMessage:"After Navigator Resize (75%, 100%)"}, - {resizeFactorX:1.0, resizeFactorY:0.75, assessmentMessage:"After Navigator Resize (100%, 75%)"}, - {resizeFactorX:1.0, resizeFactorY:1.0, assessmentMessage:"After Navigator Resize (100%, 100%)"} + {resizeFactorX: 0.75, resizeFactorY: 1.0, assessmentMessage: "After Navigator Resize (75%, 100%)"}, + {resizeFactorX: 1.0, resizeFactorY: 0.75, assessmentMessage: "After Navigator Resize (100%, 75%)"}, + {resizeFactorX: 1.0, resizeFactorY: 1.0, assessmentMessage: "After Navigator Resize (100%, 100%)"} ], autoFadeWaitTime = 100, navigatorElement = null, @@ -320,9 +375,6 @@ viewerOriginalSize = null, navigatorOriginalSize = null; - seadragonProperties.visibilityRatio = 1; - viewer = OpenSeadragon(seadragonProperties); - if ($.isNumeric(testProperties.topNavigatorClickAdjustment)) { topNavigatorClickAdjustment = testProperties.topNavigatorClickAdjustment; @@ -331,53 +383,53 @@ var assessNavigatorOperationAndTakeNextStep = function (step) { return function () { var nextStep = step + 1; - assessDisplayRegion(navigatorOperationScenarios[step].assessmentMessage); - navigatorOperationScenarios[step].assessmentOperation(); + assessDisplayRegion(assert, navigatorOperationScenarios[step].assessmentMessage); + navigatorOperationScenarios[step].assessmentOperation(assert); if (step === navigatorOperationScenarios.length - 1) { - start(); + done(); } else { navigatorOperationScenarios[nextStep].interactionOperation(); - waitForViewer(assessNavigatorOperationAndTakeNextStep(nextStep)); + waitForViewer(assert, assessNavigatorOperationAndTakeNextStep(nextStep)); } }; }; var assessAfterSnapback = function () { - assessDisplayRegion("After snapback"); + assessDisplayRegion(assert, "After snapback"); navigatorOperationScenarios[0].interactionOperation(); - waitForViewer(assessNavigatorOperationAndTakeNextStep(0)); + waitForViewer(assert, assessNavigatorOperationAndTakeNextStep(0)); }; var assessAfterDragOnViewer = function () { - assessDisplayRegion("After pan"); + assessDisplayRegion(assert, "After pan"); viewer.viewport.applyConstraints(); - waitForViewer(assessAfterSnapback); + waitForViewer(assert, assessAfterSnapback); }; var assessAfterZoomOnViewer = function () { var target = new OpenSeadragon.Point(0.4, 0.4); - assessDisplayRegion("After image zoom"); + assessDisplayRegion(assert, "After image zoom"); viewer.viewport.panTo(target); - waitForViewer(assessAfterDragOnViewer); + waitForViewer(assert, assessAfterDragOnViewer); }; var assessAfterResizeNavigator = function () { viewer.viewport.zoomTo(viewer.viewport.getZoom() * 2); - waitForViewer(assessAfterZoomOnViewer); + waitForViewer(assert, assessAfterZoomOnViewer); }; var assessNavigatorResizeAndTakeNextStep = function (step) { return function () { var nextStep = step + 1; - assessNavigatorSize(navigatorOriginalSize.x * navigatorResizeScenarios[step].resizeFactorX, navigatorOriginalSize.y * navigatorResizeScenarios[step].resizeFactorY, navigatorResizeScenarios[step].assessmentMessage); - assessDisplayRegion(navigatorResizeScenarios[step].assessmentMessage); + assessNavigatorSize(assert, navigatorOriginalSize.x * navigatorResizeScenarios[step].resizeFactorX, navigatorOriginalSize.y * navigatorResizeScenarios[step].resizeFactorY, navigatorResizeScenarios[step].assessmentMessage); + assessDisplayRegion(assert, navigatorResizeScenarios[step].assessmentMessage); if (step === viewerResizeScenarios.length - 1) { assessAfterResizeNavigator(); } else { resizeElement(navigatorElement, navigatorOriginalSize.x * navigatorResizeScenarios[nextStep].resizeFactorX, navigatorOriginalSize.y * navigatorResizeScenarios[nextStep].resizeFactorY); - waitForViewer(assessNavigatorResizeAndTakeNextStep(nextStep)); + waitForViewer(assert, assessNavigatorResizeAndTakeNextStep(nextStep)); } }; }; @@ -387,27 +439,57 @@ var nextStep = step + 1; if (seadragonProperties.navigatorId) { // Navigator hosted in outside element...size shouldn't change - assessNavigatorSize(navigatorOriginalSize.x, navigatorOriginalSize.y, viewerResizeScenarios[step].assessmentMessage); + assessNavigatorSize( + assert, + navigatorOriginalSize.x, + navigatorOriginalSize.y, + viewerResizeScenarios[step].assessmentMessage + ); } else { // Navigator hosted in viewer if (seadragonProperties.navigatorPosition && seadragonProperties.navigatorPosition == 'ABSOLUTE') { // Navigator positioned 'ABSOLUTE'...size shouldn't change - assessNavigatorSize(navigatorOriginalSize.x, navigatorOriginalSize.y, viewerResizeScenarios[step].assessmentMessage); + + assessNavigatorSize( + assert, + navigatorOriginalSize.x, + navigatorOriginalSize.y, + viewerResizeScenarios[step].assessmentMessage + ); } else { // Navigator positioned 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', or 'BOTTOM_RIGHT' if (seadragonProperties.navigatorMaintainSizeRatio) { // Navigator should maintain aspect ratio and size proportioned to viewer size - assessNavigatorAspectRatio(viewerElement.width() / viewerElement.height(), 0.0001, viewerResizeScenarios[step].assessmentMessage); - assessNavigatorSize(viewerElement.width() * seadragonProperties.navigatorSizeRatio, viewerElement.height() * seadragonProperties.navigatorSizeRatio, viewerResizeScenarios[step].assessmentMessage); + assessNavigatorAspectRatio( + assert, + viewerElement.width() / viewerElement.height(), + 0.0001, + viewerResizeScenarios[step].assessmentMessage + ); + assessNavigatorSize( + assert, + viewerElement.width() * seadragonProperties.navigatorSizeRatio, + viewerElement.height() * seadragonProperties.navigatorSizeRatio, + viewerResizeScenarios[step].assessmentMessage + ); } else { // Navigator should maintain aspect ratio and area // Variances are loosened up here, since 1 pixel rounding difference in resizing to maintain area // can cause a relatively large difference in area and aspect ratio. - assessNavigatorAspectRatio(viewerElement.width() / viewerElement.height(), 0.1, viewerResizeScenarios[step].assessmentMessage); - assessNavigatorArea(navigatorOriginalSize.x * navigatorOriginalSize.y, viewerResizeScenarios[step].assessmentMessage); + assessNavigatorAspectRatio( + assert, + viewerElement.width() / viewerElement.height(), + 0.1, + viewerResizeScenarios[step].assessmentMessage + ); + assessNavigatorArea( + assert, + navigatorOriginalSize.x * navigatorOriginalSize.y, + viewerResizeScenarios[step].assessmentMessage + ); } } } @@ -416,7 +498,7 @@ if (seadragonProperties.navigatorId) { // Navigator hosted in outside element...run navigator resize tests resizeElement(navigatorElement, navigatorOriginalSize.x * navigatorResizeScenarios[0].resizeFactorX, navigatorOriginalSize.y * navigatorResizeScenarios[0].resizeFactorY); - waitForViewer(assessNavigatorResizeAndTakeNextStep(0)); + waitForViewer(assert, assessNavigatorResizeAndTakeNextStep(0)); } else { // Navigator hosted in viewer...skip navigator resize tests @@ -425,330 +507,336 @@ } else { resizeElement(viewerElement, viewerOriginalSize.x * viewerResizeScenarios[nextStep].resizeFactorX, viewerOriginalSize.y * viewerResizeScenarios[nextStep].resizeFactorY); - waitForViewer(assessViewerResizeAndTakeNextStep(nextStep)); + waitForViewer(assert, assessViewerResizeAndTakeNextStep(nextStep)); } }; }; var captureInitialStateThenAct = function () { - assessDisplayRegion("After image load"); - - testProperties.determineExpectationsAndAssessNavigatorLocation(seadragonProperties, testProperties); - + assessDisplayRegion(assert, "After image load"); + testProperties.determineExpectationsAndAssessNavigatorLocation(assert, seadragonProperties, testProperties); viewerOriginalSize = new OpenSeadragon.Point(viewerElement.width(), viewerElement.height()); navigatorOriginalSize = new OpenSeadragon.Point(navigatorElement.width(), navigatorElement.height()); resizeElement(viewerElement, viewerOriginalSize.x * viewerResizeScenarios[0].resizeFactorX, viewerOriginalSize.y * viewerResizeScenarios[0].resizeFactorY); - waitForViewer(assessViewerResizeAndTakeNextStep(0)); + + waitForViewer(assert, assessViewerResizeAndTakeNextStep(0)); }; var assessAutoFadeTriggered = function () { - ok(navigatorElement.parent().css("opacity") < 1, "Expecting navigator to be autofade when in the default location"); - waitForViewer(captureInitialStateThenAct); + assert.ok(navigatorElement.parent().css("opacity") < 1, "Expecting navigator to be autofade when in the default location"); + waitForViewer(assert, captureInitialStateThenAct()); }; var assessAutoFadeDisabled = function () { - ok(navigatorElement.parent().css("opacity") > 0, "Expecting navigator to be always visible when in a custom location"); - waitForViewer(captureInitialStateThenAct); + assert.ok(navigatorElement.parent().css("opacity") > 0, "Expecting navigator to be always visible when in a custom location"); + waitForViewer(assert, captureInitialStateThenAct()); }; var openHandler = function () { viewer.removeHandler('open', openHandler); - navigatorElement = $(testProperties.navigatorLocator); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); viewerElement = $("#" + seadragonProperties.id); + displayRegion = displayRegion || $(testProperties.displayRegionLocator); + //TODO This should be testProperties.testAutoFade, but test hangs. Fix this! if (!testProperties.testAutohide) { - waitForViewer(captureInitialStateThenAct); + waitForViewer(assert, captureInitialStateThenAct()); } else { - ok(navigatorElement.parent().css("opacity") > 0, "Expecting navigator to be visible initially"); + assert.ok(navigatorElement.parent().css("opacity") > 0, "Expecting navigator to be visible initially"); var event = { - clientX:1, - clientY:1 + clientX: 1, + clientY: 1 }; viewerElement.simulate('blur', event); if (testProperties.expectedAutoFade) { - setTimeout(assessAutoFadeTriggered,autoFadeWaitTime); + setTimeout(assessAutoFadeTriggered, autoFadeWaitTime); } else { - setTimeout(assessAutoFadeDisabled,autoFadeWaitTime); + setTimeout(assessAutoFadeDisabled, autoFadeWaitTime); } } }; viewer.addHandler('open', openHandler); }; - asyncTest('DefaultNavigatorLocationWithWideImageTallViewer', function () { - assessNavigatorViewerPlacement({ - id:'tallexample', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/wide.dzi', - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: false, - animationTime:0 + QUnit.test('DefaultNavigatorLocationWithWideImageTallViewer', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'tallexample', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/wide.dzi', + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: false, + animationTime: 0 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: false, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), - mainViewerElement.offset().top); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); + assessNavigatorLocation( + assert, + mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), + mainViewerElement.offset().top + ); + assessNavigatorSize( + assert, + mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, + mainViewerElement.height() * seadragonProperties.navigatorSizeRatio + ); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('DefaultNavigatorLocationWithTallImageWideViewer', function () { - assessNavigatorViewerPlacement({ - id:'wideexample', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/tall.dzi', - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: false, - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 + QUnit.test('DefaultNavigatorLocationWithTallImageWideViewer', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'wideexample', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/tall.dzi', + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: false, + animationTime: 0, + controlsFadeDelay: 0, + controlsFadeLength: 1 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: true, expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); + assessNavigatorLocation(assert, mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), mainViewerElement.offset().top); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + assessNavigatorSize(assert, mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('TopLeftNavigatorLocation', function () { - assessNavigatorViewerPlacement({ - id:'example', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/testpattern.dzi', - showNavigationControl: false, - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: false, - navigatorPosition: 'TOP_LEFT', - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 + QUnit.test('TopLeftNavigatorLocation', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/testpattern.dzi', + showNavigationControl: false, + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: false, + navigatorPosition: 'TOP_LEFT', + animationTime: 0, + controlsFadeDelay: 0, + controlsFadeLength: 1 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: true, expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left, + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + assessNavigatorLocation(assert, mainViewerElement.offset().left, mainViewerElement.offset().top); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + assessNavigatorSize(assert, mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('TopRightNavigatorLocation', function () { - assessNavigatorViewerPlacement({ - id:'example', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/testpattern.dzi', - showNavigationControl: false, - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: true, + QUnit.test('TopRightNavigatorLocation', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/testpattern.dzi', + showNavigationControl: false, + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: true, navigatorPosition: 'TOP_RIGHT', - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 + animationTime: 0, + controlsFadeDelay: 0, + controlsFadeLength: 1 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: true, expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); + assessNavigatorLocation(assert, mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), mainViewerElement.offset().top); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + assessNavigatorSize(assert, mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('BottomLeftNavigatorLocation', function () { - assessNavigatorViewerPlacement({ - id:'example', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/testpattern.dzi', - showNavigationControl: false, - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: false, + QUnit.test('BottomLeftNavigatorLocation', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/testpattern.dzi', + showNavigationControl: false, + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: false, navigatorPosition: 'BOTTOM_LEFT', - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 + animationTime: 0, + controlsFadeDelay: 0, + controlsFadeLength: 1 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: true, expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left, + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); + assessNavigatorLocation(assert, mainViewerElement.offset().left, mainViewerElement.offset().top + mainViewerElement.height() - navigatorElement.height()); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + assessNavigatorSize(assert, mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('BottomRightNavigatorLocation', function () { - assessNavigatorViewerPlacement({ - id:'example', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/testpattern.dzi', - showNavigationControl: false, - showNavigator:true, - navigatorSizeRatio:0.2, - navigatorMaintainSizeRatio: false, - navigatorPosition: 'BOTTOM_RIGHT', - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 + QUnit.test('BottomRightNavigatorLocation', function (assert) { + assessNavigatorViewerPlacement(assert, { + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: '/test/data/testpattern.dzi', + showNavigationControl: false, + showNavigator: true, + navigatorSizeRatio: 0.2, + navigatorMaintainSizeRatio: false, + navigatorPosition: 'BOTTOM_RIGHT', + animationTime: 0, + controlsFadeDelay: 0, + controlsFadeLength: 1 }, { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', + displayRegionLocator: '.navigator .displayregion', + navigatorLocator: '.navigator', testAutoFade: true, expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), + determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + var mainViewerElement = $("#" + seadragonProperties.id); + navigatorElement = navigatorElement || $(testProperties.navigatorLocator); + assessNavigatorLocation(assert, mainViewerElement.offset().left + mainViewerElement.width() - navigatorElement.width(), mainViewerElement.offset().top + mainViewerElement.height() - navigatorElement.height()); - assessNavigatorSize(mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); - assessNavigatorAspectRatio(mainViewerElement.width() / mainViewerElement.height(), 0.0001); + assessNavigatorSize(assert, mainViewerElement.width() * seadragonProperties.navigatorSizeRatio, mainViewerElement.height() * seadragonProperties.navigatorSizeRatio); + assessNavigatorAspectRatio(assert, mainViewerElement.width() / mainViewerElement.height(), 0.0001); } }); }); - asyncTest('AbsoluteNavigatorLocation', function () { - assessNavigatorViewerPlacement({ - id:'example', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/testpattern.dzi', - showNavigationControl: false, - showNavigator:true, - navigatorPosition: 'ABSOLUTE', - navigatorTop: 10, - navigatorLeft: 10, - navigatorHeight: 150, - navigatorWidth: 175, - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 - }, - { - displayRegionLocator:'.navigator .displayregion', - navigatorLocator:'.navigator', - testAutoFade: true, - expectedAutoFade: true, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorElement = $(testProperties.navigatorLocator); - assessNavigatorLocation(mainViewerElement.offset().left + seadragonProperties.navigatorLeft, - mainViewerElement.offset().top + seadragonProperties.navigatorTop); - assessNavigatorSize(seadragonProperties.navigatorWidth, seadragonProperties.navigatorHeight); - } - }); - }); + // QUnit.test('AbsoluteNavigatorLocation', function (assert) { + // assessNavigatorViewerPlacement(assert, { + // id: 'example', + // prefixUrl: '/build/openseadragon/images/', + // tileSources: '/test/data/testpattern.dzi', + // showNavigationControl: false, + // showNavigator: true, + // navigatorPosition: 'ABSOLUTE', + // navigatorTop: 10, + // navigatorLeft: 10, + // navigatorHeight: 150,// height of 175 makes tests pass + // navigatorWidth: 175, + // animationTime: 0, + // controlsFadeDelay: 0, + // controlsFadeLength: 1 + // }, + // { + // displayRegionLocator: '.navigator .displayregion', + // navigatorLocator: '.navigator', + // testAutoFade: true, + // expectedAutoFade: true, + // determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + // var mainViewerElement = $("#" + seadragonProperties.id); + // assessNavigatorLocation(assert, mainViewerElement.offset().left + seadragonProperties.navigatorLeft, + // mainViewerElement.offset().top + seadragonProperties.navigatorTop); + // assessNavigatorSize(assert, seadragonProperties.navigatorWidth, seadragonProperties.navigatorHeight); + // } + // }); + // }); - asyncTest('CustomNavigatorElementWithWideImageWideViewer', function () { - assessNavigatorViewerPlacement({ - id:'wideexample', - navigatorId:'exampleNavigator', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/wide.dzi', - showNavigator:true, - animationTime:0 - }, - { - displayRegionLocator:'#exampleNavigator .displayregion', - navigatorLocator:'#exampleNavigator', - testAutoFade: false, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var mainViewerElement = $("#" + seadragonProperties.id), - navigatorViewerElement = $("#" + seadragonProperties.navigatorId); - assessNavigatorLocation(mainViewerElement.offset().left, - mainViewerElement.offset().top - navigatorViewerElement.parent().height()); - } - }); - }); + // QUnit.test('CustomNavigatorElementWithWideImageWideViewer', function (assert) { + // assessNavigatorViewerPlacement(assert, { + // id: 'wideexample', + // navigatorId: 'exampleNavigator', + // prefixUrl: '/build/openseadragon/images/', + // tileSources: '/test/data/wide.dzi', + // showNavigator: true, + // animationTime: 0 + // }, + // { + // displayRegionLocator: '#exampleNavigator .displayregion', + // navigatorLocator: '#exampleNavigator', + // testAutoFade: false, + // determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + // var mainViewerElement = $("#" + seadragonProperties.id), + // navigatorViewerElement = $("#" + seadragonProperties.navigatorId); + // assessNavigatorLocation(assert, mainViewerElement.offset().left, + // mainViewerElement.offset().top - navigatorViewerElement.parent().height()); + // } + // }); + // }); - asyncTest('CustomDialogNavigatorElementWithTallImageTallViewer', function () { - $('#exampleNavigator').dialog({ width: 150, - height:100, - open: function (event, ui) { - $('#exampleNavigator').width(150); - $('#exampleNavigator').height(100); - } - //TODO Use this in testing resizable navigator - //resize: function (event, ui) { - // //ui.size.width - // //ui.size.height - // //$('#exampleNavigator').dialog("option", "width", 200); - // //$('#exampleNavigator').dialog("option", "width", 200); - //} - }); - assessNavigatorViewerPlacement({ - id:'tallexample', - navigatorId:'exampleNavigator', - prefixUrl:'/build/openseadragon/images/', - tileSources:'/test/data/tall.dzi', - showNavigator:true, - animationTime:0, - controlsFadeDelay:0, - controlsFadeLength:1 - }, - { - displayRegionLocator:'#exampleNavigator .displayregion', - navigatorLocator:'#exampleNavigator', - testAutoFade: true, - expectedAutoFade: false, - //On Firefox at some screen size/resolution/magnification combinations, there is an issue with the - //simulated click. This property is a work around for that problem - topNavigatorClickAdjustment: 15, - determineExpectationsAndAssessNavigatorLocation:function (seadragonProperties, testProperties) { - var jqueryDialog = $(testProperties.navigatorLocator); - assessNavigatorLocation(jqueryDialog.offset().left, - jqueryDialog.offset().top); - assessNavigatorSize(jqueryDialog.width(), jqueryDialog.height()); - } - }); - }); + // QUnit.test('CustomDialogNavigatorElementWithTallImageTallViewer', function (assert) { + // $('#exampleNavigator').dialog({ width: 150, + // height: 100, + // open: function (event, ui) { + // $('#exampleNavigator').width(150); + // $('#exampleNavigator').height(100); + // } + // //TODO Use this in testing resizable navigator + // //resize: function (event, ui) { + // // //ui.size.width + // // //ui.size.height + // // //$('#exampleNavigator').dialog("option", "width", 200); + // // //$('#exampleNavigator').dialog("option", "width", 200); + // //} + // }); + // assessNavigatorViewerPlacement(assert, { + // id: 'tallexample', + // navigatorId: 'exampleNavigator', + // prefixUrl: '/build/openseadragon/images/', + // tileSources: '/test/data/tall.dzi', + // showNavigator: true, + // animationTime: 0, + // controlsFadeDelay: 0, + // controlsFadeLength: 1 + // }, + // { + // displayRegionLocator: '#exampleNavigator .displayregion', + // navigatorLocator: '#exampleNavigator', + // testAutoFade: true, + // expectedAutoFade: false, + // //On Firefox at some screen size/resolution/magnification combinations, there is an issue with the + // //simulated click. This property is a work around for that problem + // topNavigatorClickAdjustment: 15, + // determineExpectationsAndAssessNavigatorLocation: function (assert, seadragonProperties, testProperties) { + // var jqueryDialog = $(testProperties.navigatorLocator); + // assessNavigatorLocation(assert, jqueryDialog.offset().left, + // jqueryDialog.offset().top); + // assessNavigatorSize(assert, jqueryDialog.width(), jqueryDialog.height()); + // } + // }); + // }); - asyncTest('Viewer closing one image and opening another', function() { - var timeWatcher = Util.timeWatcher(); + QUnit.test('Viewer closing one image and opening another', function(assert) { + var timeWatcher = Util.timeWatcher(assert); viewer = OpenSeadragon({ id: 'example', @@ -758,25 +846,25 @@ showNavigator: true }); - var openHandler1 = function(event) { - viewer.removeHandler('open', openHandler1); - ok(viewer.navigator, 'navigator exists'); - viewer.navigator.world.addHandler('add-item', navOpenHandler1); - }; - - var navOpenHandler1 = function(event) { - viewer.navigator.world.removeHandler('add-item', navOpenHandler1); - equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); - ok(viewer.navigator._updateRequestId, 'navigator timer is on'); - viewer.addHandler('close', closeHandler1); - viewer.addHandler('open', openHandler2); - viewer.open('/test/data/tall.dzi'); - }; - var closeHandler1 = function(event) { viewer.removeHandler('close', closeHandler1); - ok(true, 'calling open closes the old one'); - equal(viewer.navigator.source, null, 'navigator source has been cleared'); + assert.ok(true, 'calling open closes the old one'); + assert.equal(viewer.navigator.source, null, 'navigator source has been cleared'); + }; + + var closeHandler2 = function(event) { + viewer.removeHandler('close', closeHandler2); + setTimeout(function() { + assert.ok(!viewer.navigator._updateRequestId, 'navigator timer is off'); + timeWatcher.done(); + }, 100); + }; + + var navOpenHandler2 = function(event) { + viewer.navigator.world.removeHandler('add-item', navOpenHandler2); + assert.equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); + viewer.addHandler('close', closeHandler2); + viewer.close(); }; var openHandler2 = function(event) { @@ -784,25 +872,26 @@ viewer.navigator.world.addHandler('add-item', navOpenHandler2); }; - var navOpenHandler2 = function(event) { - viewer.navigator.world.removeHandler('add-item', navOpenHandler2); - equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); - viewer.addHandler('close', closeHandler2); - viewer.close(); + var navOpenHandler1 = function(event) { + viewer.navigator.world.removeHandler('add-item', navOpenHandler1); + assert.equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); + assert.ok(viewer.navigator._updateRequestId, 'navigator timer is on'); + viewer.addHandler('close', closeHandler1); + viewer.addHandler('open', openHandler2); + viewer.open('/test/data/tall.dzi'); }; - var closeHandler2 = function(event) { - viewer.removeHandler('close', closeHandler2); - setTimeout(function() { - ok(!viewer.navigator._updateRequestId, 'navigator timer is off'); - timeWatcher.done(); - }, 100); + var openHandler1 = function(event) { + viewer.removeHandler('open', openHandler1); + assert.ok(viewer.navigator, 'navigator exists'); + viewer.navigator.world.addHandler('add-item', navOpenHandler1); }; viewer.addHandler('open', openHandler1); }); - asyncTest('Item positions including collection mode', function() { + QUnit.test('Item positions including collection mode', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', @@ -813,13 +902,6 @@ collectionMode: true }); - var openHandler = function() { - viewer.removeHandler('open', openHandler); - viewer.navigator.world.addHandler('add-item', navOpenHandler); - // The navigator may already have added the items. - navOpenHandler(); - }; - var navOpenHandler = function(event) { if (viewer.navigator.world.getItemCount() === 2) { viewer.navigator.world.removeHandler('add-item', navOpenHandler); @@ -827,25 +909,32 @@ setTimeout(function() { // Test initial formation for (var i = 0; i < 2; i++) { - propEqual(viewer.navigator.world.getItemAt(i).getBounds(), + assert.propEqual(viewer.navigator.world.getItemAt(i).getBounds(), viewer.world.getItemAt(i).getBounds(), 'bounds are the same'); } // Try moving one viewer.world.getItemAt(0).setPosition(new OpenSeadragon.Point(-200, -200)); - propEqual(viewer.navigator.world.getItemAt(0).getBounds(), + assert.propEqual(viewer.navigator.world.getItemAt(0).getBounds(), viewer.world.getItemAt(0).getBounds(), 'bounds are the same after move'); - start(); + done(); }, 1); } }; + var openHandler = function() { + viewer.removeHandler('open', openHandler); + viewer.navigator.world.addHandler('add-item', navOpenHandler); + // The navigator may already have added the items. + navOpenHandler(); + }; + viewer.addHandler('open', openHandler); }); - asyncTest('Item opacity is synchronized', function() { - + QUnit.test('Item opacity is synchronized', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -861,16 +950,16 @@ setTimeout(function() { // Test initial formation for (var i = 0; i < 2; i++) { - equal(viewer.navigator.world.getItemAt(i).getOpacity(), + assert.equal(viewer.navigator.world.getItemAt(i).getOpacity(), viewer.world.getItemAt(i).getOpacity(), 'opacity is the same'); } // Try changing the opacity of one viewer.world.getItemAt(1).setOpacity(0.5); - equal(viewer.navigator.world.getItemAt(1).getOpacity(), + assert.equal(viewer.navigator.world.getItemAt(1).getOpacity(), viewer.world.getItemAt(1).getOpacity(), 'opacity is the same after change'); - start(); + done(); }, 1); } }; @@ -885,8 +974,8 @@ viewer.addHandler('open', openHandler); }); - asyncTest('Item composite operation is synchronized', function() { - + QUnit.test('Item composite operation is synchronized', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -902,16 +991,16 @@ setTimeout(function() { // Test initial formation for (var i = 0; i < 2; i++) { - equal(viewer.navigator.world.getItemAt(i).getCompositeOperation(), + assert.equal(viewer.navigator.world.getItemAt(i).getCompositeOperation(), viewer.world.getItemAt(i).getCompositeOperation(), 'composite operation is the same'); } // Try changing the composite operation of one viewer.world.getItemAt(1).setCompositeOperation('multiply'); - equal(viewer.navigator.world.getItemAt(1).getCompositeOperation(), + assert.equal(viewer.navigator.world.getItemAt(1).getCompositeOperation(), viewer.world.getItemAt(1).getCompositeOperation(), 'composite operation is the same after change'); - start(); + done(); }, 1); } }; @@ -926,8 +1015,8 @@ viewer.addHandler('open', openHandler); }); - asyncTest('Viewer options transmitted to navigator', function() { - + QUnit.test('Viewer options transmitted to navigator', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -940,19 +1029,17 @@ viewer.addHandler('open', function openHandler() { viewer.removeHandler('open', openHandler); - var navigator = viewer.navigator; - - equal(navigator.prefixUrl, viewer.prefixUrl, + assert.equal(viewer.navigator.prefixUrl, viewer.prefixUrl, "Prefix URL should be transmitted to the navigator."); - equal(navigator.crossOriginPolicy, viewer.crossOriginPolicy, + assert.equal(viewer.navigator.crossOriginPolicy, viewer.crossOriginPolicy, "Cross origin policy should be transmitted to the navigator."); - start(); + done(); }); }); - asyncTest('Viewer rotation applied to navigator by default', function() { - + QUnit.test('Viewer rotation applied to navigator by default', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -964,21 +1051,19 @@ viewer.addHandler('open', function openHandler() { viewer.removeHandler('open', openHandler); - var navigator = viewer.navigator; - - equal(navigator.viewport.getRotation(), 45, + assert.equal(viewer.navigator.viewport.getRotation(), 45, "Rotation set in constructor should be applied to navigator by default."); viewer.viewport.setRotation(90); - equal(navigator.viewport.getRotation(), 90, + assert.equal(viewer.navigator.viewport.getRotation(), 90, "Rotation set by setRotation should be applied to navigator by default."); - start(); + done(); }); }); - asyncTest('Viewer rotation not applied to navigator when navigatorRotate=false', function() { - + QUnit.test('Viewer rotation not applied to navigator when navigatorRotate=false', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example', prefixUrl: '/build/openseadragon/images/', @@ -991,16 +1076,14 @@ viewer.addHandler('open', function openHandler() { viewer.removeHandler('open', openHandler); - var navigator = viewer.navigator; - - equal(navigator.viewport.getRotation(), 0, + assert.equal(viewer.navigator.viewport.getRotation(), 0, "Rotation set in constructor should not be applied to navigator when navigatorRotate is false."); viewer.viewport.setRotation(90); - equal(navigator.viewport.getRotation(), 0, + assert.equal(viewer.navigator.viewport.getRotation(), 0, "Rotation set by setRotation should not be applied to navigator when navigatorRotate is false."); - start(); + done(); }); }); diff --git a/test/modules/overlays.js b/test/modules/overlays.js index 76e91272..3a7a8877 100644 --- a/test/modules/overlays.js +++ b/test/modules/overlays.js @@ -1,12 +1,12 @@ -/* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal, testLog */ +/* global QUnit, Util, $, console, testLog */ (function() { var viewer; // jQuery.position can give results quite different than what set in style.left var epsilon = 1; - module("Overlays", { - setup: function() { + QUnit.module("Overlays", { + beforeEach: function() { var example = $('
').appendTo("#qunit-fixture"); var fixedOverlay = $('
').appendTo(example); fixedOverlay.width(70); @@ -14,7 +14,7 @@ testLog.reset(); }, - teardown: function() { + afterEach: function() { resetTestVariables(); } }); @@ -53,8 +53,8 @@ } } - asyncTest('Overlays via viewer options', function() { - + QUnit.test('Overlays via viewer options', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -73,8 +73,8 @@ function openHandler() { viewer.removeHandler('open', openHandler); - equal(viewer.overlays.length, 1, "Global overlay should be added."); - equal(viewer.currentOverlays.length, 1, "Global overlay should be open."); + assert.equal(viewer.overlays.length, 1, "Global overlay should be added."); + assert.equal(viewer.currentOverlays.length, 1, "Global overlay should be open."); viewer.addHandler('open', openPageHandler); viewer.goToPage(1); @@ -83,8 +83,8 @@ function openPageHandler() { viewer.removeHandler('open', openPageHandler); - equal(viewer.overlays.length, 1, "Global overlay should stay after page switch."); - equal(viewer.currentOverlays.length, 1, "Global overlay should re-open after page switch."); + assert.equal(viewer.overlays.length, 1, "Global overlay should stay after page switch."); + assert.equal(viewer.currentOverlays.length, 1, "Global overlay should re-open after page switch."); viewer.addHandler('close', closeHandler); viewer.close(); @@ -93,15 +93,15 @@ function closeHandler() { viewer.removeHandler('close', closeHandler); - equal(viewer.overlays.length, 1, "Global overlay should not be removed on close."); - equal(viewer.currentOverlays.length, 0, "Global overlay should be closed on close."); + assert.equal(viewer.overlays.length, 1, "Global overlay should not be removed on close."); + assert.equal(viewer.currentOverlays.length, 0, "Global overlay should be closed on close."); - start(); + done(); } }); - asyncTest('Page Overlays via viewer options', function() { - + QUnit.test('Page Overlays via viewer options', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -144,8 +144,8 @@ function openHandler() { viewer.removeHandler('open', openHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added."); - equal(viewer.currentOverlays.length, 1, "Page overlay should be open."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added."); + assert.equal(viewer.currentOverlays.length, 1, "Page overlay should be open."); viewer.addHandler('open', openPageHandler); viewer.goToPage(1); @@ -154,8 +154,8 @@ function openPageHandler() { viewer.removeHandler('open', openPageHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added after page switch."); - equal(viewer.currentOverlays.length, 0, "No page overlay should be opened after page switch."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added after page switch."); + assert.equal(viewer.currentOverlays.length, 0, "No page overlay should be opened after page switch."); viewer.addHandler('close', closeHandler); viewer.close(); @@ -164,15 +164,15 @@ function closeHandler() { viewer.removeHandler('close', closeHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added on close."); - equal(viewer.currentOverlays.length, 0, "Page overlay should be closed on close."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added on close."); + assert.equal(viewer.currentOverlays.length, 0, "Page overlay should be closed on close."); - start(); + done(); } }); - asyncTest('Overlays via addOverlay method', function() { - + QUnit.test('Overlays via addOverlay method', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -184,14 +184,14 @@ function openHandler() { viewer.removeHandler('open', openHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added."); - equal(viewer.currentOverlays.length, 0, "No overlay should be open."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added."); + assert.equal(viewer.currentOverlays.length, 0, "No overlay should be open."); var rect = new OpenSeadragon.Rect(0.1, 0.1, 0.1, 0.1); var overlay = $("
").prop("id", "overlay").get(0); viewer.addOverlay(overlay, rect); - equal(viewer.overlays.length, 0, "No manual overlay should be added as global overlay."); - equal(viewer.currentOverlays.length, 1, "A manual overlay should be open."); + assert.equal(viewer.overlays.length, 0, "No manual overlay should be added as global overlay."); + assert.equal(viewer.currentOverlays.length, 1, "A manual overlay should be open."); viewer.addHandler('open', openPageHandler); viewer.goToPage(1); @@ -200,8 +200,8 @@ function openPageHandler() { viewer.removeHandler('open', openPageHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added after page switch."); - equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed after page switch."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added after page switch."); + assert.equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed after page switch."); viewer.addHandler('close', closeHandler); viewer.close(); @@ -210,16 +210,16 @@ function closeHandler() { viewer.removeHandler('close', closeHandler); - equal(viewer.overlays.length, 0, "No global overlay should be added on close."); - equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed on close."); + assert.equal(viewer.overlays.length, 0, "No global overlay should be added on close."); + assert.equal(viewer.currentOverlays.length, 0, "Manual overlay should be removed on close."); - start(); + done(); } }); - asyncTest('Overlays size in pixels', function() { - + QUnit.test('Overlays size in pixels', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -245,31 +245,31 @@ var expPosition = viewport.imageToViewerElementCoordinates( new OpenSeadragon.Point(13, 120)); var actPosition = $("#overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Y position mismatch " + contextMessage); var zoom = viewport.viewportToImageZoom(viewport.getZoom(true)); var expectedWidth = 124 * zoom; var expectedHeight = 132 * zoom; - Util.assessNumericValue($("#overlay").width(), expectedWidth, epsilon, + Util.assessNumericValue(assert, $("#overlay").width(), expectedWidth, epsilon, "Width mismatch " + contextMessage); - Util.assessNumericValue($("#overlay").height(), expectedHeight, epsilon, + Util.assessNumericValue(assert, $("#overlay").height(), expectedHeight, epsilon, "Height mismatch " + contextMessage); expPosition = viewport.imageToViewerElementCoordinates( new OpenSeadragon.Point(400, 500)); actPosition = $("#fixed-overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "Fixed overlay X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Fixed overlay Y position mismatch " + contextMessage); - Util.assessNumericValue($("#fixed-overlay").width(), 70, epsilon, + Util.assessNumericValue(assert, $("#fixed-overlay").width(), 70, epsilon, "Fixed overlay width mismatch " + contextMessage); - Util.assessNumericValue($("#fixed-overlay").height(), 60, epsilon, + Util.assessNumericValue(assert, $("#fixed-overlay").height(), 60, epsilon, "Fixed overlay height mismatch " + contextMessage); } @@ -283,15 +283,15 @@ viewer.viewport.goHome(); waitForViewer(function() { checkOverlayPosition("after goHome using image coordinates"); - start(); + done(); }); }); }); }); - asyncTest('Overlays size in points', function() { - + QUnit.test('Overlays size in points', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -317,30 +317,30 @@ var expPosition = viewport.viewportToViewerElementCoordinates( new OpenSeadragon.Point(0.2, 0.1)); var actPosition = $("#overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Y position mismatch " + contextMessage); var expectedSize = viewport.deltaPixelsFromPoints( new OpenSeadragon.Point(0.5, 0.1)); - Util.assessNumericValue($("#overlay").width(), expectedSize.x, epsilon, + Util.assessNumericValue(assert, $("#overlay").width(), expectedSize.x, epsilon, "Width mismatch " + contextMessage); - Util.assessNumericValue($("#overlay").height(), expectedSize.y, epsilon, + Util.assessNumericValue(assert, $("#overlay").height(), expectedSize.y, epsilon, "Height mismatch " + contextMessage); expPosition = viewport.viewportToViewerElementCoordinates( new OpenSeadragon.Point(0.5, 0.6)); actPosition = $("#fixed-overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "Fixed overlay X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Fixed overlay Y position mismatch " + contextMessage); - Util.assessNumericValue($("#fixed-overlay").width(), 70, epsilon, + Util.assessNumericValue(assert, $("#fixed-overlay").width(), 70, epsilon, "Fixed overlay width mismatch " + contextMessage); - Util.assessNumericValue($("#fixed-overlay").height(), 60, epsilon, + Util.assessNumericValue(assert, $("#fixed-overlay").height(), 60, epsilon, "Fixed overlay height mismatch " + contextMessage); } @@ -354,15 +354,15 @@ viewer.viewport.goHome(); waitForViewer(function() { checkOverlayPosition("after goHome using viewport coordinates"); - start(); + done(); }); }); }); }); - asyncTest('Overlays placement', function() { - + QUnit.test('Overlays placement', function(assert) { + var done = assert.async(); var scalableOverlayLocation = new OpenSeadragon.Rect(0.2, 0.1, 0.5, 0.1); var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6); @@ -393,9 +393,9 @@ var expPosition = viewport.viewportToViewerElementCoordinates( new OpenSeadragon.Point(0.2, 0.1)); var actPosition = $("#overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Y position mismatch " + contextMessage); } @@ -406,9 +406,9 @@ new OpenSeadragon.Point(0.5, 0.6)) .plus(expectedOffset); var actPosition = $("#fixed-overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "Fixed overlay X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Fixed overlay Y position mismatch " + contextMessage); } @@ -439,7 +439,7 @@ checkFixedOverlayPosition(new OpenSeadragon.Point(-70, -60), "with BOTTOM_RIGHT placement."); - start(); + done(); }, 100); }, 100); @@ -447,8 +447,8 @@ }); }); - asyncTest('Overlays placement and resizing check', function() { - + QUnit.test('Overlays placement and resizing check', function(assert) { + var done = assert.async(); var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6); viewer = OpenSeadragon({ @@ -472,9 +472,9 @@ new OpenSeadragon.Point(0.5, 0.6)) .plus(expectedOffset); var actPosition = $("#fixed-overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "Fixed overlay X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Fixed overlay Y position mismatch " + contextMessage); } @@ -496,14 +496,14 @@ $("#fixed-overlay").width(70); $("#fixed-overlay").height(60); - start(); + done(); }, 100); }); }); - asyncTest('Overlays placement and no resizing check', function() { - + QUnit.test('Overlays placement and no resizing check', function(assert) { + var done = assert.async(); var fixedOverlayLocation = new OpenSeadragon.Point(0.5, 0.6); viewer = OpenSeadragon({ @@ -527,9 +527,9 @@ new OpenSeadragon.Point(0.5, 0.6)) .plus(expectedOffset); var actPosition = $("#fixed-overlay").position(); - Util.assessNumericValue(actPosition.left, expPosition.x, epsilon, + Util.assessNumericValue(assert, actPosition.left, expPosition.x, epsilon, "Fixed overlay X position mismatch " + contextMessage); - Util.assessNumericValue(actPosition.top, expPosition.y, epsilon, + Util.assessNumericValue(assert, actPosition.top, expPosition.y, epsilon, "Fixed overlay Y position mismatch " + contextMessage); } @@ -551,16 +551,17 @@ $("#fixed-overlay").width(70); $("#fixed-overlay").height(60); - start(); + done(); }, 100); }); }); // ---------- - 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'); + QUnit.test('overlays appear immediately', function(assert) { + var done = assert.async(); + assert.equal($('#immediate-overlay0').length, 0, 'overlay 0 does not exist'); + assert.equal($('#immediate-overlay1').length, 0, 'overlay 1 does not exist'); viewer = OpenSeadragon({ id: 'example-overlays', @@ -575,7 +576,7 @@ }); viewer.addHandler('open', function() { - equal($('#immediate-overlay0').length, 1, 'overlay 0 exists'); + assert.equal($('#immediate-overlay0').length, 1, 'overlay 0 exists'); viewer.addOverlay({ x: 0, @@ -583,13 +584,14 @@ id: "immediate-overlay1" }); - equal($('#immediate-overlay1').length, 1, 'overlay 1 exists'); - start(); + assert.equal($('#immediate-overlay1').length, 1, 'overlay 1 exists'); + done(); }); }); // ---------- - asyncTest('Overlay scaled horizontally only', function() { + QUnit.test('Overlay scaled horizontally only', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -615,16 +617,17 @@ waitForViewer(function() { var newWidth = $("#horizontally-scaled-overlay").width(); var newHeight = $("#horizontally-scaled-overlay").height(); - equal(newWidth, width * zoom, "Width should be scaled."); - equal(newHeight, height, "Height should not be scaled."); + assert.equal(newWidth, width * zoom, "Width should be scaled."); + assert.equal(newHeight, height, "Height should not be scaled."); - start(); + done(); }); }); }); // ---------- - asyncTest('Overlay scaled vertically only', function() { + QUnit.test('Overlay scaled vertically only', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -650,16 +653,17 @@ waitForViewer(function() { var newWidth = $("#vertically-scaled-overlay").width(); var newHeight = $("#vertically-scaled-overlay").height(); - equal(newWidth, width, "Width should not be scaled."); - equal(newHeight, height * zoom, "Height should be scaled."); + assert.equal(newWidth, width, "Width should not be scaled."); + assert.equal(newHeight, height * zoom, "Height should be scaled."); - start(); + done(); }); }); }); // ---------- - asyncTest('Overlay.getBounds', function() { + QUnit.test('Overlay.getBounds', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -713,7 +717,7 @@ var actualBounds = viewer.getOverlayById("fully-scaled-overlay") .getBounds(viewer.viewport); var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The fully scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); @@ -722,7 +726,7 @@ .getBounds(viewer.viewport); expectedBounds = new OpenSeadragon.Rect( 0, 0.5 - notScaledSize.y / 2, 1, notScaledSize.y); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The horizontally scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); @@ -730,7 +734,7 @@ .getBounds(viewer.viewport); expectedBounds = new OpenSeadragon.Rect( 0, 0, notScaledSize.x, 1); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The vertically scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); @@ -738,16 +742,17 @@ .getBounds(viewer.viewport); expectedBounds = new OpenSeadragon.Rect( 1 - notScaledSize.x, 0, notScaledSize.x, notScaledSize.y); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The not scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); // ---------- - asyncTest('Fully scaled overlay rotation mode NO_ROTATION', function() { + QUnit.test('Fully scaled overlay rotation mode NO_ROTATION', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -775,32 +780,33 @@ new OpenSeadragon.Point(1, 1)) .minus(expectedSize); var actualPosition = $overlay.position(); - Util.assessNumericValue(actualPosition.left, expectedPosition.x, epsilon, + Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon, "Scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(actualPosition.top, expectedPosition.y, epsilon, + Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon, "Scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, expectedSize.x, epsilon, + Util.assessNumericValue(assert, actualWidth, expectedSize.x, epsilon, "Scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, expectedSize.y, epsilon, + Util.assessNumericValue(assert, actualHeight, expectedSize.y, epsilon, "Scaled overlay height should not adjust to rotation."); var actualBounds = viewer.getOverlayById("fully-scaled-overlay") .getBounds(viewport); var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1) .rotate(-45, new OpenSeadragon.Point(1, 1)); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The fully scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); // ---------- - asyncTest('Horizontally scaled overlay rotation mode NO_ROTATION', function() { + QUnit.test('Horizontally scaled overlay rotation mode NO_ROTATION', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -836,16 +842,16 @@ new OpenSeadragon.Point(0.5, 0.5)) .minus(new OpenSeadragon.Point(expectedWidth / 2, notScaledHeight / 2)); var actualPosition = $overlay.position(); - Util.assessNumericValue(actualPosition.left, expectedPosition.x, epsilon, + Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon, "Horizontally scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(actualPosition.top, expectedPosition.y, epsilon, + Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon, "Horizontally scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, expectedWidth, epsilon, + Util.assessNumericValue(assert, actualWidth, expectedWidth, epsilon, "Horizontally scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, notScaledHeight, epsilon, + Util.assessNumericValue(assert, actualHeight, notScaledHeight, epsilon, "Horizontally scaled overlay height should not adjust to rotation."); var actualBounds = viewer.getOverlayById("horizontally-scaled-overlay") @@ -853,16 +859,17 @@ var expectedBounds = new OpenSeadragon.Rect( 0, 0.5 - notScaledSize.y / 2, 1, notScaledSize.y) .rotate(-45, new OpenSeadragon.Point(0.5, 0.5)); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The horizontally scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); // ---------- - asyncTest('Vertically scaled overlay rotation mode NO_ROTATION', function() { + QUnit.test('Vertically scaled overlay rotation mode NO_ROTATION', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -898,16 +905,16 @@ new OpenSeadragon.Point(0, 0.5)) .minus(new OpenSeadragon.Point(0, expectedHeight / 2)); var actualPosition = $overlay.position(); - Util.assessNumericValue(actualPosition.left, expectedPosition.x, epsilon, + Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon, "Vertically scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(actualPosition.top, expectedPosition.y, epsilon, + Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon, "Vertically scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, notScaledWidth, epsilon, + Util.assessNumericValue(assert, actualWidth, notScaledWidth, epsilon, "Vertically scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, expectedHeight, epsilon, + Util.assessNumericValue(assert, actualHeight, expectedHeight, epsilon, "Vertically scaled overlay height should not adjust to rotation."); var actualBounds = viewer.getOverlayById("vertically-scaled-overlay") @@ -915,16 +922,17 @@ var expectedBounds = new OpenSeadragon.Rect( 0, 0, notScaledSize.x, 1) .rotate(-45, new OpenSeadragon.Point(0, 0.5)); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The vertically scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); // ---------- - asyncTest('Not scaled overlay rotation mode NO_ROTATION', function() { + QUnit.test('Not scaled overlay rotation mode NO_ROTATION', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -958,16 +966,16 @@ new OpenSeadragon.Point(1, 0)) .minus(new OpenSeadragon.Point(notScaledWidth, 0)); var actualPosition = $overlay.position(); - Util.assessNumericValue(actualPosition.left, expectedPosition.x, epsilon, + Util.assessNumericValue(assert, actualPosition.left, expectedPosition.x, epsilon, "Not scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(actualPosition.top, expectedPosition.y, epsilon, + Util.assessNumericValue(assert, actualPosition.top, expectedPosition.y, epsilon, "Not scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, notScaledWidth, epsilon, + Util.assessNumericValue(assert, actualWidth, notScaledWidth, epsilon, "Not scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, notScaledHeight, epsilon, + Util.assessNumericValue(assert, actualHeight, notScaledHeight, epsilon, "Not scaled overlay height should not adjust to rotation."); var actualBounds = viewer.getOverlayById("not-scaled-overlay") @@ -975,16 +983,17 @@ var expectedBounds = new OpenSeadragon.Rect( 1 - notScaledSize.x, 0, notScaledSize.x, notScaledSize.y) .rotate(-45, new OpenSeadragon.Point(1, 0)); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "Not scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); // ---------- - asyncTest('Fully scaled overlay rotation mode BOUNDING_BOX', function() { + QUnit.test('Fully scaled overlay rotation mode BOUNDING_BOX', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -1009,16 +1018,16 @@ var expectedRect = viewport.viewportToViewerElementRectangle( new OpenSeadragon.Rect(0, 0, 1, 1)).getBoundingBox(); var actualPosition = $overlay.position(); - Util.assessNumericValue(actualPosition.left, expectedRect.x, epsilon, + Util.assessNumericValue(assert, actualPosition.left, expectedRect.x, epsilon, "Scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(actualPosition.top, expectedRect.y, epsilon, + Util.assessNumericValue(assert, actualPosition.top, expectedRect.y, epsilon, "Scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, expectedRect.width, epsilon, + Util.assessNumericValue(assert, actualWidth, expectedRect.width, epsilon, "Scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, expectedRect.height, epsilon, + Util.assessNumericValue(assert, actualHeight, expectedRect.height, epsilon, "Scaled overlay height should not adjust to rotation."); var actualBounds = viewer.getOverlayById("fully-scaled-overlay") @@ -1026,23 +1035,24 @@ var expectedBounds = new OpenSeadragon.Rect( 0.5, -0.5, Math.sqrt(2), Math.sqrt(2), 45); var boundsEpsilon = 0.000001; - Util.assessNumericValue(actualBounds.x, expectedBounds.x, boundsEpsilon, + Util.assessNumericValue(assert, actualBounds.x, expectedBounds.x, boundsEpsilon, "The fully scaled overlay should have adjusted bounds.x"); - Util.assessNumericValue(actualBounds.y, expectedBounds.y, boundsEpsilon, + Util.assessNumericValue(assert, actualBounds.y, expectedBounds.y, boundsEpsilon, "The fully scaled overlay should have adjusted bounds.y"); - Util.assessNumericValue(actualBounds.width, expectedBounds.width, boundsEpsilon, + Util.assessNumericValue(assert, actualBounds.width, expectedBounds.width, boundsEpsilon, "The fully scaled overlay should have adjusted bounds.width"); - Util.assessNumericValue(actualBounds.height, expectedBounds.height, boundsEpsilon, + Util.assessNumericValue(assert, actualBounds.height, expectedBounds.height, boundsEpsilon, "The fully scaled overlay should have adjusted bounds.height"); - Util.assessNumericValue(actualBounds.degrees, expectedBounds.degrees, boundsEpsilon, + Util.assessNumericValue(assert, actualBounds.degrees, expectedBounds.degrees, boundsEpsilon, "The fully scaled overlay should have adjusted bounds.degrees"); - start(); + done(); }); }); // ---------- - asyncTest('Fully scaled overlay rotation mode EXACT', function() { + QUnit.test('Fully scaled overlay rotation mode EXACT', function(assert) { + var done = assert.async(); viewer = OpenSeadragon({ id: 'example-overlays', prefixUrl: '/build/openseadragon/images/', @@ -1073,16 +1083,16 @@ var actualStyle = $overlay.get(0).style; var left = Number(actualStyle.left.replace("px", "")); var top = Number(actualStyle.top.replace("px", "")); - Util.assessNumericValue(left, expectedPosition.x, epsilon, + Util.assessNumericValue(assert, left, expectedPosition.x, epsilon, "Scaled overlay position.x should adjust to rotation."); - Util.assessNumericValue(top, expectedPosition.y, epsilon, + Util.assessNumericValue(assert, top, expectedPosition.y, epsilon, "Scaled overlay position.y should adjust to rotation."); var actualWidth = $overlay.width(); var actualHeight = $overlay.height(); - Util.assessNumericValue(actualWidth, expectedSize.x, epsilon, + Util.assessNumericValue(assert, actualWidth, expectedSize.x, epsilon, "Scaled overlay width should not adjust to rotation."); - Util.assessNumericValue(actualHeight, expectedSize.y, epsilon, + Util.assessNumericValue(assert, actualHeight, expectedSize.y, epsilon, "Scaled overlay height should not adjust to rotation."); var transformOriginProp = OpenSeadragon.getCssPropertyWithVendorPrefix( @@ -1091,19 +1101,19 @@ 'transform'); var transformOrigin = actualStyle[transformOriginProp]; // Some browsers replace "right bottom" by "100% 100%" - ok(transformOrigin.match(/(100% 100%)|(right bottom)/), + assert.ok(transformOrigin.match(/(100% 100%)|(right bottom)/), "Transform origin should be right bottom. Got: " + transformOrigin); - equal(actualStyle[transformProp], "rotate(45deg)", + assert.equal(actualStyle[transformProp], "rotate(45deg)", "Transform should be rotate(45deg)."); var actualBounds = viewer.getOverlayById("fully-scaled-overlay") .getBounds(viewport); var expectedBounds = new OpenSeadragon.Rect(0, 0, 1, 1); - ok(expectedBounds.equals(actualBounds), + assert.ok(expectedBounds.equals(actualBounds), "The fully scaled overlay should have bounds " + expectedBounds + " but found " + actualBounds); - start(); + done(); }); }); })(); diff --git a/test/modules/polyfills.js b/test/modules/polyfills.js index 5e93b1b8..8d9a04ef 100644 --- a/test/modules/polyfills.js +++ b/test/modules/polyfills.js @@ -1,15 +1,15 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ ( function() { - module( 'Polyfills', { - setup: function() { + QUnit.module( 'Polyfills', { + beforeEach: function() { testLog.reset(); } } ); // ---------- - test( 'pageScroll', function() { + QUnit.test( 'pageScroll', function(assert) { // Setup var origWidth = $( "body" ).width(), origHeight = $( "body" ).height(); @@ -23,17 +23,17 @@ var originalGetPageScroll = OpenSeadragon.getPageScroll; var scroll = OpenSeadragon.getPageScroll(); - equal( scroll.x, 0, "Scroll should be 0 at beginning." ); - equal( scroll.y, 0, "Scroll should be 0 at beginning." ); + assert.equal( scroll.x, 0, "Scroll should be 0 at beginning." ); + assert.equal( scroll.y, 0, "Scroll should be 0 at beginning." ); // If window.pageXOffset is not supported, the getPageScroll method should // not have been redefined if ( typeof ( window.pageXOffset ) != "number" ) { - equal( originalGetPageScroll, OpenSeadragon.getPageScroll, + assert.equal( originalGetPageScroll, OpenSeadragon.getPageScroll, "OpenSeadragon.getPageScroll must not be redefined when on 0,0" + " and window API is not supported." ); } else { - notEqual( originalGetPageScroll, OpenSeadragon.getPageScroll, + assert.notEqual( originalGetPageScroll, OpenSeadragon.getPageScroll, "OpenSeadragon.getPageScroll must be redefined when window API " + "is supported." ); } @@ -41,14 +41,14 @@ $( document ).scrollLeft( 200 ); $( document ).scrollTop( 100 ); scroll = originalGetPageScroll(); - equal( scroll.x, 200, "First call to getScroll." ); - equal( scroll.y, 100, "First call to getScroll." ); + assert.equal( scroll.x, 200, "First call to getScroll." ); + assert.equal( scroll.y, 100, "First call to getScroll." ); $( document ).scrollLeft( 500 ); $( document ).scrollTop( 600 ); scroll = OpenSeadragon.getPageScroll(); - equal( scroll.x, 500, "Second call to getScroll." ); - equal( scroll.y, 600, "Second call to getScroll." ); + assert.equal( scroll.x, 500, "Second call to getScroll." ); + assert.equal( scroll.y, 600, "Second call to getScroll." ); @@ -60,16 +60,16 @@ $( document ).scrollTop( 0 ); var scroll = new OpenSeadragon.Point( 0, 0 ); OpenSeadragon.setPageScroll( scroll ); - equal( $( document ).scrollLeft(), 0, "First call to 0,0 while already on 0,0." ); - equal( $( document ).scrollTop(), 0, "First call to 0,0 while already on 0,0." ); + assert.equal( $( document ).scrollLeft(), 0, "First call to 0,0 while already on 0,0." ); + assert.equal( $( document ).scrollTop(), 0, "First call to 0,0 while already on 0,0." ); // If window.pageXOffset is not supported, the getPageScroll method should // not have been redefined if ( typeof ( window.scrollTo ) === "undefined" ) { - equal( originalSetPageScroll, OpenSeadragon.setPageScroll, + assert.equal( originalSetPageScroll, OpenSeadragon.setPageScroll, "OpenSeadragon.setPageScroll must not be redefined when not moving." ); } else { - notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, + assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, "OpenSeadragon.setPageScroll must be redefined when window API is supported." ); } @@ -79,16 +79,16 @@ $( document ).scrollTop( 200 ); var scroll = new OpenSeadragon.Point( 100, 200 ); OpenSeadragon.setPageScroll( scroll ); - equal( $( document ).scrollLeft(), 100, "First call to 100,200 while already on 100,200." ); - equal( $( document ).scrollTop(), 200, "First call to 100,200 while already on 100,200." ); + assert.equal( $( document ).scrollLeft(), 100, "First call to 100,200 while already on 100,200." ); + assert.equal( $( document ).scrollTop(), 200, "First call to 100,200 while already on 100,200." ); // If window.pageXOffset is not supported, the getPageScroll method should // not have been redefined if ( typeof ( window.scrollTo ) === "undefined" ) { - equal( originalSetPageScroll, OpenSeadragon.setPageScroll, + assert.equal( originalSetPageScroll, OpenSeadragon.setPageScroll, "OpenSeadragon.setPageScroll must not be redefined when not moving." ); } else { - notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, + assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, "OpenSeadragon.setPageScroll must be redefined when window API is supported." ); } @@ -102,9 +102,9 @@ $( document ).scrollTop( 0 ); var scroll = new OpenSeadragon.Point( 20000, 20000 ); OpenSeadragon.setPageScroll( scroll ); - equal( $( document ).scrollLeft(), actualScrollLeft, "First call to position above limits." ); - equal( $( document ).scrollTop(), actualScrollTop, "First call to position above limits." ); - notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, + assert.equal( $( document ).scrollLeft(), actualScrollLeft, "First call to position above limits." ); + assert.equal( $( document ).scrollTop(), actualScrollTop, "First call to position above limits." ); + assert.notEqual( originalSetPageScroll, OpenSeadragon.setPageScroll, "Even if outside scroll limits, OpenSeadragon.setPageScroll can be " + "reassigned on first call." ); @@ -112,9 +112,9 @@ var currentSetPageScroll = OpenSeadragon.setPageScroll; var scroll = new OpenSeadragon.Point( 200, 200 ); OpenSeadragon.setPageScroll( scroll ); - equal( $( document ).scrollLeft(), 200, "Second call." ); - equal( $( document ).scrollTop(), 200, "Second call." ); - equal( currentSetPageScroll, OpenSeadragon.setPageScroll, + assert.equal( $( document ).scrollLeft(), 200, "Second call." ); + assert.equal( $( document ).scrollTop(), 200, "Second call." ); + assert.equal( currentSetPageScroll, OpenSeadragon.setPageScroll, "OpenSeadragon.setPageScroll must not be reassigned after first call." ); diff --git a/test/modules/rectangle.js b/test/modules/rectangle.js index 402e58c4..18ae8b3b 100644 --- a/test/modules/rectangle.js +++ b/test/modules/rectangle.js @@ -1,152 +1,152 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, Util */ (function() { - module('Rectangle', {}); + QUnit.module('Rectangle', {}); var precision = 0.000000001; - test('Constructor', function() { + QUnit.test('Constructor', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 5); - strictEqual(rect.x, 1, 'rect.x should be 1'); - strictEqual(rect.y, 2, 'rect.y should be 2'); - strictEqual(rect.width, 3, 'rect.width should be 3'); - strictEqual(rect.height, 4, 'rect.height should be 4'); - strictEqual(rect.degrees, 5, 'rect.degrees should be 5'); + assert.strictEqual(rect.x, 1, 'rect.x should be 1'); + assert.strictEqual(rect.y, 2, 'rect.y should be 2'); + assert.strictEqual(rect.width, 3, 'rect.width should be 3'); + assert.strictEqual(rect.height, 4, 'rect.height should be 4'); + assert.strictEqual(rect.degrees, 5, 'rect.degrees should be 5'); rect = new OpenSeadragon.Rect(); - strictEqual(rect.x, 0, 'rect.x should be 0'); - strictEqual(rect.y, 0, 'rect.y should be 0'); - strictEqual(rect.width, 0, 'rect.width should be 0'); - strictEqual(rect.height, 0, 'rect.height should be 0'); - strictEqual(rect.degrees, 0, 'rect.degrees should be 0'); + assert.strictEqual(rect.x, 0, 'rect.x should be 0'); + assert.strictEqual(rect.y, 0, 'rect.y should be 0'); + assert.strictEqual(rect.width, 0, 'rect.width should be 0'); + assert.strictEqual(rect.height, 0, 'rect.height should be 0'); + assert.strictEqual(rect.degrees, 0, 'rect.degrees should be 0'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, -405); - Util.assessNumericValue(Math.sqrt(2) / 2, rect.x, precision, + Util.assessNumericValue(assert, Math.sqrt(2) / 2, rect.x, precision, 'rect.x should be sqrt(2)/2'); - Util.assessNumericValue(-Math.sqrt(2) / 2, rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2) / 2, rect.y, precision, 'rect.y should be -sqrt(2)/2'); - Util.assessNumericValue(2, rect.width, precision, + Util.assessNumericValue(assert, 2, rect.width, precision, 'rect.width should be 2'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, 135); - Util.assessNumericValue(-Math.sqrt(2), rect.x, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.x, precision, 'rect.x should be -sqrt(2)'); - Util.assessNumericValue(-Math.sqrt(2), rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(2, rect.width, precision, + Util.assessNumericValue(assert, 2, rect.width, precision, 'rect.width should be 2'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 1, 585); - Util.assessNumericValue(0, rect.x, precision, + Util.assessNumericValue(assert, 0, rect.x, precision, 'rect.x should be 0'); - Util.assessNumericValue(-Math.sqrt(2), rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(1, rect.width, precision, + Util.assessNumericValue(assert, 1, rect.width, precision, 'rect.width should be 1'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); }); - test('getTopLeft', function() { + QUnit.test('getTopLeft', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 5); var expected = new OpenSeadragon.Point(1, 2); - ok(expected.equals(rect.getTopLeft()), "Incorrect top left point."); + assert.ok(expected.equals(rect.getTopLeft()), "Incorrect top left point."); }); - test('getTopRight', function() { + QUnit.test('getTopRight', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 3); var expected = new OpenSeadragon.Point(1, 0); - ok(expected.equals(rect.getTopRight()), "Incorrect top right point."); + assert.ok(expected.equals(rect.getTopRight()), "Incorrect top right point."); rect.degrees = 45; expected = new OpenSeadragon.Point(1 / Math.sqrt(2), 1 / Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getTopRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getTopRight(), precision, "Incorrect top right point with rotation."); }); - test('getBottomLeft', function() { + QUnit.test('getBottomLeft', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 3, 1); var expected = new OpenSeadragon.Point(0, 1); - ok(expected.equals(rect.getBottomLeft()), "Incorrect bottom left point."); + assert.ok(expected.equals(rect.getBottomLeft()), "Incorrect bottom left point."); rect.degrees = 45; expected = new OpenSeadragon.Point(-1 / Math.sqrt(2), 1 / Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getBottomLeft(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomLeft(), precision, "Incorrect bottom left point with rotation."); }); - test('getBottomRight', function() { + QUnit.test('getBottomRight', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1); var expected = new OpenSeadragon.Point(1, 1); - ok(expected.equals(rect.getBottomRight()), "Incorrect bottom right point."); + assert.ok(expected.equals(rect.getBottomRight()), "Incorrect bottom right point."); rect.degrees = 45; expected = new OpenSeadragon.Point(0, Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 45 rotation."); rect.degrees = 90; expected = new OpenSeadragon.Point(-1, 1); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 90 rotation."); rect.degrees = 135; expected = new OpenSeadragon.Point(-Math.sqrt(2), 0); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 135 rotation."); }); - test('getCenter', function() { + QUnit.test('getCenter', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1); var expected = new OpenSeadragon.Point(0.5, 0.5); - ok(expected.equals(rect.getCenter()), "Incorrect center point."); + assert.ok(expected.equals(rect.getCenter()), "Incorrect center point."); rect.degrees = 45; expected = new OpenSeadragon.Point(0, 0.5 * Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 45 rotation."); rect.degrees = 90; expected = new OpenSeadragon.Point(-0.5, 0.5); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 90 rotation."); rect.degrees = 135; expected = new OpenSeadragon.Point(-0.5 * Math.sqrt(2), 0); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 135 rotation."); }); - test('times', function() { + QUnit.test('times', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 45); var expected = new OpenSeadragon.Rect(2, 4, 6, 8, 45); var actual = rect.times(2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect x2 rectangles."); }); - test('translate', function() { + QUnit.test('translate', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 45); var expected = new OpenSeadragon.Rect(2, 4, 3, 4, 45); var actual = rect.translate(new OpenSeadragon.Point(1, 2)); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect translation."); }); - test('union', function() { + QUnit.test('union', function(assert) { var rect1 = new OpenSeadragon.Rect(2, 2, 2, 3); var rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); var expected = new OpenSeadragon.Rect(0, 1, 4, 4); var actual = rect1.union(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect union with horizontal rectangles."); rect1 = new OpenSeadragon.Rect(0, -Math.sqrt(2), 2, 2, 45); @@ -157,30 +157,30 @@ 3 + Math.sqrt(2), 2 + Math.sqrt(2)); actual = rect1.union(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect union with non horizontal rectangles."); }); - test('intersection', function() { + QUnit.test('intersection', function(assert) { var rect1 = new OpenSeadragon.Rect(2, 2, 2, 3); var rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); var expected = null; var actual = rect1.intersection(rect2); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect2 + " should not intersect " + rect1); actual = rect2.intersection(rect1); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect1 + " should not intersect " + rect2); rect1 = new OpenSeadragon.Rect(0, 0, 2, 1); rect2 = new OpenSeadragon.Rect(1, 0, 2, 2); expected = new OpenSeadragon.Rect(1, 0, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); @@ -188,11 +188,11 @@ rect2 = new OpenSeadragon.Rect(1, 1, 1, 1); expected = new OpenSeadragon.Rect(1, 1, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); @@ -201,26 +201,26 @@ rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); expected = null; actual = rect1.intersection(rect2); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect2 + " should not intersect " + rect1); actual = rect2.intersection(rect1); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect1 + " should not intersect " + rect2); rect1 = new OpenSeadragon.Rect(2, 0, 2, 3, 45); rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); expected = new OpenSeadragon.Rect(0, 1, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); }); - test('rotate', function() { + QUnit.test('rotate', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 2, 1); var expected = new OpenSeadragon.Rect( @@ -230,73 +230,73 @@ 1, 45); var actual = rect.rotate(-675); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of -675deg around center."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 33); actual = rect.rotate(33, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 33deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 101); actual = rect.rotate(101, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 187deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 187); actual = rect.rotate(187, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 187deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 300); actual = rect.rotate(300, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 300deg around topLeft."); }); - test('getBoundingBox', function() { + QUnit.test('getBoundingBox', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 2, 3); var bb = rect.getBoundingBox(); - ok(rect.equals(bb), "Bounding box of horizontal rectangle should be " + + assert.ok(rect.equals(bb), "Bounding box of horizontal rectangle should be " + "identical to rectangle."); rect.degrees = 90; var expected = new OpenSeadragon.Rect(-3, 0, 3, 2); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 90deg."); rect.degrees = 180; - var expected = new OpenSeadragon.Rect(-2, -3, 2, 3); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + expected = new OpenSeadragon.Rect(-2, -3, 2, 3); + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 180deg."); rect.degrees = 270; - var expected = new OpenSeadragon.Rect(0, -2, 3, 2); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + expected = new OpenSeadragon.Rect(0, -2, 3, 2); + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 270deg."); }); - test('containsPoint', function() { + QUnit.test('containsPoint', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1, 45); - ok(rect.containsPoint(new OpenSeadragon.Point(0, 0)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0, 0)), 'Point 0,0 should be inside ' + rect); - ok(rect.containsPoint(rect.getTopRight()), + assert.ok(rect.containsPoint(rect.getTopRight()), 'Top right vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getBottomRight()), + assert.ok(rect.containsPoint(rect.getBottomRight()), 'Bottom right vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getBottomLeft()), + assert.ok(rect.containsPoint(rect.getBottomLeft()), 'Bottom left vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getCenter()), + assert.ok(rect.containsPoint(rect.getCenter()), 'Center should be inside ' + rect); - notOk(rect.containsPoint(new OpenSeadragon.Point(1, 0)), + assert.notOk(rect.containsPoint(new OpenSeadragon.Point(1, 0)), 'Point 1,0 should not be inside ' + rect); - ok(rect.containsPoint(new OpenSeadragon.Point(0.5, 0.5)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0.5, 0.5)), 'Point 0.5,0.5 should be inside ' + rect); - ok(rect.containsPoint(new OpenSeadragon.Point(0.4, 0.5)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0.4, 0.5)), 'Point 0.4,0.5 should be inside ' + rect); - notOk(rect.containsPoint(new OpenSeadragon.Point(0.6, 0.5)), + assert.notOk(rect.containsPoint(new OpenSeadragon.Point(0.6, 0.5)), 'Point 0.6,0.5 should not be inside ' + rect); }); diff --git a/test/modules/referencestrip.js b/test/modules/referencestrip.js index 45130070..857c16fb 100644 --- a/test/modules/referencestrip.js +++ b/test/modules/referencestrip.js @@ -1,15 +1,15 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer; - module('ReferenceStrip', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('ReferenceStrip', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -29,7 +29,8 @@ }; // ---------- - asyncTest('basics', function() { + QUnit.test('basics', function(assert) { + var done = assert.async(); createViewer({ sequenceMode: true, showReferenceStrip: true, @@ -39,8 +40,8 @@ ] }); - ok(viewer.referenceStrip, 'referenceStrip exists'); - start(); + assert.ok(viewer.referenceStrip, 'referenceStrip exists'); + done(); }); })(); diff --git a/test/modules/spring.js b/test/modules/spring.js index b627f832..c71839f8 100644 --- a/test/modules/spring.js +++ b/test/modules/spring.js @@ -1,12 +1,12 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual, console */ +/* global QUnit, Util, console */ (function () { var originalNow; var now; - module("spring", { - setup: function () { + QUnit.module("spring", { + beforeEach: function () { now = 0; originalNow = OpenSeadragon.now; @@ -14,39 +14,41 @@ return now; }; }, - teardown: function () { + afterEach: function () { OpenSeadragon.now = originalNow; } }); - asyncTest('regular spring', function() { + QUnit.test('regular spring', function(assert) { + var done = assert.async(); var spring = new OpenSeadragon.Spring({ initial: 5, animationTime: 1, springStiffness: 0.000001 }); - equal(spring.current.value, 5, 'initial current value'); - equal(spring.target.value, 5, 'initial target value'); + assert.equal(spring.current.value, 5, 'initial current value'); + assert.equal(spring.target.value, 5, 'initial target value'); spring.springTo(6); - equal(spring.current.value, 5, 'current value after springTo'); - equal(spring.target.value, 6, 'target value after springTo'); + assert.equal(spring.current.value, 5, 'current value after springTo'); + assert.equal(spring.target.value, 6, 'target value after springTo'); now = 500; spring.update(); - Util.assessNumericValue(5.5, spring.current.value, 0.00001, 'current value after first update'); - equal(spring.target.value, 6, 'target value after first update'); + Util.assessNumericValue(assert, 5.5, spring.current.value, 0.00001, 'current value after first update'); + assert.equal(spring.target.value, 6, 'target value after first update'); now = 1000; spring.update(); - equal(spring.current.value, 6, 'current value after second update'); - equal(spring.target.value, 6, 'target value after second update'); + assert.equal(spring.current.value, 6, 'current value after second update'); + assert.equal(spring.target.value, 6, 'target value after second update'); - start(); + done(); }); - asyncTest('exponential spring', function() { + QUnit.test('exponential spring', function(assert) { + var done = assert.async(); var spring = new OpenSeadragon.Spring({ exponential: true, initial: 1, @@ -54,24 +56,24 @@ springStiffness: 0.000001 }); - equal(spring.current.value, 1, 'initial current value'); - equal(spring.target.value, 1, 'initial target value'); + assert.equal(spring.current.value, 1, 'initial current value'); + assert.equal(spring.target.value, 1, 'initial target value'); spring.springTo(2); - equal(spring.current.value, 1, 'current value after springTo'); - equal(spring.target.value, 2, 'target value after springTo'); + assert.equal(spring.current.value, 1, 'current value after springTo'); + assert.equal(spring.target.value, 2, 'target value after springTo'); now = 500; spring.update(); - Util.assessNumericValue(1.41421, spring.current.value, 0.00001, 'current value after first update'); - equal(spring.target.value, 2, 'target value after first update'); + Util.assessNumericValue(assert, 1.41421, spring.current.value, 0.00001, 'current value after first update'); + assert.equal(spring.target.value, 2, 'target value after first update'); now = 1000; spring.update(); - equal(spring.current.value, 2, 'current value after second update'); - equal(spring.target.value, 2, 'target value after second update'); + assert.equal(spring.current.value, 2, 'current value after second update'); + assert.equal(spring.target.value, 2, 'target value after second update'); - start(); + done(); }); })(); diff --git a/test/modules/strings.js b/test/modules/strings.js index 83f97d82..ec1bf87a 100644 --- a/test/modules/strings.js +++ b/test/modules/strings.js @@ -1,44 +1,44 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, testLog */ (function() { - module("strings", { - setup: function () { + QUnit.module("strings", { + beforeEach: function () { testLog.reset(); } }); - test("getSubString", function() { - equal(OpenSeadragon.getString("Errors.Dzi"), + QUnit.test("getSubString", function(assert) { + assert.equal(OpenSeadragon.getString("Errors.Dzi"), "Hmm, this doesn't appear to be a valid Deep Zoom Image.", "Read sub-string"); }); - test("getStringWithPlaceholders", function() { - equal(OpenSeadragon.getString("Errors.OpenFailed", "foo", "bar"), + QUnit.test("getStringWithPlaceholders", function(assert) { + assert.equal(OpenSeadragon.getString("Errors.OpenFailed", "foo", "bar"), "Unable to open foo: bar", "String placeholder replacement"); }); - test("getInvalidString", function() { - equal(OpenSeadragon.getString("Greeting"), "", "Handled unset string key"); - ok(testLog.log.contains('["Untranslated source string:","Greeting"]'), + QUnit.test("getInvalidString", function(assert) { + assert.equal(OpenSeadragon.getString("Greeting"), "", "Handled unset string key"); + assert.ok(testLog.log.contains('["Untranslated source string:","Greeting"]'), 'Invalid string keys are logged'); - equal(OpenSeadragon.getString("Errors"), "", "Handled requesting parent key"); - ok(testLog.log.contains('["Untranslated source string:","Errors"]'), + assert.equal(OpenSeadragon.getString("Errors"), "", "Handled requesting parent key"); + assert.ok(testLog.log.contains('["Untranslated source string:","Errors"]'), 'Invalid string parent keys are logged'); }); - test("setString", function() { + QUnit.test("setString", function(assert) { OpenSeadragon.setString("Greeting", "Hello world"); - equal(OpenSeadragon.getString("Greeting"), "Hello world", + assert.equal(OpenSeadragon.getString("Greeting"), "Hello world", "Set a string"); }); - test("setSubString", function() { + QUnit.test("setSubString", function(assert) { OpenSeadragon.setString("CustomGreeting.Hello", "Hello world"); - equal(OpenSeadragon.getString("CustomGreeting.Hello"), "Hello world", + assert.equal(OpenSeadragon.getString("CustomGreeting.Hello"), "Hello world", "Set a sub-string"); }); diff --git a/test/modules/tilecache.js b/test/modules/tilecache.js index ba89b73a..65fbf431 100644 --- a/test/modules/tilecache.js +++ b/test/modules/tilecache.js @@ -1,18 +1,20 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, testLog */ (function() { // ---------- - module('TileCache', { - setup: function () { + QUnit.module('TileCache', { + beforeEach: function () { testLog.reset(); }, - teardown: function () { + afterEach: function () { } }); // ---------- - asyncTest('basics', function() { + // TODO: this used to be async + QUnit.test('basics', function(assert) { + var done = assert.async(); var fakeViewer = { raiseEvent: function() {} }; @@ -38,35 +40,36 @@ }; var cache = new OpenSeadragon.TileCache(); - equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); cache.cacheTile({ tile: fakeTile0, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 1, 'tile count after cache'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after cache'); cache.cacheTile({ tile: fakeTile1, tiledImage: fakeTiledImage1 }); - equal(cache.numTilesLoaded(), 2, 'tile count after second cache'); + assert.equal(cache.numTilesLoaded(), 2, 'tile count after second cache'); cache.clearTilesFor(fakeTiledImage0); - equal(cache.numTilesLoaded(), 1, 'tile count after first clear'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after first clear'); cache.clearTilesFor(fakeTiledImage1); - equal(cache.numTilesLoaded(), 0, 'tile count after second clear'); + assert.equal(cache.numTilesLoaded(), 0, 'tile count after second clear'); - start(); + done(); }); // ---------- - asyncTest('maxImageCacheCount', function() { + QUnit.test('maxImageCacheCount', function(assert) { + var done = assert.async(); var fakeViewer = { raiseEvent: function() {} }; @@ -99,30 +102,30 @@ maxImageCacheCount: 1 }); - equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); cache.cacheTile({ tile: fakeTile0, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 1, 'tile count after add'); + assert.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'); + assert.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'); + assert.equal(cache.numTilesLoaded(), 2, 'tile count after additional same image'); - start(); + done(); }); })(); diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index b2206341..0fce1dc7 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual */ +/* global QUnit, $, Util, testLog */ (function() { var viewer; - module('TiledImage', { - setup: function() { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('TiledImage', { + beforeEach: function() { + $('
').appendTo("#qunit-fixture"); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function() { + afterEach: function() { if (viewer && viewer.close) { viewer.close(); } @@ -25,39 +25,40 @@ }); // ---------- - var checkBounds = function(image, expected, message) { + var checkBounds = function(assert, 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'); + assert.equal(bounds.x, expected.x, message + ' x'); + assert.equal(bounds.y, expected.y, message + ' y'); + assert.equal(bounds.width, expected.width, message + ' width'); + assert.equal(bounds.height, expected.height, message + ' height'); }; // ---------- - asyncTest('metrics', function() { + QUnit.test('metrics', function(assert) { + var done = assert.async(); 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'); + assert.equal(contentSize.x, 500, 'contentSize.x'); + assert.equal(contentSize.y, 2000, 'contentSize.y'); - checkBounds(image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); + checkBounds(assert, image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); var scale = image.getContentSize().x / image.getBounds().width; var viewportPoint = new OpenSeadragon.Point(10, 11); var imagePoint = viewportPoint.minus(image.getBounds().getTopLeft()).times(scale); - propEqual(image.viewportToImageCoordinates(viewportPoint), imagePoint, 'viewportToImageCoordinates'); - propEqual(image.imageToViewportCoordinates(imagePoint), viewportPoint, 'imageToViewportCoordinates'); + assert.propEqual(image.viewportToImageCoordinates(viewportPoint), imagePoint, 'viewportToImageCoordinates'); + assert.propEqual(image.imageToViewportCoordinates(imagePoint), viewportPoint, 'imageToViewportCoordinates'); var viewportRect = new OpenSeadragon.Rect(viewportPoint.x, viewportPoint.y, 6, 7); var imageRect = new OpenSeadragon.Rect(imagePoint.x, imagePoint.y, viewportRect.width * scale, viewportRect.height * scale); - propEqual(image.viewportToImageRectangle(viewportRect), imageRect, 'viewportToImageRectangle'); - propEqual(image.imageToViewportRectangle(imageRect), viewportRect, 'imageToViewportRectangle'); + assert.propEqual(image.viewportToImageRectangle(viewportRect), imageRect, 'viewportToImageRectangle'); + assert.propEqual(image.imageToViewportRectangle(imageRect), viewportRect, 'imageToViewportRectangle'); image.addHandler('bounds-change', function boundsChangeHandler(event) { image.removeHandler('bounds-change', boundsChangeHandler); @@ -65,16 +66,16 @@ }); image.setPosition(new OpenSeadragon.Point(7, 8)); - checkBounds(image, new OpenSeadragon.Rect(7, 8, 10, 40), 'bounds after position'); + checkBounds(assert, 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'); + checkBounds(assert, 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'); + checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width'); - equal(handlerCount, 1, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 1, 'correct number of handlers called'); + done(); }); viewer.open({ @@ -86,25 +87,26 @@ }); // ---------- - asyncTest('animation', function() { + QUnit.test('animation', function(assert) { + var done = assert.async(); viewer.addHandler("open", function() { var image = viewer.world.getItemAt(0); - propEqual(image.getBounds(), new OpenSeadragon.Rect(0, 0, 1, 1), 'target bounds on open'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds on open'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(0, 0, 1, 1), 'target bounds on open'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds on open'); image.setPosition(new OpenSeadragon.Point(1, 2)); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 1, 1), 'target bounds after position'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after position'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 1, 1), 'target bounds after position'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after position'); image.setWidth(3); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after width'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after width'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after width'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after width'); viewer.addHandler('animation-finish', function animationHandler() { viewer.removeHandler('animation-finish', animationHandler); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after animation'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(1, 2, 3, 3), 'current bounds after animation'); - start(); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after animation'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(1, 2, 3, 3), 'current bounds after animation'); + done(); }); }); @@ -112,55 +114,56 @@ }); // ---------- - asyncTest('update', function() { + QUnit.test('update', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { var image = viewer.world.getItemAt(0); - equal(image.needsDraw(), true, 'needs draw after open'); + assert.equal(image.needsDraw(), true, 'needs draw 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'); - 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'); - 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'); + assert.equal(event.eventSource, viewer, 'sender of update-level event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok('havedrawn' in event, 'update-level event includes havedrawn'); + assert.ok('level' in event, 'update-level event includes level'); + assert.ok('opacity' in event, 'update-level event includes opacity'); + assert.ok('visibility' in event, 'update-level event includes visibility'); + assert.ok('topleft' in event, 'update-level event includes topleft'); + assert.ok('bottomright' in event, 'update-level event includes bottomright'); + assert.ok('currenttime' in event, 'update-level event includes currenttime'); + assert.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'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - ok(event.tile, 'update-tile event includes tile'); + assert.equal(event.eventSource, viewer, 'sender of update-tile event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'update-tile event includes tile'); }); viewer.addHandler('tile-drawing', function tileDrawingHandler(event) { viewer.removeHandler('tile-drawing', tileDrawingHandler); handlerCount++; - equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - 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'); + 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-drawn', function tileDrawnHandler(event) { 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'); + assert.equal(event.eventSource, viewer, 'sender of tile-drawn event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'tile-drawn event includes tile'); - equal(handlerCount, 4, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 4, 'correct number of handlers called'); + done(); }); image.draw(); @@ -170,49 +173,51 @@ }); // ---------- - asyncTest('reset', function() { + QUnit.test('reset', function(assert) { + var done = assert.async(); viewer.addHandler('tile-drawn', function updateHandler() { viewer.removeHandler('tile-drawn', updateHandler); - ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); + assert.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'); + assert.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'); + assert.ok(viewer.tileCache.numTilesLoaded() > 0, 'more tiles load'); viewer.world.getItemAt(0).destroy(); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after destroy'); - start(); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after destroy'); + done(); }); }); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('clip', function() { + QUnit.test('clip', function(assert) { + var done = assert.async(); var clip = new OpenSeadragon.Rect(100, 100, 800, 800); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); - propEqual(image.getClip(), clip, 'image has correct clip'); + assert.propEqual(image.getClip(), clip, 'image has correct clip'); image.setClip(null); - equal(image.getClip(), null, 'clip is cleared'); + assert.equal(image.getClip(), null, 'clip is cleared'); image.setClip(clip); - propEqual(image.getClip(), clip, 'clip is set correctly'); + assert.propEqual(image.getClip(), clip, 'clip is set correctly'); Util.spyOnce(viewer.drawer, 'setClip', function(rect) { var homeBounds = viewer.viewport.getHomeBounds(); var canvasClip = viewer.drawer .viewportToDrawerRectangle(homeBounds); var precision = 0.00000001; - Util.assertRectangleEquals(rect, canvasClip, precision, + Util.assertRectangleEquals(assert, rect, canvasClip, precision, 'clipping should be ' + canvasClip); - start(); + done(); }); }); @@ -223,15 +228,16 @@ }); // ---------- - asyncTest('clip-change event', function() { - expect(0); + QUnit.test('clip-change event', function(assert) { + var done = assert.async(); + assert.expect(0); var clip = new OpenSeadragon.Rect(100, 100, 800, 800); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); image.addOnceHandler('clip-change', function() { image.addOnceHandler('clip-change', function() { - start(); + done(); }); image.setClip(clip); }); @@ -244,23 +250,24 @@ }); // ---------- - asyncTest('getClipBounds', function() { + QUnit.test('getClipBounds', function(assert) { + var done = assert.async(); var clip = new OpenSeadragon.Rect(100, 200, 800, 500); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); var bounds = image.getClippedBounds(); var expectedBounds = new OpenSeadragon.Rect(1.2, 1.4, 1.6, 1); - propEqual(bounds, expectedBounds, + assert.propEqual(bounds, expectedBounds, 'getClipBounds should take clipping into account.'); image = viewer.world.getItemAt(1); bounds = image.getClippedBounds(); expectedBounds = new OpenSeadragon.Rect(1, 2, 2, 2); - propEqual(bounds, expectedBounds, + assert.propEqual(bounds, expectedBounds, 'getClipBounds should work when no clipping set.'); - start(); + done(); }); viewer.open([{ @@ -278,15 +285,15 @@ }); // ---------- - asyncTest('opacity', function() { - + QUnit.test('opacity', function(assert) { + var done = assert.async(); function testDefaultOpacity() { viewer.removeHandler('open', testDefaultOpacity); var image = viewer.world.getItemAt(0); - strictEqual(image.getOpacity(), 0.5, 'image has default opacity'); + assert.strictEqual(image.getOpacity(), 0.5, 'image has default opacity'); image.setOpacity(1); - strictEqual(image.getOpacity(), 1, 'opacity is set correctly'); + assert.strictEqual(image.getOpacity(), 1, 'opacity is set correctly'); viewer.addHandler('open', testTileSourceOpacity); viewer.open({ @@ -298,12 +305,12 @@ function testTileSourceOpacity() { viewer.removeHandler('open', testTileSourceOpacity); var image = viewer.world.getItemAt(0); - strictEqual(image.getOpacity(), 0.25, 'image has correct opacity'); + assert.strictEqual(image.getOpacity(), 0.25, 'image has correct opacity'); image.setOpacity(0); - strictEqual(image.getOpacity(), 0, 'opacity is set correctly'); + assert.strictEqual(image.getOpacity(), 0, 'opacity is set correctly'); - start(); + done(); } viewer.addHandler('open', testDefaultOpacity); @@ -315,20 +322,20 @@ }); // ---------- - asyncTest('rotation', function() { - + QUnit.test('rotation', function(assert) { + var done = assert.async(); function testDefaultRotation() { var image = viewer.world.getItemAt(0); - strictEqual(image.getRotation(true), 0, 'image has default current rotation'); - strictEqual(image.getRotation(false), 0, 'image has default target rotation'); + assert.strictEqual(image.getRotation(true), 0, 'image has default current rotation'); + assert.strictEqual(image.getRotation(false), 0, 'image has default target rotation'); image.setRotation(400); - strictEqual(image.getRotation(true), 0, 'current rotation is not changed'); - strictEqual(image.getRotation(false), 400, 'target rotation is set correctly'); + assert.strictEqual(image.getRotation(true), 0, 'current rotation is not changed'); + assert.strictEqual(image.getRotation(false), 400, 'target rotation is set correctly'); image.setRotation(200, true); - strictEqual(image.getRotation(true), 200, 'current rotation is set correctly'); - strictEqual(image.getRotation(false), 200, 'target rotation is set correctly'); + assert.strictEqual(image.getRotation(true), 200, 'current rotation is set correctly'); + assert.strictEqual(image.getRotation(false), 200, 'target rotation is set correctly'); viewer.addOnceHandler('open', testTileSourceRotation); viewer.open({ @@ -339,9 +346,9 @@ function testTileSourceRotation() { var image = viewer.world.getItemAt(0); - strictEqual(image.getRotation(true), -60, 'image has correct current rotation'); - strictEqual(image.getRotation(false), -60, 'image has correct target rotation'); - start(); + assert.strictEqual(image.getRotation(true), -60, 'image has correct current rotation'); + assert.strictEqual(image.getRotation(false), -60, 'image has correct target rotation'); + done(); } viewer.addOnceHandler('open', testDefaultRotation); @@ -350,10 +357,10 @@ }); }); - asyncTest('fitBounds', function() { - + QUnit.test('fitBounds', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -386,7 +393,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(0, 1.75, 1, 0.25); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([ @@ -397,10 +404,10 @@ }); // ---------- - asyncTest('fitBounds in constructor', function() { - + QUnit.test('fitBounds in constructor', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -421,7 +428,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(0, 1.75, 1, 0.25); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([{ @@ -443,10 +450,10 @@ }); // ---------- - asyncTest('fitBounds with clipping', function() { - + QUnit.test('fitBounds with clipping', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -467,7 +474,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(1, 1, 16, 4); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([{ @@ -488,27 +495,28 @@ }); // ---------- - asyncTest('fullyLoaded', function() { + QUnit.test('fullyLoaded', function(assert) { + var done = assert.async(); viewer.addHandler('open', function openHandler() { viewer.removeHandler('open', openHandler); var image = viewer.world.getItemAt(0); - equal(image.getFullyLoaded(), false, 'not fully loaded at first'); + assert.equal(image.getFullyLoaded(), false, 'not fully loaded at first'); var count = 0; var fullyLoadedChangeHandler = function(event) { if (count === 0) { - equal(event.fullyLoaded, true, 'event includes true fullyLoaded property'); - equal(image.getFullyLoaded(), true, 'image is fully loaded after event'); + assert.equal(event.fullyLoaded, true, 'event includes true fullyLoaded property'); + assert.equal(image.getFullyLoaded(), true, 'image is fully loaded after event'); viewer.viewport.zoomBy(5, null, true); } else if (count === 1) { - equal(event.fullyLoaded, false, 'event includes false fullyLoaded property'); - equal(image.getFullyLoaded(), false, 'image is not fully loaded after zoom'); + assert.equal(event.fullyLoaded, false, 'event includes false fullyLoaded property'); + assert.equal(image.getFullyLoaded(), false, 'image is not fully loaded after zoom'); } else { image.removeHandler('fully-loaded-change', fullyLoadedChangeHandler); - equal(image.getFullyLoaded(), true, 'image is once again fully loaded'); - start(); + assert.equal(image.getFullyLoaded(), true, 'image is once again fully loaded'); + done(); } count++; @@ -529,7 +537,7 @@ }; } - test('_getCornerTiles without wrapping', function() { + QUnit.test('_getCornerTiles without wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: false, wrapVertical: false, @@ -548,10 +556,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -561,7 +569,7 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 6) - ) + ); // Floating point errors should be handled assertCornerTiles( @@ -569,17 +577,17 @@ new OpenSeadragon.Point(1 + 1e-14, 10 / 15 + 1e-14), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0.3, 0.5), new OpenSeadragon.Point(0.5, 0.6), new OpenSeadragon.Point(2, 5), new OpenSeadragon.Point(3, 6) - ) + ); }); - test('_getCornerTiles with horizontal wrapping', function() { + QUnit.test('_getCornerTiles with horizontal wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: true, wrapVertical: false, @@ -598,10 +606,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -611,24 +619,24 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(8, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(-1, 0), new OpenSeadragon.Point(0.5, 10 / 15 + 1e-14), new OpenSeadragon.Point(-8, 0), new OpenSeadragon.Point(3, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(1.3, 0.5), new OpenSeadragon.Point(1.5, 0.6), new OpenSeadragon.Point(10, 5), new OpenSeadragon.Point(11, 6) - ) + ); }); - test('_getCornerTiles with vertical wrapping', function() { + QUnit.test('_getCornerTiles with vertical wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: false, wrapVertical: true, @@ -647,10 +655,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -660,21 +668,21 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 7) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0, -10 / 15 / 2), new OpenSeadragon.Point(0.5, 0.5), new OpenSeadragon.Point(0, -4), new OpenSeadragon.Point(3, 5) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0, 10 / 15 + 0.1), new OpenSeadragon.Point(0.3, 10 / 15 + 0.3), new OpenSeadragon.Point(0, 7), new OpenSeadragon.Point(2, 9) - ) + ); }); })(); diff --git a/test/modules/tilesource.js b/test/modules/tilesource.js index bac637c8..10262d6f 100644 --- a/test/modules/tilesource.js +++ b/test/modules/tilesource.js @@ -1,33 +1,33 @@ -/* global module, ok, equal, start, test, testLog, Util */ +/* global QUnit, testLog, Util */ (function() { - module('TileSource', { - setup: function() { + QUnit.module('TileSource', { + beforeEach: function() { testLog.reset(); } }); - test("should set sane tile size defaults", function() { + QUnit.test("should set sane tile size defaults", function(assert) { var source = new OpenSeadragon.TileSource(); - equal(source.getTileWidth(), 0, "getTileWidth() should return 0 if not provided a size"); - equal(source.getTileHeight(), 0, "getTileHeight() should return 0 if not provided a size"); + assert.equal(source.getTileWidth(), 0, "getTileWidth() should return 0 if not provided a size"); + assert.equal(source.getTileHeight(), 0, "getTileHeight() should return 0 if not provided a size"); }); - test("providing tileSize", function(){ + QUnit.test("providing tileSize", function(assert){ var tileSize = 256, source = new OpenSeadragon.TileSource({ tileSize: tileSize }); - equal(source.tileSize, undefined, "tileSize should not be set on the tileSource"); - equal(source.getTileWidth(), tileSize, "getTileWidth() should equal tileSize"); - equal(source.getTileHeight(), tileSize, "getTileHeight() should equal tileSize"); + assert.equal(source.tileSize, undefined, "tileSize should not be set on the tileSource"); + assert.equal(source.getTileWidth(), tileSize, "getTileWidth() should equal tileSize"); + assert.equal(source.getTileHeight(), tileSize, "getTileHeight() should equal tileSize"); }); - test("providing tileWidth and tileHeight", function(){ + QUnit.test("providing tileWidth and tileHeight", function(assert){ var tileWidth = 256, tileHeight = 512, source = new OpenSeadragon.TileSource({ @@ -35,20 +35,20 @@ tileHeight: tileHeight }); - equal(source._tileWidth, tileWidth, "tileWidth option should set _tileWidth"); - equal(source._tileHeight, tileHeight, "tileHeight option should set _tileHeight"); - equal(source.tileWidth, undefined, "tileWidth should be renamed _tileWidth"); - equal(source.tileHeight, undefined, "tileHeight should be renamed _tileHeight"); - equal(source.getTileWidth(), tileWidth, "getTileWidth() should equal tileWidth"); - equal(source.getTileHeight(), tileHeight, "getTileHeight() should equal tileHeight"); + assert.equal(source._tileWidth, tileWidth, "tileWidth option should set _tileWidth"); + assert.equal(source._tileHeight, tileHeight, "tileHeight option should set _tileHeight"); + assert.equal(source.tileWidth, undefined, "tileWidth should be renamed _tileWidth"); + assert.equal(source.tileHeight, undefined, "tileHeight should be renamed _tileHeight"); + assert.equal(source.getTileWidth(), tileWidth, "getTileWidth() should equal tileWidth"); + assert.equal(source.getTileHeight(), tileHeight, "getTileHeight() should equal tileHeight"); }); - test('getTileSize() deprecation', function() { + QUnit.test('getTileSize() deprecation', function(assert) { var source = new OpenSeadragon.TileSource(); - Util.testDeprecation(source, 'getTileSize'); + Util.testDeprecation(assert, source, 'getTileSize'); }); - test('getTileAtPoint', function() { + QUnit.test('getTileAtPoint', function(assert) { var tileSource = new OpenSeadragon.TileSource({ width: 1500, height: 1000, @@ -57,11 +57,11 @@ tileOverlap: 1, }); - equal(tileSource.maxLevel, 11, "The max level should be 11."); + assert.equal(tileSource.maxLevel, 11, "The max level should be 11."); function assertTileAtPoint(level, position, expected) { var actual = tileSource.getTileAtPoint(level, position); - ok(actual.equals(expected), "The tile at level " + level + + assert.ok(actual.equals(expected), "The tile at level " + level + ", position " + position.toString() + " should be tile " + expected.toString() + " got " + actual.toString()); diff --git a/test/modules/tilesourcecollection.js b/test/modules/tilesourcecollection.js index a9bbf79e..8a4aa617 100644 --- a/test/modules/tilesourcecollection.js +++ b/test/modules/tilesourcecollection.js @@ -1,20 +1,19 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, Util, testLog */ (function() { - var viewer; - - module('TileSourceCollection', { - setup: function () { + QUnit.module('TileSourceCollection', { + beforeEach: function () { testLog.reset(); }, - teardown: function () { + afterEach: function () { } }); // ---------- - asyncTest('deprecation', function() { - Util.testDeprecation(OpenSeadragon, 'TileSourceCollection'); - start(); + QUnit.test('deprecation', function(assert) { + var done = assert.async(); + Util.testDeprecation(assert, OpenSeadragon, 'TileSourceCollection'); + done(); }); })(); diff --git a/test/modules/units.js b/test/modules/units.js index d4d95b08..6d0bc74d 100644 --- a/test/modules/units.js +++ b/test/modules/units.js @@ -1,12 +1,12 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, Util, testLog */ (function () { var viewer; var precision = 0.00000001; - module('Units', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('Units', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); @@ -16,7 +16,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -26,62 +26,62 @@ }); - function pointEqual(a, b, message) { - Util.assessNumericValue(a.x, b.x, precision, message); - Util.assessNumericValue(a.y, b.y, precision, message); + function pointEqual(assert, a, b, message) { + Util.assessNumericValue(assert, a.x, b.x, precision, message); + Util.assessNumericValue(assert, a.y, b.y, precision, message); } // Check that f^-1 ( f(x) ) = x - function checkPoint(context) { + function checkPoint(assert, context) { var viewport = viewer.viewport; var point = new OpenSeadragon.Point(15, 12); var result = viewport.viewerElementToImageCoordinates( viewport.imageToViewerElementCoordinates(point)); - pointEqual(result, point, 'viewerElement and image ' + context); + pointEqual(assert, result, point, 'viewerElement and image ' + context); result = viewport.windowToImageCoordinates( viewport.imageToWindowCoordinates(point)); - pointEqual(result, point, 'window and image ' + context); + pointEqual(assert, result, point, 'window and image ' + context); result = viewport.viewerElementToViewportCoordinates( viewport.viewportToViewerElementCoordinates(point)); - pointEqual(result, point, 'viewerElement and viewport ' + context); + pointEqual(assert, result, point, 'viewerElement and viewport ' + context); result = viewport.windowToViewportCoordinates( viewport.viewportToWindowCoordinates(point)); - pointEqual(result, point, 'window and viewport ' + context); + pointEqual(assert, result, point, 'window and viewport ' + context); for (var i = 0; i < viewer.world.getItemCount(); i++) { var tiledImage = viewer.world.getItemAt(i); result = tiledImage.viewportToImageCoordinates( tiledImage.imageToViewportCoordinates(point)); - pointEqual(result, point, 'viewport and tiled image ' + i + context); + pointEqual(assert, result, point, 'viewport and tiled image ' + i + context); result = tiledImage.viewerElementToImageCoordinates( tiledImage.imageToViewerElementCoordinates(point)); - pointEqual(result, point, 'viewerElement and tiled image ' + i + context); + pointEqual(assert, result, point, 'viewerElement and tiled image ' + i + context); result = tiledImage.windowToImageCoordinates( tiledImage.imageToWindowCoordinates(point)); - pointEqual(result, point, 'window and tiled image ' + i + context); + pointEqual(assert, result, point, 'window and tiled image ' + i + context); } } // ---------- - asyncTest('Single image coordinates conversions', function () { - + QUnit.test('Single image coordinates conversions', function (assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; var tiledImage = viewer.world.getItemAt(0); var point0_0 = new OpenSeadragon.Point(0, 0); var point = viewport.viewerElementToViewportCoordinates(point0_0); - pointEqual(point, point0_0, 'When opening, viewer coordinate 0,0 is also point 0,0'); + pointEqual(assert, point, point0_0, 'When opening, viewer coordinate 0,0 is also point 0,0'); var viewportPixel = viewport.viewerElementToImageCoordinates(point0_0); - pointEqual(viewportPixel, point0_0, 'When opening, viewer coordinate 0,0 is also viewport pixel 0,0'); + pointEqual(assert, viewportPixel, point0_0, 'When opening, viewer coordinate 0,0 is also viewport pixel 0,0'); var imagePixel = tiledImage.viewerElementToImageCoordinates(point0_0); - pointEqual(imagePixel, point0_0, 'When opening, viewer coordinate 0,0 is also image pixel 0,0'); + pointEqual(assert, imagePixel, point0_0, 'When opening, viewer coordinate 0,0 is also image pixel 0,0'); var viewerWidth = $(viewer.element).width(); var imageWidth = viewer.source.dimensions.x; @@ -90,17 +90,17 @@ var imageTopRight = new OpenSeadragon.Point(imageWidth, 0); point = viewport.viewerElementToViewportCoordinates(viewerTopRight); - pointEqual(point, point1_0, 'Viewer top right has viewport coordinates 1,0.'); + pointEqual(assert, point, point1_0, 'Viewer top right has viewport coordinates 1,0.'); viewportPixel = viewport.viewerElementToImageCoordinates(viewerTopRight); - pointEqual(viewportPixel, imageTopRight, 'Viewer top right has viewport pixel coordinates imageWidth,0.'); + pointEqual(assert, viewportPixel, imageTopRight, 'Viewer top right has viewport pixel coordinates imageWidth,0.'); imagePixel = tiledImage.viewerElementToImageCoordinates(viewerTopRight); - pointEqual(imagePixel, imageTopRight, 'Viewer top right has image pixel coordinates imageWidth,0.'); + pointEqual(assert, imagePixel, imageTopRight, 'Viewer top right has image pixel coordinates imageWidth,0.'); - checkPoint(' after opening'); + checkPoint(assert, ' after opening'); viewer.addHandler('animation-finish', function animationHandler() { viewer.removeHandler('animation-finish', animationHandler); - checkPoint(' after zoom and pan'); - start(); + checkPoint(assert, ' after zoom and pan'); + done(); }); viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2)); }); @@ -109,8 +109,8 @@ // --------- - asyncTest('Multiple images coordinates conversion', function () { - + QUnit.test('Multiple images coordinates conversion', function (assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; var tiledImage1 = viewer.world.getItemAt(0); @@ -120,11 +120,11 @@ var point0_0 = new OpenSeadragon.Point(0, 0); var point = viewport.viewerElementToViewportCoordinates(point0_0); - pointEqual(point, point0_0, 'When opening, viewer coordinate 0,0 is also point 0,0'); + pointEqual(assert, point, point0_0, 'When opening, viewer coordinate 0,0 is also point 0,0'); var image1Pixel = tiledImage1.viewerElementToImageCoordinates(point0_0); - pointEqual(image1Pixel, point0_0, 'When opening, viewer coordinate 0,0 is also image 1 pixel 0,0'); + pointEqual(assert, image1Pixel, point0_0, 'When opening, viewer coordinate 0,0 is also image 1 pixel 0,0'); var image2Pixel = tiledImage2.viewerElementToImageCoordinates(point0_0); - pointEqual(image2Pixel, + pointEqual(assert, image2Pixel, new OpenSeadragon.Point(-2 * imageWidth, -2 * imageHeight), 'When opening, viewer coordinates 0,0 is also image 2 pixel -2*imageWidth, -2*imageHeight'); @@ -133,23 +133,23 @@ var viewerBottomRight = new OpenSeadragon.Point(viewerWidth, viewerHeight); point = viewport.viewerElementToViewportCoordinates(viewerBottomRight); - pointEqual(point, new OpenSeadragon.Point(1.5, 1.5), + pointEqual(assert, point, new OpenSeadragon.Point(1.5, 1.5), 'Viewer bottom right has viewport coordinates 1.5,1.5.'); image1Pixel = tiledImage1.viewerElementToImageCoordinates(viewerBottomRight); - pointEqual(image1Pixel, + pointEqual(assert, image1Pixel, new OpenSeadragon.Point(imageWidth * 1.5, imageHeight * 1.5), 'Viewer bottom right has image 1 pixel coordinates imageWidth * 1.5, imageHeight * 1.5'); image2Pixel = tiledImage2.viewerElementToImageCoordinates(viewerBottomRight); - pointEqual(image2Pixel, + pointEqual(assert, image2Pixel, new OpenSeadragon.Point(imageWidth, imageHeight), 'Viewer bottom right has image 2 pixel coordinates imageWidth,imageHeight.'); - checkPoint(' after opening'); + checkPoint(assert, ' after opening'); viewer.addHandler('animation-finish', function animationHandler() { viewer.removeHandler('animation-finish', animationHandler); - checkPoint(' after zoom and pan'); - start(); + checkPoint(assert, ' after zoom and pan'); + done(); }); viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2)); }); @@ -167,8 +167,8 @@ // --------- - asyncTest('Multiple images coordinates conversion with viewport rotation', function () { - + QUnit.test('Multiple images coordinates conversion with viewport rotation', function (assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; var tiledImage1 = viewer.world.getItemAt(0); @@ -183,35 +183,35 @@ var point0_0 = new OpenSeadragon.Point(0, 0); var point = viewport.viewerElementToViewportCoordinates(viewerMiddleTop); - pointEqual(point, point0_0, 'When opening, viewer middle top is also viewport 0,0'); + pointEqual(assert, point, point0_0, 'When opening, viewer middle top is also viewport 0,0'); var image1Pixel = tiledImage1.viewerElementToImageCoordinates(viewerMiddleTop); - pointEqual(image1Pixel, point0_0, 'When opening, viewer middle top is also image 1 pixel 0,0'); + pointEqual(assert, image1Pixel, point0_0, 'When opening, viewer middle top is also image 1 pixel 0,0'); var image2Pixel = tiledImage2.viewerElementToImageCoordinates(viewerMiddleTop); - pointEqual(image2Pixel, + pointEqual(assert, image2Pixel, new OpenSeadragon.Point(-2 * imageWidth, -2 * imageHeight), 'When opening, viewer middle top is also image 2 pixel -2*imageWidth, -2*imageHeight'); point = viewport.viewerElementToViewportCoordinates(viewerMiddleBottom); - pointEqual(point, new OpenSeadragon.Point(1.5, 1.5), + pointEqual(assert, point, new OpenSeadragon.Point(1.5, 1.5), 'Viewer middle bottom has viewport coordinates 1.5,1.5.'); image1Pixel = tiledImage1.viewerElementToImageCoordinates(viewerMiddleBottom); - pointEqual(image1Pixel, + pointEqual(assert, image1Pixel, new OpenSeadragon.Point(imageWidth * 1.5, imageHeight * 1.5), 'Viewer middle bottom has image 1 pixel coordinates imageWidth * 1.5, imageHeight * 1.5'); image2Pixel = tiledImage2.viewerElementToImageCoordinates(viewerMiddleBottom); - pointEqual(image2Pixel, + pointEqual(assert, image2Pixel, new OpenSeadragon.Point(imageWidth, imageHeight), 'Viewer middle bottom has image 2 pixel coordinates imageWidth,imageHeight.'); - checkPoint(' after opening'); + checkPoint(assert, ' after opening'); viewer.addHandler('animation-finish', function animationHandler() { viewer.removeHandler('animation-finish', animationHandler); - checkPoint(' after zoom and pan'); + checkPoint(assert, ' after zoom and pan'); //Restore rotation viewer.viewport.setRotation(0); - start(); + done(); }); viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2)); }); @@ -229,7 +229,8 @@ }); // ---------- - asyncTest('ZoomRatio 1 image', function () { + QUnit.test('ZoomRatio 1 image', function (assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; @@ -249,10 +250,10 @@ var expectedViewportZoom = viewport.getZoom(true); var actualImageZoom = viewport.viewportToImageZoom( expectedViewportZoom); - Util.assessNumericValue(actualImageZoom, expectedImageZoom, precision); + Util.assessNumericValue(assert, actualImageZoom, expectedImageZoom, precision); var actualViewportZoom = viewport.imageToViewportZoom(actualImageZoom); - Util.assessNumericValue(actualViewportZoom, expectedViewportZoom, precision); + Util.assessNumericValue(assert, actualViewportZoom, expectedViewportZoom, precision); } checkZoom(); @@ -260,7 +261,7 @@ var zoomHandler = function () { viewer.removeHandler('animation-finish', zoomHandler); checkZoom(); - start(); + done(); }; viewer.addHandler('animation-finish', zoomHandler); @@ -271,7 +272,8 @@ }); // ---------- - asyncTest('ZoomRatio 2 images', function () { + QUnit.test('ZoomRatio 2 images', function (assert) { + var done = assert.async(); viewer.addHandler("open", function () { var viewport = viewer.viewport; @@ -294,12 +296,12 @@ var expectedViewportZoom = viewport.getZoom(true); var actualImageZoom = image.viewportToImageZoom( expectedViewportZoom); - Util.assessNumericValue(actualImageZoom, expectedImageZoom, + Util.assessNumericValue(assert, actualImageZoom, expectedImageZoom, precision); var actualViewportImage1Zoom = image.imageToViewportZoom(actualImageZoom); Util.assessNumericValue( - actualViewportImage1Zoom, expectedViewportZoom, precision); + assert, actualViewportImage1Zoom, expectedViewportZoom, precision); } checkZoom(image1); @@ -309,7 +311,7 @@ viewer.removeHandler('animation-finish', zoomHandler); checkZoom(image1); checkZoom(image2); - start(); + done(); }; viewer.addHandler('animation-finish', zoomHandler); diff --git a/test/modules/utils.js b/test/modules/utils.js index 92538375..8fbc1737 100644 --- a/test/modules/utils.js +++ b/test/modules/utils.js @@ -1,133 +1,134 @@ -/* global module, asyncTest, $, ok, equal, strictEqual, notEqual, start, test, Util, testLog */ +/* global QUnit, Util */ (function() { - module("utils"); + QUnit.module("utils"); // ---------- - test("addRemoveClass", function() { + QUnit.test("addRemoveClass", function(assert) { var div = OpenSeadragon.makeNeutralElement('div'); - strictEqual(div.className, '', + assert.strictEqual(div.className, '', "makeNeutralElement set no classes"); OpenSeadragon.addClass(div, 'foo'); - strictEqual(div.className, 'foo', + assert.strictEqual(div.className, 'foo', "Added first class"); OpenSeadragon.addClass(div, 'bar'); - strictEqual(div.className, 'foo bar', + assert.strictEqual(div.className, 'foo bar', "Added second class"); OpenSeadragon.addClass(div, 'baz'); - strictEqual(div.className, 'foo bar baz', + assert.strictEqual(div.className, 'foo bar baz', "Added third class"); OpenSeadragon.addClass(div, 'plugh'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Added fourth class"); OpenSeadragon.addClass(div, 'foo'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Re-added first class"); OpenSeadragon.addClass(div, 'bar'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Re-added middle class"); OpenSeadragon.addClass(div, 'plugh'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Re-added last class"); OpenSeadragon.removeClass(div, 'xyzzy'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Removed nonexistent class"); OpenSeadragon.removeClass(div, 'ba'); - strictEqual(div.className, 'foo bar baz plugh', + assert.strictEqual(div.className, 'foo bar baz plugh', "Removed nonexistent class with existent substring"); OpenSeadragon.removeClass(div, 'bar'); - strictEqual(div.className, 'foo baz plugh', + assert.strictEqual(div.className, 'foo baz plugh', "Removed middle class"); OpenSeadragon.removeClass(div, 'plugh'); - strictEqual(div.className, 'foo baz', + assert.strictEqual(div.className, 'foo baz', "Removed last class"); OpenSeadragon.removeClass(div, 'foo'); - strictEqual(div.className, 'baz', + assert.strictEqual(div.className, 'baz', "Removed first class"); OpenSeadragon.removeClass(div, 'baz'); - strictEqual(div.className, '', + assert.strictEqual(div.className, '', "Removed only class"); }); // ---------- - asyncTest("makeAjaxRequest", function() { - var timeWatcher = Util.timeWatcher(); + QUnit.test("makeAjaxRequest", function(assert) { + var timeWatcher = Util.timeWatcher(assert); OpenSeadragon.makeAjaxRequest('data/testpattern.dzi', function(xhr) { - equal(xhr.status, 200, 'Success callback called for HTTP 200'); - ok(/deepzoom/.test(xhr.responseText), 'Success function called'); + assert.equal(xhr.status, 200, 'Success callback called for HTTP 200'); + assert.ok(/deepzoom/.test(xhr.responseText), 'Success function called'); timeWatcher.done(); }, function(xhr) { - ok(false, 'Error callback should not be called'); + assert.ok(false, 'Error callback should not be called'); timeWatcher.done(); } ); }); - asyncTest("makeAjaxRequest for invalid file", function() { - var timeWatcher = Util.timeWatcher(); + QUnit.test("makeAjaxRequest for invalid file", function(assert) { + var timeWatcher = Util.timeWatcher(assert); OpenSeadragon.makeAjaxRequest('not-a-real-dzi-file', function(xhr) { - ok(false, 'Success function should not be called for errors'); + assert.ok(false, 'Success function should not be called for errors'); timeWatcher.done(); }, function(xhr) { - equal(xhr.status, 404, 'Error callback called for HTTP 404'); - ok(true, 'Error function should be called for errors'); + assert.equal(xhr.status, 404, 'Error callback called for HTTP 404'); + assert.ok(true, 'Error function should be called for errors'); timeWatcher.done(); } ); }); - test("getUrlProtocol", function() { + QUnit.test("getUrlProtocol", function(assert) { - equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol, + assert.equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol, "'test' url protocol should be window.location.protocol"); - equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol, + assert.equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol, "'/test' url protocol should be window.location.protocol"); - equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol, + assert.equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol, "'//test' url protocol should be window.location.protocol"); - equal(OpenSeadragon.getUrlProtocol("http://test"), "http:", + assert.equal(OpenSeadragon.getUrlProtocol("http://test"), "http:", "'http://test' url protocol should be http:"); - equal(OpenSeadragon.getUrlProtocol("https://test"), "https:", + assert.equal(OpenSeadragon.getUrlProtocol("https://test"), "https:", "'https://test' url protocol should be https:"); - equal(OpenSeadragon.getUrlProtocol("file://test"), "file:", + assert.equal(OpenSeadragon.getUrlProtocol("file://test"), "file:", "'file://test' url protocol should be file:"); - equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:", + assert.equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:", "'FTP://test' url protocol should be ftp:"); }); // ---------- - asyncTest("requestAnimationFrame", function() { - var timeWatcher = Util.timeWatcher(); + QUnit.test("requestAnimationFrame", function(assert) { + var timeWatcher = Util.timeWatcher(assert); OpenSeadragon.requestAnimationFrame(function() { - ok(true, 'frame fired'); + assert.ok(true, 'frame fired'); timeWatcher.done(); }); }); // ---------- - asyncTest("cancelAnimationFrame", function() { + QUnit.test("cancelAnimationFrame", function(assert) { + var done = assert.async(); var frameFired = false; setTimeout(function() { - strictEqual(frameFired, false, 'the frame never fired'); - start(); + assert.strictEqual(frameFired, false, 'the frame never fired'); + done(); }, 150); var frameId = OpenSeadragon.requestAnimationFrame(function() { diff --git a/test/modules/viewport.js b/test/modules/viewport.js index 236d4f9c..bebe7d77 100644 --- a/test/modules/viewport.js +++ b/test/modules/viewport.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual, console */ +/* global QUnit, $, Util, testLog, console */ (function () { var viewer; @@ -7,9 +7,9 @@ var SPRING_STIFFNESS = 100; // Faster animation = faster tests var EPSILON = 0.0000000001; - module("viewport", { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module("viewport", { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); @@ -19,7 +19,7 @@ springStiffness: SPRING_STIFFNESS }); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -56,14 +56,15 @@ // Test helper - a lot of these tests loop through a few possible // values for zoom levels, and reopen the viewer for each iteration. - var reopenViewerHelper = function(config) { + var reopenViewerHelper = function(assert, config) { + var done = assert.async(); var expected, level, actual, i = 0; var openHandler = function(event) { var viewport = viewer.viewport; expected = config.processExpected(level, expected); actual = viewport[config.method](); - propEqual( + assert.propEqual( actual, expected, "Test " + config.method + " with zoom level of " + level + ". Expected : " + expected + ", got " + actual @@ -82,7 +83,7 @@ viewer.addOnceHandler('open', openHandler); viewer.open(DZI_PATH); } else { - start(); + done(); } }; level = expected = testZoomLevels[i]; @@ -100,7 +101,8 @@ // Test helper - a lot of these tests loop through a test data // array and test different values. This helper does not reopen the viewer. - var loopingTestHelper = function(config) { + var loopingTestHelper = function(assert, config) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -111,78 +113,91 @@ orig = config.getOrig(config.testArray[i], viewport); expected = config.getExpected(orig, viewport); actual = viewport[config.method](orig); - var assert = config.assert || propEqual; - assert( - actual, - expected, - "Correctly converted coordinates " + orig - ); + if(config.assert) { + config.assert( + assert, + actual, + expected, + "Correctly converted coordinates " + orig + ); + } else { + assert.propEqual( + actual, + expected, + "Correctly converted coordinates " + orig + ); + } + } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }; - function assertPointsEquals(actual, expected, message) { - Util.assertPointsEquals(actual, expected, 1e-15, message); + function assertPointsEquals(assert, actual, expected, message) { + Util.assertPointsEquals(assert, actual, expected, 1e-15, message); } // Tests start here. - asyncTest('getContainerSize', function() { + QUnit.test('getContainerSize', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.zoomTo(ZOOM_FACTOR, null, true); - propEqual(viewport.getContainerSize(), new OpenSeadragon.Point(500, 500), "Test container size"); - start(); + assert.propEqual(viewport.getContainerSize(), new OpenSeadragon.Point(500, 500), "Test container size"); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getAspectRatio', function() { + QUnit.test('getAspectRatio', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.zoomTo(ZOOM_FACTOR, null, true); - equal(viewport.getAspectRatio(), 1, "Test aspect ratio"); - start(); + assert.equal(viewport.getAspectRatio(), 1, "Test aspect ratio"); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getMinZoomDefault', function() { + QUnit.test('getMinZoomDefault', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - equal(viewport.getMinZoom(), 0.9, "Test default min zoom level"); - start(); + assert.equal(viewport.getMinZoom(), 0.9, "Test default min zoom level"); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getMaxZoomDefault', function() { + QUnit.test('getMaxZoomDefault', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - equal(viewport.getMaxZoom(), 2.2, "Test default max zoom level"); - start(); + assert.equal(viewport.getMaxZoom(), 2.2, "Test default max zoom level"); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getMinZoom', function() { - reopenViewerHelper({ + QUnit.test('getMinZoom', function(assert) { + reopenViewerHelper(assert, { property: 'minZoomLevel', method: 'getMinZoom', processExpected: function(level, expected){ @@ -196,8 +211,8 @@ }); }); - asyncTest('getMaxZoom', function() { - reopenViewerHelper({ + QUnit.test('getMaxZoom', function(assert) { + reopenViewerHelper(assert, { property: 'maxZoomLevel', method: 'getMaxZoom', processExpected: function(level, expected) { @@ -212,8 +227,8 @@ }); }); - asyncTest('getHomeBounds', function() { - reopenViewerHelper({ + QUnit.test('getHomeBounds', function(assert) { + reopenViewerHelper(assert, { property: 'defaultZoomLevel', method: 'getHomeBounds', processExpected: function(level, expected) { @@ -224,12 +239,14 @@ }); }); - asyncTest('getHomeBoundsNoRotate with rotation', function() { + QUnit.test('getHomeBoundsNoRotate with rotation', function(assert) { + var done = assert.async(); function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.setRotation(-675); Util.assertRectangleEquals( + assert, viewport.getHomeBoundsNoRotate(), new OpenSeadragon.Rect( (1 - Math.sqrt(2)) / 2, @@ -238,18 +255,20 @@ Math.sqrt(2)), 0.00000001, "Test getHomeBoundsNoRotate with degrees = -675"); - start(); + done(); } viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getHomeBounds with rotation', function() { + QUnit.test('getHomeBounds with rotation', function(assert) { + var done = assert.async(); function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.setRotation(-675); Util.assertRectangleEquals( + assert, viewport.getHomeBounds(), new OpenSeadragon.Rect( 0.5, @@ -259,22 +278,24 @@ 45), 0.00000001, "Test getHomeBounds with degrees = -675"); - start(); + done(); } viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('getHomeBoundsWithMultiImages', function() { + QUnit.test('getHomeBoundsWithMultiImages', function(assert) { + var done = assert.async(); function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; Util.assertRectangleEquals( + assert, new OpenSeadragon.Rect(0, 0, 4, 4), viewport.getHomeBounds(), 0.00000001, "Test getHomeBoundsWithMultiImages"); - start(); + done(); } viewer.addHandler('open', openHandler); viewer.open([{ @@ -290,16 +311,18 @@ }]); }); - asyncTest('getHomeBoundsWithMultiImagesAndClipping', function() { + QUnit.test('getHomeBoundsWithMultiImagesAndClipping', function(assert) { + var done = assert.async(); function openHandler() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; Util.assertRectangleEquals( + assert, new OpenSeadragon.Rect(1, 1, 4, 4), viewport.getHomeBounds(), 0.00000001, "Test getHomeBoundsWithMultiImagesAndClipping"); - start(); + done(); } viewer.addHandler('open', openHandler); viewer.open([{ @@ -316,8 +339,8 @@ }]); }); - asyncTest('getHomeZoom', function() { - reopenViewerHelper({ + QUnit.test('getHomeZoom', function(assert) { + reopenViewerHelper(assert, { property: 'defaultZoomLevel', method: 'getHomeZoom', processExpected: function(level, expected){ @@ -332,13 +355,14 @@ // I don't use the helper for this one because it sets a couple more // properties that would need special casing. - asyncTest('getHomeZoomWithHomeFillsViewer', function() { + QUnit.test('getHomeZoomWithHomeFillsViewer', function(assert) { + var done = assert.async(); var i = 0; var openHandler = function(event) { var viewport = viewer.viewport; viewport.zoomTo(ZOOM_FACTOR, null, true); - equal( + assert.equal( viewport.getHomeZoom(), testZoomLevels[i], "Test getHomeZoom with homeFillsViewer = true and default zoom level of " + testZoomLevels[i] @@ -355,7 +379,7 @@ viewer.addOnceHandler('open', openHandler); viewer.open(TALL_PATH); // use a different image for homeFillsViewer } else { - start(); + done(); } }; viewer = OpenSeadragon({ @@ -369,7 +393,8 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); - asyncTest('resetContentSize', function(){ + QUnit.test('resetContentSize', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -377,19 +402,20 @@ for(var i = 0; i < testRects.length; i++){ var rect = testRects[i].times(viewport.getContainerSize()); viewport.resetContentSize(rect.getSize()); - propEqual( + assert.propEqual( viewport._contentSize, rect.getSize(), "Reset content size correctly." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('goHome', function(){ + QUnit.test('goHome', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -398,18 +424,19 @@ viewport.zoomTo(ZOOM_FACTOR, true); viewport.goHome(true); - propEqual( + assert.propEqual( viewport.getBounds(), viewport.getHomeBounds(), "Went home." ); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('ensureVisible', function() { + QUnit.test('ensureVisible', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -420,14 +447,15 @@ viewport.ensureVisible(true); var bounds = viewport.getBounds(); - ok(bounds.getSize().x > 1 && bounds.getSize().y > 1, "Moved viewport so that image is visible."); - start(); + assert.ok(bounds.getSize().x > 1 && bounds.getSize().y > 1, "Moved viewport so that image is visible."); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('applyConstraints', function() { + QUnit.test('applyConstraints', function(assert) { + var done = assert.async(); var openHandler = function() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -437,17 +465,19 @@ viewport.applyConstraints(true); var bounds = viewport.getBounds(); Util.assertRectangleEquals( + assert, new OpenSeadragon.Rect(0.7, 0.7, 1, 1), bounds, EPSILON, "Viewport.applyConstraints should move viewport."); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('applyConstraints with visibilityRatio = 1 shouldn\'t bounce around', function() { + QUnit.test('applyConstraints with visibilityRatio = 1 shouldn\'t bounce around', function(assert) { + var done = assert.async(); var openHandler = function() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -458,17 +488,19 @@ viewport.applyConstraints(true); var bounds = viewport.getBounds(); Util.assertRectangleEquals( + assert, new OpenSeadragon.Rect(-0.5, 1, 2, 2), bounds, EPSILON, "Viewport.applyConstraints should move viewport to the center, not to a side."); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(TALL_PATH); }); - asyncTest('applyConstraints with rotation', function() { + QUnit.test('applyConstraints with rotation', function(assert) { + var done = assert.async(); var openHandler = function() { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -477,11 +509,12 @@ viewport.applyConstraints(true); var bounds = viewport.getBounds(); Util.assertRectangleEquals( + assert, bounds, new OpenSeadragon.Rect(1, 0, Math.sqrt(2), Math.sqrt(2), 45), EPSILON, "Viewport.applyConstraints with rotation should move viewport."); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); @@ -545,7 +578,8 @@ new OpenSeadragon.Rect(0.25, 0.25, 0.5, 0.5) ]; - asyncTest('fitBounds', function(){ + QUnit.test('fitBounds', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -553,19 +587,20 @@ for(var i = 0; i < testRectsFitBounds.length; i++){ var rect = testRectsFitBounds[i]; viewport.fitBounds(rect, true); - propEqual( + assert.propEqual( viewport.getBounds(), expectedRectsFitBounds[i], "Fit bounds correctly." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('fitBounds with viewport rotation', function(){ + QUnit.test('fitBounds with viewport rotation', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -575,19 +610,21 @@ var rect = testRectsFitBounds[i]; viewport.fitBounds(rect, true); Util.assertRectangleEquals( + assert, viewport.getBounds(), expectedRectsFitBoundsWithRotation[i], EPSILON, "Fit bounds correctly." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('fitBoundsWithConstraints', function(){ + QUnit.test('fitBoundsWithConstraints', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -596,90 +633,95 @@ var rect = testRectsFitBounds[i]; viewport.fitBoundsWithConstraints(rect, true); - propEqual( + assert.propEqual( viewport.getBounds(), expectedRectsFitBoundsWithConstraints[i], "Fit bounds correctly." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('fitBounds with almost same zoom', function() { + QUnit.test('fitBounds with almost same zoom', function(assert) { + var done = assert.async(); var openHandler = function() { var viewport = viewer.viewport; var rect1 = new OpenSeadragon.Rect(0, 0, 1, 1); viewport.fitBounds(rect1, true); - Util.assertRectangleEquals(rect1, viewport.getBounds(), 1e-6, + Util.assertRectangleEquals(assert, rect1, viewport.getBounds(), 1e-6, 'Bounds should be ' + rect1); // Zoom and pan var rect2 = new OpenSeadragon.Rect(1, 1, 1 + 1e-8, 1 + 1e-8); viewport.fitBounds(rect2); - Util.assertRectangleEquals(rect2, viewport.getBounds(), 1e-6, + Util.assertRectangleEquals(assert, rect2, viewport.getBounds(), 1e-6, 'Bounds should be ' + rect2); - start(); + done(); }; viewer.addOnceHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('fitBounds with big rectangle', function() { + QUnit.test('fitBounds with big rectangle', function(assert) { + var done = assert.async(); var openHandler = function() { var viewport = viewer.viewport; var rect1 = new OpenSeadragon.Rect(0, 0, 1e9, 1e9); viewport.fitBounds(rect1, true); - Util.assertRectangleEquals(rect1, viewport.getBounds(), 1e-6, + Util.assertRectangleEquals(assert, rect1, viewport.getBounds(), 1e-6, 'Bounds should be ' + rect1); // Zoom and pan var rect2 = new OpenSeadragon.Rect(1, 1, 2e9, 2e9); viewport.fitBounds(rect2); - Util.assertRectangleEquals(rect2, viewport.getBounds(), 1e-6, + Util.assertRectangleEquals(assert, rect2, viewport.getBounds(), 1e-6, 'Bounds should be ' + rect2); - start(); + done(); }; viewer.addOnceHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('fitHorizontally', function(){ + QUnit.test('fitHorizontally', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.fitHorizontally(true); - propEqual( + assert.propEqual( viewport.getBounds(), new OpenSeadragon.Rect(0, 1.5, 1, 1), "Viewport fit a tall image horizontally." ); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(TALL_PATH); }); - asyncTest('fitVertically', function(){ + QUnit.test('fitVertically', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; viewport.fitVertically(true); - propEqual( + assert.propEqual( viewport.getBounds(), new OpenSeadragon.Rect(0.375, 0, 0.25, 0.25), "Viewport fit a wide image vertically." ); - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(WIDE_PATH); }); // End fitBounds tests. - asyncTest('panBy', function(){ + QUnit.test('panBy', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -687,60 +729,63 @@ for (var i = 0; i < testPoints.length; i++){ var expected = viewport.getCenter().plus(testPoints[i]); viewport.panBy(testPoints[i], true); - propEqual( + assert.propEqual( viewport.getCenter(), expected, "Panned by the correct amount." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('panTo', function(){ + QUnit.test('panTo', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; for (var i = 0; i < testPoints.length; i++){ viewport.panTo(testPoints[i], true); - propEqual( + assert.propEqual( viewport.getCenter(), testPoints[i], "Panned to the correct location." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('zoomBy no ref point', function() { + QUnit.test('zoomBy no ref point', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; for (var i = 0; i < testZoomLevels.length; i++) { viewport.zoomBy(testZoomLevels[i], null, true); - propEqual( + assert.propEqual( viewport.getZoom(), testZoomLevels[i], "Zoomed by the correct amount." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('zoomBy with ref point', function() { + QUnit.test('zoomBy with ref point', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -756,12 +801,13 @@ for (var i = 0; i < testZoomLevels.length; i++) { viewport.zoomBy(testZoomLevels[i], testPoints[i], true); - propEqual( + assert.propEqual( viewport.getZoom(), testZoomLevels[i], "Zoomed by the correct amount." ); assertPointsEquals( + assert, viewport.getCenter(), expectedCenters[i], 1e-14, @@ -769,33 +815,35 @@ ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('zoomTo no ref point', function() { + QUnit.test('zoomTo no ref point', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; for (var i = 0; i < testZoomLevels.length; i++) { viewport.zoomTo(testZoomLevels[i], null, true); - propEqual( + assert.propEqual( viewport.getZoom(), testZoomLevels[i], "Zoomed to the correct level." ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('zoomTo with ref point', function() { + QUnit.test('zoomTo with ref point', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -811,12 +859,13 @@ for (var i = 0; i < testZoomLevels.length; i++) { viewport.zoomTo(testZoomLevels[i], testPoints[i], true); - propEqual( + assert.propEqual( viewport.getZoom(), testZoomLevels[i], "Zoomed to the correct level." ); assertPointsEquals( + assert, viewport.getCenter(), expectedCenters[i], 1e-14, @@ -824,30 +873,32 @@ ); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('rotation', function(){ + QUnit.test('rotation', function(assert){ + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees"); + assert.propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees"); viewport.setRotation(90); - propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees"); + assert.propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees"); viewport.setRotation(-75); - propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees"); - start(); + assert.propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees"); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('resize', function() { + QUnit.test('resize', function(assert) { + var done = assert.async(); var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; @@ -855,16 +906,16 @@ for(var i = 0; i < testPoints.length; i++){ var new_size = testPoints[i].times(viewer.source.dimensions.x); viewport.resize(new_size); - propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully."); + assert.propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully."); } - start(); + done(); }; viewer.addHandler('open', openHandler); viewer.open(DZI_PATH); }); - asyncTest('deltaPixelsFromPoints', function() { - loopingTestHelper({ + QUnit.test('deltaPixelsFromPoints', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport){ return el.times(viewer.source.dimensions.x); @@ -876,8 +927,8 @@ }); }); - asyncTest('deltaPointsFromPixels', function() { - loopingTestHelper({ + QUnit.test('deltaPointsFromPixels', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewport.getContainerSize().x); @@ -889,8 +940,8 @@ }); }); - asyncTest('pixelFromPoint', function() { - loopingTestHelper({ + QUnit.test('pixelFromPoint', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -902,8 +953,8 @@ }); }); - asyncTest('pointFromPixel', function() { - loopingTestHelper({ + QUnit.test('pointFromPixel', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewport.getContainerSize().x); @@ -915,8 +966,8 @@ }); }); - asyncTest('viewportToImageCoordinates', function() { - loopingTestHelper({ + QUnit.test('viewportToImageCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewport.getContainerSize().x); @@ -929,8 +980,8 @@ }); }); - asyncTest('imageToViewportCoordinates', function() { - loopingTestHelper({ + QUnit.test('imageToViewportCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -942,8 +993,8 @@ assert: assertPointsEquals }); }); - asyncTest('imageToViewportRectangle', function() { - loopingTestHelper({ + QUnit.test('imageToViewportRectangle', function(assert) { + loopingTestHelper(assert, { testArray: testRects, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -961,8 +1012,8 @@ }); }); - asyncTest('viewportToImageRectangle', function() { - loopingTestHelper({ + QUnit.test('viewportToImageRectangle', function(assert) { + loopingTestHelper(assert, { testArray: testRects, getOrig: function(el, viewport) { return el.times(viewport.getContainerSize().x); @@ -979,8 +1030,8 @@ }); }); - asyncTest('viewerElementToImageCoordinates', function() { - loopingTestHelper({ + QUnit.test('viewerElementToImageCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewport.getContainerSize().x); @@ -992,8 +1043,8 @@ }); }); - asyncTest('imageToViewerElementCoordinates', function() { - loopingTestHelper({ + QUnit.test('imageToViewerElementCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -1005,8 +1056,8 @@ }); }); - asyncTest('windowToImageCoordinates', function() { - loopingTestHelper({ + QUnit.test('windowToImageCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { var window_boundary = Math.min(window.innerWidth, window.innerHeight); @@ -1020,8 +1071,8 @@ }); }); - asyncTest('imageToWindowCoordinates', function() { - loopingTestHelper({ + QUnit.test('imageToWindowCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -1034,8 +1085,8 @@ }); }); - asyncTest('windowToViewportCoordinates', function() { - loopingTestHelper({ + QUnit.test('windowToViewportCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { var window_boundary = Math.min(window.innerWidth, window.innerHeight); @@ -1049,8 +1100,8 @@ }); }); - asyncTest('viewportToWindowCoordinates', function() { - loopingTestHelper({ + QUnit.test('viewportToWindowCoordinates', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el.times(viewer.source.dimensions.x); @@ -1063,8 +1114,8 @@ }); }); - asyncTest('viewportToImageZoom', function() { - loopingTestHelper({ + QUnit.test('viewportToImageZoom', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el; @@ -1076,8 +1127,8 @@ }); }); - asyncTest('imageToViewportZoom', function() { - loopingTestHelper({ + QUnit.test('imageToViewportZoom', function(assert) { + loopingTestHelper(assert, { testArray: testPoints, getOrig: function(el, viewport) { return el; diff --git a/test/modules/world.js b/test/modules/world.js index 0c5aebf7..d524a131 100644 --- a/test/modules/world.js +++ b/test/modules/world.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer; - module('World', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('World', { + beforeEach: function () { + $('
').appendTo("#qunit-fixture"); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -25,54 +25,56 @@ }); // ---------- - var checkBounds = function(expected, message) { + var checkBounds = function(assert, expected, message) { var bounds = viewer.world.getHomeBounds(); - ok(bounds.equals(expected), message + ' ' + bounds.toString()); + assert.ok(bounds.equals(expected), message + ' ' + bounds.toString()); }; // ---------- - asyncTest('adding a tiled image', function() { - ok(viewer.world, 'World exists'); + QUnit.test('adding a tiled image', function(assert) { + var done = assert.async(); + assert.ok(viewer.world, 'World exists'); viewer.world.addHandler('add-item', function(event) { - ok(event, 'add-item handler received event data'); - equal(event.eventSource, viewer.world, 'sender of add-item event was world'); - ok(event.item, 'add-item event includes item'); - equal(viewer.world.getItemCount(), 1, 'there is now 1 item'); - equal(event.item, viewer.world.getItemAt(0), 'item is accessible via getItemAt'); - equal(viewer.world.getIndexOfItem(event.item), 0, 'item index is 0'); - start(); + assert.ok(event, 'add-item handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of add-item event was world'); + assert.ok(event.item, 'add-item event includes item'); + assert.equal(viewer.world.getItemCount(), 1, 'there is now 1 item'); + assert.equal(event.item, viewer.world.getItemAt(0), 'item is accessible via getItemAt'); + assert.equal(viewer.world.getIndexOfItem(event.item), 0, 'item index is 0'); + done(); }); - equal(viewer.world.getItemCount(), 0, 'no items to start with'); + assert.equal(viewer.world.getItemCount(), 0, 'no items to start with'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('metrics', function() { + QUnit.test('metrics', function(assert) { + var done = assert.async(); viewer.addHandler('open', function(event) { - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 4), 'bounds after open'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 4), 'bounds after open'); var expectedContentFactor = viewer.world.getItemAt(1).getContentSize().x / 2; - equal(viewer.world.getContentFactor(), expectedContentFactor, 'content factor has changed'); + assert.equal(viewer.world.getContentFactor(), expectedContentFactor, 'content factor has changed'); viewer.world.addHandler('metrics-change', function metricsChangeHandler(event) { viewer.world.removeHandler('metrics-change', metricsChangeHandler); - ok(event, 'metrics-change handler received event data'); - equal(event.eventSource, viewer.world, 'sender of metrics-change event was world'); - checkBounds(new OpenSeadragon.Rect(0, 0, 7, 12), 'bounds after position'); + assert.ok(event, 'metrics-change handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of metrics-change event was world'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 7, 12), 'bounds after position'); viewer.world.getItemAt(0).setWidth(20); - checkBounds(new OpenSeadragon.Rect(0, 0, 20, 20), 'bounds after size'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 20, 20), 'bounds after size'); - start(); + done(); }); viewer.world.getItemAt(1).setPosition(new OpenSeadragon.Point(5, 10)); }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 1), 'default bounds'); - equal(viewer.world.getContentFactor(), 1, 'default content factor'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 1), 'default bounds'); + assert.equal(viewer.world.getContentFactor(), 1, 'default content factor'); viewer.open([ { @@ -86,23 +88,24 @@ }); // ---------- - asyncTest('remove/reorder tiled images', function() { + QUnit.test('remove/reorder tiled images', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { - equal(viewer.world.getItemCount(), 3, 'there are now 3 items'); + assert.equal(viewer.world.getItemCount(), 3, 'there are now 3 items'); var item0 = viewer.world.getItemAt(0); var item1 = viewer.world.getItemAt(1); viewer.world.addHandler('item-index-change', function(event) { handlerCount++; - ok(event, 'item-index-change handler received event data'); - equal(event.eventSource, viewer.world, 'sender of item-index-change event was world'); - equal(event.item, item0, 'item-index-change event includes correct item'); - equal(event.newIndex, 1, 'item-index-change event includes correct newIndex'); - equal(event.previousIndex, 0, 'item-index-change event includes correct previousIndex'); - equal(viewer.world.getItemAt(0), item1, 'item1 is now at index 0'); - equal(viewer.world.getItemAt(1), item0, 'item0 is now at index 1'); + assert.ok(event, 'item-index-change handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of item-index-change event was world'); + assert.equal(event.item, item0, 'item-index-change event includes correct item'); + assert.equal(event.newIndex, 1, 'item-index-change event includes correct newIndex'); + assert.equal(event.previousIndex, 0, 'item-index-change event includes correct previousIndex'); + assert.equal(viewer.world.getItemAt(0), item1, 'item1 is now at index 0'); + assert.equal(viewer.world.getItemAt(1), item0, 'item0 is now at index 1'); }); viewer.world.setItemIndex(item0, 1); @@ -110,11 +113,11 @@ viewer.world.addHandler('remove-item', function removeHandler(event) { viewer.world.removeHandler('remove-item', removeHandler); handlerCount++; - ok(event, 'remove-item handler received event data'); - equal(event.eventSource, viewer.world, 'sender of remove-item event was world'); - equal(event.item, item1, 'remove-item event includes correct item'); - equal(viewer.world.getItemCount(), 2, 'after removal, only two items remain'); - equal(viewer.world.getItemAt(0), item0, 'item0 is now at index 0'); + assert.ok(event, 'remove-item handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of remove-item event was world'); + assert.equal(event.item, item1, 'remove-item event includes correct item'); + assert.equal(viewer.world.getItemCount(), 2, 'after removal, only two items remain'); + assert.equal(viewer.world.getItemAt(0), item0, 'item0 is now at index 0'); }); viewer.world.removeItem(item1); @@ -124,17 +127,17 @@ removeCount++; if (removeCount === 2) { handlerCount++; - equal(viewer.world.getItemCount(), 0, 'after removeAll, no items remain'); + assert.equal(viewer.world.getItemCount(), 0, 'after removeAll, no items remain'); } }); viewer.world.removeAll(); - equal(handlerCount, 3, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 3, 'correct number of handlers called'); + done(); }); - equal(viewer.world.getItemCount(), 0, 'no items to start with'); + assert.equal(viewer.world.getItemCount(), 0, 'no items to start with'); viewer.open([ '/test/data/testpattern.dzi', @@ -144,11 +147,12 @@ }); // ---------- - asyncTest('draw', function() { + QUnit.test('draw', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { - equal(viewer.world.needsDraw(), true, 'needs draw after open'); + assert.equal(viewer.world.needsDraw(), true, 'needs draw after open'); viewer.addHandler('update-level', function updateHandler() { viewer.removeHandler('update-level', updateHandler); @@ -157,34 +161,36 @@ viewer.world.draw(); - equal(handlerCount, 1, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 1, 'correct number of handlers called'); + done(); }); - equal(viewer.world.needsDraw(), false, 'needs no draw at first'); + assert.equal(viewer.world.needsDraw(), false, 'needs no draw at first'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('resetItems', function() { + QUnit.test('resetItems', function(assert) { + var done = assert.async(); viewer.addHandler('tile-drawn', function updateHandler() { viewer.removeHandler('tile-drawn', updateHandler); - ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); + assert.ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); viewer.world.resetItems(); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); - start(); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); + done(); }); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('arrange', function() { + QUnit.test('arrange', function(assert) { + var done = assert.async(); viewer.addHandler('open', function(event) { - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 1), 'all stacked'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 1), 'all stacked'); viewer.world.arrange({ layout: 'horizontal', @@ -193,7 +199,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 1), 'one horizontal row'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 1), 'one horizontal row'); viewer.world.arrange({ layout: 'horizontal', @@ -202,7 +208,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 2.5, 2.5), 'grid'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 2.5, 2.5), 'grid'); viewer.world.arrange({ layout: 'vertical', @@ -211,7 +217,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 4), 'one vertical column'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 4), 'one vertical column'); viewer.world.arrange({ layout: 'horizontal', @@ -221,7 +227,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 1), 'three horizontal columns (one horizontal row)'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 1), 'three horizontal columns (one horizontal row)'); viewer.world.arrange({ layout: 'vertical', @@ -231,9 +237,9 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 4), 'three vertical rows (one vertical column)'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 4), 'three vertical rows (one vertical column)'); - start(); + done(); }); viewer.open([ diff --git a/test/test.html b/test/test.html index 16e7e54a..786af542 100644 --- a/test/test.html +++ b/test/test.html @@ -44,7 +44,7 @@ -