Bug 1617857 [wpt PR 21955] - SharedWorker: Add WPTs for failure with importing non-existing scripts, a=testonly

Automatic update from web-platform-tests
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: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745395}

--

wpt-commits: 7cff683a32daccabe364078fa9a66305d6ed908c
wpt-pr: 21955
This commit is contained in:
Eriko Kurimoto 2020-03-03 13:30:47 +00:00 коммит произвёл moz-wptsync-bot
Родитель ba81aefc3c
Коммит 6448aced5d
1 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -7,8 +7,12 @@
// TODO: Factor out the test cases into a separate file.
// (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 () => {
const scriptURL = 'resources/import-scripts-worker.js';
@ -25,6 +29,29 @@ promise_test(() => {
}, 'Worker construction for non-existent script should dispatch an ' +
'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(() => {
const scriptURL = 'http://invalid:123$';
assert_throws_dom('SyntaxError',