Making createUrlObject more reliable. Tests demonstrate what to expect. r=elemoine (pullup #2060)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9413 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-05-27 17:49:05 +00:00
parent ebaa5066fc
commit 94437d3e5f
2 changed files with 131 additions and 104 deletions
+110
View File
@@ -680,6 +680,116 @@
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "absolute and relative path without host works for "+url2)
}
function test_createUrlObject(t) {
var cases = [{
url: "http://example.com/",
exp: {
protocol: "http:",
host: "example.com",
port: "80",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:80/",
opt: {ignorePort80: true},
exp: {
protocol: "http:",
host: "example.com",
port: "",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com/",
opt: {ignorePort80: true},
exp: {
protocol: "http:",
host: "example.com",
port: "",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:88/",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/",
args: {},
hash: ""
}
}, {
url: "http://example.com:88/foo#bar",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/foo",
args: {},
hash: "#bar"
}
}, {
url: "http://example.com:88/?foo=bar",
exp: {
protocol: "http:",
host: "example.com",
port: "88",
pathname: "/",
args: {foo: "bar"},
hash: ""
}
}, {
url: "http://example.com/bogus/../bogus/../path",
exp: {
protocol: "http:",
host: "example.com",
port: "80",
pathname: "/path",
args: {},
hash: ""
}
}, {
url: "/relative#foo",
exp: {
protocol: window.location.protocol,
host: window.location.hostname,
port: window.location.port || "80",
pathname: "/relative",
args: {},
hash: "#foo"
}
}, {
url: "../foo",
exp: {
protocol: window.location.protocol,
host: window.location.hostname,
port: window.location.port || "80",
pathname: (function() {
var parts = window.location.pathname.split("/");
return parts.slice(0, parts.length -2).join("/") + "/foo";
})(),
args: {},
hash: ""
}
}];
t.plan(cases.length);
var c, obj;
for(var i=0; i<cases.length; ++i) {
c = cases[i];
obj = OpenLayers.Util.createUrlObject(c.url, c.opt);
t.eq(obj, c.exp, i + ": '" + c.url + "'");
}
}
function test_Util_createUniqueIDSeq(t) {
t.plan(1);