diff --git a/src/tilesource.js b/src/tilesource.js
index fa51915b..48d5bf10 100644
--- a/src/tilesource.js
+++ b/src/tilesource.js
@@ -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
*/
diff --git a/test/modules/tilesource.js b/test/modules/tilesource.js
new file mode 100644
index 00000000..59d8b77f
--- /dev/null
+++ b/test/modules/tilesource.js
@@ -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');
+ });
+
+}());
diff --git a/test/test.html b/test/test.html
index ae4863e8..e52eb66a 100644
--- a/test/test.html
+++ b/test/test.html
@@ -36,6 +36,7 @@
+