~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Util.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <script src="../lib/OpenLayers.js"></script>
 
4
  <script type="text/javascript">
 
5
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
 
6
    var map; 
 
7
    
 
8
    function test_Util_getImagesLocation (t) {
 
9
        t.plan( 1 );
 
10
        t.ok( OpenLayers.Util.getImagesLocation(), "../img/",
 
11
                    "getImagesLocation()" );
 
12
    }
 
13
 
 
14
    function test_Util_Array(t) {
 
15
        t.plan( 2 );
 
16
 
 
17
        var array = new Array(1,2,3,4,4,5);
 
18
 
 
19
        OpenLayers.Util.removeItem(array, 3);
 
20
        t.eq( array.toString(), "1,2,4,4,5", "Util.removeItem works on one element");    
 
21
        OpenLayers.Util.removeItem(array, 4);
 
22
        t.eq( array.toString(), "1,2,5", "Util.removeItem works on more than one element ");    
 
23
    }
 
24
    
 
25
    function test_Util_pagePosition(t) {
 
26
        t.plan( 1 );
 
27
        var pp = OpenLayers.Util.pagePosition(window);
 
28
        t.eq( pp.toString(), "0,0", "Page position doesn't bail if passed 'window'")
 
29
        
 
30
    }
 
31
 
 
32
    function test_Util_createDiv(t) {
 
33
        t.plan( 24 );
 
34
 
 
35
        var id = "boo";
 
36
        var px = new OpenLayers.Pixel(5,5);
 
37
        var sz = new OpenLayers.Size(10,10);
 
38
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
 
39
        var position = "absolute";
 
40
        var border = "13px solid";
 
41
        var overflow = "hidden";
 
42
        var opacity = 0.5;
 
43
 
 
44
        var div = OpenLayers.Util.createDiv(id, px, sz, img, position, border, overflow, opacity);
 
45
 
 
46
        if (!isMozilla)
 
47
            t.ok( true, "skipping element test outside of Mozilla");
 
48
        else
 
49
            t.ok( div instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
 
50
        t.eq( div.id, id, "div.id set correctly");    
 
51
        t.eq( div.style.left, px.x + "px", "div.style.left set correctly");    
 
52
        t.eq( div.style.top, px.y + "px", "div.style.top set correctly");    
 
53
 
 
54
        t.eq( div.style.width, sz.w + "px", "div.style.width set correctly");    
 
55
        t.eq( div.style.height, sz.h + "px", "div.style.height set correctly");    
 
56
 
 
57
        bImg = div.style.backgroundImage;
 
58
        imgCorrect = ( (bImg == "url(" + img + ")") ||  
 
59
                       (bImg == "url(\"" + img + "\")") );
 
60
        t.ok(imgCorrect, "div.style.backgroundImage correctly");    
 
61
 
 
62
        t.eq( div.style.position, position, "div.style.positionset correctly");    
 
63
        //Safari 3 separates the border style into separate entities when reading it
 
64
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
65
          var s = border.split(' ');
 
66
          t.ok(div.style.borderTopWidth == s[0] && div.style.borderTopStyle == s[1], "good default popup.border")
 
67
        } else {
 
68
          t.ok( (div.style.border.indexOf(border) != -1), "div.style.border set correctly");
 
69
        }
 
70
            
 
71
        //Safari 3 separates style overflow into overflow-x and overflow-y
 
72
        var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
 
73
        t.eq( div.style[prop], overflow, "div.style.overflow set correctly");    
 
74
        t.eq( parseFloat(div.style.opacity), opacity, "element.style.opacity set correctly");    
 
75
        //Safari 3 returns null for this value, which is okay
 
76
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
77
        t.eq( div.style.filter, filterString, "element.style.filter set correctly");
 
78
 
 
79
        //test defaults
 
80
        var div = OpenLayers.Util.createDiv();
 
81
 
 
82
        if (!isMozilla)
 
83
            t.ok( true, "skipping element test outside of Mozilla");
 
84
        else
 
85
            t.ok( div instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
 
86
        t.ok( (div.id != ""), "div.id set correctly");    
 
87
        t.eq(div.style.left, "", "div.style.left set correctly");    
 
88
        t.eq(div.style.top, "", "div.style.top set correctly");    
 
89
 
 
90
        t.eq( div.style.width, "", "div.style.width set correctly");    
 
91
        t.eq( div.style.height, "", "div.style.height set correctly");    
 
92
 
 
93
        t.eq(div.style.backgroundImage, "", "div.style.backgroundImage correctly");    
 
94
 
 
95
        t.eq( div.style.position, "absolute", "div.style.positionset correctly");    
 
96
        //Safari 3 separates the border style into separate entities when reading it
 
97
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
98
          t.ok(div.style.borderTopWidth == '' && div.style.borderTopStyle == '', "good default popup.border")
 
99
        } else {
 
100
          t.eq( div.style.border, "", "div.style.border set correctly");    
 
101
        }
 
102
        //Safari 3 separates style overflow into overflow-x and overflow-y
 
103
        var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
 
104
        t.eq(div.style[prop], "", "div.style.overflow set correctly");    
 
105
        t.ok( !div.style.opacity, "element.style.opacity set correctly");    
 
106
        t.ok( !div.style.filter, "element.style.filter set correctly");
 
107
 
 
108
    }
 
