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/tests/mochitest/script/test_bug1656248.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/tests/mochitest/script/test_bug1656248.html | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/dom/tests/mochitest/script/test_bug1656248.html b/dom/tests/mochitest/script/test_bug1656248.html new file mode 100644 index 0000000000..3b12fdaf80 --- /dev/null +++ b/dom/tests/mochitest/script/test_bug1656248.html @@ -0,0 +1,93 @@ +<!DOCTYPE html> +<html> +<!-- +Repeated reload an iframe. When iframe's script is loaded from the bytecode +cache, dynamic module import should still resolve modules based on the +script's URL. +--> +<head> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + + <script> + const iframeId = "test_iframe"; + + var checkResult = null; + + async function startTest() { + SimpleTest.waitForExplicitFinish(); + + // Setting dom.expose_test_interfaces pref causes the + // nsScriptLoadRequest to fire event on script tags, with information + // about its internal state. The ScriptLoader source send events to + // trace these and resolve a promise with the path taken by the + // script loader. + // + // Setting dom.script_loader.bytecode_cache.strategy to -1 causes the + // nsScriptLoadRequest to force all the conditions necessary to make a + // script be saved as bytecode in the alternate data storage provided + // by the channel (necko cache). + await SpecialPowers.pushPrefEnv({ + set: [ + ['dom.script_loader.bytecode_cache.enabled', true], + ['dom.expose_test_interfaces', true], + ["dom.script_loader.bytecode_cache.strategy", -1] + ]}); + + for (let i = 0; i < 3; i++) { + let iframe = document.getElementById(iframeId); + if (iframe) { + document.body.removeChild(iframe); + } + + iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + iframe.id = iframeId; + + let iwin = iframe.contentWindow; + + let eventPromise = new Promise(resolve => { + // Both regular script and imported module scripts are encoded/decoded + // Wait for 2 encode/load events to be fired. + let count = 0; + if (i == 0) { + iwin.addEventListener("scriptloader_bytecode_saved", event => { + count++; + ok(true, "Bytecode encoding succeeded"); + if (count == 2) { + resolve(); + } + }); + } else { + iwin.addEventListener("scriptloader_load_bytecode", event => { + count++; + ok(true, "Script loaded from bytecode"); + if (count == 2) { + resolve(); + } + }); + } + + iwin.addEventListener("scriptloader_bytecode_failed", () => { + ok(false, "Bytecode encoding failed"); + SimpleTest.finish(); + }); + }); + + let resultPromise = new Promise(resolve => { + checkResult = resolve; + }); + + iframe.src = "bug1656248_frame.html"; + + let [_, result] = await Promise.all([eventPromise, resultPromise]); + + is(result, 42, `Module was loaded successfully (${i})`); + } + + SimpleTest.finish(); + } + </script> +</head> + +<body onload="startTest()"></body> |