summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/microtask-queuing
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/microtask-queuing')
-rw-r--r--testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html28
-rw-r--r--testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js15
-rw-r--r--testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.any.js39
-rw-r--r--testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.window.js45
4 files changed, 127 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html
new file mode 100644
index 0000000000..fa153f8f96
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-cross-realm-callback-report-exception.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>queueMicrotask() reports the exception from its callback in the callback's global object</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<iframe></iframe>
+<iframe></iframe>
+<iframe></iframe>
+<script>
+setup({ allow_uncaught_exception: true });
+
+const onerrorCalls = [];
+window.onerror = () => { onerrorCalls.push("top"); };
+frames[0].onerror = () => { onerrorCalls.push("frame0"); };
+frames[1].onerror = () => { onerrorCalls.push("frame1"); };
+frames[2].onerror = () => { onerrorCalls.push("frame2"); };
+
+async_test(t => {
+ window.onload = t.step_func(() => {
+ frames[0].queueMicrotask(new frames[1].Function(`throw new parent.frames[2].Error("PASS");`));
+
+ t.step_timeout(() => {
+ assert_array_equals(onerrorCalls, ["frame1"]);
+ t.done();
+ }, 4);
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js
new file mode 100644
index 0000000000..01f32ac9ba
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js
@@ -0,0 +1,15 @@
+// META: global=window,worker
+"use strict";
+
+setup({
+ allow_uncaught_exception: true
+});
+
+async_test(t => {
+ const error = new Error("boo");
+ self.addEventListener("error", t.step_func_done(ev => {
+ assert_equals(ev.error, error);
+ }));
+
+ queueMicrotask(() => { throw error; });
+}, "It rethrows exceptions");
diff --git a/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.any.js b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.any.js
new file mode 100644
index 0000000000..e67765fade
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/microtask-queuing/queue-microtask.any.js
@@ -0,0 +1,39 @@
+// META: global=window,worker
+"use strict";
+
+test(() => {
+ assert_equals(typeof queueMicrotask, "function");
+}, "It exists and is a function");
+
+test(() => {
+ assert_throws_js(TypeError, () => queueMicrotask(), "no argument");
+ assert_throws_js(TypeError, () => queueMicrotask(undefined), "undefined");
+ assert_throws_js(TypeError, () => queueMicrotask(null), "null");
+ assert_throws_js(TypeError, () => queueMicrotask(0), "0");
+ assert_throws_js(TypeError, () => queueMicrotask({ handleEvent() { } }), "an event handler object");
+ assert_throws_js(TypeError, () => queueMicrotask("window.x = 5;"), "a string");
+}, "It throws when given non-functions");
+
+async_test(t => {
+ let called = false;
+ queueMicrotask(t.step_func_done(() => {
+ called = true;
+ }));
+ assert_false(called);
+}, "It calls the callback asynchronously");
+
+async_test(t => {
+ queueMicrotask(t.step_func_done(function () { // note: intentionally not an arrow function
+ assert_array_equals(arguments, []);
+ }), "x", "y");
+}, "It does not pass any arguments");
+
+async_test(t => {
+ const happenings = [];
+ Promise.resolve().then(() => happenings.push("a"));
+ queueMicrotask(() => happenings.push("b"));
+ Promise.reject().catch(() => happenings.push("c"));
+ queueMicrotask(t.step_func_done(() => {
+ assert_array_equals(happenings, ["a", "b", "c"]);
+ }));
+}, "It interleaves with promises as expected");
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");