test_bug479485.js (1819B)
1 "use strict"; 2 3 function run_test() { 4 var ios = Services.io; 5 6 var test_port = function (port, exception_expected) { 7 dump((port || "no port provided") + "\n"); 8 var exception_threw = false; 9 try { 10 var newURI = ios.newURI("http://foo.com" + port); 11 } catch (e) { 12 exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; 13 } 14 if (exception_threw != exception_expected) { 15 do_throw( 16 "We did" + 17 (exception_expected ? "n't" : "") + 18 " throw NS_ERROR_MALFORMED_URI when creating a new URI with " + 19 port + 20 " as a port" 21 ); 22 } 23 Assert.equal(exception_threw, exception_expected); 24 25 exception_threw = false; 26 newURI = ios.newURI("http://foo.com"); 27 try { 28 newURI 29 .mutate() 30 .setSpec("http://foo.com" + port) 31 .finalize(); 32 } catch (e) { 33 exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI; 34 } 35 if (exception_threw != exception_expected) { 36 do_throw( 37 "We did" + 38 (exception_expected ? "n't" : "") + 39 " throw NS_ERROR_MALFORMED_URI when setting a spec of a URI with " + 40 port + 41 " as a port" 42 ); 43 } 44 Assert.equal(exception_threw, exception_expected); 45 }; 46 47 test_port(":invalid", true); 48 test_port(":-2", true); 49 test_port(":-1", true); 50 test_port(":0", false); 51 test_port( 52 ":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", 53 true 54 ); 55 56 // Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber 57 test_port(":5870:80", true); 58 test_port(":5870-80", true); 59 test_port(":5870+80", true); 60 61 // Just a regression check 62 test_port(":5870", false); 63 test_port(":80", false); 64 test_port("", false); 65 }