4 function makeURI(aURLSpec, aCharset) {
5 return Services.io.newURI(aURLSpec, aCharset);
8 var httpURI = makeURI("http://foo.com");
9 Assert.equal(-1, httpURI.port);
11 // Setting to default shouldn't cause a change
12 httpURI = httpURI.mutate().setPort(80).finalize();
13 Assert.equal(-1, httpURI.port);
15 // Setting to default after setting to non-default shouldn't cause a change (bug 403480)
16 httpURI = httpURI.mutate().setPort(123).finalize();
17 Assert.equal(123, httpURI.port);
18 httpURI = httpURI.mutate().setPort(80).finalize();
19 Assert.equal(-1, httpURI.port);
20 Assert.ok(!/80/.test(httpURI.spec));
22 // URL parsers shouldn't set ports to default value (bug 407538)
23 httpURI = httpURI.mutate().setSpec("http://foo.com:81").finalize();
24 Assert.equal(81, httpURI.port);
25 httpURI = httpURI.mutate().setSpec("http://foo.com:80").finalize();
26 Assert.equal(-1, httpURI.port);
27 Assert.ok(!/80/.test(httpURI.spec));
29 httpURI = makeURI("http://foo.com");
30 Assert.equal(-1, httpURI.port);
31 Assert.ok(!/80/.test(httpURI.spec));
33 httpURI = makeURI("http://foo.com:80");
34 Assert.equal(-1, httpURI.port);
35 Assert.ok(!/80/.test(httpURI.spec));
37 httpURI = makeURI("http://foo.com:80");
38 Assert.equal(-1, httpURI.port);
39 Assert.ok(!/80/.test(httpURI.spec));
41 httpURI = makeURI("https://foo.com");
42 Assert.equal(-1, httpURI.port);
43 Assert.ok(!/443/.test(httpURI.spec));
45 httpURI = makeURI("https://foo.com:443");
46 Assert.equal(-1, httpURI.port);
47 Assert.ok(!/443/.test(httpURI.spec));
49 // XXX URL parsers shouldn't set ports to default value, even when changing scheme?
50 // not really possible given current nsIURI impls
51 //httpURI.spec = "https://foo.com:443";
52 //do_check_eq(-1, httpURI.port);