summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/script
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests/mochitest/script')
-rw-r--r--dom/tests/mochitest/script/bug1656248_frame.html11
-rw-r--r--dom/tests/mochitest/script/file_blocked_script.sjs70
-rw-r--r--dom/tests/mochitest/script/mochitest.ini15
-rw-r--r--dom/tests/mochitest/script/slow.sjs15
-rw-r--r--dom/tests/mochitest/script/subdir/.eslintrc.js11
-rw-r--r--dom/tests/mochitest/script/subdir/bug1656248_import.js1
-rw-r--r--dom/tests/mochitest/script/subdir/bug1656248_script.js18
-rw-r--r--dom/tests/mochitest/script/test_bug1053321.html50
-rw-r--r--dom/tests/mochitest/script/test_bug1656248.html93
-rw-r--r--dom/tests/mochitest/script/test_bug1788532.html21
-rw-r--r--dom/tests/mochitest/script/test_bug1788532_moduleA.mjs15
-rw-r--r--dom/tests/mochitest/script/test_bug1788532_moduleB.mjs2
-rw-r--r--dom/tests/mochitest/script/test_whitespace.html31
13 files changed, 353 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..9030b4cbcf
--- /dev/null
+++ b/dom/tests/mochitest/script/bug1656248_frame.html
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ </head>
+ <body>
+ <script type="text/javascript">
+const script = document.createElement("script");
+script.setAttribute("src", "./subdir/bug1656248_script.js");
+document.body.appendChild(script);
+ </script>
+ </body>
+</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..a5b375a23d
--- /dev/null
+++ b/dom/tests/mochitest/script/file_blocked_script.sjs
@@ -0,0 +1,70 @@
+/* -*- 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,
+ QueryInterface(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..d792777d41
--- /dev/null
+++ b/dom/tests/mochitest/script/mochitest.ini
@@ -0,0 +1,15 @@
+[DEFAULT]
+support-files =
+ file_blocked_script.sjs
+ bug1656248_frame.html
+ subdir/bug1656248_script.js
+ subdir/bug1656248_import.js
+ test_bug1788532_moduleA.mjs
+ test_bug1788532_moduleB.mjs
+ slow.sjs
+
+[test_bug1053321.html]
+[test_whitespace.html]
+[test_bug1656248.html]
+skip-if = verify
+[test_bug1788532.html]
diff --git a/dom/tests/mochitest/script/slow.sjs b/dom/tests/mochitest/script/slow.sjs
new file mode 100644
index 0000000000..7139eb91f3
--- /dev/null
+++ b/dom/tests/mochitest/script/slow.sjs
@@ -0,0 +1,15 @@
+function handleRequest(request, response) {
+ response.processAsync();
+
+ timer = Components.classes["@mozilla.org/timer;1"].createInstance(
+ Components.interfaces.nsITimer
+ );
+ timer.init(
+ function () {
+ response.write("Here the content. But slowly.");
+ response.finish();
+ },
+ 5000,
+ Components.interfaces.nsITimer.TYPE_ONE_SHOT
+ );
+}
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..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>
diff --git a/dom/tests/mochitest/script/test_bug1788532.html b/dom/tests/mochitest/script/test_bug1788532.html
new file mode 100644
index 0000000000..8465c3a1fc
--- /dev/null
+++ b/dom/tests/mochitest/script/test_bug1788532.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<!--
+Test interaction of dynamic module loading and synchronous XHR.
+
+Load a module A that starts a dynamic import of module B which imports A, then
+run a sync XHR at top level. The dynamic import should complete successfully
+after the XHR has finished loading.
+-->
+<head>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+
+ <script>
+ SimpleTest.waitForExplicitFinish();
+ </script>
+
+ <script type="module" src="./test_bug1788532_moduleA.mjs"></script>
+</head>
+
+</html>
diff --git a/dom/tests/mochitest/script/test_bug1788532_moduleA.mjs b/dom/tests/mochitest/script/test_bug1788532_moduleA.mjs
new file mode 100644
index 0000000000..d667aac482
--- /dev/null
+++ b/dom/tests/mochitest/script/test_bug1788532_moduleA.mjs
@@ -0,0 +1,15 @@
+let xhrFinished = false;
+
+import("./test_bug1788532_moduleB.mjs")
+ .then(() => {
+ ok(xhrFinished, "Loaded after XHR finished");
+ SimpleTest.finish();
+ })
+ .catch(e => {
+ ok(false, "Caught exception: " + e);
+ });
+
+let request = new XMLHttpRequest();
+request.open("GET", "./slow.sjs", false);
+request.send(null);
+xhrFinished = true;
diff --git a/dom/tests/mochitest/script/test_bug1788532_moduleB.mjs b/dom/tests/mochitest/script/test_bug1788532_moduleB.mjs
new file mode 100644
index 0000000000..71e2e7009b
--- /dev/null
+++ b/dom/tests/mochitest/script/test_bug1788532_moduleB.mjs
@@ -0,0 +1,2 @@
+/* eslint-disable-next-line import/no-unassigned-import */
+import "./test_bug1788532_moduleA.mjs";
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>