3 <script src="../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 function test_Control_constructor(t) {
8 var control = new OpenLayers.Control();
10 t.ok(control instanceof OpenLayers.Control, "new OpenLayers.Control returns object");
11 t.eq(control.displayClass, "olControl", "displayClass set correctly");
12 t.ok(control.id != null, "default id assigned to control");
15 control = new OpenLayers.Control({ 'id': testID });
16 t.ok(control.id == testID, "if id specified in options, no default assigned.");
19 function test_Control_addControl(t) {
22 var map = new OpenLayers.Map('map');
23 var control = new OpenLayers.Control();
24 map.addControl(control);
26 t.ok(control.map === map, "Control.map is set to the map object" );
27 t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control");
30 function test_Control_title(t) {
32 var titleText = 'Title test';
33 control = new OpenLayers.Control({title:titleText});
34 t.eq( control.title, titleText, "control.title set correctly" );
37 function test_eventListeners(t) {
40 var method = OpenLayers.Events.prototype.on;
41 // test that events.on is called at control construction
43 eventListeners: {foo: "bar"}
45 OpenLayers.Events.prototype.on = function(obj) {
46 t.eq(obj, options.eventListeners, "events.on called with eventListeners");
48 var control = new OpenLayers.Control(options);
49 OpenLayers.Events.prototype.on = method;
52 // if events.on is called again, this will fail due to an extra test
53 // test control without eventListeners
54 OpenLayers.Events.prototype.on = function(obj) {
55 t.fail("events.on called without eventListeners");
57 var control2 = new OpenLayers.Control();
58 OpenLayers.Events.prototype.on = method;
62 function test_Control_destroy(t) {
65 var map = new OpenLayers.Map('map');
66 var control = new OpenLayers.Control();
67 map.addControl(control);
70 t.ok(map.controls[map.controls.length - 1] != control, "map.controls doesn't contains control");
72 t.ok(control.map == null, "Control.map is null");
73 t.ok(control.handler == null, "Control.handler is null");
79 <div id="map" style="width: 1024px; height: 512px;"/>