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 /testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.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 'testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js')
-rw-r--r-- | testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js new file mode 100644 index 0000000000..06c8dc3c59 --- /dev/null +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js @@ -0,0 +1,68 @@ +"use strict"; + +const { XPCShellContentUtils } = ChromeUtils.import( + "resource://testing-common/XPCShellContentUtils.jsm" +); + +XPCShellContentUtils.init(this); + +const HTML = String.raw`<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title></title> +</head> +<body> + <span id="span">Hello there.</span> +</body> +</html>`; + +const server = XPCShellContentUtils.createHttpServer({ + hosts: ["example.com"], +}); + +server.registerPathHandler("/", (request, response) => { + response.setHeader("Content-Type", "text/html"); + response.write(HTML); +}); + +add_task(async function () { + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + let page = await XPCShellContentUtils.loadContentPage("http://example.com/", { + remote: true, + remoteSubframes: true, + }); + + let { SpecialPowers, browsingContext } = page; + + let result = await SpecialPowers.spawn( + browsingContext, + ["#span"], + selector => { + let elem = content.document.querySelector(selector); + return elem.textContent; + } + ); + + equal(result, "Hello there.", "Got correct element text from frame"); + + let line = Components.stack.lineNumber + 1; + let callback = () => { + let e = new Error("Hello."); + return { filename: e.fileName, lineNumber: e.lineNumber }; + }; + + let loc = await SpecialPowers.spawn(browsingContext, [], callback); + equal( + loc.filename, + Components.stack.filename, + "Error should have correct script filename" + ); + equal( + loc.lineNumber, + line + 2, + "Error should have correct script line number" + ); + + await page.close(); +}); |