blob: fa58d7df174af381da420c52d289b252ddc1b54a [file] [log] [blame]
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
var scope = "";
var activeWorker;
promise_test(async (test) => {
var registration = await navigator.serviceWorker.register("online-worker.js", { scope : scope });
activeWorker = registration.active;
if (activeWorker)
return;
activeWorker = registration.installing;
return new Promise(resolve => {
activeWorker.addEventListener('statechange', () => {
if (activeWorker.state === "activated")
resolve();
});
});
}, "Setup worker");
promise_test(async (test) => {
var promise = new Promise((resolve, reject) => {
navigator.serviceWorker.addEventListener("message", (event) => {
resolve(event.data);
});
});
activeWorker.postMessage("ONLINE");
var result = await promise;
assert_equals(result, "PASS");
}, "Test service worker online/offline");
</script>
</body>
</html>