Commit f90cc712 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[WPT] Test forcible worker termination (modules/dynamic imports)

This CL adds tests for forcible worker termination during:

- Module top-level script evaluation,
- Evaluation of dynamic import()ed script evaluation
  (from module/classic workers),

The failure of
"Worker is terminated during top-level script evaluation (module)"
test on Chromium is tracked by crbug.com/1129793.

Bug: 1111134, 1129785, 1129793
Change-Id: I7babf738848a2de51a62679e080a389519fd5884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418751Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810096}
parent 78555b55
This is a testharness.js-based test.
PASS Worker is terminated during top-level script evaluation
FAIL Worker is terminated during top-level script evaluation (module) assert_unreached: onerror Reached unreachable code
PASS Worker is terminated during importScripts() call
PASS Worker is terminated during nested importScripts() call
PASS Worker is terminated during dynamic import()
PASS Worker is terminated during dynamic import() (module)
Harness: the test ran to completion.
...@@ -5,32 +5,60 @@ ...@@ -5,32 +5,60 @@
<script> <script>
// The tests here are to provide execution coverage for the code paths for // The tests here are to provide execution coverage for the code paths for
// forcible worker termination. // forcible worker termination.
// Currently, no specific expectation are set here, i.e. expectation here is // Expectation here is:
// not to crush, not to cause assertion failures, etc. // - Not to crash, not to cause assertion failures
// - No WorkerGlobalScope error events and thus Worker error events are fired
// (#report-the-exception is not called when a script is terminated during
// #run-a-classic-script/#run-a-module-script according to the spec)
// - Nothing after infinte loop, promise resolusion/rejection etc. occurs.
async_test((t) => { for (const test of [
const worker = new Worker('support/Worker-run-forever.js'); {
worker.onmessage = () => { url: 'support/Worker-run-forever.js',
worker.terminate(); description: 'Worker is terminated during top-level script evaluation'
// To make the worker forcibly terminated, because in Chromium worker is },
// forcibly terminated after 2 seconds. {
t.step_timeout(function() { t.done(); }, 4000); url: 'support/Worker-run-forever.js',
}; options: {type: 'module'},
}, 'Worker is terminated during top-level script evaluation'); description: 'Worker is terminated during top-level script evaluation (module)'
},
async_test((t) => { {
const worker = new Worker('support/Worker-run-forever-during-importScripts.js'); url: 'support/Worker-run-forever-during-importScripts.js',
worker.onmessage = () => { description: 'Worker is terminated during importScripts() call'
worker.terminate(); },
t.step_timeout(function() { t.done(); }, 4000); {
}; url: 'support/Worker-run-forever-during-nested-importScripts.js',
}, 'Worker is terminated during importScripts() call'); description: 'Worker is terminated during nested importScripts() call'
},
async_test((t) => { {
const worker = new Worker('support/Worker-run-forever-during-nested-importScripts.js'); url: 'support/Worker-run-forever-during-dynamic-import.js',
worker.onmessage = () => { description: 'Worker is terminated during dynamic import()'
worker.terminate(); },
t.step_timeout(function() { t.done(); }, 4000); {
}; url: 'support/Worker-run-forever-during-dynamic-import.js',
}, 'Worker is terminated during nested importScripts() call'); options: {type: 'module'},
description: 'Worker is terminated during dynamic import() (module)'
}
]) {
async_test((t) => {
const worker = new Worker(test.url, test.options);
worker.onerror = t.step_func(e => {
// Calls preventDefault() to prevent this event from being considered
// as an uncaught exception.
e.preventDefault();
assert_unreached('onerror');
});
worker.onmessage = t.step_func((e) => {
if (e.data === 'start') {
worker.terminate();
// To make the worker forcibly terminated, because in Chromium worker is
// forcibly terminated after 2 seconds.
t.step_timeout(function() { t.done(); }, 4000);
}
else {
assert_unreached('Unexpected message received: ' + e.data);
}
});
}, test.description);
}
</script> </script>
import('./Worker-run-forever.js')
.then(r => postMessage('resolved: ' + r))
.catch(e => postMessage('rejected: ' + e));
importScripts('Worker-run-forever.js'); importScripts('Worker-run-forever.js');
// This is not expected to run.
postMessage('after importScripts()');
postMessage('start'); postMessage('start');
onerror = () => postMessage('onerror');
while(1); while(1);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment