Commit a20746ba authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

SharedWorker: Add WPTs for failure with importing non-existing scripts

This CL adds tests to static/dynamic import of non-existing scripts
modules shared workers.

Without 'static import on classic worker' test, all the tests
corresponding to dedicated-worker-import-failure.html have added.
'static import on classic worker' is treated as parse error, and the way
to handle parse error differs from fetching non-existing or invalid
scripts which are tested in this test file.
Therefore, I will add WPTs for parse error in separated files by the
following CLs.

Change-Id: I1f4555f2ea8597f0c0fc197494f0ba5d1510db75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071466
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745395}
parent 8aecc924
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
// TODO: Factor out the test cases into a separate file. // TODO: Factor out the test cases into a separate file.
// (like import-test-cases.js) // (like import-test-cases.js)
// TODO: Add rest of the tests correponding to
// 'dedicated-worker-import-failure.html' // SharedWorkers doesn't fire error events when runtime script errors occur.
//
// "For shared workers, if the error is still not handled afterwards, the error
// may be reported to a developer console." [spec text]
// https://html.spec.whatwg.org/C/#runtime-script-errors-2
promise_test(async () => { promise_test(async () => {
const scriptURL = 'resources/import-scripts-worker.js'; const scriptURL = 'resources/import-scripts-worker.js';
...@@ -25,6 +29,29 @@ promise_test(() => { ...@@ -25,6 +29,29 @@ promise_test(() => {
}, 'Worker construction for non-existent script should dispatch an ' + }, 'Worker construction for non-existent script should dispatch an ' +
'ErrorEvent.'); 'ErrorEvent.');
promise_test(() => {
const scriptURL = 'resources/static-import-non-existent-script-worker.js';
const worker = new SharedWorker(scriptURL, { type: 'module' });
return new Promise(resolve => worker.onerror = resolve);
}, 'Static import for non-existent script should dispatch an ErrorEvent.');
promise_test(async () => {
const scriptURL = './non-existent-worker.js';
const worker =
new SharedWorker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.port.postMessage(scriptURL);
const msg_event = await new Promise((resolve, reject) => {
worker.port.onmessage = resolve;
worker.onerror = error => {
const msg = error instanceof ErrorEvent ? error.message
: 'unknown error';
reject(msg);
};
});
assert_equals(msg_event.data, 'TypeError');
}, 'Dynamic import for non-existent script should throw an exception.');
test(() => { test(() => {
const scriptURL = 'http://invalid:123$'; const scriptURL = 'http://invalid:123$';
assert_throws_dom('SyntaxError', assert_throws_dom('SyntaxError',
......
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