summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js')
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersSpawn.js68
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();
+});