109
 
 
110
    function test_Util_createImage(t) {
 
111
        t.plan( 22 );
 
112
 
 
113
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
 
114
        var sz = new OpenLayers.Size(10,10);
 
115
        var xy = new OpenLayers.Pixel(5,5);
 
116
        var position = "absolute";
 
117
        var id = "boo";
 
118
        var border = "1px solid";
 
119
        var opacity = 0.5;
 
120
 
 
121
        var image = OpenLayers.Util.createImage(id, xy, sz, img, position, border, opacity);
 
122
 
 
123
        if (!isMozilla)
 
124
            t.ok( true, "skipping element test outside of Mozilla");
 
125
        else
 
126
            t.ok( image.nodeName == "IMG", "createImage creates a valid HTMLImageElement" );
 
127
        t.eq( image.id, id, "image.id set correctly");    
 
128
        t.eq( image.style.left, xy.x + "px", "image.style.left set correctly");    
 
129
        t.eq( image.style.top, xy.y + "px", "image.style.top set correctly");    
 
130
 
 
131
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");    
 
132
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");    
 
133
 
 
134
        //Safari 3 separates the border style into separate entities when reading it
 
135
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
136
          var s = border.split(' ');
 
137
          t.ok(image.style.borderTopWidth == s[0] && image.style.borderTopStyle == s[1], "good default popup.border")
 
138
        } else {
 
139
          t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
 
140
        }
 
141
        t.eq( image.src, img, "image.style.backgroundImage correctly");    
 
142
        t.eq( image.style.position, position, "image.style.position set correctly");    
 
143
        t.eq( parseFloat(image.style.opacity), opacity, "image.style.opacity set correctly");    
 
144
        //Safari 3 returns null for this value, which is okay
 
145
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
146
        t.eq( image.style.filter, filterString, "element.style.filter set correctly");
 
147
 
 
148
        //test defaults
 
149
        var image = OpenLayers.Util.createImage();
 
150
 
 
151
        if (!isMozilla)
 
152
            t.ok( true, "skipping element test outside of Mozilla");
 
153
        else
 
154
            t.ok( image.nodeName == "IMG", "createDiv creates a valid HTMLDivElement" );
 
155
        t.ok( (image.id != ""), "image.id set to something");    
 
156
        t.eq( image.style.left, "", "image.style.left set correctly");    
 
157
        t.eq( image.style.top, "", "image.style.top set correctly");    
 
158
 
 
159
        t.eq( image.style.width, "", "image.style.width set correctly");    
 
160
        t.eq( image.style.height, "", "image.style.height set correctly");    
 
161
 
 
162
        t.ok((image.style.border == ""), "image.style.border set correctly");    
 
163
        t.eq(image.src, "", "image.style.backgroundImage correctly");    
 
164
        t.eq( image.style.position, "relative", "image.style.positionset correctly");    
 
165
        t.ok( !image.style.opacity, "element.style.opacity default unset");    
 
166
        t.ok( !image.style.filter, "element.style.filter default unset");
 
167
 
 
168
    }
 
169
 
 
170
    function test_Util_applyDefaults(t) {
 
171
    
 
172
        t.plan(12);
 
173
        
 
174
        var to = { 
 
175
            'a': "abra",
 
176
            'b': "blorg",
 
177
            'n': null
 
178
        };
 
179
 
 
180
        var from = { 
 
181
            'b': "zoink",
 
182
            'c': "press",
 
183
            'toString': function() {return 'works'},
 
184
            'n': "broken"
 
185
        };
 
186
 
 
187
        OpenLayers.Util.applyDefaults(to, from);
 
188
 
 
189
        t.ok( to instanceof Object, " applyDefaults returns an object");
 
190
        t.eq( to["a"], "abra", "key present in to but not from maintained");
 
191
        t.eq( to["b"], "blorg", "key present in to and from, maintained in to");
 
192
        t.eq( to["c"], "press", "key present in from and not to successfully copied to to");
 
193
 
 
194
        var ret = OpenLayers.Util.applyDefaults({'a': "abra",'b': "blorg"}, from);
 
195
        t.ok( ret instanceof Object, " applyDefaults returns an object");
 
196
        t.eq( ret["a"], "abra", "key present in ret but not from maintained");
 
197
        t.eq( ret["b"], "blorg", "key present in ret and from, maintained in ret");
 
198
        t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret");
 
199
        t.eq(to.toString(), "works", "correctly applies custom toString");
 
200
        t.eq(to.n, null, "correctly preserves null");
 
201
        
 
202
        var to;
 
203
        var from = {rand: Math.random()};
 
204
        
 
205
        var ret = OpenLayers.Util.applyDefaults(to, from);
 
206
        t.eq(ret.rand, from.rand, "works with undefined to");
 
207
 
 
208
        //regression test for #1716 -- allow undefined from
 
209
        try {
 
210
            OpenLayers.Util.applyDefaults({}, undefined);
 
211
            t.ok(true, "no exception thrown when from is undefined");
 
212
        } catch(err) {
 
213
            t.fail("exception thrown when from is undefined:" + err);
 
214
        }
 
215
 
 
216
    }
 
