1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_Control_TouchNavigation_constructor (t) {
t.plan( 2 );
var options = {bar: "foo"};
var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function(opt) {
t.eq(opt, options,
"constructor calls parent with the correct options");
};
var control = new OpenLayers.Control.TouchNavigation(options);
t.ok(control instanceof OpenLayers.Control.TouchNavigation,
"new OpenLayers.Control returns object");
OpenLayers.Control.prototype.initialize = temp;
}
function test_Control_TouchNavigation_destroy(t) {
t.plan(6);
var control = {
events: {
destroy: function() {
t.ok(true, "events destroyed");
}
},
deactivate: function() {
t.ok(true, "navigation control deactivated before being destroyed");
},
dragPan: {
destroy: function() {
t.ok(true, "dragPan destroyed");
}
},
handlers: {
click: {
destroy: function() {
t.ok(true, "clickHandler destroyed");
}
}
}
};
//this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.TouchNavigation.prototype.destroy.apply(control, []);
t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.handlers, null, "handlers set to null");
}
function test_documentDrag(t) {
t.plan(2);
/**
* These tests confirm that the documentDrag property is false by
* default and is passed on to the DragPan control. Tests of panning
* while dragging outside the viewport should go in the DragPan tests.
* Tests of the document events and appropriate callbacks from the
* handler should go in the Drag handler tests.
*/
var nav = new OpenLayers.Control.TouchNavigation();
t.eq(nav.documentDrag, false, "documentDrag false by default");
var map = new OpenLayers.Map({
div: document.body,
controls: [new OpenLayers.Control.TouchNavigation({documentDrag: true})]
});
nav = map.controls[0];
t.eq(nav.dragPan.documentDrag, true, "documentDrag set on the DragPan control");
map.destroy();
}
function test_dragPanOptions(t) {
t.plan(2);
var nav = new OpenLayers.Control.TouchNavigation();
t.eq(nav.dragPanOptions, null, "dragPanOptions null by default");
var map = new OpenLayers.Map({
div: document.body,
controls: [
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {foo: 'bar'}
})
]
});
nav = map.controls[0];
t.eq(nav.dragPan.foo, 'bar',
"foo property is set on the DragPan control");
map.destroy();
}
function test_clickHandlerOptions(t) {
t.plan(3);
var nav = new OpenLayers.Control.TouchNavigation();
t.eq(nav.clickHandlerOptions, null, "clickHandlerOptions null by default");
var map = new OpenLayers.Map({
div: document.body,
controls: [
new OpenLayers.Control.TouchNavigation({
clickHandlerOptions: {foo: "bar"}
})
]
});
nav = map.controls[0];
t.eq(nav.handlers.click.foo, "bar", "foo property is set on the click handler");
t.eq(nav.handlers.click.pixelTolerance, 2, "pixelTolerance is 2 by default");
map.destroy();
}
function test_zoomOut(t) {
t.plan(1);
var map = new OpenLayers.Map('map', {zoomMethod: null});
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'} );
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0, 0), 5);
var origSetTimeout = window.setTimeout;
window.setTimeout = function(fn) { fn(); return 'id'; };
var control = new OpenLayers.Control.TouchNavigation();
map.addControl(control);
var handler = control.handlers.click;
handler.touchstart({xy: new OpenLayers.Pixel(1 ,1), touches: ["foo", "bar"]});
handler.touchend({});
t.eq(map.getZoom(), 4, "Did we zoom out?");
// tear down
map.destroy();
window.setTimeout = origSetTimeout;
}
</script>
</head>
<body>
<div id="map" style="width:512px;height:256px"></div>
</body>
</html>
|