better tests for the polygon handler, and minor changes to the path handler tests, tests only change

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11769 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-03-30 07:09:31 +00:00
parent 4918785ca1
commit c15ffab9bc
2 changed files with 181 additions and 81 deletions
+3 -9
View File
@@ -774,7 +774,6 @@
// a) tap // a) tap
// b) tap
// c) doubletap // c) doubletap
function test_touch_sequence1(t) { function test_touch_sequence1(t) {
t.plan(17); t.plan(17);
@@ -824,7 +823,7 @@
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75), t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75),
"[touchend] correct point"); "[touchend] correct point");
// tap on (10, 10) // doubletap on (10, 10)
log = null; log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)}); ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
t.ok(ret, '[touchstart] event propagates'); t.ok(ret, '[touchstart] event propagates');
@@ -837,8 +836,6 @@
t.eq(log.type, 'modify', '[touchend] feature modified'); t.eq(log.type, 'modify', '[touchend] feature modified');
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65), t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
"[touchend] correct point"); "[touchend] correct point");
// tap on (11, 10) -> doubletap
log = null; log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)}); ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
t.ok(!ret, '[touchstart] event does not propagate'); t.ok(!ret, '[touchstart] event does not propagate');
@@ -856,8 +853,7 @@
// a) tap // a) tap
// b) tap-move // b) tap-move
// c) tap // c) doubletap
// d) doubletap
function test_touch_sequence2(t) { function test_touch_sequence2(t) {
t.plan(23); t.plan(23);
@@ -918,7 +914,7 @@
t.ok(ret, '[touchend] event propagates'); t.ok(ret, '[touchend] event propagates');
t.eq(log, null, '[touchend] feature not finalized or modified'); t.eq(log, null, '[touchend] feature not finalized or modified');
// tap on (10, 10) // doubletap on (10, 10)
log = null; log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)}); ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
t.ok(ret, '[touchstart] event propagates'); t.ok(ret, '[touchstart] event propagates');
@@ -931,8 +927,6 @@
t.eq(log.type, 'modify', '[touchend] feature modified'); t.eq(log.type, 'modify', '[touchend] feature modified');
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65), t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
"[touchend] correct point"); "[touchend] correct point");
// tap on (11, 10) -> doubletap
log = null; log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)}); ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
t.ok(!ret, '[touchstart] event does not propagate'); t.ok(!ret, '[touchstart] event does not propagate');
+171 -65
View File
@@ -904,103 +904,209 @@
]), "geometry is correct"); ]), "geometry is correct");
} }
// a) tap
// b) tap
// c) doubletap
function test_touch_sequence1(t) {
t.plan(24);
function test_sequence_touch_1(t) { // set up
t.plan(19);
log = []; var log;
var map = new OpenLayers.Map("map", { // 300 x 150 var map = new OpenLayers.Map("map", {
resolutions: [1] resolutions: [1]
}); });
var layer = new OpenLayers.Layer.Vector("foo", { 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 isBaseLayer: true
}); });
map.addLayer(layer); map.addLayer(layer);
var control = new OpenLayers.Control({}); var control = new OpenLayers.Control({});
var handler = new OpenLayers.Handler.Polygon(control, { var handler = new OpenLayers.Handler.Polygon(control, {
"done": function(g, f) { done: function(g, f) {
log.push({geometry: g, feature: f}); log = {type: 'done', geometry: g, feature: f};
},
modify: function(g, f) {
log = {type: 'modify', geometry: g, feature: f};
} }
}, {
dblclickTolerance: 2
}); });
control.handler = handler; control.handler = handler;
control.layer = layer;
map.addControl(control); map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 5); map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.activate(); handler.activate();
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(49, 75)}); // test
t.eq(log.length, 0, "touch start 1");
var expectedRing = new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-100, 0)
]);
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(50, 75)}); var ret;
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"}); // tap on (0, 0)
t.eq(log.length, 0, "touch end"); log = null;
expectedRing.addComponent(new OpenLayers.Geometry.Point(-100,0), 1); ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 0)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] feature not finalized or modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 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(-150, 75),
"[touchend] correct point");
t.geom_eq(handler.polygon.geometry.components[0], expectedRing, "geometry is correct"); // tap on (0, 10)
log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 10)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] feature not finalized or modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 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(-150, 65),
"[touchend] correct point");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)}); // doubletap on (10, 10)
t.eq(log.length, 0, "touch start 2"); log = null;
var expectedRing = new OpenLayers.Geometry.LinearRing([ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
new OpenLayers.Geometry.Point(-100, 0), t.ok(ret, '[touchstart] event propagates');
new OpenLayers.Geometry.Point(-100, 0) 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");
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.Polygon([
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
])
]), "[touchstart] geometry is correct");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 75)}); // tear down
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"}); map.destroy();
t.eq(log.length, 0, "touch end"); }
expectedRing.addComponent(new OpenLayers.Geometry.Point(-100,0), 1);
t.geom_eq(handler.polygon.geometry.components[0], expectedRing, "geometry is correct"); // a) tap
// b) tap-move
// c) tap
// d) doubletap
function test_touch_sequence2(t) {
t.plan(30);
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)}); // set up
t.eq(log.length, 0, "touch start 3");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(100, 75)}); var log;
t.eq(log.length, 0, "touch move"); 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.Polygon(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.touchend({type: "touchend"}); // test
t.eq(log.length, 0, "touch end");
t.geom_eq(handler.polygon.geometry,
new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-50, 0),
new OpenLayers.Geometry.Point(-50, 0),
new OpenLayers.Geometry.Point(-100, 0)
])]), "geometry is correct");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(252, 100)}); var ret;
t.eq(log.length, 0, "touch start 4");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(252, 100)}); // tap on (0, 0)
t.eq(log.length, 0, "touch move"); log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 0)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] feature not finalized or modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 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(-150, 75),
"[touchend] correct point");
handler.touchend({type: "touchend"}); // tap-move
t.eq(log.length, 0, "touch end"); log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 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');
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(250, 100)}); // tap on (0, 10)
t.eq(log.length, 1, "touch start"); log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 10)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] feature not finalized or modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 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(-150, 65),
"[touchend] correct point");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 100)}); // doubletap on (10, 10)
t.eq(log.length, 1, "touch 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(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");
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.Polygon([
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
])
]), "[touchstart] geometry is correct");
handler.touchend({type: "touchend"}); // tear down
t.eq(log.length, 1, "touch end");
t.geom_eq(log[0].geometry, map.destroy();
new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-50, 0),
new OpenLayers.Geometry.Point(102, -25),
new OpenLayers.Geometry.Point(-100, 0)
])]), "geometry is correct");
} }
</script> </script>