Truly independent web browser
Tests/LibWeb: Import WPT tests for microtask checkpoints after events
Andreas Kling8b717a1ad953
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 49e8b551406..4db1765daa6 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -162,6 +162,9 @@ Text/input/navigation/pushstate-in-abort-handler-of-superseded-navigate-event.htText/input/navigation/navigation-activation-push-replace-traverse.htmlText/input/navigation/navigation-activation-in-sandboxed-frame.html+; Loads a module script, which needs an HTTP origin.+Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.html+; navigation.updateCurrentEntry() requires a non-opaque origin.Text/input/navigation/targeted-entry-updates-reach-the-session-store.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.txtnew file mode 100644index 00000000000..f60f3a3aa45--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 2 tests++1 Pass+1 Fail+Pass Promise resolved during #report-the-error+Fail Promise resolved during event handlers other than error\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.txtnew file mode 100644index 00000000000..f60f3a3aa45--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 2 tests++1 Pass+1 Fail+Pass Promise resolved during #report-the-error+Fail Promise resolved during event handlers other than error\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.htmlnew file mode 100644index 00000000000..4f3f8191229--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.html@@ -0,0 +1,9 @@+<!DOCTYPE html>+<head>+ <meta charset="utf-8">+ <title>Microtask checkpoint after window.onerror events (module)</title>+ <script src="../../../../../resources/testharness.js"></script>+ <script src="../../../../../resources/testharnessreport.js"></script>+ <script src="resources/checkpoint-after-error-event.js" type="module"></script>+ <script type="module">self.postMessage("foo");</script>+</head>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.htmlnew file mode 100644index 00000000000..80b285ce033--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror.html@@ -0,0 +1,9 @@+<!DOCTYPE html>+<head>+ <meta charset="utf-8">+ <title>Microtask checkpoint after window.onerror events (classic)</title>+ <script src="../../../../../resources/testharness.js"></script>+ <script src="../../../../../resources/testharnessreport.js"></script>+ <script src="resources/checkpoint-after-error-event.js"></script>+ <script>self.postMessage("foo");</script>+</head>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.jsnew file mode 100644index 00000000000..1a2b9404a7e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.js@@ -0,0 +1,89 @@+// The `then` handlers for `Promise.resolve()` are evaluated in the first+// microtasks checkpoint after `Promise.resolve()`.++self.setup({allow_uncaught_exception: true});++// ----------------------------------------------------------------+// Check when microtasks checkpoint is performed+// - Around `self`'s error event fired via+// https://html.spec.whatwg.org/C/#report-the-error during+// - https://html.spec.whatwg.org/C/#run-a-classic-script or+// - https://html.spec.whatwg.org/C/#run-a-module-script.++// The expectation is: the `then` handlers are evaluated after all error event+// handlers are evaluated, not after each error event handler.++// Just after each event handler is invoked,+// https://webidl.spec.whatwg.org/#call-a-user-objects-operation+// calls #clean-up-after-running-script, but this doesn't execute new+// microtasks immediately, because:+// - Before https://github.com/whatwg/html/pull/4352:+// #report-the-error is called before #clean-up-after-running-script by+// #run-a-classic-script/#run-a-module-script, so microtask checkpoint+// is not performed because JavaScript execution context stack is not empty.+// - After https://github.com/whatwg/html/pull/4352:+// #report-the-error is called during #perform-a-microtask-checkpoint (because+// it is called on rejection of promises), so #perform-a-microtask-checkpoint+// is executed but early exited.+self.log = [];++self.addEventListener('error', () => {+ log.push('handler 1');+ Promise.resolve().then(() => log.push('handler 1 promise'));+});+self.addEventListener('error', () => {+ log.push('handler 2');+ Promise.resolve().then(() => log.push('handler 2 promise'));+});++// Microtasks should be executed before+// #run-a-classic-script/#run-a-module-script is completed, and thus before+// script evaluation scheduled by setTimeout().+async_test(t => {+ t.step_timeout(() => {+ assert_array_equals(log, [+ 'handler 1',+ 'handler 2',+ 'handler 1 promise',+ 'handler 2 promise'+ ]);+ t.done();+ },+ 0);+}, "Promise resolved during #report-the-error");++// ----------------------------------------------------------------+// Check when microtasks checkpoint is performed+// around event events other than the `self` error event cases above.+// In this case, microtasks are executed just after each event handler is+// invoked via #clean-up-after-running-script called from+// https://webidl.spec.whatwg.org/#call-a-user-objects-operation,+// because the event handlers are executed outside the+// #prepare-to-run-script/#clean-up-after-running-script scopes in+// #run-a-classic-script/#run-a-module-script.+self.log2 = [];+self.t2 = async_test(+ "Promise resolved during event handlers other than error");++self.addEventListener('message', () => {+ log2.push('handler 1');+ Promise.resolve().then(() => log2.push('handler 1 promise'));+});+self.addEventListener('message', () => {+ log2.push('handler 2');+ Promise.resolve().then(t2.step_func_done(() => {+ log2.push('handler 2 promise');+ assert_array_equals(log2, [+ 'handler 1',+ 'handler 1 promise',+ 'handler 2',+ 'handler 2 promise'+ ]);+ }));+});++// ----------------------------------------------------------------++done();++throw new Error('script 1');