/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function testVal(aExpected) {
gURLBar.value = aExpected.replace(/[<>]/g, "");
let selectionController = gURLBar.editor.selectionController;
let selection = selectionController.getSelection(selectionController.SELECTION_URLSECONDARY);
let value = gURLBar.editor.rootElement.textContent;
let result = "";
for (let i = 0; i < selection.rangeCount; i++) {
let range = selection.getRangeAt(i).toString();
let pos = value.indexOf(range);
result += value.substring(0, pos) + "<" + range + ">";
value = value.substring(pos + range.length);
}
result += value;
is(result, aExpected);
}
function test() {
const prefname = "browser.urlbar.formatting.enabled";
registerCleanupFunction(function () {
Services.prefs.clearUserPref(prefname);
URLBarSetURI();
});
Services.prefs.setBoolPref(prefname, true);
gURLBar.focus();
testVal("https://mozilla.org");
gBrowser.selectedBrowser.focus();
testVal("mozilla.org");
testVal("mözilla.org");
testVal("mozilla.imaginatory");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org");
testVal("mozilla.org<:666/file.ext>");
testVal("mozilla.org<:666/file.ext>");
testVal("localhost<:666/file.ext>");
let IPs = ["192.168.1.1",
"[::]",
"[::1]",
"[1::]",
"[::]",
"[::1]",
"[1::]",
"[1:2:3:4:5:6:7::]",
"[::1:2:3:4:5:6:7]",
"[1:2:a:B:c:D:e:F]",
"[1::8]",
"[1:2::8]",
"[fe80::222:19ff:fe11:8c76]",
"[0000:0123:4567:89AB:CDEF:abcd:ef00:0000]",
"[::192.168.1.1]",
"[1::0.0.0.0]",
"[1:2::255.255.255.255]",
"[1:2:3::255.255.255.255]",
"[1:2:3:4::255.255.255.255]",
"[1:2:3:4:5::255.255.255.255]",
"[1:2:3:4:5:6:255.255.255.255]"];
IPs.forEach(function (IP) {
testVal(IP);
testVal(IP + "");
testVal(IP + "<:666/file.ext>");
testVal("" + IP);
testVal("" + IP + "");
testVal("" + IP + "<:666/file.ext>");
testVal("" + IP + "<:666/file.ext>");
});
testVal("mailto:admin@mozilla.org");
testVal("gopher://mozilla.org/");
testVal("about:config");
testVal("jar:http://mozilla.org/example.jar!/");
testVal("view-source:http://mozilla.org/");
testVal("foo9://mozilla.org/");
testVal("foo+://mozilla.org/");
testVal("foo.://mozilla.org/");
testVal("foo-://mozilla.org/");
Services.prefs.setBoolPref(prefname, false);
testVal("https://mozilla.org");
}