blob: 01fc23d8a918a67f27b236c3af34fd007601b83c [file] [log] [blame]
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<pre id="console"></pre>
<script>
description('Tests that using location.replace to update the hash of a page preserves it when navigating back to it.');
jsTestIsAsync = true;
var testWindow;
onload = function()
{
if (window.testRunner) {
testRunner.setCanOpenWindows();
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
testWindow = window.open('resources/location-replace-hash-1.html');
if (!testWindow)
testFailed('Could not open test window');
}
var currentState = 0;
var currentPageId;
function onTestWindowNavigation(pageId)
{
// The page ID is put in a global so that the eval() inside of shouldBe can
// see it
currentPageId = pageId;
currentState++;
switch (currentState) {
case 1:
shouldBe('currentPageId', '1');
testWindow.location.replace('#foo');
break;
case 2:
shouldBe('currentPageId', '1');
shouldBe('testWindow.location.hash', '"#foo"');
testWindow.location = 'location-replace-hash-2.html';
break;
case 3:
shouldBe('currentPageId', '2');
testWindow.history.back();
break;
case 4:
shouldBe('currentPageId', '1');
shouldBe('testWindow.location.hash', '"#foo"');
break;
default:
testFailed('Should not be in state ' + currentState);
break;
}
if (currentState == 4) {
testPassed('Complete: navigated through all the states');
finishJSTest();
}
}
</script>
<script src="../../resources/js-test-post.js"></script>
</body>