blob: 2f81c09cedd2e71b511c28149aade103ef1641de [file] [log] [blame]
<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests that a page with an active fetch request is able to enter the back/forward cache.');
window.jsTestIsAsync = true;
let restoredFromCache = false;
window.addEventListener("pageshow", function(event) {
debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
if (event.persisted) {
testPassed("Page did enter and was restored from the back/forward cache");
restoredFromCache = true;
finishJSTest();
}
}, false);
window.addEventListener("pagehide", function(event) {
debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
if (!event.persisted) {
testFailed("Page did not enter the back/forward cache.");
finishJSTest();
}
}, false);
var textData = JSON.stringify("This is the body");
function tryGetRequestBlob()
{
blob = new Blob([textData], { "type" : "text/plain" });
request = new Request("", {"method": "POST", "body": blob });
readableStream = request.body;
readableStream.getReader().read().then(() => {
if (restoredFromCache) {
return;
}
setTimeout(tryGetRequestBlob, 0);
}, (e) => {
setTimeout(tryGetRequestBlob, 0);
});
}
window.addEventListener('load', function() {
setTimeout(() => {
tryGetRequestBlob();
window.location.href = "resources/page-cache-helper.html";
}, 0);
}, false);
</script>
</body>
</html>