Skip to content

Commit

Permalink
Bug 1479573 [wpt PR 6334] - Add tests for self.queueMicrotask(), a=te…
Browse files Browse the repository at this point in the history
…stonly

Automatic update from web-platform-testsAdd tests for self.queueMicrotask()

Follows whatwg/html#2789.
--

wpt-commits: 0c3bed38df6d9dcd1441873728fb5c1bb59c92df
wpt-pr: 6334

UltraBlame original commit: 141be436c496b0715eac4f3a7c0c6a0c25392a59
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent d191bf3 commit 8fceba0
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
54 changes: 54 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -361560,6 +361560,48 @@
{}
]
],
"html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js": [
[
"/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.sharedworker.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask-exceptions.https.any.serviceworker.html",
{}
]
],
"html/webappapis/microtask-queuing/queue-microtask.any.js": [
[
"/html/webappapis/microtask-queuing/queue-microtask.any.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask.any.sharedworker.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask.any.worker.html",
{}
],
[
"/html/webappapis/microtask-queuing/queue-microtask.https.any.serviceworker.html",
{}
]
],
"html/webappapis/microtask-queuing/queue-microtask.window.js": [
[
"/html/webappapis/microtask-queuing/queue-microtask.window.html",
{}
]
],
"html/webappapis/scripting/event-loops/microtask_after_raf.html": [
[
"/html/webappapis/scripting/event-loops/microtask_after_raf.html",
Expand Down Expand Up @@ -600691,6 +600733,18 @@
"704130abfe91a25e26fc6d452d0981d3dc104642",
"testharness"
],
"html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js": [
"01f32ac9ba14962fa99d4b263a8ca0f5a0daa161",
"testharness"
],
"html/webappapis/microtask-queuing/queue-microtask.any.js": [
"b39931719a88ad525511d8f8745a9b752a6a6465",
"testharness"
],
"html/webappapis/microtask-queuing/queue-microtask.window.js": [
"78cdcfc5d989a81882a10b7d70050408aadfe924",
"testharness"
],
"html/webappapis/scripting/event-loops/contains.json": [
"5d7e5e600e90861a1703ae37321b1b2583024d19",
"support"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

"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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

"use strict";

test(() => {
assert_equals(typeof queueMicrotask, "function");
}, "It exists and is a function");

test(() => {
assert_throws(new TypeError(), () => queueMicrotask(), "no argument");
assert_throws(new TypeError(), () => queueMicrotask(undefined), "undefined");
assert_throws(new TypeError(), () => queueMicrotask(null), "null");
assert_throws(new TypeError(), () => queueMicrotask(0), "0");
assert_throws(new TypeError(), () => queueMicrotask({ handleEvent() { } }), "an event handler object");
assert_throws(new 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 () {
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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";



function queueMicrotaskViaMO(cb) {
const observer = new MutationObserver(cb);
const node = document.createTextNode("");
observer.observe(node, { characterData: true });
node.data = "foo";
}




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");

0 comments on commit 8fceba0

Please sign in to comment.