Support container.register() / registration.unregister() / inside service workers
[WebKit-https.git] / LayoutTests / http / tests / workers / service / resources / ServiceWorkerGlobalScope_register-worker.js
1 let client = null;
2
3 function log(msg)
4 {
5     client.postMessage(msg);
6 }
7
8 async function runTest()
9 {
10     try {
11         let r = await navigator.serviceWorker.register("empty-worker.js", { scope: "/test", updateViaCache: "none" });
12         log("PASS: Registration succeeded");
13
14         if (r.scope == "http://127.0.0.1:8000/test")
15             log("PASS: registration object's scope is valid");
16         else
17             log("FAIL: registration object's scope is invalid, got: " + r.scope);
18
19         if (r.updateViaCache == "none")
20             log("PASS: registration object's updateViaCache is valid");
21         else
22             log("FAIL: registration object's updateViaCache is invalid, got: " + r.updateViaCache);
23
24         worker = r.installing;
25         worker.addEventListener("statechange", function() {
26             if (worker.state === "activated") {
27                 log("PASS: service worker is now active");
28                 log("DONE");
29             }
30         });
31     } catch (e) {
32         log("FAIL: " + e);
33         log("DONE");
34     }
35 }
36
37 self.addEventListener("message", (event) => {
38     client = event.source;
39     runTest();
40 });