openseadragon/test/modules/tilecache.js

135 lines
3.3 KiB
JavaScript
Raw Normal View History

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 = {
viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype
2015-06-11 22:27:36 +03:00
};
var fakeTiledImage1 = {
viewer: fakeViewer,
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',
cacheKey: 'foo.jpg',
2014-11-20 22:51:24 +03:00
image: {},
unload: function() {}
};
var fakeTile1 = {
url: 'foo.jpg',
cacheKey: 'foo.jpg',
2014-11-20 22:51:24 +03:00
image: {},
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 = {
viewer: fakeViewer,
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',
cacheKey: 'different.jpg',
2014-11-20 22:51:24 +03:00
image: {},
unload: function() {}
};
var fakeTile1 = {
url: 'same.jpg',
cacheKey: 'same.jpg',
2014-11-20 22:51:24 +03:00
image: {},
unload: function() {}
};
var fakeTile2 = {
url: 'same.jpg',
cacheKey: 'same.jpg',
2014-11-20 22:51:24 +03:00
image: {},
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
});
})();