1 /* -*- Mode: javascript; indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* This test exercises the nsIStandardURL "setDefaultPort" API. */
12 function stringToURL(str
) {
13 return Cc
["@mozilla.org/network/standard-url-mutator;1"]
14 .createInstance(Ci
.nsIStandardURLMutator
)
15 .init(Ci
.nsIStandardURL
.URLTYPE_AUTHORITY
, 80, str
, "UTF-8", null)
17 .QueryInterface(Ci
.nsIStandardURL
);
20 // Create a nsStandardURL:
21 var origUrlStr
= "http://foo.com/";
22 var stdUrl
= stringToURL(origUrlStr
);
23 Assert
.equal(-1, stdUrl
.port
);
25 // Changing default port shouldn't adjust the value returned by "port",
26 // or the string representation.
27 let def100Url
= stdUrl
29 .QueryInterface(Ci
.nsIStandardURLMutator
)
32 Assert
.equal(-1, def100Url
.port
);
33 Assert
.equal(def100Url
.spec
, origUrlStr
);
35 // Changing port directly should update .port and .spec, though:
36 let port200Url
= stdUrl
.mutate().setPort("200").finalize();
37 Assert
.equal(200, port200Url
.port
);
38 Assert
.equal(port200Url
.spec
, "http://foo.com:200/");
40 // ...but then if we change default port to match the custom port,
41 // the custom port should reset to -1 and disappear from .spec:
42 let def200Url
= port200Url
44 .QueryInterface(Ci
.nsIStandardURLMutator
)
47 Assert
.equal(-1, def200Url
.port
);
48 Assert
.equal(def200Url
.spec
, origUrlStr
);
50 // And further changes to default port should not make custom port reappear.
51 let def300Url
= def200Url
53 .QueryInterface(Ci
.nsIStandardURLMutator
)
56 Assert
.equal(-1, def300Url
.port
);
57 Assert
.equal(def300Url
.spec
, origUrlStr
);