From 364d371f10db2931da8336377ad9659b802b49ca Mon Sep 17 00:00:00 2001 From: ejn Date: Mon, 28 Jan 2013 16:16:16 +0100 Subject: [PATCH] Add unit test for cleared cache, and adjust existing unit test which assumed cached position --- tests/Handler/Feature.html | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Handler/Feature.html b/tests/Handler/Feature.html index 7c768e1a69..580d419d70 100644 --- a/tests/Handler/Feature.html +++ b/tests/Handler/Feature.html @@ -564,10 +564,10 @@ handler = new OpenLayers.Handler.Feature( control, layer, callbacks, {clickTolerance: 4}); handler.activate(); - handler.down = {x: 0, y: 0}; // distance between down and up is 1, which is // lower than clickTolerance so "click" should trigger + handler.down = {x: 0, y: 0}; handler.up = {x: 1, y: 0}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -575,6 +575,7 @@ // distance between down and up is 4, which is // equal to clickTolerance so "click" should trigger + handler.down = {x: 0, y: 0}; // cached handler.down cleared (#857) handler.up = {x: 0, y: 4}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -582,6 +583,7 @@ // distance between down and up is 5, which is // greater than clickTolerance so "click" should not trigger + handler.down = {x: 0, y: 0}; // cached handler.down cleared (#857) handler.up = {x: 5, y: 0}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -660,6 +662,36 @@ } + function test_clear_event_position_cache(t) { + t.plan(2); + + var map, control, layer, feature, evtPx; + + map = new OpenLayers.Map('map', {controls: []}); + control = new OpenLayers.Control(); + map.addControl(control); + layer = new OpenLayers.Layer(); + layer.getFeatureFromEvent = function(evt) { return feature; }; + map.addLayer(layer); + feature = new OpenLayers.Feature.Vector(); + feature.layer = layer; + + evtPx = { + xy: new OpenLayers.Pixel(Math.random(), Math.random()), + type: "click" + }; + + handler = new OpenLayers.Handler.Feature( + control, layer, {}, {}); + handler.activate(); + + handler.down = {x: 0, y: 0}; + handler.up = {x: 1, y: 0}; + map.events.triggerEvent("click", evtPx); + t.eq(handler.down, null, "cached mousedown position is cleared after handling click"); + t.eq(handler.up, null, "cached mouseup position is cleared after handling click") + } +