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 /toolkit/components/reader/test/head.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/reader/test/head.js')
-rw-r--r-- | toolkit/components/reader/test/head.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/toolkit/components/reader/test/head.js b/toolkit/components/reader/test/head.js new file mode 100644 index 0000000000..6a8e09ecb2 --- /dev/null +++ b/toolkit/components/reader/test/head.js @@ -0,0 +1,63 @@ +ChromeUtils.defineESModuleGetters(this, { + PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs", +}); + +/* exported promiseTabLoadEvent, is_element_visible, is_element_hidden */ + +/** + * Waits for a load (or custom) event to finish in a given tab. If provided + * load an uri into the tab. + * + * @param tab + * The tab to load into. + * @param [optional] url + * The url to load, or the current url. + * @return {Promise} resolved when the event is handled. + * @resolves to the received event + * @rejects if a valid load event is not received within a meaningful interval + */ +function promiseTabLoadEvent(tab, url) { + let deferred = PromiseUtils.defer(); + info("Wait tab event: load"); + + function handle(loadedUrl) { + if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) { + info(`Skipping spurious load event for ${loadedUrl}`); + return false; + } + + info("Tab event received: load"); + return true; + } + + // Create two promises: one resolved from the content process when the page + // loads and one that is rejected if we take too long to load the url. + let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle); + + let timeout = setTimeout(() => { + deferred.reject(new Error("Timed out while waiting for a 'load' event")); + }, 30000); + + loaded.then(() => { + clearTimeout(timeout); + deferred.resolve(); + }); + + if (url) { + BrowserTestUtils.loadURIString(tab.linkedBrowser, url); + } + + // Promise.all rejects if either promise rejects (i.e. if we time out) and + // if our loaded promise resolves before the timeout, then we resolve the + // timeout promise as well, causing the all promise to resolve. + return Promise.all([deferred.promise, loaded]); +} + +function is_element_visible(element, msg) { + isnot(element, null, "Element should not be null, when checking visibility"); + ok(BrowserTestUtils.is_visible(element), msg || "Element should be visible"); +} +function is_element_hidden(element, msg) { + isnot(element, null, "Element should not be null, when checking visibility"); + ok(BrowserTestUtils.is_hidden(element), msg || "Element should be hidden"); +} |