adding more handler tests

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3868 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-08-06 21:15:37 +00:00
parent 04f1fe5385
commit 18e0b12b5d
+54 -15
View File
@@ -19,7 +19,7 @@
t.eq(opt, options, t.eq(opt, options,
"constructor calls parent with the correct options"); "constructor calls parent with the correct options");
} }
var drag = new OpenLayers.Handler.Drag(control, callbacks, options); var handler = new OpenLayers.Handler.Drag(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit; OpenLayers.Handler.prototype.initialize = oldInit;
} }
@@ -29,37 +29,76 @@
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control(); var control = new OpenLayers.Control();
map.addControl(control); map.addControl(control);
var drag = new OpenLayers.Handler.Drag(control); var handler = new OpenLayers.Handler.Drag(control);
drag.active = true; handler.active = true;
var activated = drag.activate(); var activated = handler.activate();
t.ok(!activated, t.ok(!activated,
"activate returns false if the handler was already active"); "activate returns false if the handler was already active");
drag.active = false; handler.active = false;
drag.dragging = true; handler.dragging = true;
activated = drag.activate(); activated = handler.activate();
t.ok(activated, t.ok(activated,
"activate returns true if the handler was not already active"); "activate returns true if the handler was not already active");
t.ok(!drag.dragging, t.ok(!handler.dragging,
"activate sets dragging to false"); "activate sets dragging to false");
} }
function test_Handler_Drag_events(t) {
t.plan(25);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Drag(control);
// list below events that should be handled (events) and those
// that should not be handled (nonevents) by the handler
var events = ["mousedown", "mouseup", "mousemove", "mouseout", "click"];
var nonevents = ["dblclick", "resize", "focus", "blur"];
map.events.registerPriority = function(type, obj, func) {
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
"registered method is not one of the events " +
"that should not be handled");
t.ok(OpenLayers.Util.indexOf(events, type) > -1,
"activate calls registerPriority with browser event: " + type);
t.eq(typeof func, "function",
"activate calls registerPriority with a function");
t.eq(func(), type,
"activate calls registerPriority with the correct method");
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Drag",
"activate calls registerPriority with the handler");
}
// set browser event like properties on the handler
for(var i=0; i<events.length; ++i) {
setMethod(events[i]);
}
function setMethod(key) {
handler[key] = function() {return key};
}
var activated = handler.activate();
}
function test_Handler_Drag_deactivate(t) { function test_Handler_Drag_deactivate(t) {
t.plan(3); t.plan(3);
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control(); var control = new OpenLayers.Control();
map.addControl(control); map.addControl(control);
var drag = new OpenLayers.Handler.Drag(control); var handler = new OpenLayers.Handler.Drag(control);
drag.active = false; handler.active = false;
var deactivated = drag.deactivate(); var deactivated = handler.deactivate();
t.ok(!deactivated, t.ok(!deactivated,
"deactivate returns false if the handler was not already active"); "deactivate returns false if the handler was not already active");
drag.active = true; handler.active = true;
drag.dragging = true; handler.dragging = true;
deactivated = drag.deactivate(); deactivated = handler.deactivate();
t.ok(deactivated, t.ok(deactivated,
"deactivate returns true if the handler was active already"); "deactivate returns true if the handler was active already");
t.ok(!drag.dragging, t.ok(!handler.dragging,
"deactivate sets dragging to false"); "deactivate sets dragging to false");
} }