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("http://mozilla.org/"); gBrowser.selectedBrowser.focus(); testVal("mozilla.org"); 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<:666/file.ext>"); testVal("[fe80::222:19ff:fe11:8c76]"); testVal("[fe80::222:19ff:fe11:8c76]<:666/file.ext>"); testVal("mailto:admin@mozilla.org"); testVal("gopher://mozilla.org/"); testVal("about:config"); Services.prefs.setBoolPref(prefname, false); testVal("http://mozilla.org/"); }