blob: f298fc0acdf3441dabeeea73ff0275d34583d854 [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: "all" });
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: "all" });
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>