diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/tests/mochitest/script | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/script')
-rw-r--r-- | dom/tests/mochitest/script/bug1656248_frame.html | 5 | ||||
-rw-r--r-- | dom/tests/mochitest/script/file_blocked_script.sjs | 69 | ||||
-rw-r--r-- | dom/tests/mochitest/script/mochitest.ini | 10 | ||||
-rw-r--r-- | dom/tests/mochitest/script/subdir/.eslintrc.js | 11 | ||||
-rw-r--r-- | dom/tests/mochitest/script/subdir/bug1656248_import.js | 1 | ||||
-rw-r--r-- | dom/tests/mochitest/script/subdir/bug1656248_script.js | 18 | ||||
-rw-r--r-- | dom/tests/mochitest/script/test_bug1053321.html | 50 | ||||
-rw-r--r-- | dom/tests/mochitest/script/test_bug1656248.html | 104 | ||||
-rw-r--r-- | dom/tests/mochitest/script/test_whitespace.html | 31 |
9 files changed, 299 insertions, 0 deletions
diff --git a/dom/tests/mochitest/script/bug1656248_frame.html b/dom/tests/mochitest/script/bug1656248_frame.html new file mode 100644 index 0000000000..40b858e7c7 --- /dev/null +++ b/dom/tests/mochitest/script/bug1656248_frame.html @@ -0,0 +1,5 @@ +<html> + <head> + <script src="./subdir/bug1656248_script.js"></script> + </head> +</html> diff --git a/dom/tests/mochitest/script/file_blocked_script.sjs b/dom/tests/mochitest/script/file_blocked_script.sjs new file mode 100644 index 0000000000..d33db5950b --- /dev/null +++ b/dom/tests/mochitest/script/file_blocked_script.sjs @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function setGlobalState(data, key) +{ + x = { data: data, QueryInterface: function(iid) { return this } }; + x.wrappedJSObject = x; + setObjectState(key, x); +} + +function getGlobalState(key) +{ + var data; + getObjectState(key, function(x) { + data = x && x.wrappedJSObject.data; + }); + return data; +} + +function finishBlockedRequest(request, response, query) +{ + response.setStatusLine(request.httpVersion, 200, "OK"); + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "application/javascript", false); + response.write("scriptLoaded('" + query[1] + "');"); + response.finish(); + + setGlobalState(undefined, query[1]); +} + +function handleRequest(request, response) +{ + var query = request.queryString.split('&'); + switch (query[0]) { + case "blocked": + var alreadyUnblocked = getGlobalState(query[1]); + + response.processAsync(); + if (alreadyUnblocked === true) { + // the unblock request came before the blocked request, just go on and finish synchronously + finishBlockedRequest(request, response, query); + } else { + setGlobalState(response, query[1]); + } + break; + + case "unblock": + response.setStatusLine(request.httpVersion, 200, "OK"); + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "image/png", false); + response.write("\x89PNG"); // just a broken image is enough for our purpose + + var blockedResponse = getGlobalState(query[1]); + if (blockedResponse === undefined) { + // the unblock request came before the blocked request, remember to not block it + setGlobalState(true, query[1]); + } else if (typeof blockedResponse == "object") { + finishBlockedRequest(request, blockedResponse, query); + } + break; + + default: + response.setStatusLine(request.httpVersion, 400, "Bad request"); + break; + } +} diff --git a/dom/tests/mochitest/script/mochitest.ini b/dom/tests/mochitest/script/mochitest.ini new file mode 100644 index 0000000000..bf2eccafd6 --- /dev/null +++ b/dom/tests/mochitest/script/mochitest.ini @@ -0,0 +1,10 @@ +[DEFAULT] +support-files = + file_blocked_script.sjs + bug1656248_frame.html + subdir/bug1656248_script.js + subdir/bug1656248_import.js + +[test_bug1053321.html] +[test_whitespace.html] +[test_bug1656248.html] diff --git a/dom/tests/mochitest/script/subdir/.eslintrc.js b/dom/tests/mochitest/script/subdir/.eslintrc.js new file mode 100644 index 0000000000..c85129a731 --- /dev/null +++ b/dom/tests/mochitest/script/subdir/.eslintrc.js @@ -0,0 +1,11 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +module.exports = { + parserOptions: { + sourceType: "module", + }, +}; diff --git a/dom/tests/mochitest/script/subdir/bug1656248_import.js b/dom/tests/mochitest/script/subdir/bug1656248_import.js new file mode 100644 index 0000000000..7a4e8a723a --- /dev/null +++ b/dom/tests/mochitest/script/subdir/bug1656248_import.js @@ -0,0 +1 @@ +export default 42; diff --git a/dom/tests/mochitest/script/subdir/bug1656248_script.js b/dom/tests/mochitest/script/subdir/bug1656248_script.js new file mode 100644 index 0000000000..25cd8c241f --- /dev/null +++ b/dom/tests/mochitest/script/subdir/bug1656248_script.js @@ -0,0 +1,18 @@ +// Import a module which should be resolved relative to this script's URL. +import("./bug1656248_import.js") + .then(ns => window.parent.checkResult(ns.default)) + .catch(e => window.parent.checkResult(`error: ${e}`)); + +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. +// To trigger the bytecode cache, this script needs to be at least 1KB. diff --git a/dom/tests/mochitest/script/test_bug1053321.html b/dom/tests/mochitest/script/test_bug1053321.html new file mode 100644 index 0000000000..bad2b4b4c4 --- /dev/null +++ b/dom/tests/mochitest/script/test_bug1053321.html @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<html> +<!-- +This test confirms we don't block body referred sub-resources by head-referenced defer and async scripts. +If this test times out, the two image requests, that unblock the two script requests, never happen, hence +are unexpectedly blocked. +--> + +<head> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + + <script> + // The two scripts below are expected to load and call scriptLoaded(). + SimpleTest.waitForExplicitFinish(); + + window.expected_scripts = { + "defer": true, + "async": true, + }; + + function scriptLoaded(script) + { + ok(true, 'Script ' + script + ' executed'); + delete window.expected_scripts[script]; + + let expecting = Object.keys(window.expected_scripts).length; + info("Expecting " + expecting + " more script(s) to execute"); + + if (expecting == 0) { + SimpleTest.finish(); + } + } + </script> + + <!-- this script is not loaded until file_blocked_script.sjs?unblock&defer request is made, + when this script is executed, it calls SimpleTest.finish(). + --> + <script defer src="file_blocked_script.sjs?blocked&defer"></script> + + <!-- this script is not loaded until file_blocked_script.sjs?unblock&async request is made, + when this script is executed, it calls SimpleTest.finish(). + --> + <script async src="file_blocked_script.sjs?blocked&async"></script> +</head> + +<body> + <img src="file_blocked_script.sjs?unblock&defer"/> + <img src="file_blocked_script.sjs?unblock&async"/> +</body> diff --git a/dom/tests/mochitest/script/test_bug1656248.html b/dom/tests/mochitest/script/test_bug1656248.html new file mode 100644 index 0000000000..af043ec25e --- /dev/null +++ b/dom/tests/mochitest/script/test_bug1656248.html @@ -0,0 +1,104 @@ +<!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"; + + let count = 0; + let waitForLoadOrEncode = true; + + 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). + SpecialPowers.pushPrefEnv({ + set: [ + ['dom.script_loader.bytecode_cache.enabled', true], + ['dom.expose_test_interfaces', true], + ["dom.script_loader.bytecode_cache.strategy", -1] + ]}).then(nextIteration); + } + + function nextIteration() { + let iframe = document.getElementById(iframeId) + if (iframe) { + document.body.removeChild(iframe); + } + + iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + iframe.id = iframeId; + + var iwin = iframe.contentWindow; + iwin.addEventListener("scriptloader_bytecode_saved", + handleScriptLoaderEvent); + iwin.addEventListener("scriptloader_bytecode_failed", + handleScriptLoaderEvent); + iwin.addEventListener("scriptloader_load_bytecode", + handleScriptLoaderEvent); + + iframe.src = "bug1656248_frame.html"; + } + + function handleScriptLoaderEvent(event) { + ok(true, `handleScriptLoaderEvent received ${event.type}`); + + if (!waitForLoadOrEncode) { + return; + } + + if (event.type === 'scriptloader_load_bytecode') { + ok(true, "Script loaded from bytecode") + waitForLoadOrEncode = false; + nextIteration(); + return; + } + + if (event.type === 'scriptloader_bytecode_saved') { + ok(true, "Bytecode encoding succeeded") + waitForLoadOrEncode = false; + nextIteration(); + return; + } + + if (event.type === 'scriptloader_bytecode_failed') { + ok(false, "Bytecode encoding failed") + SimpleTest.finish(); + return; + } + } + + function checkResult(result) { + is(result, 42, "Module was loaded successfully"); + + count++; + if (count === 3) { + SimpleTest.finish(); + return; + } + + if (!waitForLoadOrEncode) { + nextIteration(); + } + } + </script> +</head> + +<body onload="startTest()"></body> diff --git a/dom/tests/mochitest/script/test_whitespace.html b/dom/tests/mochitest/script/test_whitespace.html new file mode 100644 index 0000000000..7ab14d9b67 --- /dev/null +++ b/dom/tests/mochitest/script/test_whitespace.html @@ -0,0 +1,31 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for ScriptLoader and type with whitespaces</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> + +<script type="application/javascript"> +let passed = false; + +let tests = [ + " application/javascript", + "\tapplication/javascript\n\r \t", +]; + +for (let i = 0; i < tests.length; ++i) { + passed = false; + + let script = document.createElement('script'); + script.setAttribute('type', tests[i]); + script.innerText = "passed = true;"; + document.body.appendChild(script); + + ok (passed, "Test " + tests[i] + " passed"); +} +</script> + +</body> +</html> |