diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/favicons/head.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/favicons/head.js')
-rw-r--r-- | browser/base/content/test/favicons/head.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/browser/base/content/test/favicons/head.js b/browser/base/content/test/favicons/head.js new file mode 100644 index 0000000000..ce16afd33f --- /dev/null +++ b/browser/base/content/test/favicons/head.js @@ -0,0 +1,98 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +ChromeUtils.defineESModuleGetters(this, { + LinkHandlerParent: "resource:///actors/LinkHandlerParent.sys.mjs", + PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs", + PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs", + + XPCShellContentUtils: + "resource://testing-common/XPCShellContentUtils.sys.mjs", +}); + +// Clear the network cache between every test to make sure we get a stable state +Services.cache2.clear(); + +function waitForFaviconMessage(isTabIcon = undefined, expectedURL = undefined) { + return new Promise((resolve, reject) => { + let listener = (name, data) => { + if (name != "SetIcon" && name != "SetFailedIcon") { + return; // Ignore unhandled messages + } + + // If requested filter out loads of the wrong kind of icon. + if (isTabIcon != undefined && isTabIcon != data.canUseForTab) { + return; + } + + if (expectedURL && data.originalURL != expectedURL) { + return; + } + + LinkHandlerParent.removeListenerForTests(listener); + + if (name == "SetIcon") { + resolve({ + iconURL: data.originalURL, + dataURL: data.iconURL, + canUseForTab: data.canUseForTab, + }); + } else { + reject({ + iconURL: data.originalURL, + canUseForTab: data.canUseForTab, + }); + } + }; + + LinkHandlerParent.addListenerForTests(listener); + }); +} + +function waitForFavicon(browser, url) { + return new Promise(resolve => { + let listener = { + onLinkIconAvailable(b, dataURI, iconURI) { + if (b !== browser || iconURI != url) { + return; + } + + gBrowser.removeTabsProgressListener(listener); + resolve(); + }, + }; + + gBrowser.addTabsProgressListener(listener); + }); +} + +function waitForLinkAvailable(browser) { + let resolve, reject; + + let listener = { + onLinkIconAvailable(b, dataURI, iconURI) { + // Ignore icons for other browsers or empty icons. + if (browser !== b || !iconURI) { + return; + } + + gBrowser.removeTabsProgressListener(listener); + resolve(iconURI); + }, + }; + + let promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + + gBrowser.addTabsProgressListener(listener); + }); + + promise.cancel = () => { + gBrowser.removeTabsProgressListener(listener); + + reject(); + }; + + return promise; +} |