Project

General

Profile

1 3032 perry
<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
    function test_01_Util_getImagesLocation (t) {
8
        t.plan( 1 );
9
        t.ok( OpenLayers.Util.getImagesLocation(), "../img/",
10
                    "getImagesLocation()" );
11
    }
12
13
    function test_02_Util_Strings(t) {
14
        t.plan(5);
15
16
        var str = "  chicken pox  ";
17
18
        t.ok(str.contains("chicken"), "contains() function correctly finds an embedded string");
19
        t.ok(!str.contains("marsupial"), "contains() function correctly does not finds an random string");
20
21
22
        var trimmedStr = str.trim();
23
24
        t.eq(trimmedStr, "chicken pox", "String.trim works correctly");
25
26
        t.eq(trimmedStr.startsWith("chicken"), true, "String.startsWith correctly finds chicken");
27
        t.eq(trimmedStr.startsWith("dolphin"), false, "String.startsWith correctly does not find turkey");
28
29
30
    }
31
32
    function test_03_Util_Array(t) {
33
        t.plan( 5 );
34
35
        var array = new Array(1,2,3,4,5);
36
37
        array.remove(3);
38
        t.eq( array.toString(), "1,2,4,5", "array.remove works");
39
40
        copy = array.clone();
41
        t.eq( copy.toString(), "1,2,4,5", "array.clone() works");
42
        array.push(7);
43
        t.eq( copy.toString(), "1,2,4,5", "changing a value in the copied array doesnt affect the new array");
44
45
46
        t.eq( copy.indexOf(5), 3, "indexOf function returns index of value in an array");
47
        t.eq( copy.indexOf(75), -1, "indexOf function returns -1 when element not found in array");
48
49
    }
