diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html')
-rw-r--r-- | testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html new file mode 100644 index 0000000000..7946a18236 --- /dev/null +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersSandbox.html @@ -0,0 +1,125 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for SpecialPowers sandboxes</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> + +<iframe id="iframe"></iframe> + +<script> +/** + * Tests that the shared sandbox functionality for cross-process script + * execution works as expected. In particular, ensures that Assert methods + * report the correct diagnostics in the caller scope. + */ + +/* globals SpecialPowers, Assert */ + +async function interceptDiagnostics(func) { + let originalRecord = SimpleTest.record; + try { + let diags = []; + + SimpleTest.record = (condition, name, diag, stack) => { + diags.push({condition, name, diag, stack}); + }; + + await func(); + + return diags; + } finally { + SimpleTest.record = originalRecord; + } +} + +add_task(async function() { + const frameSrc = "https://example.com/tests/testing/mochitest/tests/Harness_sanity/file_spawn.html"; + const subframeSrc = "https://example.org/tests/testing/mochitest/tests/Harness_sanity/file_spawn.html"; + + let frame = document.getElementById("iframe"); + frame.src = frameSrc; + + await new Promise(resolve => { + frame.addEventListener("load", resolve, {once: true}); + }); + + let expected = [ + [false, "Thing - 1 == 2", "got 1, expected 2 (operator ==)"], + [true, "Hmm - 1 == 1", undefined], + [true, "Yay. - true == true", undefined], + [false, "Boo!. - false == true", "got false, expected true (operator ==)"], + ]; + + // Test that a representative variety of assertions work as expected, and + // trigger the expected calls to the harness's reporting function. + // + // Note: Assert.sys.mjs has its own tests, and defers all of its reporting to a + // single reporting function, so we don't need to test it comprehensively. We + // just need to make sure that the general functionality works as expected. + let tests = { + "SpecialPowers.spawn": () => { + return SpecialPowers.spawn(frame, [], async () => { + Assert.equal(1, 2, "Thing"); + Assert.equal(1, 1, "Hmm"); + Assert.ok(true, "Yay."); + Assert.ok(false, "Boo!."); + }); + }, + "SpecialPowers.spawn-subframe": () => { + return SpecialPowers.spawn(frame, [subframeSrc], async src => { + let subFrame = this.content.document.createElement("iframe"); + subFrame.src = src; + this.content.document.body.appendChild(subFrame); + + await new Promise(resolve => { + subFrame.addEventListener("load", resolve, { once: true }); + }); + + await SpecialPowers.spawn(subFrame, [], () => { + Assert.equal(1, 2, "Thing"); + Assert.equal(1, 1, "Hmm"); + Assert.ok(true, "Yay."); + Assert.ok(false, "Boo!."); + }); + }); + }, + "SpecialPowers.spawnChrome": () => { + return SpecialPowers.spawnChrome([], async () => { + Assert.equal(1, 2, "Thing"); + Assert.equal(1, 1, "Hmm"); + Assert.ok(true, "Yay."); + Assert.ok(false, "Boo!."); + }); + }, + "SpecialPowers.loadChromeScript": async () => { + let script = SpecialPowers.loadChromeScript(() => { + /* eslint-env mozilla/chrome-script */ + this.addMessageListener("ping", () => "pong"); + + Assert.equal(1, 2, "Thing"); + Assert.equal(1, 1, "Hmm"); + Assert.ok(true, "Yay."); + Assert.ok(false, "Boo!."); + }); + + await script.sendQuery("ping"); + script.destroy(); + }, + }; + + for (let [name, func] of Object.entries(tests)) { + info(`Starting task: ${name}`); + + let diags = await interceptDiagnostics(func); + + let results = diags.map(diag => [diag.condition, diag.name, diag.diag]); + + isDeeply(results, expected, "Got expected assertions"); + } +}); +</script> +</body> +</html> |