Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: os == 'android'
- This test failed 15 times in the preceding 30 days. quicksearch this test
- Manifest: dom/workers/test/mochitest.toml
<html>
<head>
<title>Workers background flag test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
let worker = new Worker("test_worker_in_background.js");
var newtab;
async function waitForWorkerEvent(stage) {
return new Promise(resolve => {
worker.addEventListener("message", e => {
is(e.data.status, "PASS", stage);
resolve();
}, {
once: true
});
});
}
add_task(async function enable_testing_prefs() {
await SpecialPowers.pushPrefEnv({
set: [
["dom.workers.testing.enabled", true]
],
});
ok(true, "testing settings enabled");
});
add_task(async function test_worker_in_foreground() {
const stage = "CheckIsForeground";
worker.postMessage(stage);
await waitForWorkerEvent(stage);
});
add_task(async function test_worker_in_background() {
const stage = "CheckIsBackground";
document.onvisibilitychange = () => {
if (document.visibilityState === "hidden") {
worker.postMessage(stage);
}
}
newtab = window.open('about:blank', '_blank');
await waitForWorkerEvent(stage);
});
add_task(async function test_worker_return_to_foreground() {
const stage = "CheckIsForegroundAgain";
document.onvisibilitychange = () => {
if (document.visibilityState === "visible") {
worker.postMessage(stage);
}
}
newtab.close();
await waitForWorkerEvent(stage);
});
</script>
</head>
<body>
</body>
</html>