217
 
 
218
    function test_Util_getParameterString(t) {
 
219
        t.plan( 4 );
 
220
 
 
221
        var params = { 
 
222
            'foo': "bar",
 
223
            'chicken': 1.5
 
224
        };
 
225
 
 
226
        t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");    
 
227
        t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values");    
 
228
        
 
229
 
 
230
        // Parameters which are a list should end up being a comma-seperated
 
231
        // list of the URL encoded strings
 
232
        var params = { foo: ["bar,baz"] };
 
233
        t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays");    
 
234
        
 
235
        var params = { foo: ["bar","baz,"] };
 
236
        t.eq( OpenLayers.Util.getParameterString(params), "foo=bar,baz%2C", "getParameterString returns with list of CSVs when given a list. ");    
 
237
    }
 
238
 
 
239
    function test_Util_createAlphaImageDiv(t) {
 
240
        t.plan( 19 );
 
241
 
 
242
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
 
243
        var sz = new OpenLayers.Size(10,10);
 
244
        var xy = new OpenLayers.Pixel(5,5);
 
245
        var position = "absolute";
 
246
        var id = "boo";
 
247
        var border = "1px solid";
 
248
        var sizing = "crop";
 
249
        var opacity = 0.5;
 
250
 
 
251
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border, sizing, opacity);
 
252
 
 
253
        if (!isMozilla)
 
254
            t.ok( true, "skipping element test outside of Mozilla");
 
255
        else
 
256
            t.ok( imageDiv instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
 
257
 
 
258
        t.eq( imageDiv.id, id, "image.id set correctly");    
 
259
        t.eq( imageDiv.style.left, xy.x + "px", "image.style.left set correctly");    
 
260
        t.eq( imageDiv.style.top, xy.y + "px", "image.style.top set correctly");    
 
261
 
 
262
        t.eq( imageDiv.style.width, sz.w + "px", "image.style.width set correctly");    
 
263
        t.eq( imageDiv.style.height, sz.h + "px", "image.style.height set correctly");    
 
264
 
 
265
        t.eq( imageDiv.style.position, position, "image.style.positionset correctly");    
 
266
        t.eq( parseFloat(imageDiv.style.opacity), opacity, "element.style.opacity set correctly");    
 
267
        
 
268
        var filterString;
 
269
        if (OpenLayers.Util.alphaHack()) {
 
270
            filterString = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.openlayers.org/images/OpenLayers.trac.png', sizingMethod='crop') alpha(opacity=50)";
 
271
        } else {
 
272
            //Safari 3 returns null for this value, which is okay
 
273
            var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
274
        }        
 
275
        t.eq( imageDiv.style.filter, filterString, "element.style.filter set correctly");
 
276
 
 
277
 
 
278
        image = imageDiv.firstChild;
 
279
        if (!isMozilla)
 
280
            t.ok( true, "skipping element test outside of Mozilla");
 
281
        else
 
282
            t.ok( image.nodeName == "IMG", "createImage creates a valid HTMLImageElement" );
 
283
        t.eq( image.id, id + "_innerImage", "image.id set correctly");    
 
284
 
 
285
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");    
 
286
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");    
 
287
 
 
288
        //Safari 3 separates the border style into separate entities when reading it
 
289
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
290
          var s = border.split(' ');
 
291
          t.ok(image.style.borderTopWidth == s[0] && image.style.borderTopStyle == s[1], "good default popup.border")
 
292
        } else {
 
293
          t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
 
294
        }
 
295
        
 
296
        t.eq( image.style.position, "relative", "image.style.positionset correctly");    
 
