зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
69fd0b52c4
Коммит
197c474795
|
@ -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");
|
|
@ -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"
|
||||
);
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
// META: global=dedicatedworker,sharedworker
|
||||
// META: script=report-error-helper.js
|
||||
runTest(
|
||||
"/workers/modules/resources/syntax-error.js",
|
||||
false,
|
||||
"SyntaxError"
|
||||
);
|
|
@ -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"
|
||||
);
|
|
@ -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"
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
// META: global=dedicatedworker,sharedworker
|
||||
// META: script=report-error-helper.js
|
||||
runTest(
|
||||
"/workers/modules/resources/syntax-error.js",
|
||||
true,
|
||||
"SyntaxError"
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
throw new Error('custom message');
|
Загрузка…
Ссылка в новой задаче