Files
openlayers/tests/test_Handler.html
Tim Schaub 21d97f45f0 88 tests for the handler base class
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3688 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2007-07-10 22:38:49 +00:00

113 lines
4.1 KiB
HTML

<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
function test_Handler_constructor(t) {
t.plan(4);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var handler = new OpenLayers.Handler(control, callbacks, options);
t.ok(handler instanceof OpenLayers.Handler,
"new OpenLayers.Handler returns object");
t.eq(handler.map.id, map.id,
"constructing a handler with a map sets the map on the handler");
t.eq(handler.callbacks.foo, callbacks.foo,
"constructor correctly sets callbacks");
t.eq(handler.bar, options.bar,
"constructor correctly extends handler with options");
}
function test_Handler_activate(t) {
t.plan(42);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var events = ["mouseover", "mouseout", "mousedown",
"mouseup", "mousemove", "click",
"dblclick", "resize", "focus", "blur"];
var handler = new OpenLayers.Handler(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler is already active");
handler.active = false;
map.events.registerPriority = function(type, obj, func) {
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",
"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};
}
activated = handler.activate();
t.ok(activated,
"activated returns true if the handler is not already active");
}
function test_Handler_deactivate(t) {
t.plan(42);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var events = ["mouseover", "mouseout", "mousedown",
"mouseup", "mousemove", "click",
"dblclick", "resize", "focus", "blur"];
var handler = new OpenLayers.Handler(control);
handler.active = false;
var deactivated = handler.deactivate();
t.ok(!deactivated,
"deactivate returns false if the handler is already deactive");
handler.activate();
map.events.unregister = function(type, obj, func) {
t.ok(OpenLayers.Util.indexOf(events, type) > -1,
"deactivate calls unregister with browser event: " + type);
t.eq(typeof func, "function",
"activate calls unregister with a function");
t.eq(func(), type,
"activate calls unregister with the correct method");
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler",
"activate calls unregister 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};
}
deactivated = handler.deactivate();
t.ok(deactivated,
"deactivated returns true if the handler is already active");
}
// -->
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>