<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Verify that tasks nested in microtasks can be properly tracked.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/task-ids.js"></script>
</head>
<body>
<script>
promise_test(t => {
const scriptId = initializeTaskId();
return scheduler.postTask(async _ => {
// We should be in a new task.
const postTaskId = scheduler.taskId;
assert_equals(scriptId, postTaskId,
"postTaskId should be equal to the script task ID.");
let eventFired = false;
// Set things up so the abort event listener is an ancestor of this task.
const controller = new AbortController();
controller.signal.onabort = t.step_func(() => {
assert_equals(scheduler.taskId, postTaskId,
"aborted task ID is the same as the postTask ID, as it is fired" +
" synchronously.");
eventFired = true;
});
await fetch("/resources/blank.html");
// We're now in a new browser task that is running microtasks.
controller.abort();
assert_true(eventFired);
// Make sure the previous ID was reset properly.
assert_equals(scheduler.taskId, postTaskId);
});
}, "Task tracking should work when a new task scope starts during a microtask");
</script>
</body>
</html>