3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 function test_Handler_Keyboard_initialize(t) {
7 var control = new OpenLayers.Control();
8 control.id = Math.random();
9 var callbacks = {foo: "bar"};
10 var options = {bar: "foo"};
12 var oldInit = OpenLayers.Handler.prototype.initialize;
14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
15 t.eq(con.id, control.id,
16 "constructor calls parent with the correct control");
18 "constructor calls parent with the correct callbacks");
20 "constructor calls parent with the correct options");
22 var handler = new OpenLayers.Handler.Keyboard(control, callbacks,
25 OpenLayers.Handler.prototype.initialize = oldInit;
28 function test_Handler_Keyboard_destroy(t) {
30 var control = new OpenLayers.Control();
31 var handler = new OpenLayers.Handler.Keyboard(control);
32 var old = OpenLayers.Handler.prototype.destroy;
33 t.ok(handler.eventListener != null,
34 "eventListener is not null before destroy");
35 OpenLayers.Handler.prototype.destroy = function() {
36 t.ok(true, "destroy calls destroy on correct parent");
39 t.ok(handler.eventListener == null,
40 "eventListeners is null after destroy");
41 OpenLayers.Handler.prototype.destroy = old;
44 function test_Handler_Keyboard_activate(t) {
46 var map = new OpenLayers.Map('map');
47 var control = new OpenLayers.Control();
48 map.addControl(control);
49 var handler = new OpenLayers.Handler.Keyboard(control);
50 handler.active = true;
51 var activated = handler.activate();
53 "activate returns false if the handler was already active");
54 handler.active = false;
55 handler.dragging = true;
56 var old = OpenLayers.Event.stopObserving;
57 var types = ["keydown", "keyup"];
58 OpenLayers.Event.observe = function(obj, type, method) {
60 "activate calls observing with correct object");
61 var validType = (OpenLayers.Util.indexOf(types, type) != -1);
62 t.ok(validType, "activate calls observe for " + type);
63 t.ok(method == handler.eventListener,
64 "activate calls observing with correct method");
66 activated = handler.activate();
68 "activate returns true if the handler was not already active");
69 OpenLayers.Event.observe = old;
73 function test_Handler_Drag_deactivate(t) {
75 var map = new OpenLayers.Map('map');
76 var control = new OpenLayers.Control();
77 map.addControl(control);
78 var handler = new OpenLayers.Handler.Keyboard(control);
79 handler.active = false;
80 var deactivated = handler.deactivate();
82 "deactivate returns false if the handler was not already active");
83 handler.active = true;
84 var old = OpenLayers.Event.stopObserving;
85 var types = ["keydown", "keyup"];
86 OpenLayers.Event.stopObserving = function(obj, type, method) {
88 "deactivate calls stopObserving with correct object");
89 var validType = (OpenLayers.Util.indexOf(types, type) != -1);
90 t.ok(validType, "deactivate calls stopObserving for " + type);
91 t.ok(method == handler.eventListener,
92 "deactivate calls stopObserving with correct method");
94 deactivated = handler.deactivate();
96 "deactivate returns true if the handler was active already");
97 OpenLayers.Event.stopObserving = old;
104 <div id="map" style="width: 300px; height: 150px;"/>