Bug 1656160 [wpt PR 24810] - [WPT] Errors caught/reported for importScripts(), a=testonly
☠☠ backed out by a6e9c6ea61f6 ☠ ☠
authorBlink WPT Bot <blink-w3c-test-autoroller@chromium.org>
Fri, 07 Aug 2020 12:47:20 +0000
changeset 543985 56c33dd1f130926b70374e6efcfed25849880d24
parent 543984 5482dc7e339d66c5618ca10af382b9c9404156ed
child 543986 9584ddf5d03ab64684143b0f959cfe3b0b2d91c8
push id123742
push userwptsync@mozilla.com
push dateFri, 07 Aug 2020 23:31:06 +0000
treeherderautoland@9584ddf5d03a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1656160, 24810, 2328394, 1111134, 1111750, 795636, 2327787, 794474
milestone81.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 1656160 [wpt PR 24810] - [WPT] Errors caught/reported for importScripts(), a=testonly Automatic update from web-platform-tests [WPT] Errors caught/reported for importScripts() (#24810) This CL adds WPTs for exceptions in importScripts() captured by - WorkerGlobalScope error event handler or - try/catch. Some of the tests are migrated from non-WPT web_tests. The tests are failing on Chromium right now, and will pass after https://chromium-review.googlesource.com/c/chromium/src/+/2328394/. Bug: 1111134, 1111750, 795636 Change-Id: Ie19085171261d4baf307b6544ff6a8da1a8e9041 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2327787 Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Reviewed-by: Kenichi Ishibashi <bashi@chromium.org> Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Dominic Farolino <dom@chromium.org> Cr-Commit-Position: refs/heads/master@{#794474} Co-authored-by: Hiroshige Hayashizaki <hiroshige@chromium.org> -- wpt-commits: 059a8ae79c2c44ef2eda3ccb412b0773e99c26b6 wpt-pr: 24810
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/catch.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.js
testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.js
testing/web-platform/tests/workers/modules/resources/throw.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/catch.sub.any.js
@@ -0,0 +1,47 @@
+// META: global=worker
+
+const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
+const redirectToCrossOrigin = "/common/redirect.py?location=" + crossOrigin;
+
+test(function() {
+  assert_throws_js(SyntaxError, function() {
+    importScripts("/workers/modules/resources/syntax-error.js");
+  });
+}, "Same-origin syntax error");
+
+test(function() {
+  assert_throws_js(Error, function() {
+    importScripts("/workers/modules/resources/throw.js");
+  });
+}, "Same-origin throw");
+
+// https://html.spec.whatwg.org/C/#run-a-classic-script
+// Step 8.2. If rethrow errors is true and script's muted errors is true, then:
+// Step 8.2.2. Throw a "NetworkError" DOMException.
+test(function() {
+  assert_throws_dom("NetworkError", function() {
+    importScripts(crossOrigin +
+                  "/workers/modules/resources/syntax-error.js");
+  });
+}, "Cross-origin syntax error");
+
+test(function() {
+  assert_throws_dom("NetworkError", function() {
+    importScripts(crossOrigin +
+                  "/workers/modules/resources/throw.js");
+  });
+}, "Cross-origin throw");
+
+test(function() {
+  assert_throws_dom("NetworkError", function() {
+    importScripts(redirectToCrossOrigin +
+                  "/workers/modules/resources/syntax-error.js");
+  });
+}, "Redirect-to-cross-origin syntax error");
+
+test(function() {
+  assert_throws_dom("NetworkError", function() {
+    importScripts(redirectToCrossOrigin +
+                  "/workers/modules/resources/throw.js");
+  });
+}, "Redirect-to-Cross-origin throw");
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.js
@@ -0,0 +1,8 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
+runTest(
+  crossOrigin + "/workers/modules/resources/syntax-error.js",
+  false,
+  "NetworkError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js
@@ -0,0 +1,80 @@
+setup({ allow_uncaught_exception:true });
+
+// For SyntaxError, the line in doImportScripts() is expected to be reported
+// as `e.lineno` etc. below.
+// doImportScripts() is introduced here to prevent the line number from being
+// affected by changes in runTest(), use of setTimeout(), etc.
+function doImportScripts(url) {
+  importScripts(url);
+}
+
+const t0 = async_test("WorkerGlobalScope error event: error");
+const t1 = async_test("WorkerGlobalScope error event: message");
+const t2 = async_test("WorkerGlobalScope error event: filename");
+const t3 = async_test("WorkerGlobalScope error event: lineno");
+
+function runTest(importScriptUrl, shouldUseSetTimeout, expected) {
+  self.addEventListener("error", e => {
+    if (expected === "NetworkError") {
+      t0.step_func_done(() => {
+        assert_equals(e.error.constructor, DOMException,
+            "e.error should be a DOMException")
+        assert_equals(e.error.name, "NetworkError");
+      })();
+
+      t1.step_func_done(() => {
+        assert_not_equals(e.message, "Script error.",
+            "e.message should not be muted to 'Script error.'");
+      })();
+
+      // filename, lineno etc. should NOT point to the location within
+      // `syntax-error.js` (otherwise parse errors to be muted are
+      // leaked to JavaScript).
+      // we expect they point to the caller of `importScripts()`,
+      // while this is not explicitly stated in the spec.
+      t2.step_func_done(() => {
+        assert_equals(e.filename, self.location.origin +
+            '/workers/interfaces/WorkerUtils/importScripts/report-error-helper.js');
+      })();
+      t3.step_func_done(() => {
+        assert_equals(e.lineno, 8);
+      })();
+      // We don't check `e.colno` for now, because browsers set different
+      // `colno` values.
+    } else if (expected === "SyntaxError") {
+      t0.step_func_done(() => {
+        assert_equals(e.error.constructor, SyntaxError);
+        assert_equals(e.error.name, "SyntaxError");
+      })();
+
+      t1.step_func_done(() => {
+        assert_not_equals(e.message, "Script error.",
+            "e.message should not be muted to 'Script error.'");
+      })();
+
+      // filename, lineno etc. are expected to point to the location within
+      // `syntax-error.js` because it is same-origin,
+      // while this is not explicitly stated in the spec.
+      t2.step_func_done(() => {
+        assert_equals(e.filename, self.location.origin +
+            '/workers/modules/resources/syntax-error.js');
+      })();
+      t3.step_func_done(() => {
+        assert_equals(e.lineno, 1);
+      })();
+      // We don't check `e.colno` for now, because browsers set different
+      // `colno` values.
+    }
+
+    // Because importScripts() throws, we call done() here.
+    done();
+  });
+
+  if (shouldUseSetTimeout) {
+    setTimeout(
+      () => doImportScripts(importScriptUrl),
+      0);
+  } else {
+    doImportScripts(importScriptUrl);
+  }
+}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.js
@@ -0,0 +1,9 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
+runTest(
+  "/common/redirect.py?location=" + crossOrigin +
+      "/workers/modules/resources/syntax-error.js",
+  false,
+  "NetworkError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.js
@@ -0,0 +1,7 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+runTest(
+  "/workers/modules/resources/syntax-error.js",
+  false,
+  "SyntaxError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.js
@@ -0,0 +1,8 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
+runTest(
+  crossOrigin + "/workers/modules/resources/syntax-error.js",
+  true,
+  "NetworkError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.js
@@ -0,0 +1,9 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+const crossOrigin = "https://{{hosts[alt][]}}:{{ports[https][0]}}";
+runTest(
+  "/common/redirect.py?location=" + crossOrigin +
+      "/workers/modules/resources/syntax-error.js",
+  true,
+  "NetworkError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.js
@@ -0,0 +1,7 @@
+// META: global=dedicatedworker,sharedworker
+// META: script=report-error-helper.js
+runTest(
+  "/workers/modules/resources/syntax-error.js",
+  true,
+  "SyntaxError"
+);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/modules/resources/throw.js
@@ -0,0 +1,1 @@
+throw new Error('custom message');