Commit 0b796d63 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[WPT] Add more tests for exceptions in WorkerGlobalScope.onerror

Failing on Chromium and passing on Firefox and Safari.

third_party/blink/web_tests/fast/workers/worker-onerror-04.html
is removed because now it's covered by the WPT.

Bug: 1112228
Change-Id: If407eb1c96b29357bbc0468e1a6abb30d2891447
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2331794
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795348}
parent 1d21b497
This is a testharness.js-based test.
PASS Throw in worker initialization: classic: listener
PASS Throw in worker initialization: classic: handler
FAIL Throw in setTimeout(function): classic: listener assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in setTimeout(function): classic: handler assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
PASS Throw in setTimeout(string): classic: listener
PASS Throw in setTimeout(string): classic: handler
FAIL Throw in message handler: classic: listener assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in message handler: classic: handler assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in worker initialization: module: listener assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in worker initialization: module: handler assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in setTimeout(function): module: listener assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in setTimeout(function): module: handler assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
PASS Throw in setTimeout(string): module: listener
PASS Throw in setTimeout(string): module: handler
FAIL Throw in message handler: module: listener assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
FAIL Throw in message handler: module: handler assert_unreached: Worker.onerror not fired for: Throw in error handler Reached unreachable code
Harness: the test ran to completion.
<!doctype html> <!doctype html>
<title>onerror, "not handled" with an error in the onerror function</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script> <script>
async_test(function() { // 1. Exception is thrown somewhere in a Worker.
var worker = new Worker('exception-in-onerror.js'); // Various contexts are tested: from worker initialization,
worker.onerror = this.step_func(function(e) { // from setTimeout, from event handlers, etc.
assert_true(e instanceof ErrorEvent, 'e instanceof ErrorEvent'); // 2. WorkerGlobalScope.onerror event handler is called.
assert_equals(typeof e.message, 'string', 'typeof e.message'); // (i.e. `onerror` in the worker script)
assert_equals(e.filename, document.URL.replace('.html', '.js'), 'e.filename'); // 3. From the event handler, another exception is thrown.
assert_equals(typeof e.lineno, 'number', 'typeof e.lineno'); // 4. Each of Worker.onerror handler (on the parent Document) and
assert_equals(typeof e.colno, 'number', 'typeof e.column'); // Worker error event listener should be called twice:
e.preventDefault(); // "handled" // once for each of the exceptions thrown in Step 1 and 2, respectively.
this.done(); // (We don't check the ordering of two Worker.onerror calls, because
}); // browsers fires them in different orders)
});
</script> function prepareHandler(t, messages) {
\ No newline at end of file const fired = {};
let fired_count = 0;
t.step_timeout(() => {
if (fired_count < messages.length) {
let error_description = 'Worker.onerror not fired for:';
for (const message of messages) {
if (!fired[message]) {
error_description += ' ';
error_description += message;
}
}
assert_unreached(error_description);
}
}, 2000);
return t.step_func(e => {
e.preventDefault();
for (const message of messages) {
if (!fired[message] && e.message.indexOf(message) >= 0) {
fired[message] = true;
++fired_count;
if (fired_count === messages.length) {
// Worker.onerror is fired for all messages.
t.done();
}
return;
}
}
assert_unreached("Unexpected worker.onerror message: " + e.message);
});
}
function expectErrors(worker, title, messages) {
async_test(t => {
worker.addEventListener('error', prepareHandler(t, messages));
}, title+ ': listener');
async_test(t => {
worker.onerror = prepareHandler(t, messages);
}, title + ': handler');
}
for (const type of ['classic', 'module']) {
const workerOptions = type === 'module' ? {type: 'module'}: {};
const worker1 = new Worker(
'exception-in-onerror.js?throw-in-worker-initialization',
workerOptions);
expectErrors(
worker1,
'Throw in worker initialization: ' + type,
['Throw in worker initialization', 'Throw in error handler']);
const worker2 = new Worker(
'exception-in-onerror.js?throw-in-setTimeout-function', workerOptions);
expectErrors(
worker2,
'Throw in setTimeout(function): ' + type,
['Throw in setTimeout function', 'Throw in error handler']);
const worker3 = new Worker(
'exception-in-onerror.js?throw-in-setTimeout-string', workerOptions);
expectErrors(
worker3,
'Throw in setTimeout(string): ' + type,
['Throw in setTimeout string', 'Throw in error handler']);
const worker4 = new Worker('exception-in-onerror.js', workerOptions);
worker4.postMessage('foo');
expectErrors(
worker4,
'Throw in message handler: ' + type,
['Throw in message handler', 'Throw in error handler']);
}
</script>
onerror = function(a, b, c, d) { onerror = function() {
y(); // the error is "not handled" throw new Error('Throw in error handler');
return false;
};
onmessage = function() {
throw new Error('Throw in message handler');
return false;
};
if (self.location.href.indexOf(
'throw-in-worker-initialization') >= 0) {
throw new Error('Throw in worker initialization');
} }
function x() {
y(); if (self.location.href.indexOf(
'throw-in-setTimeout-function') >= 0) {
// To test the behavior of setTimeout(), raw setTimeout() is used.
setTimeout(() => { throw new Error('Throw in setTimeout function') }, 0);
}
if (self.location.href.indexOf(
'throw-in-setTimeout-string') >= 0) {
// To test the behavior of setTimeout(), raw setTimeout() is used.
setTimeout("throw new Error('Throw in setTimeout string')", 0);
} }
x();
\ No newline at end of file
CONSOLE ERROR: line 7: Uncaught ReferenceError: foo is not defined
This tests that unhandled exceptions in a worker's onerror handler trigger 'worker.onerror'.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Page-level worker.onerror handler triggered:
PASS errorEvent.message is "Uncaught ReferenceError: foo is not defined"
PASS stripURL(errorEvent.filename) is "[blob: URL]"
PASS errorEvent.lineno is 7
PASS errorEvent.colno is 9
PASS errorEvent.error is null
Page-level worker.onerror handler triggered:
PASS errorEvent.message is "Uncaught ReferenceError: bar is not defined"
PASS stripURL(errorEvent.filename) is "[blob: URL]"
PASS errorEvent.lineno is 3
PASS errorEvent.colno is 13
PASS errorEvent.error is null
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script>
window.isOnErrorTest = true;
</script>
<script src="../../resources/js-test.js"></script>
<script src="resources/onerror-test.js"></script>
</head>
<body>
<!-- This script's body will be used to build a Blob URL to use as a Worker. -->
<script id="workerCode" type="text/plain">
onerror = function(message, url, lineno, colno, error) {
bar.foo = 0;
return false;
}
foo.bar = 0;
</script>
<script>
description("This tests that unhandled exceptions in a worker's onerror handler trigger 'worker.onerror'.");
checkErrorEventInHandler([
// foo.bar = 0 triggers an error that isn't handled.
{
message: "Uncaught ReferenceError: foo is not defined",
filename: "[blob: URL]",
lineno: 7,
colno: 9,
},
// the error handler triggers an error
{
message: "Uncaught ReferenceError: bar is not defined",
filename: "[blob: URL]",
lineno: 3,
colno: 13,
}]);
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment