4e5ed923ed1ec15754b1b79db42c4cd803da2b59
[WebKit-https.git] / LayoutTests / http / tests / workers / service / resources / postmessage-after-sw-process-crash.js
1 var messageNumber = 1;
2 navigator.serviceWorker.addEventListener("message", function(event) {
3     log("PASS: Client received message from service worker, origin: " + event.origin);
4     log(event.data);
5     if (messageNumber == 1) {
6         log("* Simulating Service Worker process crash");
7         testRunner.terminateServiceWorkerProcess();
8         setTimeout(function() {
9             log("* Sending 'Message 2' to Service Worker");
10             event.source.postMessage("Message 2");
11             messageNumber++;
12             handle = setTimeout(function() {
13                 log("FAIL: Did not receive message from service worker process after the crash");
14                 finishSWTest();
15             }, 1000);
16         }, 0);
17         return;
18     }
19     if (messageNumber == 2) {
20         clearTimeout(handle);
21         finishSWTest();
22     }
23 });
24
25 navigator.serviceWorker.register("resources/postmessage-echo-worker.js", { }).then(function(registration) {
26     log("* Sending 'Message 1' to Service Worker");
27     registration.installing.postMessage("Message 1");
28 });