Bug 1630540 [wpt PR 22994] - DedicatedWorker: Refine WPTs to test parse error handling, a=testonly
authorEriko Kurimoto <elkurin@chromium.org>
Tue, 28 Apr 2020 11:37:53 +0000
changeset 527578 175fd05289e15654205f9cd95a2ad89c6caa4649
parent 527577 c810496118ef82f0f29650c7deebfda23ab36ea9
child 527579 99abccb00c35e87ee213a206b75c9bb9558eaa30
push id37368
push userbtara@mozilla.com
push dateFri, 01 May 2020 21:45:51 +0000
treeherdermozilla-central@0f9c5a59e45d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1630540, 22994, 1071345
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1630540 [wpt PR 22994] - DedicatedWorker: Refine WPTs to test parse error handling, a=testonly Automatic update from web-platform-tests DedicatedWorker: Refine WPTs to test parse error handling This CL modifies web-platform-test for parse error handling in classic and module dedicated workers. This CL does followings: 1. Divide workers/modules/dedicated-worker-parse-error-failure.html into the tests for classic workers and for module workers. 2. For module workers, check if module script is supported before testing parse error handling. 3. Check the content of the dispatched event. This change is based on WPTs for shared workers parse error handling. Bug: 1071345 Change-Id: I738c89d5241a94df17092a3b106b5b795a26a7de -- wpt-commits: f6f6077aab9fea53099084cd009e0701ca5dcfa7 wpt-pr: 22994
testing/web-platform/tests/workers/dedicated-worker-parse-error-failure.html
testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/dedicated-worker-parse-error-failure.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>DedicatedWorker: parse error failure</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script> setup({allow_uncaught_exception: true}); </script>
+<script src="./support/check-error-arguments.js"></script>
+<script>
+
+promise_test(async () => {
+  const scriptURL = 'modules/resources/syntax-error.js';
+  const worker = new Worker(scriptURL, { type: 'classic' });
+  const args = await new Promise(resolve =>
+      worker.onerror = (...args) => resolve(args));
+  window.checkErrorArguments(args);
+}, 'Classic worker construction for script with syntax error should dispatch ' +
+   'an event named error.');
+
+promise_test(async () => {
+  const scriptURL = 'modules/resources/static-import-worker.js';
+  const worker = new Worker(scriptURL, { type: 'classic' });
+  worker.postMessage('Send message for tests from main script.');
+  const args = await new Promise(resolve =>
+      worker.onerror = (...args) => resolve(args));
+  window.checkErrorArguments(args);
+}, 'Static import on classic worker should dispatch an event named error.');
+
+</script>
--- a/testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html
+++ b/testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html
@@ -1,35 +1,51 @@
 <!DOCTYPE html>
 <title>DedicatedWorker: parse error failure</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script> setup({allow_uncaught_exception: true}); </script>
+<script src="../support/check-error-arguments.js"></script>
 <script>
 
-promise_test(async () => {
-  const scriptURL = 'resources/syntax-error.js';
-  const worker = new Worker(scriptURL, { type: 'classic' });
-  return new Promise(resolve => worker.onerror = resolve);
-}, 'Classic worker construction for script with syntax error should dispatch ' +
-   'an ErrorEvent.');
+// Check if module scripts are supported on dedicated workers. There is no
+// direct way to detect it, so we assume it's supported when static import is
+// available on the workers.
+//
+// This check is necessary to appropriately test parse error handling because
+// we need to distinguish the parse error invoked by unsupported "import" in
+// the top-level script from the parse error invoked by the statically imported
+// script which is the one we want to check in this test.
+promise_setup(async () => {
+  const scriptURL = 'resources/static-import-worker.js';
+  const worker = new Worker(scriptURL, { type: 'module' });
+  worker.postMessage('Send message for tests from main script.');
+  const supportsModuleWorkers = await new Promise((resolve, reject) => {
+    worker.onmessage = e => {
+      resolve(e.data.length == 1 && e.data[0] == 'export-on-load-script.js');
+    };
+    worker.onerror = () => resolve(false);
+  });
+  assert_precondition(
+    supportsModuleWorkers,
+    "Static import must be supported on module dedicated worker to run this test."
+  );
+});
 
 promise_test(async () => {
   const scriptURL = 'resources/syntax-error.js';
   const worker = new Worker(scriptURL, { type: 'module' });
-  return new Promise(resolve => worker.onerror = resolve);
+  const args = await new Promise(resolve =>
+      worker.onerror = (...args) => resolve(args));
+  window.checkErrorArguments(args);
 }, 'Module worker construction for script with syntax error should dispatch ' +
-   'an ErrorEvent.');
+   'an event named error.');
 
 promise_test(async () => {
   const scriptURL = 'resources/static-import-syntax-error.js';
   const worker = new Worker(scriptURL, { type: 'module' });
-  return new Promise(resolve => worker.onerror = resolve);
+  const args = await new Promise(resolve =>
+      worker.onerror = (...args) => resolve(args));
+  window.checkErrorArguments(args);
 }, 'Static import on module worker for script with syntax error should ' +
-   'dispatch an ErrorEvent.');
-
-promise_test(() => {
-  const scriptURL = 'resources/static-import-worker.js';
-  const worker = new Worker(scriptURL, { type: 'classic' });
-  return new Promise(resolve => worker.onerror = resolve);
-}, 'Static import on classic worker should dispatch an ErrorEvent.');
+   'dispatch an event named error.');
 
 </script>