michael@0: function run_test() { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: michael@0: var test_port = function(port, exception_expected) michael@0: { michael@0: dump((port || "no port provided") + "\n"); michael@0: var exception_threw = false; michael@0: try { michael@0: var newURI = ios.newURI("http://foo.com"+port, null, null); michael@0: } michael@0: catch (e) { michael@0: exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; michael@0: } michael@0: if (exception_threw != exception_expected) michael@0: do_throw("We did"+(exception_expected?"n't":"")+" throw NS_ERROR_MALFORMED_URI when creating a new URI with "+port+" as a port"); michael@0: do_check_eq(exception_threw, exception_expected); michael@0: michael@0: exception_threw = false; michael@0: newURI = ios.newURI("http://foo.com", null, null); michael@0: try { michael@0: newURI.spec = "http://foo.com"+port; michael@0: } michael@0: catch (e) { michael@0: exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; michael@0: } michael@0: if (exception_threw != exception_expected) michael@0: 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"); michael@0: do_check_eq(exception_threw, exception_expected); michael@0: } michael@0: michael@0: test_port(":invalid", true); michael@0: test_port(":-2", true); michael@0: test_port(":-1", true); michael@0: test_port(":0", false); michael@0: test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true); michael@0: michael@0: // Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber michael@0: test_port(":5870:80", true); michael@0: test_port(":5870-80", true); michael@0: test_port(":5870+80", true); michael@0: michael@0: // Just a regression check michael@0: test_port(":5870", false); michael@0: test_port(":80", false); michael@0: test_port("", false); michael@0: }