blob: 514e57722b5d5db8b6e911a656dbbf9e2303d5d0 [file] [log] [blame]
<!-- webkit-test-runner [ UsesBackForwardCache=true ] -->
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<script>
description('Tests that a page with a pending getUserMedia request is able to go into the back/forward cache.');
jsTestIsAsync = true;
let restoredFromPageCache = false;
if (window.testRunner)
testRunner.setUserMediaPermission(true);
window.addEventListener("pageshow", function(event) {
debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
if (event.persisted) {
testPassed("Page was restored from Page Cache");
restoredFromPageCache = true;
}
});
window.addEventListener("pagehide", function(event) {
debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
if (!event.persisted) {
testFailed("Page failed to enter the Page Cache");
finishJSTest();
}
navigator.mediaDevices.getUserMedia({ audio: true }).then(() => {
testPassed("Promised was resolved");
shouldBeTrue("restoredFromPageCache");
finishJSTest();
}, () => {
testFailed("Promise was rejected");
finishJSTest();
});
});
onload = () => {
setTimeout(() => {
testLink.click();
}, 0);
}
</script>
<a id="testLink" href="resources/page-cache-helper.html" style="display: none">Link</a>
</body>
</html>