2009-09-28 19:10:34 +04:00
|
|
|
function run_test() {
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2010-10-11 23:39:09 +04:00
|
|
|
|
|
|
|
var test_port = function(port, exception_expected)
|
|
|
|
{
|
|
|
|
dump((port || "no port provided") + "\n");
|
|
|
|
var exception_threw = false;
|
|
|
|
try {
|
2017-01-09 22:27:26 +03:00
|
|
|
var newURI = ios.newURI("http://foo.com"+port);
|
2010-10-11 23:39:09 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
if (exception_threw != exception_expected)
|
|
|
|
do_throw("We did"+(exception_expected?"n't":"")+" throw NS_ERROR_MALFORMED_URI when creating a new URI with "+port+" as a port");
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(exception_threw, exception_expected);
|
2010-10-11 23:39:09 +04:00
|
|
|
|
|
|
|
exception_threw = false;
|
2017-01-09 22:27:26 +03:00
|
|
|
newURI = ios.newURI("http://foo.com");
|
2010-10-11 23:39:09 +04:00
|
|
|
try {
|
2018-01-08 17:20:29 +03:00
|
|
|
newURI = newURI.mutate().setSpec("http://foo.com"+port).finalize();
|
2010-10-11 23:39:09 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
if (exception_threw != exception_expected)
|
|
|
|
do_throw("We did"+(exception_expected?"n't":"")+" throw NS_ERROR_MALFORMED_URI when setting a spec of a URI with "+port+" as a port");
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(exception_threw, exception_expected);
|
2009-09-28 19:10:34 +04:00
|
|
|
}
|
2010-10-11 23:39:09 +04:00
|
|
|
|
|
|
|
test_port(":invalid", true);
|
|
|
|
test_port(":-2", true);
|
|
|
|
test_port(":-1", true);
|
2014-01-05 00:42:42 +04:00
|
|
|
test_port(":0", false);
|
2010-10-11 23:39:09 +04:00
|
|
|
test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true);
|
|
|
|
|
|
|
|
// Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber
|
|
|
|
test_port(":5870:80", true);
|
|
|
|
test_port(":5870-80", true);
|
|
|
|
test_port(":5870+80", true);
|
2009-09-28 19:10:34 +04:00
|
|
|
|
2010-10-11 23:39:09 +04:00
|
|
|
// Just a regression check
|
|
|
|
test_port(":5870", false);
|
|
|
|
test_port(":80", false);
|
|
|
|
test_port("", false);
|
2009-09-28 19:10:34 +04:00
|
|
|
}
|