| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
|
|---|
| 6 |
function test_Control_Navigation_constructor (t) { |
|---|
| 7 |
t.plan( 3 ); |
|---|
| 8 |
var temp = OpenLayers.Control.prototype.initialize; |
|---|
| 9 |
OpenLayers.Control.prototype.initialize = function() { |
|---|
| 10 |
t.ok(true, "OpenLayers.Control's constructor called"); |
|---|
| 11 |
}; |
|---|
| 12 |
|
|---|
| 13 |
var control = new OpenLayers.Control.Navigation(); |
|---|
| 14 |
t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" ); |
|---|
| 15 |
|
|---|
| 16 |
t.ok( !control.handleRightClicks, "'handleRightClicks' property is disabled by default"); |
|---|
| 17 |
|
|---|
| 18 |
OpenLayers.Control.prototype.initialize = temp; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
function test_Control_Navigation_destroy (t) { |
|---|
| 22 |
t.plan(10); |
|---|
| 23 |
|
|---|
| 24 |
var temp = OpenLayers.Control.prototype.destroy; |
|---|
| 25 |
OpenLayers.Control.prototype.destroy = function() { |
|---|
| 26 |
t.ok(true, "OpenLayers.Control's destroy called"); |
|---|
| 27 |
temp.call(this); |
|---|
| 28 |
}; |
|---|
| 29 |
|
|---|
| 30 |
var control = { |
|---|
| 31 |
events: { |
|---|
| 32 |
destroy: function() { |
|---|
| 33 |
t.ok(true, "events destroyed"); |
|---|
| 34 |
} |
|---|
| 35 |
}, |
|---|
| 36 |
'deactivate': function() { |
|---|
| 37 |
t.ok(true, "navigation control deactivated before being destroyed"); |
|---|
| 38 |
}, |
|---|
| 39 |
'dragPan': { |
|---|
| 40 |
'destroy': function() { |
|---|
| 41 |
t.ok(true, "dragPan destroyed"); |
|---|
| 42 |
} |
|---|
| 43 |
}, |
|---|
| 44 |
'zoomBox': { |
|---|
| 45 |
'destroy': function() { |
|---|
| 46 |
t.ok(true, "zoomBox destroyed"); |
|---|
| 47 |
} |
|---|
| 48 |
}, |
|---|
| 49 |
handlers: { |
|---|
| 50 |
'wheel': { |
|---|
| 51 |
'destroy': function() { |
|---|
| 52 |
t.ok(true, "wheelHandler destroyed"); |
|---|
| 53 |
} |
|---|
| 54 |
}, |
|---|
| 55 |
'click': { |
|---|
| 56 |
'destroy': function() { |
|---|
| 57 |
t.ok(true, "clickHandler destroyed"); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
}; |
|---|
| 62 |
|
|---|
| 63 |
//this will also trigger one test by calling OpenLayers.Control's destroy |
|---|
| 64 |
// and three more for the destruction of dragPan, zoomBox, and wheelHandler |
|---|
| 65 |
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []); |
|---|
| 66 |
|
|---|
| 67 |
t.eq(control.dragPan, null, "'dragPan' set to null"); |
|---|
| 68 |
t.eq(control.zoomBox, null, "'zoomBox' set to null"); |
|---|
| 69 |
t.eq(control.handlers, null, "handlers set to null"); |
|---|
| 70 |
|
|---|
| 71 |
OpenLayers.Control.prototype.destroy = temp; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
function test_Control_Navigation_disableZoomWheel(t) { |
|---|
| 75 |
t.plan(2); |
|---|
| 76 |
var nav = new OpenLayers.Control.Navigation(); |
|---|
| 77 |
var wheel = new OpenLayers.Handler.MouseWheel(nav, {}); |
|---|
| 78 |
nav.handlers.wheel = wheel; |
|---|
| 79 |
wheel.register = function() {}; |
|---|
| 80 |
wheel.unregister = function() {}; |
|---|
| 81 |
wheel.activate(); |
|---|
| 82 |
nav.disableZoomWheel(); |
|---|
| 83 |
t.eq(nav.zoomWheelEnabled, false, "mouse wheel deactivated"); |
|---|
| 84 |
t.eq(wheel.active, false, "mouse wheel handler deactivated"); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
function test_Control_Navigation_enableZoomWheel(t) { |
|---|
| 88 |
t.plan(2); |
|---|
| 89 |
var nav = new OpenLayers.Control.Navigation({zoomWheelEnabled: false}); |
|---|
| 90 |
nav.active = true; |
|---|
| 91 |
var wheel = new OpenLayers.Handler.MouseWheel(nav, {}); |
|---|
| 92 |
wheel.register = function() {}; |
|---|
| 93 |
wheel.unregister = function() {}; |
|---|
| 94 |
nav.handlers.wheel = wheel; |
|---|
| 95 |
nav.enableZoomWheel(); |
|---|
| 96 |
t.eq(nav.zoomWheelEnabled, true, "mouse wheel activated"); |
|---|
| 97 |
t.eq(wheel.active, true, "mouse wheel handler activated"); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
</script> |
|---|
| 101 |
</head> |
|---|
| 102 |
<body> |
|---|
| 103 |
</body> |
|---|
| 104 |
</html> |
|---|