OpenLayers OpenLayers

root/trunk/openlayers/tests/Handler/Path.html

Revision 7552, 4.0 kB (checked in by pgiraud, 6 months ago)

handlers test are not reflecting the reality, we now simulate a click, move then click \n
that way geometry bounds are cleared, and the tests don't fail in IE6 anymore (See #1602), r=ahocevar,crschmidt (Closes #1623)

  • Property svn:eol-style set to native
Line 
1 <html>
2 <head>
3   <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5     function test_Handler_Path_constructor(t) {
6         t.plan(3);
7         var control = new OpenLayers.Control();
8         control.id = Math.random();
9         var callbacks = {foo: "bar"};
10         var options = {bar: "foo"};
11        
12         var oldInit = OpenLayers.Handler.prototype.initialize;
13        
14         OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
15             t.eq(con.id, control.id,
16                  "constructor calls parent with the correct control");
17             t.eq(call, callbacks,
18                  "constructor calls parent with the correct callbacks");
19             t.eq(opt, options,
20                  "constructor calls parent with the correct options");
21         }
22         var handler = new OpenLayers.Handler.Path(control, callbacks, options);
23
24         OpenLayers.Handler.prototype.initialize = oldInit;
25     }
26
27     function test_Handler_Path_activation(t) {
28         t.plan(3);
29         var map = new OpenLayers.Map('map');
30         var control = new OpenLayers.Control();
31         map.addControl(control);
32         var handler = new OpenLayers.Handler.Path(control);
33         handler.active = true;
34         var activated = handler.activate();
35         t.ok(!activated,
36              "activate returns false if the handler was already active");
37         handler.active = false;
38         activated = handler.activate();
39         t.ok(activated,
40              "activate returns true if the handler was not already active");
41         activated = handler.deactivate();
42         t.ok(activated,
43              "deactivate returns true if the handler was active already");
44         map.destroy();     
45     }
46
47     function test_Handler_Path_bounds(t) {
48         t.plan(2);
49         var map = new OpenLayers.Map('map');
50         map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
51         map.zoomToMaxExtent();
52         var control = new OpenLayers.Control();
53         map.addControl(control);
54         var handler = new OpenLayers.Handler.Path(control, {});
55         var activated = handler.activate();
56         var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
57         handler.mousedown(evt);
58         handler.mouseup(evt);
59         var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
60         handler.mousemove(evt);
61         handler.mousedown(evt);
62         handler.mouseup(evt);
63         t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
64         var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
65         handler.mousedown(evt);
66         var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
67         handler.mousemove(evt);
68         t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
69         map.destroy();     
70     }     
71        
72     function test_Handler_Path_destroy(t) {
73         t.plan(6);
74         var map = new OpenLayers.Map('map');
75         map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
76         map.zoomToMaxExtent();
77         var control = new OpenLayers.Control();
78         map.addControl(control);
79         var handler = new OpenLayers.Handler.Path(control, {foo: 'bar'});
80
81         handler.activate();
82         var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
83         handler.mousedown(evt);
84
85         t.ok(handler.layer,
86              "handler has a layer prior to destroy");
87         t.ok(handler.point,
88              "handler has a point prior to destroy");
89         t.ok(handler.line,
90              "handler has a line prior to destroy");
91         handler.destroy();
92         t.eq(handler.layer, null,
93              "handler.layer is null after destroy");
94         t.eq(handler.point, null,
95              "handler.point is null after destroy");
96         t.eq(handler.line, null,
97              "handler.line is null after destroy");
98         map.destroy();     
99     }
100    
101
102
103   </script>
104 </head>
105 <body>
106     <div id="map" style="width: 300px; height: 150px;"/>
107 </body>
108 </html>
Note: See TracBrowser for help on using the browser.