Revision control

1
<!doctype html><!-- webkit-test-runner [ UsesBackForwardCache=true ] -->
2
<html>
3
<script>
4
5
let suspended = false;
6
let restored = false;
7
8
function finish(msg)
9
{
10
document.getElementById("result").textContent = msg;
11
if (window.testRunner)
12
testRunner.notifyDone();
13
}
14
15
window.addEventListener("pagehide", event => {
16
suspended = event.persisted;
17
if (!suspended)
18
finish("FAIL: event.persisted was false for pagehide event.")
19
});
20
21
window.addEventListener("pageshow", event => {
22
// If we haven't been suspended, then this is the initial page load, not the back navigation.
23
if (!suspended)
24
return;
25
26
restored = event.persisted;
27
if (!restored)
28
finish("FAIL: event.persisted was false for pageshow event.")
29
});
30
31
window.addEventListener("DOMContentLoaded", event => {
32
if (window.testRunner) {
33
testRunner.dumpAsText();
34
testRunner.waitUntilDone();
35
}
36
37
// We start an animation that is just long enough that it would finish while the page is hidden.
38
document.body.animate({ backgroundColor: "red" }, 500).finished.then(() => {
39
if (!suspended)
40
finish("FAIL: Animation finished but prevented the page from being suspended.");
41
else if (!restored)
42
finish("FAIL: Animation finished but prevented the page from being restored.");
43
else
44
finish("PASS.");
45
});
46
47
requestAnimationFrame(() => {
48
// Load a new page, and let it go back after 250ms.
49
window.location.href = "data:text/html,<body onload='setTimeout(() => history.back(), 250)'></body>";
50
});
51
});
52
53
</script>
54
<body>
55
This test verifies that the page cache suspends and resumes Web Animations from the page cache. The test starts an animation, then navigates away, waits a bit, navigates back, confirming that the timeline froze at a given time and resumed in the same spot, advancing the animation. If successful, it outputs 'PASS' below.
56
<div id="result"></div>
57
</body>
58
</html>