ServiceWorker registration should store any script fetched through importScripts
[WebKit-https.git] / LayoutTests / http / wpt / service-workers / persistent-importScripts.html
1 <html>
2 <head>
3 <script src="resources/routines.js"></script>
4 </head>
5 <body>
6 <script>
7 function getRandomIdFromWorker(worker)
8 {
9     worker.postMessage("getRandomId");
10     return new Promise(function(resolve) {
11       navigator.serviceWorker.addEventListener('message', function(e) {
12             resolve(e.data);
13         });
14     });
15 }
16
17 if (window.testRunner) {
18     testRunner.waitUntilDone();
19     testRunner.dumpAsText();
20 }
21
22 var registration;
23 var worker;
24 async function doTest() {
25     if (!window.testRunner)
26         return Promise.reject('Internals API needed for this test');
27
28     registration = await navigator.serviceWorker.register("resources/persistent-importScripts-worker.js");
29     if (registration.installing) {
30         worker = registration.installing;
31         await waitForState(worker, "activated");
32     } else
33         worker = registration.active;
34
35     let frame = await withIframe("resources");
36     let randomId = await getRandomIdFromWorker(worker);
37
38     if (!window.location.hash.length) {
39         if (window.testRunner)
40             testRunner.terminateStorageProcess();
41         await waitFor(100);
42         window.location += "?test#" + randomId;
43         return;
44     }
45
46     document.body.innerHTML = ("#" + randomId) == window.location.hash ? "PASS" : "FAIL";
47     if (window.testRunner)
48         testRunner.notifyDone();
49 }
50 doTest();
51
52 </script>
53 </body>
54 </html>