Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
add_setup(function () {
Services.prefs.setBoolPref("browser.chrome.site_icons", true);
Services.prefs.setBoolPref("browser.chrome.favicons", true);
Services.prefs.setBoolPref("places.history.enabled", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.chrome.site_icons");
Services.prefs.clearUserPref("browser.chrome.favicons");
Services.prefs.clearUserPref("places.history.enabled");
});
});
add_task(async function test_relative_favicon_on_nested_page() {
httpServer.registerPathHandler("/nested/page.html", (request, response) => {
response.setHeader("Content-Type", "text/html");
response.write(
'<!doctype html><html><head><link rel="icon" href="icon.svg"></head></html>'
);
});
httpServer.registerPathHandler("/nested/icon.svg", (request, response) => {
response.setHeader("Content-Type", "image/svg+xml");
response.write(
);
});
const favicon = await FeedUtils.getFavicon(null, pageURL);
Assert.ok(
favicon.startsWith("data:image/svg+xml"),
"relative favicon URL should resolve against the nested page URL"
);
});
add_task(async function test_no_file_favicon() {
const iconPath = PathUtils.join(PathUtils.profileDir, "icon.svg");
await IOUtils.writeUTF8(
iconPath,
);
const iconURL = PathUtils.toFileURI(iconPath);
httpServer.registerPathHandler(
"/file-icon/page.html",
(request, response) => {
response.setHeader("Content-Type", "text/html");
response.write(
`<!doctype html><html><head><link rel="icon" href="${iconURL}"></head></html>`
);
}
);
Assert.equal(
await FeedUtils.getFavicon(
null,
),
"",
"a file: favicon url from a web page should not be fetched"
);
const pagePath = PathUtils.join(PathUtils.profileDir, "page.html");
await IOUtils.writeUTF8(
pagePath,
'<!doctype html><html><head><link rel="icon" href="icon.svg"></head></html>'
);
Assert.equal(
await FeedUtils.getFavicon(null, PathUtils.toFileURI(pagePath)),
"",
"a favicon should not be fetched for a file: url"
);
});