Clean up TileSource object when provided tileWidth/tileHeight for clarity. Add basic TileSource tests.

This commit is contained in:
Conner Wingard 2015-07-14 14:49:52 -04:00
parent df7bd2e5ce
commit e1e345a4bc
3 changed files with 73 additions and 6 deletions

View File

@ -191,11 +191,26 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
( options.width / options.height ) : 1;
this.dimensions = new $.Point( options.width, options.height );
if ( options.tileSize ){
this._tileWidth = this._tileHeight = options.tileSize;
if ( this.tileSize ){
this._tileWidth = this._tileHeight = this.tileSize;
delete this.tileSize;
} else {
this._tileWidth = options.tileWidth ? options.tileWidth : 0;
this._tileHeight = options.tileHeight ? options.tileHeight: 0;
if( this.tileWidth ){
// We were passed tileWidth in options, but we want to rename it
// with a leading underscore to make clear that it is not safe to directly modify it
this._tileWidth = this.tileWidth;
delete this.tileWidth;
} else {
this._tileWidth = 0;
}
if( this.tileHeight ){
// See note above about renaming this.tileWidth
this._tileHeight = this.tileHeight;
delete this.tileHeight;
} else {
this._tileHeight = 0;
}
}
this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0;
@ -230,7 +245,7 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
* Return the tileWidth for a given level.
* Subclasses should override this if tileWidth can be different at different levels
* such as in IIIFTileSource. Code should use this function rather than reading
* from .tileWidth directly.
* from ._tileWidth directly.
* @function
* @param {Number} level
*/
@ -245,7 +260,7 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
* Return the tileHeight for a given level.
* Subclasses should override this if tileHeight can be different at different levels
* such as in IIIFTileSource. Code should use this function rather than reading
* from .tileHeight directly.
* from ._tileHeight directly.
* @function
* @param {Number} level
*/

View File

@ -0,0 +1,51 @@
/* global module, ok, equal, start, test, testLog, Util */
(function() {
module('TileSource', {
setup: function() {
testLog.reset();
}
});
test("should set sane tile size defaults", function() {
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");
});
test("providing tileSize", function(){
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");
});
test("providing tileWidth and tileHeight", function(){
var tileWidth = 256,
tileHeight = 512,
source = new OpenSeadragon.TileSource({
tileWidth: tileWidth,
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");
});
test('getTileSize() deprecation', function() {
var source = new OpenSeadragon.TileSource();
Util.testDeprecation(source, 'getTileSize');
});
}());

View File

@ -36,6 +36,7 @@
<script src="/test/modules/tiledimage.js"></script>
<script src="/test/modules/tilecache.js"></script>
<script src="/test/modules/referencestrip.js"></script>
<script src="/test/modules/tilesource.js"></script>
<script src="/test/modules/tilesourcecollection.js"></script>
<script src="/test/modules/spring.js"></script>
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)