OpenLayers OpenLayers

root/trunk/openlayers/tests/Control/PanZoom.html

Revision 8571, 8.1 kB (checked in by crschmidt, 2 weeks ago)

Since opening window is the bane of our auto-testing existence -- browsers not
configured to allow popups, and so on -- add an option to turn off opening new
windows. Patch the tests to check for open_window before using it, and bail out
of tests early if they can't find it. By default, the auto-tests.html file will
not allow any window opening. This gives us *slightly* smaller test coverage,
with fewer false positives on test failures.

  • 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     var map;
6     function test_Control_PanZoom_constructor (t) {
7         t.plan( 4 );
8    
9         control = new OpenLayers.Control.PanZoom();
10         t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
11         t.eq( control.displayClass,  "olControlPanZoom", "displayClass is correct" );
12         control = new OpenLayers.Control.PanZoom({position: new OpenLayers.Pixel(100,100)});
13         t.eq( control.position.x, 100, "PanZoom X Set correctly.");
14         t.eq( control.position.y, 100, "PanZoom y Set correctly.");
15     }
16     function test_Control_PanZoom_addControl (t) {
17         t.plan( 8 );
18         map = new OpenLayers.Map('map');
19         control = new OpenLayers.Control.PanZoom();
20         t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
21         t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
22         map.addControl(control);
23         t.ok( control.map === map, "Control.map is set to the map object" );
24         t.ok( map.controls[4] === control, "map.controls contains control" );
25         t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Control div zIndexed properly" );
26         t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Viewport div contains control div" );
27         t.eq( control.div.style.top, "4px", "Control div top located correctly by default");
28
29         var control2 = new OpenLayers.Control.PanZoom();
30         map.addControl(control2, new OpenLayers.Pixel(100,100));
31         t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
32     }
33
34     function test_Control_PanZoom_control_events (t) {
35
36         if ( !window.document.createEvent || OpenLayers.Util.getBrowserName() == "opera" || !t.open_window) {
37             //ie can't simulate mouseclicks
38             t.plan(0);
39             t.debug_print("FIXME: This browser does not support the PanZoom test at this time.");
40         } else {
41             t.plan(35);
42             t.open_window( "Control/PanZoom.html", function( wnd ) {
43                 t.delay_call( 3, function() {
44                     var flag;
45                     function setFlag(evt) {
46                         flag[evt.type] = true;
47                     }
48                     function resetFlags() {
49                         flag = {
50                             mousedown: false,
51                             mouseup: false,
52                             click: false,
53                             dblclick: false
54                         };
55                     }
56                     resetFlags();
57                    
58                     wnd.mapper.events.register("mousedown", mapper, setFlag);
59                     wnd.mapper.events.register("mouseup", mapper, setFlag);
60                     wnd.mapper.events.register("click", mapper, setFlag);
61                     wnd.mapper.events.register("dblclick", mapper, setFlag);
62                    
63                     simulateClick(wnd, wnd.control.buttons[0]);
64                     t.delay_call(2, function() {
65                         t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" );
66                         t.ok(!flag.mousedown, "mousedown does not get to the map");
67                         t.ok(flag.mouseup, "mouseup does get to the map");
68                         t.ok(!flag.click, "click does not get to the map");
69                         t.ok(!flag.dblclick, "dblclick does not get to the map");
70                         resetFlags();
71
72                         simulateClick(wnd, wnd.control.buttons[1]);
73                     }, 2, function() {   
74                     t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" );
75                     t.ok(!flag.mousedown, "mousedown does not get to the map");
76                     t.ok(flag.mouseup, "mouseup does get to the map");
77                     t.ok(!flag.click, "click does not get to the map");
78                     t.ok(!flag.dblclick, "dblclick does not get to the map");
79                     resetFlags();
80
81                     simulateClick(wnd, wnd.control.buttons[2]);
82                     }, 2, function() {
83                     t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" );
84                     t.ok(!flag.mousedown, "mousedown does not get to the map");
85                     t.ok(flag.mouseup, "mouseup does get to the map");
86                     t.ok(!flag.click, "click does not get to the map");
87                     t.ok(!flag.dblclick, "dblclick does not get to the map");
88                     resetFlags();
89
90                     simulateClick(wnd, wnd.control.buttons[3]);
91                     }, 2, function() {
92                     t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" );
93                     t.ok(!flag.mousedown, "mousedown does not get to the map");
94                     t.ok(flag.mouseup, "mouseup does get to the map");
95                     t.ok(!flag.click, "click does not get to the map");
96                     t.ok(!flag.dblclick, "dblclick does not get to the map");
97                     resetFlags();
98
99                     simulateClick(wnd, wnd.control.buttons[4]);
100                     }, 2, function() {
101                     t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" );
102                     t.ok(!flag.mousedown, "mousedown does not get to the map");
103                     t.ok(flag.mouseup, "mouseup does get to the map");
104                     t.ok(!flag.click, "click does not get to the map");
105                     t.ok(!flag.dblclick, "dblclick does not get to the map");
106                     resetFlags();
107
108                     simulateClick(wnd, wnd.control.buttons[6]);
109                     }, 2, function() {
110                     t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" );
111                     t.ok(!flag.mousedown, "mousedown does not get to the map");
112                     t.ok(flag.mouseup, "mouseup does get to the map");
113                     t.ok(!flag.click, "click does not get to the map");
114                     t.ok(!flag.dblclick, "dblclick does not get to the map");
115                     resetFlags();
116
117                     simulateClick(wnd, wnd.control.buttons[5]);
118                     }, 2, function() {
119                     t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" );
120                     t.ok(!flag.mousedown, "mousedown does not get to the map");
121                     t.ok(flag.mouseup, "mouseup does get to the map");
122                     t.ok(!flag.click, "click does not get to the map");
123                     t.ok(!flag.dblclick, "dblclick does not get to the map");
124                     resetFlags();
125                     });
126                 });
127             });
128         }
129     }
130
131     function simulateClick(wnd, elem) {
132       var evt = wnd.document.createEvent("MouseEvents");
133       evt.initMouseEvent("mousedown", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
134       elem.dispatchEvent(evt);
135
136       evt = wnd.document.createEvent("MouseEvents");
137       evt.initMouseEvent("mouseup", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
138       elem.dispatchEvent(evt);
139
140       evt = wnd.document.createEvent("MouseEvents");
141       evt.initMouseEvent("click", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
142       elem.dispatchEvent(evt);
143
144       evt = wnd.document.createEvent("MouseEvents");
145       evt.initMouseEvent("dblclick", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
146       elem.dispatchEvent(evt);
147     }
148
149     function loader() {
150         control = new OpenLayers.Control.PanZoom();
151    
152         mapper = new OpenLayers.Map('map', { controls: [control]});
153        
154    
155         var layer = new OpenLayers.Layer.WMS("Test Layer",
156             "http://labs.metacarta.com/wms-c/Basic.py?",
157             {layers: "basic"});
158         mapper.addLayer(layer);
159    
160         centerLL = new OpenLayers.LonLat(0,0);
161         mapper.setCenter(centerLL, 5);
162     }
163        
164
165   </script>
166 </head>
167 <body onload="loader()">
168     <div id="map" style="width: 1024px; height: 512px;"/>
169 </body>
170 </html>
Note: See TracBrowser for help on using the browser.