diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/favicons/browser_preferred_icons.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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..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; +}); |