3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_Control_KeyboardDefaults_constructor (t) {
9 control = new OpenLayers.Control.KeyboardDefaults();
10 t.ok( control instanceof OpenLayers.Control.KeyboardDefaults,
11 "new OpenLayers.Control.KeyboardDefaults returns object" );
12 t.eq( control.displayClass, "olControlKeyboardDefaults", "displayClass is correct" );
15 function test_Control_KeyboardDefaults_addControl (t) {
18 map = new OpenLayers.Map('map');
19 control = new OpenLayers.Control.KeyboardDefaults();
20 t.ok( control instanceof OpenLayers.Control.KeyboardDefaults,
21 "new OpenLayers.Control.KeyboardDefaults returns object" );
22 t.ok( map instanceof OpenLayers.Map,
23 "new OpenLayers.Map creates map" );
24 map.addControl(control);
25 t.ok( control.map === map, "Control.map is set to the map object" );
26 t.ok( OpenLayers.Util.indexOf(map.controls, control), "map.controls contains control" );
30 * the keycodes below (including the comments associated with them),
31 * consult the URL below. For instance, the Safari browser returns
32 * "IE keycodes", and so is supported by any keycode labeled "IE".
34 * Very informative URL:
35 * http://unixpapa.com/js/key.html
37 function test_Control_KeyboardDefaults_KeyDownEvent (t) {
41 map = new OpenLayers.Map('map');
42 var layer = new OpenLayers.Layer.WMS("Test Layer",
43 "http://octo.metacarta.com/cgi-bin/mapserv?",
44 {map: "/mapdata/vmap_wms.map", layers: "basic"});
46 control = new OpenLayers.Control.KeyboardDefaults();
47 map.addControl(control);
49 var STARTING_ZOOM_LEVEL = 4;
52 var centerLL = new OpenLayers.LonLat(0,0);
53 map.setCenter(centerLL, STARTING_ZOOM_LEVEL);
56 evt.keyCode = OpenLayers.Event.KEY_LEFT;
57 control.defaultKeyPress(evt);
60 t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" );
63 evt.keyCode = OpenLayers.Event.KEY_RIGHT;
64 control.defaultKeyPress(evt);
67 t.eq( map.getCenter().lon, centerLL.lon, "key right works correctly" );
70 evt.keyCode = OpenLayers.Event.KEY_UP;
71 control.defaultKeyPress(evt);
74 t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" );
77 evt.keyCode = OpenLayers.Event.KEY_DOWN;
78 control.defaultKeyPress(evt);
81 t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" );
84 evt.keyCode = 33; //page up
85 control.defaultKeyPress(evt);
88 t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" );
91 evt.keyCode = 34; //page down
92 control.defaultKeyPress(evt);
95 t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" );
98 evt.keyCode = 35; //end
99 control.defaultKeyPress(evt);
102 t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" );
105 evt.keyCode = 36; //home
106 control.defaultKeyPress(evt);
109 t.ok( map.getCenter().lon == centerLL.lon, "key home works correctly");
112 evt.keyCode = 43; //+
113 control.defaultKeyPress(evt);
114 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 43 works correctly: +/= key (ASCII), keypad + (ASCII, Opera)" );
118 control.defaultKeyPress(evt);
119 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 61 works correctly: +/= key (Mozilla, Opera, some ASCII)");
123 control.defaultKeyPress(evt);
124 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 187 works correctly: +/= key (IE)");
128 control.defaultKeyPress(evt);
129 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 4, "key code 107 works correctly: keypad + (IE, Mozilla)");
132 // set zoomanimation flag manually,
133 // reason: loadend event in layers.js will not achieved in unittests
134 map.zoomanimationActive = false;
136 control.defaultKeyPress(evt);
137 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 45 works correctly: -/_ key (ASCII, Opera), keypad - (ASCII, Opera)");
140 // set zoomanimation flag manually,
141 // reason: loadend event in layers.js will not achieved in unittests
142 map.zoomanimationActive = false;
144 control.defaultKeyPress(evt);
145 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 109 works correctly: -/_ key (Mozilla), keypad - (Mozilla, IE)");
148 // set zoomanimation flag manually,
149 // reason: loadend event in layers.js will not achieved in unittests
150 map.zoomanimationActive = false;
152 control.defaultKeyPress(evt);
153 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 189 works correctly: -/_ key (IE)");
156 // set zoomanimation flag manually,
157 // reason: loadend event in layers.js will not achieved in unittests
158 map.zoomanimationActive = false;
160 control.defaultKeyPress(evt);
161 t.eq( map.getZoom(), STARTING_ZOOM_LEVEL, "key code 95 works correctly: -/_ key (some ASCII)");
170 <div id="map" style="width: 1024px; height: 512px;"/>