diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/base/content/test/favicons/browser_preferred_icons.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/favicons/browser_preferred_icons.js')
-rw-r--r-- | browser/base/content/test/favicons/browser_preferred_icons.js | 140 |
1 files changed, 140 insertions, 0 deletions
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..ced7c27fec --- /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; +}); |