Add tests for ol.style.IconImageCache
This commit is contained in:
@@ -437,6 +437,15 @@ ol.style.IconImageCache.getKey = function(src, crossOrigin) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME empty description for jsdoc
|
||||||
|
*/
|
||||||
|
ol.style.IconImageCache.prototype.clear = function() {
|
||||||
|
this.cache_ = {};
|
||||||
|
this.cacheSize_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME empty description for jsdoc
|
* FIXME empty description for jsdoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
71
test/spec/ol/style/iconstyle.test.js
Normal file
71
test/spec/ol/style/iconstyle.test.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
goog.provide('ol.test.style.IconImageCache');
|
||||||
|
|
||||||
|
describe('ol.style.IconImageCache', function() {
|
||||||
|
var originalMaxCacheSize;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
var cache = ol.style.IconImageCache.getInstance();
|
||||||
|
cache.clear();
|
||||||
|
originalMaxCacheSize = cache.maxCacheSize;
|
||||||
|
cache.maxCacheSize_ = 4;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
var cache = ol.style.IconImageCache.getInstance();
|
||||||
|
cache.maxCacheSize_ = originalMaxCacheSize;
|
||||||
|
cache.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#expire', function() {
|
||||||
|
it('expires images when expected', function() {
|
||||||
|
var cache = ol.style.IconImageCache.getInstance();
|
||||||
|
|
||||||
|
var i, src, iconImage, key;
|
||||||
|
|
||||||
|
for (i = 0; i < 4; ++i) {
|
||||||
|
src = i + '';
|
||||||
|
iconImage = new ol.style.IconImage_(src, null);
|
||||||
|
cache.set(src, null, iconImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(cache.cacheSize_).to.eql(4);
|
||||||
|
|
||||||
|
cache.expire();
|
||||||
|
expect(cache.cacheSize_).to.eql(4);
|
||||||
|
|
||||||
|
src = '4';
|
||||||
|
iconImage = new ol.style.IconImage_(src, null);
|
||||||
|
cache.set(src, null, iconImage);
|
||||||
|
expect(cache.cacheSize_).to.eql(5);
|
||||||
|
|
||||||
|
cache.expire(); // remove '0' and '4'
|
||||||
|
expect(cache.cacheSize_).to.eql(3);
|
||||||
|
|
||||||
|
src = '0';
|
||||||
|
iconImage = new ol.style.IconImage_(src, null);
|
||||||
|
goog.events.listen(iconImage, goog.events.EventType.CHANGE,
|
||||||
|
goog.nullFunction, false);
|
||||||
|
cache.set(src, null, iconImage);
|
||||||
|
expect(cache.cacheSize_).to.eql(4);
|
||||||
|
|
||||||
|
src = '4';
|
||||||
|
iconImage = new ol.style.IconImage_(src, null);
|
||||||
|
goog.events.listen(iconImage, goog.events.EventType.CHANGE,
|
||||||
|
goog.nullFunction, false);
|
||||||
|
cache.set(src, null, iconImage);
|
||||||
|
expect(cache.cacheSize_).to.eql(5);
|
||||||
|
|
||||||
|
// check that '0' and '4' are not removed from the cache
|
||||||
|
cache.expire();
|
||||||
|
key = ol.style.IconImageCache.getKey('0', null);
|
||||||
|
expect(key in cache.cache_).to.be.ok();
|
||||||
|
key = ol.style.IconImageCache.getKey('4', null);
|
||||||
|
expect(key in cache.cache_).to.be.ok();
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
goog.require('goog.events');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('ol.style.IconImageCache');
|
||||||
Reference in New Issue
Block a user