Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / workers / test / test_dynamicImport_early_termination.html
blobfb9096df14c818a6f22ee0c7c11f5aea5af11d9a
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE HTML>
6 <html>
7 <!--
8 Tests of Worker Dynamic Import (Bug 1540913)
9 Ensure that the script loader doesn't fail if requests are terminated early.
10 -->
11 <head>
12 <title>Test for Worker Dynamic Import (Bug 1540913)</title>
13 <script src="/tests/SimpleTest/SimpleTest.js"></script>
14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
15 </head>
16 <body onload="onLoad()">
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1540913">Worker Dynamic Import
18 Bug 1540913</a>
19 <p id="display"></p>
20 <div id="content" style="display: none">
22 </div>
23 <pre id="test">
24 <script class="testbody" type="text/javascript">
25 SimpleTest.waitForExplicitFinish();
27 async function onLoad() {
28 await SpecialPowers.pushPrefEnv(
29 { set: [["dom.workers.modules.enabled", true ]] });
31 const workers = [
32 new Worker("dynamicImport_worker.js", {type: "classic"}),
33 new Worker("dynamicImport_worker.js", {type: "module"})
36 let successCount = 0;
38 // In the implementation of dynamic import, every dynamic import has
39 // it's own ScriptLoader. To ensure that this is working correctly,
40 // this tests that if we re-order the dynamic import order,
41 // worker termination works as expected.
42 for (const worker of workers) {
43 const events = [];
44 worker.onmessage = function(event) {
45 switch (event.data) {
46 case "first":
47 ok(false, "first dynamic import returned");
48 SimpleTest.finish();
49 break;
50 case "second":
51 ok(events.length === 0,
52 "second dynamic import returned");
53 events.push(event.data);
54 worker.terminate()
55 successCount++;
56 // Cheap way to make sure we only finish successfully after
57 // both the module and classic test is finished.
58 if (successCount == 2) {
59 SimpleTest.finish();
61 break;
62 default:
63 ok(false, "Unexpected message:" + event.data);
64 SimpleTest.finish();
68 worker.onerror = function(event) {
69 ok(false, "Worker had an error:" + event.message);
70 SimpleTest.finish();
73 worker.postMessage("start");
76 </script>
77 </pre>
78 </body>
79 </html>