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 /dom/workers/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 'dom/workers/test/head.js')
-rw-r--r-- | dom/workers/test/head.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/dom/workers/test/head.js b/dom/workers/test/head.js new file mode 100644 index 0000000000..ce6cebbd06 --- /dev/null +++ b/dom/workers/test/head.js @@ -0,0 +1,75 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +/** + * Add a tab with given `url`. Returns a promise + * that will be resolved when the tab finished loading. + */ +function addTab(url) { + return BrowserTestUtils.openNewForegroundTab(gBrowser, TAB_URL); +} + +/** + * Remove the given `tab`. + */ +function removeTab(tab) { + gBrowser.removeTab(tab); +} + +/** + * Create a worker with the given `url` in the given `tab`. + */ +function createWorkerInTab(tab, url) { + info("Creating worker with url '" + url + "'\n"); + return SpecialPowers.spawn(tab.linkedBrowser, [url], urlChild => { + if (!content._workers) { + content._workers = {}; + } + content._workers[urlChild] = new content.Worker(urlChild); + }); +} + +/** + * Terminate the worker with the given `url` in the given `tab`. + */ +function terminateWorkerInTab(tab, url) { + info("Terminating worker with url '" + url + "'\n"); + return SpecialPowers.spawn(tab.linkedBrowser, [url], urlChild => { + content._workers[urlChild].terminate(); + delete content._workers[urlChild]; + }); +} + +/** + * Post the given `message` to the worker with the given `url` in the given + * `tab`. + */ +function postMessageToWorkerInTab(tab, url, message) { + info("Posting message to worker with url '" + url + "'\n"); + return SpecialPowers.spawn( + tab.linkedBrowser, + [url, message], + (urlChild, messageChild) => { + let worker = content._workers[urlChild]; + worker.postMessage(messageChild); + return new Promise(function (resolve) { + worker.onmessage = function (event) { + worker.onmessage = null; + resolve(event.data); + }; + }); + } + ); +} + +/** + * Disable the cache in the given `tab`. + */ +function disableCacheInTab(tab) { + return SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.docShell.defaultLoadFlags = + Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING; + }); +} |