2017-12-07 04:20:39 +03:00
|
|
|
/* global QUnit, testLog */
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
// ----------
|
2017-12-07 04:20:39 +03:00
|
|
|
QUnit.module('TileCache', {
|
|
|
|
beforeEach: function () {
|
2014-11-20 22:51:24 +03:00
|
|
|
testLog.reset();
|
|
|
|
},
|
2017-12-07 04:20:39 +03:00
|
|
|
afterEach: function () {
|
2014-11-20 22:51:24 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-07 04:20:39 +03:00
|
|
|
// TODO: this used to be async
|
|
|
|
QUnit.test('basics', function(assert) {
|
|
|
|
var done = assert.async();
|
2015-06-11 22:27:36 +03:00
|
|
|
var fakeViewer = {
|
|
|
|
raiseEvent: function() {}
|
|
|
|
};
|
|
|
|
var fakeTiledImage0 = {
|
2022-04-16 22:19:54 +03:00
|
|
|
viewer: fakeViewer,
|
2022-04-30 00:45:01 +03:00
|
|
|
source: OpenSeadragon.TileSource.prototype
|
2015-06-11 22:27:36 +03:00
|
|
|
};
|
|
|
|
var fakeTiledImage1 = {
|
2022-04-16 22:19:54 +03:00
|
|
|
viewer: fakeViewer,
|
2022-04-30 00:45:01 +03:00
|
|
|
source: OpenSeadragon.TileSource.prototype
|
2015-06-11 22:27:36 +03:00
|
|
|
};
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
var fakeTile0 = {
|
|
|
|
url: 'foo.jpg',
|
2016-10-22 00:28:12 +03:00
|
|
|
cacheKey: 'foo.jpg',
|
2014-11-20 22:51:24 +03:00
|
|
|
image: {},
|
2023-09-08 09:47:43 +03:00
|
|
|
loaded: true,
|
|
|
|
tiledImage: fakeTiledImage0,
|
|
|
|
_caches: [],
|
2014-11-20 22:51:24 +03:00
|
|
|
unload: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var fakeTile1 = {
|
|
|
|
url: 'foo.jpg',
|
2016-10-22 00:28:12 +03:00
|
|
|
cacheKey: 'foo.jpg',
|
2014-11-20 22:51:24 +03:00
|
|
|
image: {},
|
2023-09-08 09:47:43 +03:00
|
|
|
loaded: true,
|
|
|
|
tiledImage: fakeTiledImage1,
|
|
|
|
_caches: [],
|
2014-11-20 22:51:24 +03:00
|
|
|
unload: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var cache = new OpenSeadragon.TileCache();
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.cacheTile({
|
|
|
|
tile: fakeTile0,
|
|
|
|
tiledImage: fakeTiledImage0
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 1, 'tile count after cache');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.cacheTile({
|
|
|
|
tile: fakeTile1,
|
|
|
|
tiledImage: fakeTiledImage1
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 2, 'tile count after second cache');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.clearTilesFor(fakeTiledImage0);
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 1, 'tile count after first clear');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.clearTilesFor(fakeTiledImage1);
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 0, 'tile count after second clear');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
done();
|
2014-11-20 22:51:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// ----------
|
2017-12-07 04:20:39 +03:00
|
|
|
QUnit.test('maxImageCacheCount', function(assert) {
|
|
|
|
var done = assert.async();
|
2015-06-11 22:27:36 +03:00
|
|
|
var fakeViewer = {
|
|
|
|
raiseEvent: function() {}
|
|
|
|
};
|
|
|
|
var fakeTiledImage0 = {
|
2022-04-16 22:19:54 +03:00
|
|
|
viewer: fakeViewer,
|
2022-04-30 00:45:01 +03:00
|
|
|
source: OpenSeadragon.TileSource.prototype
|
2015-06-11 22:27:36 +03:00
|
|
|
};
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
var fakeTile0 = {
|
|
|
|
url: 'different.jpg',
|
2016-10-22 00:28:12 +03:00
|
|
|
cacheKey: 'different.jpg',
|
2014-11-20 22:51:24 +03:00
|
|
|
image: {},
|
2023-09-08 09:47:43 +03:00
|
|
|
loaded: true,
|
|
|
|
tiledImage: fakeTiledImage0,
|
|
|
|
_caches: [],
|
2014-11-20 22:51:24 +03:00
|
|
|
unload: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var fakeTile1 = {
|
|
|
|
url: 'same.jpg',
|
2016-10-22 00:28:12 +03:00
|
|
|
cacheKey: 'same.jpg',
|
2014-11-20 22:51:24 +03:00
|
|
|
image: {},
|
2023-09-08 09:47:43 +03:00
|
|
|
loaded: true,
|
|
|
|
tiledImage: fakeTiledImage0,
|
|
|
|
_caches: [],
|
2014-11-20 22:51:24 +03:00
|
|
|
unload: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var fakeTile2 = {
|
|
|
|
url: 'same.jpg',
|
2016-10-22 00:28:12 +03:00
|
|
|
cacheKey: 'same.jpg',
|
2014-11-20 22:51:24 +03:00
|
|
|
image: {},
|
2023-09-08 09:47:43 +03:00
|
|
|
loaded: true,
|
|
|
|
tiledImage: fakeTiledImage0,
|
|
|
|
_caches: [],
|
2014-11-20 22:51:24 +03:00
|
|
|
unload: function() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var cache = new OpenSeadragon.TileCache({
|
|
|
|
maxImageCacheCount: 1
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.cacheTile({
|
|
|
|
tile: fakeTile0,
|
|
|
|
tiledImage: fakeTiledImage0
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 1, 'tile count after add');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.cacheTile({
|
|
|
|
tile: fakeTile1,
|
|
|
|
tiledImage: fakeTiledImage0
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 1, 'tile count after add of second image');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
|
|
|
cache.cacheTile({
|
|
|
|
tile: fakeTile2,
|
|
|
|
tiledImage: fakeTiledImage0
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
assert.equal(cache.numTilesLoaded(), 2, 'tile count after additional same image');
|
2014-11-20 22:51:24 +03:00
|
|
|
|
2017-12-07 04:20:39 +03:00
|
|
|
done();
|
2014-11-20 22:51:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
})();
|