Worker-terminate-forever-during-evaluation.html (2559B)
1 <!DOCTYPE html> 2 <title>Test Worker.terminate() for a worker that tries to run forever after top-level script evaluation is started.</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 // The tests here are to provide execution coverage for the code paths for 7 // forcible worker termination. 8 // Expectation here is: 9 // - Not to crash, not to cause assertion failures 10 // - No WorkerGlobalScope error events and thus Worker error events are fired 11 // (#report-the-exception is not called when a script is terminated during 12 // #run-a-classic-script/#run-a-module-script according to the spec) 13 // - Nothing after infinte loop, promise resolusion/rejection etc. occurs. 14 15 for (const test of [ 16 { 17 url: 'support/Worker-run-forever.js', 18 description: 'Worker is terminated during top-level script evaluation' 19 }, 20 { 21 url: 'support/Worker-run-forever.js', 22 options: {type: 'module'}, 23 description: 'Worker is terminated during top-level script evaluation (module)' 24 }, 25 { 26 url: 'support/Worker-run-forever-during-importScripts.js', 27 description: 'Worker is terminated during importScripts() call' 28 }, 29 { 30 url: 'support/Worker-run-forever-during-nested-importScripts.js', 31 description: 'Worker is terminated during nested importScripts() call' 32 }, 33 { 34 url: 'support/Worker-run-forever-during-dynamic-import.js', 35 description: 'Worker is terminated during dynamic import()' 36 }, 37 { 38 url: 'support/Worker-run-forever-during-dynamic-import.js', 39 options: {type: 'module'}, 40 description: 'Worker is terminated during dynamic import() (module)' 41 }, 42 { 43 url: 'support/Worker-run-forever-during-top-level-await.js', 44 options: {type: 'module'}, 45 description: 'Worker is terminated during top-level await' 46 } 47 ]) { 48 async_test((t) => { 49 const worker = new Worker(test.url, test.options); 50 worker.onerror = t.step_func(e => { 51 // Calls preventDefault() to prevent this event from being considered 52 // as an uncaught exception. 53 e.preventDefault(); 54 assert_unreached('onerror'); 55 }); 56 worker.onmessage = t.step_func((e) => { 57 if (e.data === 'start') { 58 worker.terminate(); 59 // To make the worker forcibly terminated, because in Chromium worker is 60 // forcibly terminated after 2 seconds. 61 t.step_timeout(function() { t.done(); }, 4000); 62 } 63 else { 64 assert_unreached('Unexpected message received: ' + e.data); 65 } 66 }); 67 }, test.description); 68 } 69 </script>