aboutsummaryrefslogtreecommitdiff
path: root/test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-01-22 02:29:21 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-25 00:12:11 +0800
commitd20f5c7f1b3b79f11b99b6599c3ddea8dfd39a60 (patch)
tree0627f956e4050c3fdd3be7c04efac0e9a7566878 /test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js
parentd40ed71c1136c4a1c93ed5fe16bf6e3f9ca7631d (diff)
downloadandroid-node-v8-d20f5c7f1b3b79f11b99b6599c3ddea8dfd39a60.tar.gz
android-node-v8-d20f5c7f1b3b79f11b99b6599c3ddea8dfd39a60.tar.bz2
android-node-v8-d20f5c7f1b3b79f11b99b6599c3ddea8dfd39a60.zip
test: pull html/webappapis/microtask-queuing WPT
With the command: ``` git node wpt html/webappapis/microtask-queuing ``` PR-URL: https://github.com/nodejs/node/pull/25616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js')
-rw-r--r--test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js b/test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.window.js
new file mode 100644
index 0000000000..78cdcfc5d9
--- /dev/null
+++ b/test/fixtures/wpt/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");