297
 
 
298
        if (OpenLayers.Util.alphaHack()) {
 
299
        
 
300
            t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly");
 
301
 
 
302
            var filter = "progid:DXImageTransform.Microsoft" +
 
303
                         ".AlphaImageLoader(src='" + img + "', " +
 
304
                         "sizingMethod='" + sizing + "') alpha(opacity=50)";
 
305
            t.eq(imageDiv.style.filter, filter, "div filter value correctly set");
 
306
 
 
307
            filter = "alpha(opacity=0)";
 
308
            t.eq(image.style.filter, filter, "image filter set correctly");
 
309
 
 
310
        } else {
 
311
            t.eq( image.src, img, "image.style.backgroundImage correctly");    
 
312
            t.ok(true, "div filter value not set (not in IE)");
 
313
            t.ok(true, "image filter value not set (not in IE)");
 
314
        }
 
315
 
 
316
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border);
 
317
        if (OpenLayers.Util.alphaHack()) {
 
318
            var filter = "progid:DXImageTransform.Microsoft" +
 
319
                         ".AlphaImageLoader(src='" + img + "', " +
 
320
                         "sizingMethod='scale')";
 
321
            t.eq(imageDiv.style.filter, filter, "sizingMethod default correctly set to scale");
 
322
        } else {
 
323
            t.ok(true);
 
324
        }        
 
325
 
 
326
    }
 
327
 
 
328
    function test_Util_modifyDOMElement_opacity(t) {
 
329
        t.plan(8);
 
330
 
 
331
        var opacity = 0.2;
 
332
 
 
333
        var element = document.createElement("div");
 
334
 
 
335
        OpenLayers.Util.modifyDOMElement(element, null, null, null, null, 
 
336
                                         null, null, opacity);
 
337
 
 
338
        t.eq(parseFloat(element.style.opacity), opacity, 
 
339
             "element.style.opacity set correctly when opacity = " + opacity);
 
340
        //Safari 3 returns null for this value, which is okay
 
341
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
342
        t.eq(element.style.filter, filterString, 
 
343
             "element.style.filter set correctly when opacity = " + opacity);
 
344
 
 
345
        OpenLayers.Util.modifyDOMElement(element, null, null, null, null, 
 
346
                                         null, null, "5");
 
347
    
 
348
        t.eq(parseFloat(element.style.opacity), opacity, 
 
349
             "element.style.opacity not changed if the value is incorrect");
 
350
        //Safari 3 returns null for this value, which is okay
 
351
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
352
        t.eq(element.style.filter, filterString, 
 
353
             "element.style.filter not changed if the value is incorrect");
 
354
 
 
355
        OpenLayers.Util.modifyDOMElement(element, null, null, null, null, 
 
356
                                         null, null, "hello");
 
357
    
 
358
        t.eq(parseFloat(element.style.opacity), opacity, 
 
359
             "element.style.opacity not changed if the value is incorrect");
 
360
        //Safari 3 returns null for this value, which is okay
 
361
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
362
        t.eq(element.style.filter, filterString, 
 
363
             "element.style.filter not changed if the value is incorrect");
 
364
 
 
365
        opacity = 1.00;
 
366
        OpenLayers.Util.modifyDOMElement(element, null, null, null, null, 
 
367
                                         null, null, opacity);
 
368
 
 
369
        t.eq(element.style.opacity, '', 
 
370
             "element.style.opacity is removed when opacity = " + opacity);
 
371
        //Safari 3 returns null for this value, which is okay
 
372
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : '';
 
373
        t.eq(element.style.filter, filterString, 
 
374
             "element.style.filter is removed when opacity = " + opacity);
 
375
    }
 
376
 
 
377
    function test_Util_modifyDOMElement(t) {
 
378
        t.plan( 10 );
 
379
 
 
380
        var id = "boo";
 
381
        var px = new OpenLayers.Pixel(5,5);
 
382
        var sz = new OpenLayers.Size(10,10);
 
383
        var position = "absolute";
 
384
        var border = "1px solid";
 
385
        var overflow = "hidden";
 
386
        var opacity = 1/2;
 
387
 
 
388
        var element = document.createElement("div");
 
389
 
 
390
        OpenLayers.Util.modifyDOMElement(element, id, px, sz, position, 
 
391
                                         border, overflow, opacity);
 
392
 
 
393
        t.eq( element.id, id, "element.id set correctly");    
 
394
        t.eq( element.style.left, px.x + "px", "element.style.left set correctly");    
 
395
        t.eq( element.style.top, px.y + "px", "element.style.top set correctly");    
 
396
 
 
397
        t.eq( element.style.width, sz.w + "px", "element.style.width set correctly");    
 
398
        t.eq( element.style.height, sz.h + "px", "element.style.height set correctly");    
 
399
 
 
400
        t.eq( element.style.position, position, "element.style.position set correctly");    
 
401
        //Safari 3 separates the border style into separate entities when reading it
 
402
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
403
          var s = border.split(' ');
 
404
          t.ok(element.style.borderTopWidth == s[0] && element.style.borderTopStyle == s[1], "good default popup.border")
 
405
        } else {
 
406
          t.ok( (element.style.border.indexOf(border) != -1), "element.style.border set correctly");
 
407
        }
 
