summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_standardurl_port.js
blob: a69efcfea97ef7fc6396365666c398d96632e5f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";

function run_test() {
  function makeURI(aURLSpec, aCharset) {
    return Services.io.newURI(aURLSpec, aCharset);
  }

  var httpURI = makeURI("http://foo.com");
  Assert.equal(-1, httpURI.port);

  // Setting to default shouldn't cause a change
  httpURI = httpURI
    .mutate()
    .setPort(80)
    .finalize();
  Assert.equal(-1, httpURI.port);

  // Setting to default after setting to non-default shouldn't cause a change (bug 403480)
  httpURI = httpURI
    .mutate()
    .setPort(123)
    .finalize();
  Assert.equal(123, httpURI.port);
  httpURI = httpURI
    .mutate()
    .setPort(80)
    .finalize();
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/80/.test(httpURI.spec));

  // URL parsers shouldn't set ports to default value (bug 407538)
  httpURI = httpURI
    .mutate()
    .setSpec("http://foo.com:81")
    .finalize();
  Assert.equal(81, httpURI.port);
  httpURI = httpURI
    .mutate()
    .setSpec("http://foo.com:80")
    .finalize();
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/80/.test(httpURI.spec));

  httpURI = makeURI("http://foo.com");
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/80/.test(httpURI.spec));

  httpURI = makeURI("http://foo.com:80");
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/80/.test(httpURI.spec));

  httpURI = makeURI("http://foo.com:80");
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/80/.test(httpURI.spec));

  httpURI = makeURI("https://foo.com");
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/443/.test(httpURI.spec));

  httpURI = makeURI("https://foo.com:443");
  Assert.equal(-1, httpURI.port);
  Assert.ok(!/443/.test(httpURI.spec));

  // XXX URL parsers shouldn't set ports to default value, even when changing scheme?
  // not really possible given current nsIURI impls
  //httpURI.spec = "https://foo.com:443";
  //do_check_eq(-1, httpURI.port);
}