Testing deprecations

This commit is contained in:
Ian Gilman 2014-11-20 16:02:02 -08:00
parent 68fbdc7beb
commit 36831d3434
7 changed files with 115 additions and 42 deletions

View File

@ -189,25 +189,28 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
// deprecated // deprecated
needsUpdate: function() { needsUpdate: function() {
$.console.error( "[Drawer.needsUpdate] this function is deprecated." ); $.console.error( "[Drawer.needsUpdate] this function is deprecated. Use World.needsUpdate instead." );
return false; return this.viewer.world.needsUpdate();
}, },
// deprecated // deprecated
numTilesLoaded: function() { numTilesLoaded: function() {
$.console.error( "[Drawer.numTilesLoaded] this function is deprecated." ); $.console.error( "[Drawer.numTilesLoaded] this function is deprecated. Use TileCache.numTilesLoaded instead." );
return 0; return this.viewer.tileCache.numTilesLoaded();
}, },
// deprecated // deprecated
reset: function() { 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; return this;
}, },
// deprecated // deprecated
update: function() { 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; return this;
}, },

View File

@ -70,6 +70,8 @@
<script src="/test/modules/drawer.js"></script> <script src="/test/modules/drawer.js"></script>
<script src="/test/modules/tiledimage.js"></script> <script src="/test/modules/tiledimage.js"></script>
<script src="/test/modules/tilecache.js"></script> <script src="/test/modules/tilecache.js"></script>
<script src="/test/modules/referencestrip.js"></script>
<script src="/test/modules/tilesourcecollection.js"></script>
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up) <!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
so we put them last. --> so we put them last. -->
<script src="/test/modules/navigator.js"></script> <script src="/test/modules/navigator.js"></script>

View File

@ -103,6 +103,31 @@
return result; 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);
} }
}; };

View File

@ -28,31 +28,6 @@
}, options)); }, 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() { asyncTest('basics', function() {
createViewer(); createViewer();
@ -111,14 +86,14 @@
// ---------- // ----------
asyncTest('deprecations', function() { asyncTest('deprecations', function() {
createViewer(); createViewer();
testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); Util.testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay');
testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); Util.testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay');
testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); Util.testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay');
testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); Util.testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays');
testDeprecation(viewer.drawer, 'needsUpdate'); Util.testDeprecation(viewer.drawer, 'needsUpdate', viewer.world, 'needsUpdate');
testDeprecation(viewer.drawer, 'numTilesLoaded'); Util.testDeprecation(viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded');
testDeprecation(viewer.drawer, 'reset'); Util.testDeprecation(viewer.drawer, 'reset', viewer.world, 'resetItems');
testDeprecation(viewer.drawer, 'update'); Util.testDeprecation(viewer.drawer, 'update', viewer.world, 'update');
start(); start();
}); });

View File

@ -0,0 +1,46 @@
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
(function() {
var viewer;
module('ReferenceStrip', {
setup: function () {
var example = $('<div id="example"></div>').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();
});
})();

View File

@ -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();
});
})();

View File

@ -35,6 +35,8 @@
<script src="/test/modules/drawer.js"></script> <script src="/test/modules/drawer.js"></script>
<script src="/test/modules/tiledimage.js"></script> <script src="/test/modules/tiledimage.js"></script>
<script src="/test/modules/tilecache.js"></script> <script src="/test/modules/tilecache.js"></script>
<script src="/test/modules/referencestrip.js"></script>
<script src="/test/modules/tilesourcecollection.js"></script>
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up) <!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
so we put them last. --> so we put them last. -->
<script src="/test/modules/navigator.js"></script> <script src="/test/modules/navigator.js"></script>