/* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/ */
// Checks that the url formatter properly recognizes the host and de-emphasizes
// the rest of the url.
/**
* Tests a given url.
* The de-emphasized parts must be wrapped in "<" and ">" chars.
*
* @param {string} urlFormatString The URL to test.
* @param {string} [clobberedURLString] Normally the URL is de-emphasized
* in-place, thus it's enough to pass aExpected. Though, in some cases
* the formatter may decide to replace the URL with a fixed one, because
* it can't properly guess a host. In that case clobberedURLString is
* the expected de-emphasized value.
*/
async function testVal(urlFormatString, clobberedURLString = null) {
let str = urlFormatString.replace(/[<>]/g, "");
info("Setting the value property directly");
gURLBar.value = str;
gBrowser.selectedBrowser.focus();
await UrlbarTestUtils.checkFormatting(window, urlFormatString, {
clobberedURLString,
});
info("Simulating user input");
await UrlbarTestUtils.inputIntoURLBar(window, str);
Assert.equal(
gURLBar.editor.rootElement.textContent,
str,
"URL is not highlighted"
);
gBrowser.selectedBrowser.focus();
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.checkFormatting(window, urlFormatString, {
clobberedURLString,
additionalMsg: "with input simulation",
});
}
add_task(async function () {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.scotchBonnet.enableOverride", false]],
});
const PREF_FORMATTING = "browser.urlbar.formatting.enabled";
const PREF_TRIM_HTTPS = "browser.urlbar.trimHttps";
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_FORMATTING);
Services.prefs.clearUserPref(PREF_TRIM_HTTPS);
gURLBar.setURI();
});
Services.prefs.setBoolPref(PREF_TRIM_HTTPS, false);
gBrowser.selectedBrowser.focus();
await testVal("mozilla.org");
await testVal("mözilla.org");
await testVal("mozilla.imaginatory");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.com");
await testVal("mozilla.com");
await testVal("mozilla.com");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org< >");
await testVal("mozilla.org< >");
// RTL characters in domain change order of domain and suffix. Domain should
// be highlighted correctly.
await testVal("اختبار.اختبار");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("foo.bar");
await testVal("foo.bar<#mozilla.org>");
await testVal("foo.bar");
await testVal("foo.bar@mozilla.org>");
await testVal("foo.bar<#x@mozilla.org>");
await testVal("foo.bar<#@x@mozilla.org>");
await testVal("foo.bar");
await testVal("foo.bar@x@mozilla.org>");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal("mozilla.org");
await testVal(
"foopy:\\blah@somewhere.com//whatever/",
"foopy"
);
await testVal("mozilla.org<:666/file.ext>");
await testVal("mozilla.org<:666/file.ext>");
await testVal("localhost<:666/file.ext>");
let IPs = [
"192.168.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]",
];
for (let IP of IPs) {
await testVal(IP);
await testVal(IP + "");
await testVal(IP + "<:666/file.ext>");
await testVal("" + IP);
await testVal(`${IP}`);
await testVal(`${IP}<:666/file.ext>`);
await testVal(`${IP}<:666/file.ext>`);
await testVal(`user:\\pass@${IP}/`, `user`);
}
await testVal("mailto:admin@mozilla.org");
await testVal("ftp://ftp.mozilla.org");
await testVal("gopher://mozilla.org/");
await testVal("about:config");
await testVal("jar:http://mozilla.org/example.jar!/");
await testVal("view-source:http://mozilla.org/");
await testVal("foo9://mozilla.org/");
await testVal("foo+://mozilla.org/");
await testVal("foo.://mozilla.org/");
await testVal("foo-://mozilla.org/");
await testVal("ドメイン.テスト");
await testVal("ドメイン.テスト");
await testVal("дzz.ею");
// Disable formatting.
Services.prefs.setBoolPref(PREF_FORMATTING, false);
await testVal("https://mozilla.org");
});
add_task(async function test_url_formatting_after_visiting_bookmarks() {
SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.trimURLs", true],
["browser.urlbar.trimHttps", true],
["browser.urlbar.formatting.enabled", true],
],
});
await PlacesTestUtils.addBookmarkWithDetails({
uri: "https://something.example.com/test",
});
await search({
searchString: "something",
valueBefore: "something",
valueAfter: "something.example.com/",
placeholderAfter: "something.example.com/",
});
EventUtils.sendKey("DOWN");
EventUtils.sendKey("RETURN");
await BrowserTestUtils.browserLoaded(gBrowser, false, null, true);
await UrlbarTestUtils.checkFormatting(
window,
"example.com"
);
SpecialPowers.popPrefEnv();
});