blob: ed247245e342ddccba6401e7ed4e57a5458aadff [file] [log] [blame]
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<style>
body {
height: 2000px;
width: 2000px;
}
</style>
</head>
<body>
<script>
var jsTestIsAsync = true;
description("Tests that history.scrollRestoration works for same-document navigations");
if (window.testRunner)
testRunner.clearBackForwardList();
shouldBeTrue("'scrollRestoration' in history");
// Can't create history entries inside the onload handler.
window.setTimeout(testAutoScrollRestoration, 0);
function waitForPresentationUpdateUIScript()
{
return `(function() {
uiController.doAfterPresentationUpdate(function() {
uiController.uiScriptComplete();
});
})()`;
}
function testAutoScrollRestoration()
{
history.scrollRestoration = 'auto';
shouldBeEqualToString('history.scrollRestoration', 'auto');
window.scrollTo(123, 456);
history.pushState(null, '', '#1');
window.scrollTo(0, 0);
history.back();
testRunner.runUIScript(waitForPresentationUpdateUIScript(), function () {
shouldBe('window.scrollX', '123');
shouldBe('window.scrollY', '456');
testManualScrollRestoration();
});
}
function testManualScrollRestoration()
{
history.scrollRestoration = 'manual';
shouldBeEqualToString('history.scrollRestoration', 'manual');
window.scrollTo(234, 567);
history.pushState(null, '', '#2');
window.scrollTo(333, 555);
history.back();
testRunner.runUIScript(waitForPresentationUpdateUIScript(), function () {
shouldBe('window.scrollX', '333');
shouldBe('window.scrollY', '555');
window.scrollTo(0, 0);
finishJSTest();
});
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>