1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug479485.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +function run_test() { 1.5 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.6 + getService(Ci.nsIIOService); 1.7 + 1.8 + var test_port = function(port, exception_expected) 1.9 + { 1.10 + dump((port || "no port provided") + "\n"); 1.11 + var exception_threw = false; 1.12 + try { 1.13 + var newURI = ios.newURI("http://foo.com"+port, null, null); 1.14 + } 1.15 + catch (e) { 1.16 + exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; 1.17 + } 1.18 + if (exception_threw != exception_expected) 1.19 + do_throw("We did"+(exception_expected?"n't":"")+" throw NS_ERROR_MALFORMED_URI when creating a new URI with "+port+" as a port"); 1.20 + do_check_eq(exception_threw, exception_expected); 1.21 + 1.22 + exception_threw = false; 1.23 + newURI = ios.newURI("http://foo.com", null, null); 1.24 + try { 1.25 + newURI.spec = "http://foo.com"+port; 1.26 + } 1.27 + catch (e) { 1.28 + exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; 1.29 + } 1.30 + if (exception_threw != exception_expected) 1.31 + 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"); 1.32 + do_check_eq(exception_threw, exception_expected); 1.33 + } 1.34 + 1.35 + test_port(":invalid", true); 1.36 + test_port(":-2", true); 1.37 + test_port(":-1", true); 1.38 + test_port(":0", false); 1.39 + test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true); 1.40 + 1.41 + // Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber 1.42 + test_port(":5870:80", true); 1.43 + test_port(":5870-80", true); 1.44 + test_port(":5870+80", true); 1.45 + 1.46 + // Just a regression check 1.47 + test_port(":5870", false); 1.48 + test_port(":80", false); 1.49 + test_port("", false); 1.50 +}