blob: 9c175676744b77caf6d488285f0aac771266d9b4 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="resources/sw-test-pre.js"></script>
<script>
log("* Tests that a client is re-added to the list of service worker clients when it is restored from the page cache");
log("");
if (window.testRunner) {
testRunner.setCanOpenWindows();
testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
}
navigator.serviceWorker.addEventListener("message", function(event) {
if (step == "BothClientsInitiallyActive") {
if (event.data != 2) {
log("FAIL: Wrong initial number of clients: " + event.data);
finishSWTest();
return;
}
log("PASS: service worker has initially 2 clients");
otherWindow.addEventListener("pagehide", function(event) {
if (!event.persisted) {
log("FAIL: page failed to enter page cache");
finishSWTest();
return;
}
log("PASS: page is about to enter page cache");
});
otherWindow.addEventListener("pageshow", function(event) {
if (!event.persisted) {
log("FAIL: page was not restored from page cache");
finishSWTest();
return;
}
setTimeout(function() {
step = "SecondClientRestoredFromPageCache";
worker.postMessage("getClientCount");
}, 0);
});
otherWindow.location.href = "/navigation/resources/page-cache-helper.html";
return;
}
if (step == "SecondClientRestoredFromPageCache") {
if (event.data != 2) {
log("FAIL: Wrong number of clients after one client was restored from page cache: " + event.data);
finishSWTest();
}
log("PASS: service worker now has 2 clients again after restoring the second one from page cache");
finishSWTest();
}
});
navigator.serviceWorker.register("resources/getClientCount-worker.js", { }).then(function(registration) {
worker = registration.installing;
otherWindow = open("other_resources/test.html");
otherWindow.onload = function() {
step = "BothClientsInitiallyActive"
worker.postMessage("getClientCount");
};
});
</script>
</body>
</html>