Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 function run_test() {
2 var ios = Cc["@mozilla.org/network/io-service;1"].
3 getService(Ci.nsIIOService);
5 var test_port = function(port, exception_expected)
6 {
7 dump((port || "no port provided") + "\n");
8 var exception_threw = false;
9 try {
10 var newURI = ios.newURI("http://foo.com"+port, null, null);
11 }
12 catch (e) {
13 exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI;
14 }
15 if (exception_threw != exception_expected)
16 do_throw("We did"+(exception_expected?"n't":"")+" throw NS_ERROR_MALFORMED_URI when creating a new URI with "+port+" as a port");
17 do_check_eq(exception_threw, exception_expected);
19 exception_threw = false;
20 newURI = ios.newURI("http://foo.com", null, null);
21 try {
22 newURI.spec = "http://foo.com"+port;
23 }
24 catch (e) {
25 exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI;
26 }
27 if (exception_threw != exception_expected)
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");
29 do_check_eq(exception_threw, exception_expected);
30 }
32 test_port(":invalid", true);
33 test_port(":-2", true);
34 test_port(":-1", true);
35 test_port(":0", false);
36 test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true);
38 // Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber
39 test_port(":5870:80", true);
40 test_port(":5870-80", true);
41 test_port(":5870+80", true);
43 // Just a regression check
44 test_port(":5870", false);
45 test_port(":80", false);
46 test_port("", false);
47 }