diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html')
-rw-r--r-- | testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html new file mode 100644 index 0000000000..7242bd19f5 --- /dev/null +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html @@ -0,0 +1,65 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for SpecialPowers.loadChromeScript</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> + +<pre id="test"> +<script class="testbody" type="text/javascript"> + +SimpleTest.waitForExplicitFinish(); + +var url = SimpleTest.getTestFileURL("SpecialPowersLoadChromeScript.js"); +var script = SpecialPowers.loadChromeScript(url); + +var MESSAGE = { bar: true }; +script.addMessageListener("bar", function (message) { + is(JSON.stringify(message), JSON.stringify(MESSAGE), + "received back message from the chrome script"); + + checkAssert(); +}); + +function checkAssert() { + script.sendAsyncMessage("valid-assert"); + script.addMessageListener("valid-assert-done", endOfFirstTest); +} + +var script2; + +function endOfFirstTest() { + script.destroy(); + + // wantGlobalProperties should add the specified properties to the sandbox + // that is used to run the chrome script. + script2 = SpecialPowers.loadChromeScript(_ => { + /* eslint-env mozilla/chrome-script */ + addMessageListener("valid-assert", function (message) { + assert.equal(typeof XMLHttpRequest, "function", "XMLHttpRequest is defined"); + assert.equal(typeof CSS, "undefined", "CSS is not defined"); + sendAsyncMessage("valid-assert-done"); + }); + }, { wantGlobalProperties: ["ChromeUtils", "XMLHttpRequest"] }); + + script2.sendAsyncMessage("valid-assert"); + script2.addMessageListener("valid-assert-done", endOfTest); + +} + +async function endOfTest() { + is(await script.sendQuery("sync-message"), "Received a synchronous message.", + "Check sync return value"); + + script2.destroy(); + SimpleTest.finish(); +} + +script.sendAsyncMessage("foo", MESSAGE); + +</script> +</pre> +</body> +</html> |