From 6448aced5d7f3087a084ee5eefe6b5e21c0dd1cf Mon Sep 17 00:00:00 2001 From: Eriko Kurimoto Date: Tue, 3 Mar 2020 13:30:47 +0000 Subject: [PATCH] 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 Reviewed-by: Hiroki Nakagawa Cr-Commit-Position: refs/heads/master@{#745395} -- wpt-commits: 7cff683a32daccabe364078fa9a66305d6ed908c wpt-pr: 21955 --- .../modules/shared-worker-import-failure.html | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html b/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html index 5e8f547daf69..14579ba762ff 100644 --- a/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html @@ -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',