From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/favicons/browser_preferred_icons.js | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 browser/base/content/test/favicons/browser_preferred_icons.js (limited to 'browser/base/content/test/favicons/browser_preferred_icons.js') diff --git a/browser/base/content/test/favicons/browser_preferred_icons.js b/browser/base/content/test/favicons/browser_preferred_icons.js new file mode 100644 index 0000000000..25f548c717 --- /dev/null +++ b/browser/base/content/test/favicons/browser_preferred_icons.js @@ -0,0 +1,140 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const ROOT = + "http://mochi.test:8888/browser/browser/base/content/test/favicons/"; + +async function waitIcon(url) { + let icon = await waitForFaviconMessage(true, url); + is(icon.iconURL, url, "Should have seen the right icon."); +} + +function createLinks(linkInfos) { + return SpecialPowers.spawn(gBrowser.selectedBrowser, [linkInfos], links => { + let doc = content.document; + let head = doc.head; + for (let l of links) { + let link = doc.createElement("link"); + link.rel = "icon"; + link.href = l.href; + if (l.type) { + link.type = l.type; + } + if (l.size) { + link.setAttribute("sizes", `${l.size}x${l.size}`); + } + head.appendChild(link); + } + }); +} + +add_setup(async function () { + const URL = ROOT + "discovery.html"; + let iconPromise = waitIcon("http://mochi.test:8888/favicon.ico"); + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); + await iconPromise; + registerCleanupFunction(async function () { + BrowserTestUtils.removeTab(tab); + }); +}); + +add_task(async function prefer_svg() { + let promise = waitIcon(ROOT + "icon.svg"); + await createLinks([ + { href: ROOT + "icon.ico", type: "image/x-icon" }, + { href: ROOT + "icon.svg", type: "image/svg+xml" }, + { + href: ROOT + "icon.png", + type: "image/png", + size: 16 * Math.ceil(window.devicePixelRatio), + }, + ]); + await promise; +}); + +add_task(async function prefer_sized() { + let promise = waitIcon(ROOT + "moz.png"); + await createLinks([ + { href: ROOT + "icon.ico", type: "image/x-icon" }, + { + href: ROOT + "moz.png", + type: "image/png", + size: 16 * Math.ceil(window.devicePixelRatio), + }, + { href: ROOT + "icon2.ico", type: "image/x-icon" }, + ]); + await promise; +}); + +add_task(async function prefer_last_ico() { + let promise = waitIcon(ROOT + "file_generic_favicon.ico"); + await createLinks([ + { href: ROOT + "icon.ico", type: "image/x-icon" }, + { href: ROOT + "icon.png", type: "image/png" }, + { href: ROOT + "file_generic_favicon.ico", type: "image/x-icon" }, + ]); + await promise; +}); + +add_task(async function fuzzy_ico() { + let promise = waitIcon(ROOT + "file_generic_favicon.ico"); + await createLinks([ + { href: ROOT + "icon.ico", type: "image/x-icon" }, + { href: ROOT + "icon.png", type: "image/png" }, + { + href: ROOT + "file_generic_favicon.ico", + type: "image/vnd.microsoft.icon", + }, + ]); + await promise; +}); + +add_task(async function guess_svg() { + let promise = waitIcon(ROOT + "icon.svg"); + await createLinks([ + { href: ROOT + "icon.svg" }, + { + href: ROOT + "icon.png", + type: "image/png", + size: 16 * Math.ceil(window.devicePixelRatio), + }, + { href: ROOT + "icon.ico", type: "image/x-icon" }, + ]); + await promise; +}); + +add_task(async function guess_ico() { + let promise = waitIcon(ROOT + "file_generic_favicon.ico"); + await createLinks([ + { href: ROOT + "file_generic_favicon.ico" }, + { href: ROOT + "icon.png", type: "image/png" }, + ]); + await promise; +}); + +add_task(async function guess_invalid() { + let promise = waitIcon(ROOT + "icon.svg"); + // Create strange links to make sure they don't break us + await createLinks([ + { href: ROOT + "icon.svg" }, + { href: ROOT + "icon" }, + { href: ROOT + "icon?.svg" }, + { href: ROOT + "icon#.svg" }, + { href: "data:text/plain,icon" }, + { href: "file:///icon" }, + { href: "about:icon" }, + ]); + await promise; +}); + +add_task(async function guess_bestSized() { + let preferredWidth = 16 * Math.ceil(window.devicePixelRatio); + let promise = waitIcon(ROOT + "moz.png"); + await createLinks([ + { href: ROOT + "icon.png", type: "image/png", size: preferredWidth - 1 }, + { href: ROOT + "icon2.png", type: "image/png" }, + { href: ROOT + "moz.png", type: "image/png", size: preferredWidth + 1 }, + { href: ROOT + "icon4.png", type: "image/png", size: preferredWidth + 2 }, + ]); + await promise; +}); -- cgit v1.2.3