<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Verify that tasks are tracked across scripts evaluated due to document.write calls.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/task-ids.js"></script>
</head>
<body>
<script>
window.initialId = initializeTaskId();
window.results = [];
const expected = [
{ value: true, name: "Inline script task" },
{ value: true, name: "Inline module script task" },
{ value: true, name: "External blocking script task" },
];
const scriptToEval = `window.results.push(scheduler.taskId == window.initialId);`;
document.write("<script>" + scriptToEval + "<\/script>");
document.write("<script type=module>" + scriptToEval + "<\/script>");
document.write("<script src='resources/script.js'><\/script>");
// TODO(https://crbug.com/1478359): Add more tests for deferred scripts, etc.
promise_test(() => {
return new Promise(async resolve => {
// Wait till all the results come in.
while (window.results.length < expected.length) {
await new Promise(r => setTimeout(r, 10));
}
resolve();
}).then(() => {
for (let index in window.results) {
const { value, name } = expected[index];
const result = results[index];
assert_equals(result, value, `${name} got an unexpected value of '${result}' rather than '${value}'`);
}
});
}, "Scripts triggered by document.write have correct ancestor values.");
</script>