test_dynamicImport_early_termination.html (2232B)
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"> 21 22 </div> 23 <pre id="test"> 24 <script class="testbody" type="text/javascript"> 25 SimpleTest.waitForExplicitFinish(); 26 27 async function onLoad() { 28 const workers = [ 29 new Worker("dynamicImport_worker.js", {type: "classic"}), 30 new Worker("dynamicImport_worker.js", {type: "module"}) 31 ] 32 33 let successCount = 0; 34 35 // In the implementation of dynamic import, every dynamic import has 36 // it's own ScriptLoader. To ensure that this is working correctly, 37 // this tests that if we re-order the dynamic import order, 38 // worker termination works as expected. 39 for (const worker of workers) { 40 const events = []; 41 worker.onmessage = function(event) { 42 switch (event.data) { 43 case "first": 44 ok(false, "first dynamic import returned"); 45 SimpleTest.finish(); 46 break; 47 case "second": 48 ok(events.length === 0, 49 "second dynamic import returned"); 50 events.push(event.data); 51 worker.terminate() 52 successCount++; 53 // Cheap way to make sure we only finish successfully after 54 // both the module and classic test is finished. 55 if (successCount == 2) { 56 SimpleTest.finish(); 57 } 58 break; 59 default: 60 ok(false, "Unexpected message:" + event.data); 61 SimpleTest.finish(); 62 } 63 }; 64 65 worker.onerror = function(event) { 66 ok(false, "Worker had an error:" + event.message); 67 SimpleTest.finish(); 68 } 69 70 worker.postMessage("start"); 71 } 72 } 73 </script> 74 </pre> 75 </body> 76 </html>