From 36831d34346fd271db42b88ad60faccdf4732e2d Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 20 Nov 2014 16:02:02 -0800 Subject: [PATCH] Testing deprecations --- src/drawer.js | 21 +++++++------ test/coverage.html | 2 ++ test/helpers/test.js | 25 +++++++++++++++ test/modules/drawer.js | 41 +++++-------------------- test/modules/referencestrip.js | 46 ++++++++++++++++++++++++++++ test/modules/tilesourcecollection.js | 20 ++++++++++++ test/test.html | 2 ++ 7 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 test/modules/referencestrip.js create mode 100644 test/modules/tilesourcecollection.js diff --git a/src/drawer.js b/src/drawer.js index 6099dd06..804f0693 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -129,9 +129,9 @@ $.Drawer = function( options ) { * @memberof OpenSeadragon.Viewer * @type {object} * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.Tile} tile - The Tile being drawn. - * @property {OpenSeadragon.Tile} context - The HTML canvas context being drawn into. - * @property {OpenSeadragon.Tile} rendered - The HTML canvas context containing the tile imagery. + * @property {OpenSeadragon.Tile} tile - The Tile being drawn. + * @property {OpenSeadragon.Tile} context - The HTML canvas context being drawn into. + * @property {OpenSeadragon.Tile} rendered - The HTML canvas context containing the tile imagery. * @property {?Object} userData - Arbitrary subscriber-defined object. */ _this.viewer.raiseEvent('tile-drawing', args); @@ -189,25 +189,28 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{ // deprecated needsUpdate: function() { - $.console.error( "[Drawer.needsUpdate] this function is deprecated." ); - return false; + $.console.error( "[Drawer.needsUpdate] this function is deprecated. Use World.needsUpdate instead." ); + return this.viewer.world.needsUpdate(); }, // deprecated numTilesLoaded: function() { - $.console.error( "[Drawer.numTilesLoaded] this function is deprecated." ); - return 0; + $.console.error( "[Drawer.numTilesLoaded] this function is deprecated. Use TileCache.numTilesLoaded instead." ); + return this.viewer.tileCache.numTilesLoaded(); }, // deprecated reset: function() { - $.console.error( "[Drawer.reset] this function is deprecated." ); + $.console.error( "[Drawer.reset] this function is deprecated. Use World.resetItems instead." ); + this.viewer.world.resetItems(); return this; }, // deprecated update: function() { - $.console.error( "[Drawer.update] this function is deprecated." ); + $.console.error( "[Drawer.update] this function is deprecated. Use Drawer.clear and World.update instead." ); + this.clear(); + this.viewer.world.update(); return this; }, diff --git a/test/coverage.html b/test/coverage.html index 97e1a0c9..c55fd31f 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -70,6 +70,8 @@ + + diff --git a/test/helpers/test.js b/test/helpers/test.js index 389c4763..54a28412 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -103,6 +103,31 @@ return result; }; + }, + + // ---------- + testDeprecation: function(obj0, member0, obj1, member1) { + var called = false; + var errored = false; + + if (obj1 && member1) { + this.spyOnce(obj1, member1, function() { + called = true; + return false; + }); + } else { + called = true; + } + + this.spyOnce(OpenSeadragon.console, 'error', function(message) { + if (/deprecated/.test(message)) { + errored = true; + } + }); + + obj0[member0](); + equal(called, true, 'called through for ' + member0); + equal(errored, true, 'errored for ' + member0); } }; diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 64028637..e024c72e 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -28,31 +28,6 @@ }, options)); }; - // ---------- - var testDeprecation = function(obj0, member0, obj1, member1) { - var called = false; - var errored = false; - - if (obj1 && member1) { - Util.spyOnce(obj1, member1, function() { - called = true; - return false; - }); - } else { - called = true; - } - - Util.spyOnce(OpenSeadragon.console, 'error', function(message) { - if (/deprecated/.test(message)) { - errored = true; - } - }); - - obj0[member0](); - equal(called, true, 'called through for ' + member0); - equal(errored, true, 'errored for ' + member0); - }; - // ---------- asyncTest('basics', function() { createViewer(); @@ -111,14 +86,14 @@ // ---------- asyncTest('deprecations', function() { createViewer(); - testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); - testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); - testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); - testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); - testDeprecation(viewer.drawer, 'needsUpdate'); - testDeprecation(viewer.drawer, 'numTilesLoaded'); - testDeprecation(viewer.drawer, 'reset'); - testDeprecation(viewer.drawer, 'update'); + Util.testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + Util.testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + Util.testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + Util.testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + Util.testDeprecation(viewer.drawer, 'needsUpdate', viewer.world, 'needsUpdate'); + Util.testDeprecation(viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); + Util.testDeprecation(viewer.drawer, 'reset', viewer.world, 'resetItems'); + Util.testDeprecation(viewer.drawer, 'update', viewer.world, 'update'); start(); }); diff --git a/test/modules/referencestrip.js b/test/modules/referencestrip.js new file mode 100644 index 00000000..45130070 --- /dev/null +++ b/test/modules/referencestrip.js @@ -0,0 +1,46 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('ReferenceStrip', { + setup: function () { + var example = $('
').appendTo("#qunit-fixture"); + + testLog.reset(); + }, + teardown: function () { + if (viewer && viewer.close) { + viewer.close(); + } + + viewer = null; + } + }); + + // ---------- + var createViewer = function(options) { + options = options || {}; + viewer = OpenSeadragon(OpenSeadragon.extend({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }, options)); + }; + + // ---------- + asyncTest('basics', function() { + createViewer({ + sequenceMode: true, + showReferenceStrip: true, + tileSources: [ + '/test/data/tall.dzi', + '/test/data/wide.dzi', + ] + }); + + ok(viewer.referenceStrip, 'referenceStrip exists'); + start(); + }); + +})(); diff --git a/test/modules/tilesourcecollection.js b/test/modules/tilesourcecollection.js new file mode 100644 index 00000000..a9bbf79e --- /dev/null +++ b/test/modules/tilesourcecollection.js @@ -0,0 +1,20 @@ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ + +(function() { + var viewer; + + module('TileSourceCollection', { + setup: function () { + testLog.reset(); + }, + teardown: function () { + } + }); + + // ---------- + asyncTest('deprecation', function() { + Util.testDeprecation(OpenSeadragon, 'TileSourceCollection'); + start(); + }); + +})(); diff --git a/test/test.html b/test/test.html index c74148ba..65f0d5b3 100644 --- a/test/test.html +++ b/test/test.html @@ -35,6 +35,8 @@ + +