408
        //Safari 3 separates style overflow into overflow-x and overflow-y
 
409
        var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
 
410
        t.eq( element.style[prop], overflow, "element.style.overflow set correctly");    
 
411
        t.eq( parseFloat(element.style.opacity), opacity, "element.style.opacity set correctly");    
 
412
        //Safari 3 returns null for this value, which is okay
 
413
        var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
414
        t.eq( element.style.filter, filterString, "element.style.filter set correctly");
 
415
    }
 
416
 
 
417
    function test_Util_modifyAlphaImageDiv(t) {
 
418
        t.plan( 21 );
 
419
 
 
420
        var imageDiv = OpenLayers.Util.createAlphaImageDiv();
 
421
 
 
422
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
 
423
        var sz = new OpenLayers.Size(10,10);
 
424
        var xy = new OpenLayers.Pixel(5,5);
 
425
        var position = "absolute";
 
426
        var id = "boo";
 
427
        var border = "1px solid";
 
428
        var sizing = "crop";
 
429
        var opacity = 0.5;
 
430
 
 
431
        OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing, opacity);
 
432
        if (OpenLayers.Util.alphaHack())
 
433
            t.ok( true, "skipping element test outside of Mozilla");
 
434
        else
 
435
            t.ok( imageDiv.nodeName == "DIV", "createDiv creates a valid HTMLDivElement" );
 
436
 
 
437
        t.eq( imageDiv.id, id, "image.id set correctly");    
 
438
        t.eq( imageDiv.style.left, xy.x + "px", "image.style.left set correctly");    
 
439
        t.eq( imageDiv.style.top, xy.y + "px", "image.style.top set correctly");    
 
440
 
 
441
        t.eq( imageDiv.style.width, sz.w + "px", "image.style.width set correctly");    
 
442
        t.eq( imageDiv.style.height, sz.h + "px", "image.style.height set correctly");    
 
443
 
 
444
        t.eq( imageDiv.style.position, position, "image.style.position set correctly");    
 
445
        t.eq( parseFloat(imageDiv.style.opacity), opacity, "element.style.opacity set correctly");    
 
446
 
 
447
        
 
448
 
 
449
        image = imageDiv.firstChild;
 
450
 
 
451
        var filterString;
 
452
        if (OpenLayers.Util.alphaHack()) {
 
453
            filterString = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.openlayers.org/images/OpenLayers.trac.png', sizingMethod='crop') alpha(opacity=50)";
 
454
            t.ok( true, "skipping element test outside of Mozilla");
 
455
        } else {
 
456
            //Safari 3 returns null for this value, which is okay
 
457
            var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
 
458
            t.ok( image.nodeName == "IMG", "createImage creates a valid HTMLImageElement" );
 
459
        }
 
460
        t.eq( imageDiv.style.filter, filterString, "element.style.filter set correctly");
 
461
        t.eq( image.id, id + "_innerImage", "image.id set correctly");    
 
462
 
 
463
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");    
 
464
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");    
 
465
 
 
466
        //Safari 3 separates the border style into separate entities when reading it
 
467
        if (OpenLayers.Util.getBrowserName() == 'safari') {
 
468
          var s = border.split(' ');
 
469
          t.ok(image.style.borderTopWidth == s[0] && image.style.borderTopStyle == s[1], "good default popup.border")
 
470
        } else {
 
471
          t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
 
472
        }
 
473
 
 
474
        t.eq( image.style.position, "relative", "image.style.positionset correctly");    
 
475
        t.eq( image.src, img, "image.style.backgroundImage correctly");
 
476
        
 
477
        if (OpenLayers.Util.alphaHack()) {
 
478
        
 
479
            var filter = "progid:DXImageTransform.Microsoft" +
 
480
                         ".AlphaImageLoader(src='" + img + "', " +
 
481
                         "sizingMethod='" + sizing + "') alpha(opacity=" + opacity *100 + ")";
 
482
            t.eq(imageDiv.style.filter, filter, "div filter value correctly set");
 
483
 
 
484
            filter = "alpha(opacity=0)";
 
485
            t.eq(image.style.filter, filter, "image filter set correctly");
 
486
 
 
487
        } else {  
 
488
            t.ok(true, "div filter value not set (not in IE)");
 
489
            t.ok(true, "image filter value not set (not in IE)");
 
490
        }
 
491
 
 
492
        var imageDiv = OpenLayers.Util.createAlphaImageDiv();
 
