diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js')
-rw-r--r-- | testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js new file mode 100644 index 0000000000..78cdcfc5d9 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js @@ -0,0 +1,45 @@ +"use strict"; + +// This does not work as you expect because mutation observer compound microtasks are confusing. +// Basically you can only use it once per test. +function queueMicrotaskViaMO(cb) { + const observer = new MutationObserver(cb); + const node = document.createTextNode(""); + observer.observe(node, { characterData: true }); + node.data = "foo"; +} + +// Need to use promise_test to get sequential ordering; otherwise the global mutation observer +// compound microtask business screws us over. + +promise_test(() => { + return new Promise(resolve => { + const happenings = []; + + queueMicrotaskViaMO(() => happenings.push("x")); + queueMicrotask(() => happenings.push("a")); + + queueMicrotask(() => { + assert_array_equals(happenings, ["x", "a"]); + resolve(); + }); + }); +}, "It interleaves with MutationObservers as expected"); + +promise_test(() => { + return new Promise(resolve => { + const happenings = []; + + queueMicrotask(() => happenings.push("a")); + Promise.reject().catch(() => happenings.push("x")); + queueMicrotaskViaMO(() => happenings.push(1)); + Promise.resolve().then(() => happenings.push("y")); + queueMicrotask(() => happenings.push("b")); + queueMicrotask(() => happenings.push("c")); + + queueMicrotask(() => { + assert_array_equals(happenings, ["a", "x", 1, "y", "b", "c"]); + resolve(); + }); + }); +}, "It interleaves with MutationObservers and promises together as expected"); |