git-svn-id: http://svn.openlayers.org/trunk/openlayers@3705 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
173 lines
6.3 KiB
HTML
173 lines
6.3 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) {
|
|
// add in a closure for key
|
|
(function(key) {
|
|
handler[key] = function() {return key};
|
|
})(events[i]);
|
|
}
|
|
deactivated = handler.deactivate();
|
|
t.ok(deactivated,
|
|
"deactivated returns true if the handler is already active");
|
|
|
|
}
|
|
|
|
function test_Handler_destroy(t) {
|
|
t.plan(4);
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler(control);
|
|
t.ok(handler.control,
|
|
"handler has a control prior to destroy");
|
|
t.ok(handler.map,
|
|
"handler has a map prior to destroy");
|
|
handler.destroy();
|
|
t.eq(handler.control, null,
|
|
"hanlder.control is null after destroy");
|
|
t.eq(handler.map, null,
|
|
"handler.map is null after destroy");
|
|
}
|
|
|
|
function test_Handler_checkModifiers(t) {
|
|
t.plan(17);
|
|
var handler = new OpenLayers.Handler({});
|
|
handler.keyMask = null;
|
|
var proceed = handler.checkModifiers({});
|
|
t.ok(proceed,
|
|
"checkModifiers returns true if no keyMask on the handler");
|
|
|
|
var constants = {
|
|
MOD_NONE: null,
|
|
MOD_SHIFT: "shiftKey",
|
|
MOD_CTRL: "ctrlKey",
|
|
MOD_ALT: "altKey"
|
|
}
|
|
|
|
/**
|
|
* Test checkModifiers for single keyMask values. The method should
|
|
* return false if the corresponding key is associated with the
|
|
* event. For example, if evt.shiftKey is true and handler.keyMask
|
|
* is OpenLayers.Handler.MOD_SHIFT, checkModifiers should return
|
|
* true.
|
|
*/
|
|
var proceed, evt, value, c, k;
|
|
for(c in constants) {
|
|
handler.keyMask = OpenLayers.Handler[c];
|
|
// for this key mask, we want to test all single key possibilities
|
|
for(k in constants) {
|
|
value = constants[k];
|
|
evt = {};
|
|
if(value) {
|
|
// mimic a key down on an event
|
|
evt[value] = true;
|
|
}
|
|
proceed = handler.checkModifiers(evt);
|
|
// if k == c, proceed should be true - false otherwise
|
|
t.eq(k == c, proceed,
|
|
"returns " + proceed + " if keyMask is " + c +
|
|
" and " + ((value) ? value : "no key") + " is down");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// -->
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 1024px; height: 512px;"/>
|
|
</body>
|
|
</html>
|