493
        var display = "none";
 
494
        imageDiv.style.display = display;
 
495
        OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing, opacity);
 
496
        t.eq(imageDiv.style.display, display, "imageDiv.style.display set correctly, if 'none'");
 
497
 
 
498
        var imageDiv = OpenLayers.Util.createAlphaImageDiv();
 
499
        var display = "block";
 
500
        imageDiv.style.display = display;
 
501
        OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing, opacity);
 
502
        if(OpenLayers.Util.alphaHack()) {
 
503
            t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly, if not 'none'");
 
504
        } else {
 
505
            t.ok(true, "inline-block is not part of CSS2 and is not supported by Firefox 2");
 
506
        }
 
507
 
 
508
        
 
509
 
 
510
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border, "scale", opacity);
 
511
        if (OpenLayers.Util.alphaHack()) {
 
512
            var filter = "progid:DXImageTransform.Microsoft" +
 
513
                         ".AlphaImageLoader(src='" + img + "', " +
 
514
                         "sizingMethod='scale') alpha(opacity=" + opacity *100 + ")";
 
515
            t.eq(imageDiv.style.filter, filter, "sizingMethod default correctly set to scale");
 
516
        } else {
 
517
            t.ok(true);
 
518
        }        
 
519
   
 
520
    }
 
521
       
 
522
    function test_Util_upperCaseObject(t) {
 
523
        t.plan(8);
 
524
        
 
525
        var aKey = "chicken";
 
526
        var aValue = "pot pie";
 
527
 
 
528
        var bKey = "blorg";
 
529
        var bValue = "us maximus";
 
530
        
 
531
        var obj = {};
 
532
        obj[aKey] = aValue;        
 
533
        obj[bKey] = bValue;        
 
534
             
 
535
        var uObj = OpenLayers.Util.upperCaseObject(obj);          
 
536
 
 
537
        //make sure old object not modified
 
538
        t.eq(obj[aKey], aValue, "old lowercase value still present in old obj");
 
539
        t.eq(obj[bKey], bValue, "old lowercase value still present in old obj");
 
540
 
 
541
        t.eq(obj[aKey.toUpperCase()], null, "new uppercase value not present in old obj");
 
542
        t.eq(obj[bKey.toUpperCase()], null, "new uppercase value not present in old obj");
 
543
 
 
544
        //make sure new object modified
 
545
        t.eq(uObj[aKey], null, "old lowercase value not present");
 
546
        t.eq(uObj[bKey], null, "old lowercase value not present");
 
547
 
 
548
        t.eq(uObj[aKey.toUpperCase()], aValue, "new uppercase value present");
 
549
        t.eq(uObj[bKey.toUpperCase()], bValue, "new uppercase value present");
 
550
    }
 
551
    
 
552
    function test_Util_createUniqueID(t) {
 
553
        t.plan(2);
 
554
        
 
555
        var id = OpenLayers.Util.createUniqueID();
 
556
        t.ok(OpenLayers.String.startsWith(id, "id_"),
 
557
             "default OpenLayers.Util.createUniqueID starts id correctly");
 
558
 
 
559
        var id = OpenLayers.Util.createUniqueID("chicken");
 
560
        t.ok(OpenLayers.String.startsWith(id, "chicken"),
 
561
             "OpenLayers.Util.createUniqueID starts id correctly");
 
562
    }
 
563
        
 
564
    function test_Util_normalizeScale(t) {
 
565
        t.plan(2); 
 
566
        
 
567
        //normal scale
 
568
        var scale = 1/5;
 
569
        t.eq( OpenLayers.Util.normalizeScale(scale), scale, "normalizing a normal scale does nothing");
 
570
 
 
571
        //funky scale
 
572
        var scale = 5;
 
573
        t.eq( OpenLayers.Util.normalizeScale(scale), 1/5, "normalizing a wrong scale works!");
 
574
    }
 
575
    
 
576
    function test_Util_getScaleResolutionTranslation(t) {
 
577
        t.plan(4); 
 
578
        
 
579
        var scale = 1/150000000; 
 
580
        var resolution = OpenLayers.Util.getResolutionFromScale(scale);
 
581
        t.eq(resolution.toFixed(6), "0.476217", "Calculated correct resolution for " + scale);
 
582
 
 
583
        var scale = 1/150000000; 
 
584
        var resolution = OpenLayers.Util.getResolutionFromScale(scale, 'm');
 
585
        t.eq(resolution.toFixed(6), "52916.638092", "Calculated correct resolution for " + scale);
 
586
 
 
587
        scale = 150000000; 
 
588
        resolution = OpenLayers.Util.getResolutionFromScale(scale);
 
589
        t.eq(resolution.toFixed(6), "0.476217", "Calculated correct resolution for " + scale);
 
590
 
 
591
        scale = 150000000; 
 
592
        resolution = OpenLayers.Util.getResolutionFromScale(scale);
 
593
        t.eq(OpenLayers.Util.getScaleFromResolution(resolution), scale, "scale->resolution->scale works");
 
594
    }
 
