83bad0659362812f32921e2f9511226967d96b25
[WebKit-https.git] / LayoutTests / http / tests / workers / service / registration-updateViaCache-all-importScripts.html
1 <html>
2 <head>
3 <script src="resources/sw-test-pre.js"></script>
4 </head>
5 <body>
6 <script>
7
8 function getRandomIdFromWorker(worker)
9 {
10     worker.postMessage("getRandomId");
11     return new Promise(function(resolve) {
12       navigator.serviceWorker.addEventListener('message', function(e) {
13             resolve(e.data);
14         });
15     });
16 }
17
18 async function test()
19 {
20     try {
21         let registration = await navigator.serviceWorker.register("resources/import-cacheable-script-worker.js", { updateViaCache: "all" });
22         let worker1 = registration.installing;
23         await waitForState(worker1, "activated");
24         let randomId1 = await getRandomIdFromWorker(worker1);
25
26         await registration.update();
27         let worker2 = registration.installing;
28         await waitForState(worker2, "activated");
29         let randomId2 = await getRandomIdFromWorker(worker2);
30
31         if (randomId1 === randomId2)
32             log("PASS: importScripts() loaded the script came from the network cache");
33         else
34             log("FAIL: importScripts() did not load the script from the network cache");
35     } catch(e) {
36         log("Got exception: " + e);
37     }
38     finishSWTest();
39 }
40 test();
41 </script>
42 </body>
43 </html>