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