595
    
 
596
    function test_Util_getImgLocation(t) {
 
597
        t.plan(3);
 
598
 
 
599
        OpenLayers.ImgPath = "foo/";
 
600
        t.eq(OpenLayers.Util.getImagesLocation(), "foo/", "ImgPath works as expected."); 
 
601
        OpenLayers.ImgPath = null;
 
602
        t.eq(OpenLayers.Util.getImagesLocation().substr(OpenLayers.Util.getImagesLocation().length-4,4), "img/", "ImgPath works as expected when not set."); 
 
603
 
 
604
        OpenLayers.ImgPath = '';
 
605
        t.eq(OpenLayers.Util.getImagesLocation().substr(OpenLayers.Util.getImagesLocation().length-4,4), "img/", "ImgPath works as expected when set to ''."); 
 
606
    }
 
607
 
 
608
    function test_Util_isEquivalentUrl(t) {
 
609
        t.plan(8);
 
610
        
 
611
        var url1, url2, options;
 
612
 
 
613
  //CASE
 
614
 
 
615
        url1 = "http://www.openlayers.org";
 
616
        url2 = "HTTP://WWW.OPENLAYERS.ORG";
 
617
 
 
618
        t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreCase works"); 
 
619
 
 
620
  //ARGS
 
621
 
 
622
        url1 = "http://www.openlayers.org?foo=5;bar=6";
 
623
        url2 = "http://www.openlayers.org?bar=6;foo=5";
 
624
 
 
625
        t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "shuffled arguments works"); 
 
626
 
 
627
  //PORT
 
628
 
 
629
        url1 = "http://www.openlayers.org:80";
 
630
        url2 = "http://www.openlayers.org";
 
631
 
 
632
        t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignorePort80 works"); 
 
633
 
 
634
        options = {
 
635
            'ignorePort80': false
 
636
        }        
 
637
        url1 = "http://www.openlayers.org:80";
 
638
        url2 = "http://www.openlayers.org:50";
 
639
 
 
640
        t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2, options), "port check works"); 
 
641
 
 
642
 
 
643
  //HASH
 
644
 
 
645
        url1 = "http://www.openlayers.org#barf";
 
646
        url2 = "http://www.openlayers.org";
 
647
 
 
648
        t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works"); 
 
649
        options = {
 
650
            'ignoreHash': false
 
651
        }        
 
652
        t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2, options), "ignoreHash FALSE works"); 
 
653
 
 
654
  //PROTOCOL
 
655
 
 
656
        url1 = "http://www.openlayers.org";
 
657
        url2 = "ftp://www.openlayers.org";
 
658
 
 
659
        t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works"); 
 
660
 
 
661
 
 
662
  //PATHNAME
 
663
        url1 = "foo.html?bar=now#go";
 
664
        url2 = "../tests/../tests/foo.html?bar=now#go";
 
665
 
 
666
        t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "relative vs. absolute paths works"); 
 
667
    }
 
668
    
 
669
    function test_Util_createUniqueIDSeq(t) {
 
670
        t.plan(1);
 
671
 
 
672
        OpenLayers.Util.lastSeqID = 0;
 
673
        OpenLayers.Util.createDiv();
 
674
        OpenLayers.Util.createDiv();
 
675
        t.eq(OpenLayers.Util.createDiv().id, "OpenLayersDiv3", "Div created is sequential, starting at lastSeqID in Util.");
 
676
    }
 
677
 
 
678
    function test_Util_getParameters(t) {
 
679
        t.plan(6);
 
680
 
 
681
        t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {},
 
682
             "getParameters works when args = ''");
 
683
        t.eq(OpenLayers.Util.getParameters('http://www.example.com?'), {},
 
684
             "getParameters works when args = '?'");
 
685
        t.eq(OpenLayers.Util.getParameters('http://www.example.com?hello=world&foo=bar'),
 
686
             {'hello' : 'world', 'foo': 'bar'},
 
687
             "getParameters works when args = '?hello=world&foo=bar'");
 
688
        t.eq(OpenLayers.Util.getParameters('http://www.example.com?hello=&foo=bar'),
 
689
             {'hello' : '', 'foo': 'bar'},
 
690
             "getParameters works when args = '?hello=&foo=bar'");
 
691
        t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar#bugssucks'),
 
692
             {'foo': 'bar'},
 
693
             "getParameters works when using a fragment identifier");
 
