Files
openlayers/tests/Handler/test_Drag.html

76 lines
2.5 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
function test_Handler_Drag_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
OpenLayers.Handler.prototype._initialize =
OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"constructor calls parent with the correct options");
}
var drag = new OpenLayers.Handler.Drag(control, callbacks, options);
OpenLayers.Handler.prototype.initialize =
OpenLayers.Handler.prototype._initialize;
}
function test_Handler_Drag_activate(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var drag = new OpenLayers.Handler.Drag(control);
drag.active = true;
var activated = drag.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
drag.active = false;
drag.dragging = true;
activated = drag.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
t.ok(!drag.dragging,
"activate sets dragging to false");
}
function test_Handler_Drag_deactivate(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var drag = new OpenLayers.Handler.Drag(control);
drag.active = false;
var deactivated = drag.deactivate();
t.ok(!deactivated,
"deactivate returns false if the handler was not already active");
drag.active = true;
drag.dragging = true;
deactivated = drag.deactivate();
t.ok(deactivated,
"deactivate returns true if the handler was active already");
t.ok(!drag.dragging,
"deactivate sets dragging to false");
}
// -->
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>