50
51
    function test_04_Util_createDiv(t) {
52
        t.plan( 20 );
53
54
        var id = "boo";
55
        var px = new OpenLayers.Pixel(5,5);
56
        var sz = new OpenLayers.Size(10,10);
57
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
58
        var position = "absolute";
59
        var border = "13px solid";
60
        var overflow = "hidden";
61
62
        var div = OpenLayers.Util.createDiv(id, px, sz, img, position, border, overflow);
63
64
        if (!isMozilla)
65
            t.ok( true, "skipping element test outside of Mozilla");
66
        else
67
            t.ok( div instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
68
        t.eq( div.id, id, "div.id set correctly");
69
        t.eq( div.style.left, px.x + "px", "div.style.left set correctly");
70
        t.eq( div.style.top, px.y + "px", "div.style.top set correctly");
71
72
        t.eq( div.style.width, sz.w + "px", "div.style.width set correctly");
73
        t.eq( div.style.height, sz.h + "px", "div.style.height set correctly");
74
75
        t.eq( div.style.backgroundImage, "url(" + img + ")", "div.style.backgroundImage correctly");
76
77
        t.eq( div.style.position, position, "div.style.positionset correctly");
78
        t.ok( (div.style.border.indexOf(border) != -1), "div.style.border set correctly");
79
        t.eq( div.style.overflow, overflow, "div.style.overflow set correctly");
80
81
        //test defaults
82
        var div = OpenLayers.Util.createDiv();
83
84
        if (!isMozilla)
85
            t.ok( true, "skipping element test outside of Mozilla");
86
        else
87
            t.ok( div instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
88
        t.ok( (div.id != ""), "div.id set correctly");
89
        t.eq(div.style.left, "", "div.style.left set correctly");
90
        t.eq(div.style.top, "", "div.style.top set correctly");
91
92
        t.eq( div.style.width, "", "div.style.width set correctly");
93
        t.eq( div.style.height, "", "div.style.height set correctly");
94
95
        t.eq(div.style.backgroundImage, "", "div.style.backgroundImage correctly");
96
97
        t.eq( div.style.position, "absolute", "div.style.positionset correctly");
98
        t.eq( div.style.border, "", "div.style.border set correctly");
99
        t.eq(div.style.overflow, "", "div.style.overflow set correctly");
100
101
    }
102
103
    function test_05_Util_createImage(t) {
104
        t.plan( 18 );
105
106
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
107
        var sz = new OpenLayers.Size(10,10);
108
        var xy = new OpenLayers.Pixel(5,5);
109
        var position = "absolute";
110
        var id = "boo";
111
        var border = "1px solid";
112
113
        var image = OpenLayers.Util.createImage(id, xy, sz, img, position, border);
114
115
        if (!isMozilla)
116
            t.ok( true, "skipping element test outside of Mozilla");
117
        else
118
            t.ok( image instanceof HTMLImageElement, "createImage creates a valid HTMLImageElement" );
119
        t.eq( image.id, id, "image.id set correctly");
120
        t.eq( image.style.left, xy.x + "px", "image.style.left set correctly");
121
        t.eq( image.style.top, xy.y + "px", "image.style.top set correctly");
122
123
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");
124
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");
125
126
        t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
127
        t.eq( image.src, img, "image.style.backgroundImage correctly");
128
        t.eq( image.style.position, position, "image.style.positionset correctly");
129
130
        //test defaults
131
        var image = OpenLayers.Util.createImage();
132
133
        if (!isMozilla)
134
            t.ok( true, "skipping element test outside of Mozilla");
135
        else
136
            t.ok( image instanceof HTMLImageElement, "createDiv creates a valid HTMLDivElement" );
137
        t.ok( (image.id != ""), "image.id set to something");
138
        t.eq( image.style.left, "", "image.style.left set correctly");
139
        t.eq( image.style.top, "", "image.style.top set correctly");
140
141
        t.eq( image.style.width, "", "image.style.width set correctly");
142
        t.eq( image.style.height, "", "image.style.height set correctly");
143
144
        t.ok((image.style.border == ""), "image.style.border set correctly");
145
        t.eq(image.src, "", "image.style.backgroundImage correctly");
146
        t.eq( image.style.position, "relative", "image.style.positionset correctly");
147
148
    }
149
150
    function test_06_Util_applyDefaults(t) {
151
152
        t.plan(4);
153
154
        var to = { a: "abra",
155
                   b: "blorg"
156
                 };
157
158
        var from = { b: "zoink",
159
                     c: "press"
160
                   };
161
162
        OpenLayers.Util.applyDefaults(to, from);
163
164
        t.ok( to instanceof Object, " applyDefaults returns an object");
165
        t.eq( to["a"], "abra", "key present in to but not from maintained");
166
        t.eq( to["b"], "blorg", "key present in to and from, maintained in to");
167
        t.eq( to["c"], "press", "key present in from and not to successfully copied to to");
168
    }
169
170
    function test_07_Util_getParameterString(t) {
171
        t.plan( 1 );
172
173
        var params = { foo: "bar",
174
                       chicken: 1.5
175
                     }
176
177
        t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");
178
    }
179
180
    function test_08_Util_createAlphaImageDiv(t) {
181
        t.plan( 17 );
182
183
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
184
        var sz = new OpenLayers.Size(10,10);
185
        var xy = new OpenLayers.Pixel(5,5);
186
        var position = "absolute";
187
        var id = "boo";
188
        var border = "1px solid";
189
        var sizing = "crop";
190
191
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border, sizing);
192
193
        if (!isMozilla)
194
            t.ok( true, "skipping element test outside of Mozilla");
195
        else
196
            t.ok( imageDiv instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
197
198
        t.eq( imageDiv.id, id, "image.id set correctly");
199
        t.eq( imageDiv.style.left, xy.x + "px", "image.style.left set correctly");
200
        t.eq( imageDiv.style.top, xy.y + "px", "image.style.top set correctly");
201
202
        t.eq( imageDiv.style.width, sz.w + "px", "image.style.width set correctly");
203
        t.eq( imageDiv.style.height, sz.h + "px", "image.style.height set correctly");
204
205
        t.eq( imageDiv.style.position, position, "image.style.positionset correctly");
206
207
208
        image = imageDiv.firstChild;
209
210
        if (!isMozilla)
211
            t.ok( true, "skipping element test outside of Mozilla");
212
        else
213
            t.ok( image instanceof HTMLImageElement, "createImage creates a valid HTMLImageElement" );
214
        t.eq( image.id, id + "_innerImage", "image.id set correctly");
215
216
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");
217
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");
218
219
        t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
220
        t.eq( image.style.position, "relative", "image.style.positionset correctly");
221
222
        if (OpenLayers.Util.alphaHack()) {
223
224
            t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly");
225
226
            var filter = "progid:DXImageTransform.Microsoft" +
227
                         ".AlphaImageLoader(src='" + img + "', " +
228
                         "sizingMethod='" + sizing + "')";
229
            t.eq(imageDiv.style.filter, filter, "div filter value correctly set");
230
231
            filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
232
            t.eq(image.style.filter, filter, "image filter set correctly");
233
234
        } else {
235
            t.eq( image.src, img, "image.style.backgroundImage correctly");
236
            t.ok(true, "div filter value not set (not in IE)");
237
            t.ok(true, "image filter value not set (not in IE)");
238
        }
239
240
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border);
241
        if (OpenLayers.Util.alphaHack()) {
242
            var filter = "progid:DXImageTransform.Microsoft" +
243
                         ".AlphaImageLoader(src='" + img + "', " +
244
                         "sizingMethod='scale')";
245
            t.eq(imageDiv.style.filter, filter, "sizingMethod default correctly set to scale");
246
        } else {
247
            t.ok(true);
248
        }
249
250
    }
251
252
    function test_09_Util_modifyDOMElement(t) {
253
254
        t.plan( 8 );
255
256
        var id = "boo";
257
        var px = new OpenLayers.Pixel(5,5);
258
        var sz = new OpenLayers.Size(10,10);
259
        var position = "absolute";
260
        var border = "1px solid";
261
        var overflow = "hidden";
262
263
        var element = document.createElement("div");
264
265
        OpenLayers.Util.modifyDOMElement(element, id, px, sz,
266
                                         position, border, overflow);
267
268
        t.eq( element.id, id, "element.id set correctly");
269
        t.eq( element.style.left, px.x + "px", "element.style.left set correctly");
270
        t.eq( element.style.top, px.y + "px", "element.style.top set correctly");
271
272
        t.eq( element.style.width, sz.w + "px", "element.style.width set correctly");
273
        t.eq( element.style.height, sz.h + "px", "element.style.height set correctly");
274
275
        t.eq( element.style.position, position, "element.style.position set correctly");
276
        t.ok( (element.style.border.indexOf(border) != -1), "element.style.border set correctly");
277
        t.eq( element.style.overflow, overflow, "element.style.overflow set correctly");
278
279
    }
280
281
    function test_09_Util_modifyAlphaImageDiv(t) {
282
        t.plan( 17 );
283
284
        var imageDiv = OpenLayers.Util.createAlphaImageDiv();
285
286
        var img = "http://www.openlayers.org/images/OpenLayers.trac.png";
287
        var sz = new OpenLayers.Size(10,10);
288
        var xy = new OpenLayers.Pixel(5,5);
289
        var position = "absolute";
290
        var id = "boo";
291
        var border = "1px solid";
292
        var sizing = "crop";
293
294
        OpenLayers.Util.modifyAlphaImageDiv(imageDiv, id, xy, sz, img, position, border, sizing);
295
296
        if (!isMozilla)
297
            t.ok( true, "skipping element test outside of Mozilla");
298
        else
299
            t.ok( imageDiv instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
300
301
        t.eq( imageDiv.id, id, "image.id set correctly");
302
        t.eq( imageDiv.style.left, xy.x + "px", "image.style.left set correctly");
303
        t.eq( imageDiv.style.top, xy.y + "px", "image.style.top set correctly");
304
305
        t.eq( imageDiv.style.width, sz.w + "px", "image.style.width set correctly");
306
        t.eq( imageDiv.style.height, sz.h + "px", "image.style.height set correctly");
307
308
        t.eq( imageDiv.style.position, position, "image.style.positionset correctly");
309
310
311
        image = imageDiv.firstChild;
312
313
        if (!isMozilla)
314
            t.ok( true, "skipping element test outside of Mozilla");
315
        else
316
            t.ok( image instanceof HTMLImageElement, "createImage creates a valid HTMLImageElement" );
317
        t.eq( image.id, id + "_innerImage", "image.id set correctly");
318
319
        t.eq( image.style.width, sz.w + "px", "image.style.width set correctly");
320
        t.eq( image.style.height, sz.h + "px", "image.style.height set correctly");
321
322
        t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
323
        t.eq( image.style.position, "relative", "image.style.positionset correctly");
324
325
        if (OpenLayers.Util.alphaHack()) {
326
327
            t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly");
328
329
            var filter = "progid:DXImageTransform.Microsoft" +
330
                         ".AlphaImageLoader(src='" + img + "', " +
331
                         "sizingMethod='" + sizing + "')";
332
            t.eq(imageDiv.style.filter, filter, "div filter value correctly set");
333
334
            filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
335
            t.eq(image.style.filter, filter, "image filter set correctly");
336
337
        } else {
338
            t.eq( image.src, img, "image.style.backgroundImage correctly");
339
            t.ok(true, "div filter value not set (not in IE)");
340
            t.ok(true, "image filter value not set (not in IE)");
341
        }
342
343
        var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border);
344
        if (OpenLayers.Util.alphaHack()) {
345
            var filter = "progid:DXImageTransform.Microsoft" +
346
                         ".AlphaImageLoader(src='" + img + "', " +
347
                         "sizingMethod='scale')";
348
            t.eq(imageDiv.style.filter, filter, "sizingMethod default correctly set to scale");
349
        } else {
350
            t.ok(true);
351
        }
352
353
    }
354
355
    function test_10_Util_upperCaseObject(t) {
356
357
        t.plan(8);
358
359
        var aKey = "chicken";
360
        var aValue = "pot pie";
361
362
        var bKey = "blorg";
363
        var bValue = "us maximus";
364
365
        var obj = new Object();
366
        obj[aKey] = aValue;
367
        obj[bKey] = bValue;
368
369
        var uObj = OpenLayers.Util.upperCaseObject(obj);
370
371
        //make sure old object not modified
372
        t.eq(obj[aKey], aValue, "old lowercase value still present in old obj");
373
        t.eq(obj[bKey], bValue, "old lowercase value still present in old obj");
374
375
        t.eq(obj[aKey.toUpperCase()], null, "new uppercase value not present in old obj");
376
        t.eq(obj[bKey.toUpperCase()], null, "new uppercase value not present in old obj");
377
378
        //make sure new object modified
379
        t.eq(uObj[aKey], null, "old lowercase value not present");
380
        t.eq(uObj[bKey], null, "old lowercase value not present");
381
382
        t.eq(uObj[aKey.toUpperCase()], aValue, "new uppercase value present");
383
        t.eq(uObj[bKey.toUpperCase()], bValue, "new uppercase value present");
384
    }
385
386
    function test_11_Util_createUniqueID(t) {
387
        t.plan(2);
388
389
        var id = OpenLayers.Util.createUniqueID();
390
        t.ok( id.startsWith("id_"), "default OpenLayers.Util.createUniqueID starts id correctly");
391
392
        var id = OpenLayers.Util.createUniqueID("chicken");
393
        t.ok( id.startsWith("chicken"), "OpenLayers.Util.createUniqueID starts id correctly");
394
    }
395
396
    function test_12_Util_limitSigDigs(t) {
397
398
        t.plan(7);
399
400
        var x;
401
402
        x = 123456;
403
        t.eq(x.limitSigDigs(3), 123000, "correctly rounds down");
404
405
        x = 555555;
406
        t.eq(x.limitSigDigs(3), 556000, "correctly rounds up");
407
408
        x = 66;
409
        t.eq(x.limitSigDigs(3), 66, "correctly handles number smaller than sigdig");
410
411
        t.eq(x.limitSigDigs(null), 0, "correctly handles null sigdig");
412
        t.eq(x.limitSigDigs(0), 0, "correctly handles 0 sigdig");
413
        t.eq(x.limitSigDigs(-1), 0, "correctly handles negative sigdig");
414
415
        x = 0;
416
        t.eq(x.limitSigDigs(2), 0, "correctly handles 0 number");
417
418
419
420
    }
421
422
  // -->
423
  </script>
424
</head>
425
<body>
426
    <div id="map" style="width: 1024px; height: 512px;"/>
427
</body>
428
</html>