blob: 2f1be81737d5e19842a25c837c9e6c9133345b0e [file] [log] [blame]
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
var activeWorker;
var scope = "/workers/service/resources/WebSocket/";
if (window.testRunner)
testRunner.setAllowsAnySSLCertificate(true);
promise_test(async (test) => {
var registration = await navigator.serviceWorker.getRegistration(scope);
if (registration && registration.scope === scope)
await registration.unregister();
var registration = await navigator.serviceWorker.register("resources/serviceworker-websocket-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) => {
if (window.testRunner)
testRunner.setShouldLogCanAuthenticateAgainstProtectionSpace(true);
var promise = new Promise((resolve, reject) => {
navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
if (event.data === "PASS") {
resolve();
return;
}
reject(event.data);
}));
});
activeWorker.postMessage("WEBSOCKET-1");
await promise;
if (window.testRunner)
testRunner.setShouldLogCanAuthenticateAgainstProtectionSpace(false);
}, "Open a WebSocket in service worker");
</script>
</body>
</html>