Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function run_test() { |
michael@0 | 2 | var ios = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 3 | getService(Ci.nsIIOService); |
michael@0 | 4 | |
michael@0 | 5 | var test_port = function(port, exception_expected) |
michael@0 | 6 | { |
michael@0 | 7 | dump((port || "no port provided") + "\n"); |
michael@0 | 8 | var exception_threw = false; |
michael@0 | 9 | try { |
michael@0 | 10 | var newURI = ios.newURI("http://foo.com"+port, null, null); |
michael@0 | 11 | } |
michael@0 | 12 | catch (e) { |
michael@0 | 13 | exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; |
michael@0 | 14 | } |
michael@0 | 15 | if (exception_threw != exception_expected) |
michael@0 | 16 | 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 | 17 | do_check_eq(exception_threw, exception_expected); |
michael@0 | 18 | |
michael@0 | 19 | exception_threw = false; |
michael@0 | 20 | newURI = ios.newURI("http://foo.com", null, null); |
michael@0 | 21 | try { |
michael@0 | 22 | newURI.spec = "http://foo.com"+port; |
michael@0 | 23 | } |
michael@0 | 24 | catch (e) { |
michael@0 | 25 | exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; |
michael@0 | 26 | } |
michael@0 | 27 | if (exception_threw != exception_expected) |
michael@0 | 28 | 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 | 29 | do_check_eq(exception_threw, exception_expected); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | test_port(":invalid", true); |
michael@0 | 33 | test_port(":-2", true); |
michael@0 | 34 | test_port(":-1", true); |
michael@0 | 35 | test_port(":0", false); |
michael@0 | 36 | test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true); |
michael@0 | 37 | |
michael@0 | 38 | // 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 | 39 | test_port(":5870:80", true); |
michael@0 | 40 | test_port(":5870-80", true); |
michael@0 | 41 | test_port(":5870+80", true); |
michael@0 | 42 | |
michael@0 | 43 | // Just a regression check |
michael@0 | 44 | test_port(":5870", false); |
michael@0 | 45 | test_port(":80", false); |
michael@0 | 46 | test_port("", false); |
michael@0 | 47 | } |