<!-- webkit-test-runner [ UsesBackForwardCache=true ] -->
<html>
<script>
var timeoutValue = 100; //ms

var restoredFromPageCache = false;
onpageshow = function(event) {
    if (event.persisted)
        restoredFromPageCache = true;
}

var timestamp;
function verify() {
    if (!restoredFromPageCache) {
      // The timer fired too early, we haven't navigated yet.
      window.setTimeout(verify, timeoutValue);
      timestamp = new Date().getTime();
      return;
    }
    var actualTimerDelay =  new Date().getTime() - timestamp;
    document.getElementById("result").innerHTML =
        actualTimerDelay >= timeoutValue ? 'PASS' : 'FAIL with ' + actualTimerDelay + ' ms delay.';

    if (window.testRunner)
      testRunner.notifyDone();
}

function runTest() {
    if (window.testRunner) {
      testRunner.dumpAsText();
      testRunner.waitUntilDone();
    }
    // Location changes need to happen outside the onload handler to generate history entries.
    setTimeout(function() {
      window.setTimeout(verify, timeoutValue);
      timestamp = new Date().getTime();
      window.location.href = "data:text/html,<body onload='history.back()'></body>";
    }, 0);
}

</script>
<body onload='runTest()'>
This test verifies that when page is loaded from the page cache on navigation back, the suspended timers are resumed for a duration left when they were suspended. This is a test for https://bugs.webkit.org/show_bug.cgi?id=28683.<br>
The test navigates to a page, starts a timer and then navigates to another page and back. It then measures time when the timer is actually fired and makes sure that it is at least the time set at the beginning. If successful, it outputs 'PASS' below.
<div id="result"></div>
</body>
</html>
