3
<script src="../lib/OpenLayers.js"></script>
4
<script type="text/javascript">
5
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
8
function test_Util_getImagesLocation (t) {
10
t.ok( OpenLayers.Util.getImagesLocation(), "../img/",
11
"getImagesLocation()" );
14
function test_Util_Array(t) {
17
var array = new Array(1,2,3,4,4,5);
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 ");
25
function test_Util_pagePosition(t) {
27
var pp = OpenLayers.Util.pagePosition(window);
28
t.eq( pp.toString(), "0,0", "Page position doesn't bail if passed 'window'")
32
function test_Util_createDiv(t) {
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";
44
var div = OpenLayers.Util.createDiv(id, px, sz, img, position, border, overflow, opacity);
47
t.ok( true, "skipping element test outside of Mozilla");
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");
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");
57
bImg = div.style.backgroundImage;
58
imgCorrect = ( (bImg == "url(" + img + ")") ||
59
(bImg == "url(\"" + img + "\")") );
60
t.ok(imgCorrect, "div.style.backgroundImage correctly");
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")
68
t.ok( (div.style.border.indexOf(border) != -1), "div.style.border set correctly");
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");
80
var div = OpenLayers.Util.createDiv();
83
t.ok( true, "skipping element test outside of Mozilla");
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");
90
t.eq( div.style.width, "", "div.style.width set correctly");
91
t.eq( div.style.height, "", "div.style.height set correctly");
93
t.eq(div.style.backgroundImage, "", "div.style.backgroundImage correctly");
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")
100
t.eq( div.style.border, "", "div.style.border set correctly");
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");
110
function test_Util_createImage(t) {
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";
118
var border = "1px solid";
121
var image = OpenLayers.Util.createImage(id, xy, sz, img, position, border, opacity);
124
t.ok( true, "skipping element test outside of Mozilla");
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");
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");
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")
139
t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
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");
149
var image = OpenLayers.Util.createImage();
152
t.ok( true, "skipping element test outside of Mozilla");
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");
159
t.eq( image.style.width, "", "image.style.width set correctly");
160
t.eq( image.style.height, "", "image.style.height set correctly");
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");
170
function test_Util_applyDefaults(t) {
183
'toString': function() {return 'works'},
187
OpenLayers.Util.applyDefaults(to, from);
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");
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");
203
var from = {rand: Math.random()};
205
var ret = OpenLayers.Util.applyDefaults(to, from);
206
t.eq(ret.rand, from.rand, "works with undefined to");
208
//regression test for #1716 -- allow undefined from
210
OpenLayers.Util.applyDefaults({}, undefined);
211
t.ok(true, "no exception thrown when from is undefined");
213
t.fail("exception thrown when from is undefined:" + err);
218
function test_Util_getParameterString(t) {
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");
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");
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. ");
239
function test_Util_createAlphaImageDiv(t) {
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";
247
var border = "1px solid";
251
var imageDiv = OpenLayers.Util.createAlphaImageDiv(id, xy, sz, img, position, border, sizing, opacity);
254
t.ok( true, "skipping element test outside of Mozilla");
256
t.ok( imageDiv instanceof HTMLDivElement, "createDiv creates a valid HTMLDivElement" );
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");
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");
265
t.eq( imageDiv.style.position, position, "image.style.positionset correctly");
266
t.eq( parseFloat(imageDiv.style.opacity), opacity, "element.style.opacity set correctly");
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)";
272
//Safari 3 returns null for this value, which is okay
273
var filterString = (OpenLayers.Util.getBrowserName() == 'safari') ? null : 'alpha(opacity=' + (opacity * 100) + ')';
275
t.eq( imageDiv.style.filter, filterString, "element.style.filter set correctly");
278
image = imageDiv.firstChild;
280
t.ok( true, "skipping element test outside of Mozilla");
282
t.ok( image.nodeName == "IMG", "createImage creates a valid HTMLImageElement" );
283
t.eq( image.id, id + "_innerImage", "image.id set correctly");
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");
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")
293
t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
296
t.eq( image.style.position, "relative", "image.style.positionset correctly");
298
if (OpenLayers.Util.alphaHack()) {
300
t.eq(imageDiv.style.display, "inline-block", "imageDiv.style.display set correctly");
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");
307
filter = "alpha(opacity=0)";
308
t.eq(image.style.filter, filter, "image filter set correctly");
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)");
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");
328
function test_Util_modifyDOMElement_opacity(t) {
333
var element = document.createElement("div");
335
OpenLayers.Util.modifyDOMElement(element, null, null, null, null,
336
null, null, opacity);
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);
345
OpenLayers.Util.modifyDOMElement(element, null, null, null, null,
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");
355
OpenLayers.Util.modifyDOMElement(element, null, null, null, null,
356
null, null, "hello");
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");
366
OpenLayers.Util.modifyDOMElement(element, null, null, null, null,
367
null, null, opacity);
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);
377
function test_Util_modifyDOMElement(t) {
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";
388
var element = document.createElement("div");
390
OpenLayers.Util.modifyDOMElement(element, id, px, sz, position,
391
border, overflow, opacity);
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");
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");
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")
406
t.ok( (element.style.border.indexOf(border) != -1), "element.style.border set correctly");
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");
417
function test_Util_modifyAlphaImageDiv(t) {
420
var imageDiv = OpenLayers.Util.createAlphaImageDiv();
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";
427
var border = "1px solid";
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");
435
t.ok( imageDiv.nodeName == "DIV", "createDiv creates a valid HTMLDivElement" );
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");
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");
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");
449
image = imageDiv.firstChild;
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");
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" );
460
t.eq( imageDiv.style.filter, filterString, "element.style.filter set correctly");
461
t.eq( image.id, id + "_innerImage", "image.id set correctly");
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");
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")
471
t.ok( (image.style.border.indexOf(border) != -1), "image.style.border set correctly");
474
t.eq( image.style.position, "relative", "image.style.positionset correctly");
475
t.eq( image.src, img, "image.style.backgroundImage correctly");
477
if (OpenLayers.Util.alphaHack()) {
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");
484
filter = "alpha(opacity=0)";
485
t.eq(image.style.filter, filter, "image filter set correctly");
488
t.ok(true, "div filter value not set (not in IE)");
489
t.ok(true, "image filter value not set (not in IE)");
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'");
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'");
505
t.ok(true, "inline-block is not part of CSS2 and is not supported by Firefox 2");
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");
522
function test_Util_upperCaseObject(t) {
525
var aKey = "chicken";
526
var aValue = "pot pie";
529
var bValue = "us maximus";
535
var uObj = OpenLayers.Util.upperCaseObject(obj);
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");
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");
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");
548
t.eq(uObj[aKey.toUpperCase()], aValue, "new uppercase value present");
549
t.eq(uObj[bKey.toUpperCase()], bValue, "new uppercase value present");
552
function test_Util_createUniqueID(t) {
555
var id = OpenLayers.Util.createUniqueID();
556
t.ok(OpenLayers.String.startsWith(id, "id_"),
557
"default OpenLayers.Util.createUniqueID starts id correctly");
559
var id = OpenLayers.Util.createUniqueID("chicken");
560
t.ok(OpenLayers.String.startsWith(id, "chicken"),
561
"OpenLayers.Util.createUniqueID starts id correctly");
564
function test_Util_normalizeScale(t) {
569
t.eq( OpenLayers.Util.normalizeScale(scale), scale, "normalizing a normal scale does nothing");
573
t.eq( OpenLayers.Util.normalizeScale(scale), 1/5, "normalizing a wrong scale works!");
576
function test_Util_getScaleResolutionTranslation(t) {
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);
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);
588
resolution = OpenLayers.Util.getResolutionFromScale(scale);
589
t.eq(resolution.toFixed(6), "0.476217", "Calculated correct resolution for " + scale);
592
resolution = OpenLayers.Util.getResolutionFromScale(scale);
593
t.eq(OpenLayers.Util.getScaleFromResolution(resolution), scale, "scale->resolution->scale works");
596
function test_Util_getImgLocation(t) {
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.");
604
OpenLayers.ImgPath = '';
605
t.eq(OpenLayers.Util.getImagesLocation().substr(OpenLayers.Util.getImagesLocation().length-4,4), "img/", "ImgPath works as expected when set to ''.");
608
function test_Util_isEquivalentUrl(t) {
611
var url1, url2, options;
615
url1 = "http://www.openlayers.org";
616
url2 = "HTTP://WWW.OPENLAYERS.ORG";
618
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreCase works");
622
url1 = "http://www.openlayers.org?foo=5;bar=6";
623
url2 = "http://www.openlayers.org?bar=6;foo=5";
625
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "shuffled arguments works");
629
url1 = "http://www.openlayers.org:80";
630
url2 = "http://www.openlayers.org";
632
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignorePort80 works");
635
'ignorePort80': false
637
url1 = "http://www.openlayers.org:80";
638
url2 = "http://www.openlayers.org:50";
640
t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2, options), "port check works");
645
url1 = "http://www.openlayers.org#barf";
646
url2 = "http://www.openlayers.org";
648
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works");
652
t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2, options), "ignoreHash FALSE works");
656
url1 = "http://www.openlayers.org";
657
url2 = "ftp://www.openlayers.org";
659
t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works");
663
url1 = "foo.html?bar=now#go";
664
url2 = "../tests/../tests/foo.html?bar=now#go";
666
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "relative vs. absolute paths works");
669
function test_Util_createUniqueIDSeq(t) {
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.");
678
function test_Util_getParameters(t) {
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'),
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)");
699
function test_Util_getArgs(t) {
700
//DEPRECATED -- to be removed in 3.0
703
OpenLayers.Lang.setCode(OpenLayers.Lang.defaultCode);
705
var temp = OpenLayers.Console.warn;
706
OpenLayers.Console.warn = function(err) {
707
t.ok(err != null, "warning is fired on use of getArgs()");
710
var temp2 = OpenLayers.Util.getParameters;
711
OpenLayers.Util.getParameters = function(url) {
712
t.eq(url, g_Url, "correct url passed to getParameters()");
719
var ret = OpenLayers.Util.getArgs(g_Url);
720
t.ok( ret == g_Params, "correctly returns value from getParameters");
722
OpenLayers.Console.warn = temp;
723
OpenLayers.Util.getParameters = temp2;
726
function tests_Util_extend(t) {
737
toString: function() {
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.");
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");
762
function test_XX_Util_Try(t) {
765
var func1 = function() {
766
t.ok(true, "func1 executed");
770
var func2 = function() {
771
t.ok(true, "func2 executed");
776
var func3 = function() {
777
t.ok(true, "func3 executed");
782
var func4 = function() {
783
t.fail("func4 should *not* be executed");
787
var ret = OpenLayers.Util.Try(func1, func2);
788
t.ok(ret == null, "if all functions throw exceptions, null returned");
790
var ret = OpenLayers.Util.Try(func1, func2, func3, func4);
791
t.ok(ret == g_TestVal3, "try returns first sucessfully executed function's return");
795
function test_getRenderedDimensions(t) {
797
var content = (new Array(100)).join("foo ");
799
// test with fixed width
800
var fw = OpenLayers.Util.getRenderedDimensions(content, {w: 20});
801
t.eq(fw.w, 20, "got the fixed width");
803
// test with fixed height
804
var fh = OpenLayers.Util.getRenderedDimensions(content, {h: 15});
805
t.eq(fh.h, 15, "got the fixed height");
812
<div id="map" style="width: 1024px; height: 512px;"/>