blob: 8e4030c4152d10665e9cc90775e8c19c7021c44d [file] [log] [blame]
<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
<!DOCTYPE html>
<html>
<body>
<script src="../../../resources/js-test-pre.js"></script>
<div id="description"></div>
<pre id="console"></pre>
<script>
description('Tests that popstate events fire when navigating between pages (and history entries created via pushState) that are in the page cache.');
var testWindow;
onload = function()
{
if (window.testRunner)
testRunner.setCanOpenWindows();
testWindow = window.open('resources/popstate-fires-with-page-cache-1.html');
if (!testWindow)
testFailed('Could not open test window');
}
var testWindowLoadFireCount = 0;
var testWindowPopstateFireCount = 0;
function onTestWindowLoad(event)
{
debug('load fired');
testWindowLoadFireCount++;
switch (testWindowLoadFireCount) {
case 1:
debug('pushState with new state object for page 1');
testWindow.history.pushState('newState', '');
debug('going to page 2');
// Set the location in a timeout to generate a history entry
setTimeout(function() {testWindow.location.href = 'resources/popstate-fires-with-page-cache-2.html';}, 0);
break;
case 2:
debug('going back to page 1 with new state object');
setTimeout(function() {testWindow.history.back();}, 0);
break;
default:
testFailed('unexpected load event state');
break;
}
}
function onTestWindowPopState(event)
{
debug('popstate fired with state ' + event.state);
testWindowPopstateFireCount++;
switch (testWindowPopstateFireCount) {
case 1:
debug('going back to page 1 in initial state');
setTimeout(function() {testWindow.history.back();}, 0);
break;
case 2:
// Close the window in a timeout to simulate popstate firing asynchronously, otherwise closing the window in a popstate handler results in a crash.
// FIXME: remove this when http://webkit.org/b/36202 is fixed.
setTimeout(function() {
testWindow.close();
finishJSTest();
}, 0);
break;
default:
testFailed('unexpected pop state event state');
break;
}
}
var jsTestIsAsync = true;
</script>
<script src="../../../resources/js-test-post.js"></script>
</html>