[OpenLayers-Commits] r11760 - trunk/openlayers/tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Mar 29 17:59:25 EDT 2011
Author: erilem
Date: 2011-03-29 14:59:24 -0700 (Tue, 29 Mar 2011)
New Revision: 11760
Modified:
trunk/openlayers/tests/Handler/Path.html
Log:
better tests for path handler, tests only patch
Modified: trunk/openlayers/tests/Handler/Path.html
===================================================================
--- trunk/openlayers/tests/Handler/Path.html 2011-03-29 21:59:08 UTC (rev 11759)
+++ trunk/openlayers/tests/Handler/Path.html 2011-03-29 21:59:24 UTC (rev 11760)
@@ -772,95 +772,180 @@
]), "geometry is correct after mousemove");
}
- function test_sequence_touch_1(t) {
- t.plan(19);
-
- log = [];
- var map = new OpenLayers.Map("map", { // 300 x 150
+
+ // a) tap
+ // b) tap
+ // c) doubletap
+ function test_touch_sequence1(t) {
+ t.plan(17);
+
+ // set up
+
+ var log;
+ var map = new OpenLayers.Map("map", {
resolutions: [1]
});
var layer = new OpenLayers.Layer.Vector("foo", {
- maxExtent: new OpenLayers.Bounds(-100, -100, 100, 100),
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
isBaseLayer: true
});
map.addLayer(layer);
var control = new OpenLayers.Control({});
var handler = new OpenLayers.Handler.Path(control, {
- "done": function(g, f) {
- log.push({geometry: g, feature: f});
+ done: function(g, f) {
+ log = {type: 'done', geometry: g, feature: f};
+ },
+ modify: function(g, f) {
+ log = {type: 'modify', geometry: g, feature: f};
}
+ }, {
+ dblclickTolerance: 2
});
control.handler = handler;
map.addControl(control);
- map.setCenter(new OpenLayers.LonLat(0, 0), 5);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.activate();
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(49, 75)});
- t.eq(log.length, 0, "touch start 1");
+ // test
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(50, 75)});
- t.eq(log.length, 0, "touch move");
+ var ret;
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
- t.geom_eq(handler.line.geometry,
+ // tap on (1, 0)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(1, 0)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75),
+ "[touchend] correct point");
+
+ // tap on (10, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(10, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
+ "[touchend] correct point");
+
+ // tap on (11, 10) -> doubletap
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
+ t.ok(!ret, '[touchstart] event does not propagate');
+ t.eq(log.type, 'done', '[touchend] feature finalized');
+ t.geom_eq(log.geometry,
new OpenLayers.Geometry.LineString([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-100, 0)
- ]), "geometry is correct");
+ new OpenLayers.Geometry.Point(-149, 75), // (1, 0)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "[touchstart] final geometry is correct");
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch start 2");
+ // tear down
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 75)});
- t.eq(log.length, 0, "touch move");
+ map.destroy();
+ }
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
- t.geom_eq(handler.line.geometry,
- new OpenLayers.Geometry.LineString([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-100, 0)
- ]), "geometry is correct");
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch start 3");
+ // a) tap
+ // b) tap-move
+ // c) tap
+ // d) doubletap
+ function test_touch_sequence2(t) {
+ t.plan(23);
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch move");
+ // set up
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
- t.geom_eq(handler.line.geometry,
- new OpenLayers.Geometry.LineString([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-50, 0),
- new OpenLayers.Geometry.Point(-50, 0)
- ]), "geometry is correct");
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(252, 100)});
- t.eq(log.length, 0, "touch start 4");
+ var log;
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control, {
+ done: function(g, f) {
+ log = {type: 'done', geometry: g, feature: f};
+ },
+ modify: function(g, f) {
+ log = {type: 'modify', geometry: g, feature: f};
+ }
+ }, {
+ dblclickTolerance: 2
+ });
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+ handler.activate();
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(252, 100)});
- t.eq(log.length, 0, "touch move");
+ // test
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(250, 100)});
- t.eq(log.length, 1, "touch start");
+ var ret;
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 100)});
- t.eq(log.length, 1, "touch move");
+ // tap on (1, 0)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(1, 0)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75),
+ "[touchend] correct point");
- handler.touchend({type: "touchend"});
- t.eq(log.length, 1, "touch end");
- t.geom_eq(log[0].geometry,
+ // tap-move
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(20, 20)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log, null, '[touchend] feature not finalized or modified');
+
+ // tap on (10, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(10, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
+ "[touchend] correct point");
+
+ // tap on (11, 10) -> doubletap
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
+ t.ok(!ret, '[touchstart] event does not propagate');
+ t.eq(log.type, 'done', '[touchend] feature finalized');
+ t.geom_eq(log.geometry,
new OpenLayers.Geometry.LineString([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-50, 0),
- new OpenLayers.Geometry.Point(102, -25)
- ]), "geometry is correct");
+ new OpenLayers.Geometry.Point(-149, 75), // (1, 0)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "[touchstart] final geometry is correct");
+
+ // tear down
+
+ map.destroy();
}
</script>
More information about the Commits
mailing list