blob: 0757da958b4f7757a10c49a9c298e43d528c4594 [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/cacheable-script-worker.php", { updateViaCache: "all" });
let worker1 = registration.installing;
await waitForState(worker1, "activated");
let randomId1 = await getRandomIdFromWorker(worker1);
await registration.update();
if (registration.installing) {
log("FAIL: The new script should have come from the cache and thus be identical, in which case it would not have be reinstalled");
finishSWTest();
}
let worker2 = registration.active;
let randomId2 = await getRandomIdFromWorker(worker2);
if (randomId1 === randomId2)
log("PASS: The worker script came from the network cache");
else
log("FAIL: The worker script did not come from the network cache");
} catch(e) {
log("Got exception: " + e);
}
finishSWTest();
}
test();
</script>
</body>
</html>