]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Control/DragFeature.html
do not allow empty passwords
[syp.git] / openlayers / tests / Control / DragFeature.html
1 <html>
2 <head>
3     <script src="../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5     function test_Control_DragFeature_constructor(t) {
6         t.plan(3);
7         
8         var options = {
9             geometryTypes: "foo"
10         };
11         var layer = "bar";
12         var control = new OpenLayers.Control.DragFeature(layer, options);
13         t.ok(control instanceof OpenLayers.Control.DragFeature,
14              "new OpenLayers.Control.DragFeature returns an instance");
15         t.eq(control.layer, "bar",
16              "constructor sets layer correctly");        
17         t.eq(control.handlers.feature.geometryTypes, "foo",
18              "constructor sets options correctly on feature handler");
19     }
20     
21     function test_Control_DragFeature_destroy(t) {
22         t.plan(2);
23         var map = new OpenLayers.Map("map");
24         var layer = new OpenLayers.Layer.Vector();
25         map.addLayer(layer);
26         var control = new OpenLayers.Control.DragFeature(layer);
27         control.handlers.drag.destroy = function() {
28             t.ok(true,
29                  "control.destroy calls destroy on drag handler");
30         }
31         control.handlers.feature.destroy = function() {
32             t.ok(true,
33                  "control.destroy calls destroy on feature handler");
34         }
35         
36         control.destroy();
37         
38     }
39     
40     function test_Control_DragFeature_activate(t) {
41         t.plan(2);
42         var map = new OpenLayers.Map("map");
43         var layer = new OpenLayers.Layer.Vector();
44         map.addLayer(layer);
45         var control = new OpenLayers.Control.DragFeature(layer);
46         map.addControl(control);
47         t.ok(!control.handlers.feature.active,
48              "feature handler is not active prior to activating control");
49         control.activate();
50         t.ok(control.handlers.feature.active,
51              "feature handler is active after activating control");
52     }
53
54     function test_Control_DragFeature_deactivate(t) {
55         t.plan(2);
56         var map = new OpenLayers.Map("map");
57         var layer = new OpenLayers.Layer.Vector();
58         map.addLayer(layer);
59         var control = new OpenLayers.Control.DragFeature(layer);
60         map.addControl(control);
61         
62         control.handlers.drag.deactivate = function() {
63             t.ok(true,
64                  "control.deactivate calls deactivate on drag handler");
65         }
66         control.handlers.feature.deactivate = function() {
67             t.ok(true,
68                  "control.deactivate calls deactivate on feature handler");
69         }
70         control.deactivate();
71     }
72     
73     function test_Control_DragFeature_over(t) {
74         t.plan(3);
75         var map = new OpenLayers.Map("map");
76         var layer = new OpenLayers.Layer.Vector();
77         map.addLayer(layer);
78         var control = new OpenLayers.Control.DragFeature(layer);
79         map.addControl(control);
80         
81         control.activate();
82         t.ok(!control.handlers.drag.active,
83              "drag handler is not active before over a feature");
84         
85         // simulate a mouseover on a feature
86         var feature = new OpenLayers.Feature.Vector();
87         feature.layer = layer;
88         layer.getFeatureFromEvent = function(evt) {
89             return feature;
90         }
91         map.events.triggerEvent("mousemove", {type: "mousemove"});
92         
93         t.eq(control.feature.id, feature.id,
94              "control gets the proper feature from the feature handler");
95         t.ok(control.handlers.drag.active,
96              "drag handler activated when over a feature");
97     }
98
99     function test_Control_DragFeature_down(t) {
100         t.plan(3);
101         var map = new OpenLayers.Map("map");
102         var layer = new OpenLayers.Layer.Vector();
103         map.addLayer(layer);
104         var control = new OpenLayers.Control.DragFeature(layer);
105         map.addControl(control);
106         
107         control.activate();
108         
109         // simulate a mouseover on a feature
110         var feature = new OpenLayers.Feature.Vector();
111         feature.layer = layer;
112         layer.getFeatureFromEvent = function(evt) {
113             return feature;
114         }
115         map.events.triggerEvent("mousemove", {type: "mousemove"});
116
117         // simulate a mousedown on a feature
118         control.onStart = function(feat, pixel) {
119             t.eq(feat.id, feature.id, "onStart called with the correct feature");
120             t.eq(pixel, "bar", "onStart called with the correct pixel");
121         }
122         map.events.triggerEvent("mousedown", {xy: "bar", which: 1, type: "mousemove"});
123
124         t.eq(control.lastPixel, "bar",
125              "mousedown sets the lastPixel correctly");
126     }
127
128     function test_Control_DragFeature_move(t) {
129         t.plan(3);
130         var map = new OpenLayers.Map("map");
131         var layer = new OpenLayers.Layer.Vector();
132         map.addLayer(layer);
133         var control = new OpenLayers.Control.DragFeature(layer);
134         map.addControl(control);
135         map.getResolution = function() {
136             return 2;
137         }
138
139         control.activate();
140
141         // mock up a feature - for the sole purpose of testing mousemove
142         var uid = Math.random();
143         layer.getFeatureFromEvent = function() {
144             var geom = new OpenLayers.Geometry.Point(Math.random(),
145                                                      Math.random());
146             geom.move = function(x, y) {
147                 t.eq(x, 2, "move called with dx * res");
148                 t.eq(y, -4, "move called with -dy * res");
149             };
150             var feature = new OpenLayers.Feature.Vector(geom);
151             feature.layer = layer;
152             feature.uid = uid;
153             return feature;
154         };
155         layer.drawFeature = function(feature) {
156             t.eq(feature.uid, uid,
157                  "layer.drawFeature called with correct feature");
158         };
159
160         // simulate a mouseover on a feature
161         map.events.triggerEvent("mousemove", {type: "mousemove"});
162
163         // simulate a mousedown on a feature
164         var down = new OpenLayers.Pixel(0, 0);
165         map.events.triggerEvent("mousedown", {xy: down, which: 1, type: "mousemove"});
166
167         // simulate a mousemove on a feature
168         var move = new OpenLayers.Pixel(1, 2);
169         map.events.triggerEvent("mousemove", {xy: move, which: 1, type: "mousemove"});
170         
171     }
172
173     function test_Control_DragFeature_up(t) {
174         t.plan(6);
175         var map = new OpenLayers.Map("map");
176         var layer = new OpenLayers.Layer.Vector();
177         map.addLayer(layer);
178         var control = new OpenLayers.Control.DragFeature(layer);
179         map.addControl(control);
180
181         control.activate();
182
183         // simulate a mouseover on a feature
184         var feature = new OpenLayers.Feature.Vector();
185         feature.layer = layer;
186         layer.getFeatureFromEvent = function(evt) {
187             return feature;
188         }
189         map.events.triggerEvent("mousemove", {type: "mousemove"});
190         t.eq(control.over, true,
191             "mouseover on a feature sets the over property to true");
192         t.ok(OpenLayers.Element.hasClass(control.map.viewPortDiv, "olControlDragFeatureOver"),
193             "mouseover on a feature adds class name to map container");
194         t.eq(control.handlers.drag.active, true,
195             "mouseover on a feature activates drag handler");
196
197         // simulate a mouse-up on the map, with the mouse still
198         // over the dragged feature
199         control.handlers.drag.started = true;
200         map.events.triggerEvent("mouseup", {type: "mouseup"});
201         t.eq(control.handlers.drag.active, true,
202             "mouseup while still over dragged feature does not deactivate drag handler");
203
204         // simulate a mouse-up on the map, with the mouse out of
205         // the dragged feature
206         control.handlers.drag.started = true;
207         control.over = false;
208         map.events.triggerEvent("mouseup", {type: "mouseup"});
209         t.eq(control.handlers.drag.active, false,
210             "mouseup deactivates drag handler");
211
212         control.deactivate();
213         t.ok(!OpenLayers.Element.hasClass(control.map.viewPortDiv, "olControlDragFeatureOver"),
214             "deactivate removes class name from map container");
215     }
216     
217     function test_Control_DragFeature_done(t) {
218         t.plan(2);
219         var map = new OpenLayers.Map("map");
220         var layer = new OpenLayers.Layer.Vector();
221         map.addLayer(layer);
222         var control = new OpenLayers.Control.DragFeature(layer);
223         map.addControl(control);
224
225         control.activate();
226
227
228         // simulate a mouseover on a feature
229         var feature = new OpenLayers.Feature.Vector();
230         feature.layer = layer;
231         layer.getFeatureFromEvent = function() {
232             return feature;
233         };
234         map.events.triggerEvent("mousemove", {type: "mousemove"});
235         t.eq(control.feature.id, feature.id,
236              "feature is set on mouse over");
237         control.doneDragging();
238         t.eq(control.feature.id, feature.id, 
239           "feature sticks around after doneDragging is called.");
240         
241     }
242
243     function test_Control_DragFeature_out(t) {
244         t.plan(2);
245         var map = new OpenLayers.Map("map");
246         var layer = new OpenLayers.Layer.Vector();
247         map.addLayer(layer);
248         var control = new OpenLayers.Control.DragFeature(layer);
249         map.addControl(control);
250
251         control.activate();
252
253
254         // simulate a mouseover on a feature
255         var feature = new OpenLayers.Feature.Vector();
256         feature.layer = layer;
257         layer.getFeatureFromEvent = function() {
258             return feature;
259         };
260         map.events.triggerEvent("mousemove", {type: "mousemove"});
261         t.eq(control.feature.id, feature.id,
262              "feature is set on mouse over");
263         
264         // simulate a mouseout on a feature
265         layer.getFeatureFromEvent = function() {
266             return null;
267         };
268         map.events.triggerEvent("mousemove", {type: "mousemove"});
269         t.ok(control.feature == null,
270              "feature is set to null on mouse out");
271         
272     }
273
274     </script>
275 </head>
276 <body>
277     <div id="map" style="width: 400px; height: 250px;"/>
278 </body>
279 </html>