blob: d2e93df0b9d6df75de6382b0295e0423f30344a1 [file] [log] [blame]
<html>
<head>
<script src="resources/sw-test-pre.js"></script>
</head>
<body>
<script>
function getRandomIdFromWorker(worker)
{
worker.postMessage("getRandomId");
return new Promise(function(resolve) {
navigator.serviceWorker.addEventListener('message', function(e) {
resolve(e.data);
});
});
}
async function test()
{
try {
let registration = await navigator.serviceWorker.register("resources/import-cacheable-script-worker.js", { updateViaCache: "imports" });
let worker1 = registration.installing;
await waitForState(worker1, "activated");
let randomId1 = await getRandomIdFromWorker(worker1);
await registration.unregister();
registration = await navigator.serviceWorker.register("resources/import-cacheable-script-worker.js", { updateViaCache: "imports" });
let worker2 = registration.installing;
await waitForState(worker2, "activated");
let randomId2 = await getRandomIdFromWorker(worker2);
if (randomId1 === randomId2)
log("PASS: importScripts() loaded the script came from the network cache");
else
log("FAIL: importScripts() did not load the script from the network cache");
} catch(e) {
log("Got exception: " + e);
}
finishSWTest();
}
test();
</script>
</body>
</html>