694
        t.eq(OpenLayers.Util.getParameters('http://www.example.com?foo=bar,pub,disco'),
 
695
             {'foo': ['bar', 'pub', 'disco']},
 
696
             "getParameters works with a comma-separated value (parses into array)");
 
697
    }
 
698
 
 
699
    function test_Util_getArgs(t) {
 
700
        //DEPRECATED -- to be removed in 3.0
 
701
        t.plan(3);
 
702
        
 
703
        OpenLayers.Lang.setCode(OpenLayers.Lang.defaultCode);
 
704
        
 
705
        var temp = OpenLayers.Console.warn;
 
706
        OpenLayers.Console.warn = function(err) {
 
707
            t.ok(err != null, "warning is fired on use of getArgs()");
 
708
        }
 
709
 
 
710
        var temp2 = OpenLayers.Util.getParameters;
 
711
        OpenLayers.Util.getParameters = function(url) {
 
712
            t.eq(url, g_Url, "correct url passed to getParameters()");
 
713
            return g_Params;
 
714
        }
 
715
        
 
716
        g_Params = {};
 
717
        g_Url = {};
 
718
        
 
719
        var ret = OpenLayers.Util.getArgs(g_Url);
 
720
        t.ok( ret == g_Params, "correctly returns value from getParameters");
 
721
 
 
722
        OpenLayers.Console.warn = temp;
 
723
        OpenLayers.Util.getParameters = temp2;
 
724
    }
 
725
 
 
726
    function tests_Util_extend(t) {
 
727
        t.plan(7);
 
728
 
 
729
        var source = {
 
730
            num: Math.random(),
 
731
            obj: {
 
732
                foo: "bar"
 
733
            },
 
734
            method: function() {
 
735
                return "method";
 
736
            },
 
737
            toString: function() {
 
738
                return "source";
 
739
            },
 
740
            nada: undefined
 
741
        };
 
742
        var destination = OpenLayers.Util.extend({nada: "untouched"}, source);
 
743
        t.eq(destination.num, source.num,
 
744
             "extend properly sets primitive property on destination");
 
745
        t.eq(destination.obj, source.obj,
 
746
             "extend properly sets object property on destination");
 
747
        t.eq(destination.method(), "method",
 
748
             "extend properly sets function property on destination");
 
749
        t.eq(destination.toString(), "source",
 
750
             "extend properly sets custom toString method");
 
751
        t.eq(destination.nada, "untouched",
 
752
             "undefined source properties don't clobber existing properties");
 
753
        t.eq(window.property, undefined, "Property variable not clobbered.");
 
754
        
 
755
        var destination;
 
756
        var source = {rand: Math.random()};
 
757
        var ret = OpenLayers.Util.extend(destination, source);
 
758
        t.eq(destination.rand, source.rand, "works with undefined destination");
 
759
        
 
760
    }
 
761
    
 
762
    function test_XX_Util_Try(t) {
 
763
        t.plan(7);
 
764
 
 
765
        var func1 = function() {
 
766
            t.ok(true, "func1 executed");
 
767
            throw "error";
 
768
        };
 
769
        
 
770
        var func2 = function() {
 
771
            t.ok(true, "func2 executed");
 
772
            throw "error";
 
773
        };
 
774
 
 
775
        g_TestVal3 = {};
 
776
        var func3 = function() {
 
777
            t.ok(true, "func3 executed");
 
778
            return g_TestVal3;            
 
779
        };
 
780
 
 
781
        g_TestVal4 = {};
 
782
        var func4 = function() {
 
783
            t.fail("func4 should *not* be executed");
 
784
            return g_TestVal4;            
 
785
        };
 
786
 
 
787
        var ret = OpenLayers.Util.Try(func1, func2);
 
788
        t.ok(ret == null, "if all functions throw exceptions, null returned");
 
789
 
 
790
        var ret = OpenLayers.Util.Try(func1, func2, func3, func4);
 
791
        t.ok(ret == g_TestVal3, "try returns first sucessfully executed function's return");
 
792
 
 
793
    }
 
794
    
 
795
    function test_getRenderedDimensions(t) {
 
796
        t.plan(2);
 
797
        var content = (new Array(100)).join("foo ");
 
798
        
 
799
        // test with fixed width
 
800
        var fw = OpenLayers.Util.getRenderedDimensions(content, {w: 20});
 
801
        t.eq(fw.w, 20, "got the fixed width");
 
802
        
 
803
        // test with fixed height
 
804
        var fh = OpenLayers.Util.getRenderedDimensions(content, {h: 15});
 
805
        t.eq(fh.h, 15, "got the fixed height");
 
806
        
 
807
    }
 
808
 
 
809
  </script>
 
810
</head>
 
811
<body>
 
812
    <div id="map" style="width: 1024px; height: 512px;"/>
 
813
</body>
 
814
</html>