Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / workers / test / worker_suspended.js
blobf2b4146cba22584f01c52f1deeae1bfa2f2f96f9
1 var count = 0;
3 function do_magic(data) {
4   caches
5     .open("test")
6     .then(function (cache) {
7       return cache.put(
8         "http://mochi.test:888/foo",
9         new Response(data.type + "-" + count++)
10       );
11     })
12     .then(function () {
13       if (count == 1) {
14         postMessage("ready");
15       }
17       if (data.loop) {
18         setTimeout(function () {
19           do_magic(data);
20         }, 500);
21       }
22     });
25 onmessage = function (e) {
26   if (e.data.type == "page1") {
27     if (e.data.count > 0) {
28       var a = new Worker("worker_suspended.js");
29       a.postMessage({ type: "page1", count: e.data - 1 });
30       a.onmessage = function () {
31         postMessage("ready");
32       };
33     } else {
34       do_magic({ type: e.data.type, loop: true });
35     }
36   } else if (e.data.type == "page2") {
37     do_magic({ type: e.data.type, loop: false });
38   }