Add map tests for resize and animationDelay

This commit is contained in:
Andreas Hocevar
2016-02-01 16:12:25 +01:00
parent 73f5e11039
commit dc0393acff
2 changed files with 39 additions and 2 deletions

View File

@@ -291,7 +291,7 @@ ol.Map = function(options) {
ol.events.EventType.TOUCHSTART,
ol.events.EventType.MSPOINTERDOWN,
ol.MapBrowserEvent.EventType.POINTERDOWN,
goog.userAgent.GECKO ? 'DOMMouseScroll' : 'mousewheel'
goog.userAgent.GECKO ? 'DOMMouseScroll' : ol.events.EventType.MOUSEWHEEL
], ol.events.Event.stopPropagation);
this.viewport_.appendChild(this.overlayContainerStopEvent_);
@@ -578,6 +578,11 @@ ol.Map.prototype.disposeInternal = function() {
if (this.handleResize_ !== undefined) {
goog.global.removeEventListener(ol.events.EventType.RESIZE,
this.handleResize_, false);
this.handleResize_ = undefined;
}
if (this.animationDelayKey_) {
goog.global.cancelAnimationFrame(this.animationDelayKey_);
this.animationDelayKey_ = undefined;
}
goog.dom.removeNode(this.viewport_);
goog.base(this, 'disposeInternal');

View File

@@ -147,11 +147,14 @@ describe('ol.Map', function() {
document.body.removeChild(target);
});
it('results in an postrender event', function(done) {
it('calls renderFrame_ and results in an postrender event', function(done) {
var spy = sinon.spy(map, 'renderFrame_');
map.render();
map.once('postrender', function(event) {
expect(event).to.be.a(ol.MapEvent);
expect(typeof spy.firstCall.args[0]).to.be('number');
spy.restore();
var frameState = event.frameState;
expect(frameState).not.to.be(null);
done();
@@ -159,6 +162,30 @@ describe('ol.Map', function() {
});
it('uses the same render frame for subsequent calls', function(done) {
var id1, id2;
map.render();
id1 = map.animationDelayKey_;
map.once('postrender', function() {
expect(id2).to.be(id1);
done();
});
map.render();
id2 = map.animationDelayKey_;
});
it('creates a new render frame after renderSync()', function(done) {
var id1, id2;
map.render();
id1 = map.animationDelayKey_;
map.once('postrender', function() {
expect(id2).to.not.be(id1);
done();
});
map.renderSync();
id2 = map.animationDelayKey_;
});
it('results in an postrender event (for zero height map)', function(done) {
target.style.height = '0px';
map.updateSize();
@@ -202,6 +229,11 @@ describe('ol.Map', function() {
goog.dispose(map);
expect(goog.dom.getParentElement(map.getViewport())).to.be(null);
});
it('removes window listeners', function() {
goog.dispose(map);
expect(map.handleResize_).to.be(undefined);
});
});
describe('#setTarget', function() {