gecko/docshell/test/test_bug590573.html

152 lines
4.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=590573
-->
<head>
<title>Test for Bug 590573</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=590573">Mozilla Bug 590573</a>
<iframe id='iframe' width='100px' height='100px' src='file_bug590573_1.html'></iframe>
<div>iframe's scrollY=<span id='iframeScrollLabel'></span></div>
<script>
SimpleTest.waitForExplicitFinish();
setTimeout(updateIframeScroll, 100);
function updateIframeScroll()
{
document.getElementById('iframeScrollLabel').innerHTML =
document.getElementById('iframe').contentWindow.scrollY;
setTimeout(updateIframeScroll, 100);
}
// Listen to the first callback, since this indicates that the page loaded.
var iframe1PopstateCallbackEnabled = true;
function iframe1Popstate()
{
if (iframe1PopstateCallbackEnabled) {
iframe1PopstateCallbackEnabled = false;
dump('Got iframe1 popstate.\n');
iframeLoad();
}
else {
dump('Ignoring iframe1 popstate.\n');
}
}
var iframe2PopstateCallbackEnabled = false;
function iframe2Popstate()
{
if (iframe2PopstateCallbackEnabled) {
iframe2PopstateCallbackEnabled = false;
dump('Got iframe2 popstate.\n');
iframeLoad();
}
else {
dump('Ignoring iframe2 popstate.\n');
}
}
var loads = 0;
function iframeLoad()
{
var iframe = document.getElementById('iframe');
var iframeCw = iframe.contentWindow;
loads++;
dump('iframeLoad(loads=' + loads + ')\n');
if (loads == 1) {
is(iframeCw.scrollY, 0, "test 1");
iframeCw.scroll(0, 100);
iframeCw.history.pushState('', '', '?pushed');
is(iframeCw.scrollY, 100, "test 2");
iframeCw.scroll(0, 200); // set state-2's position to 200
iframeCw.history.back();
is(iframeCw.scrollY, 100, "test 3");
iframeCw.scroll(0, 150); // set original page's position to 150
iframeCw.history.forward();
is(iframeCw.scrollY, 200, "test 4");
iframeCw.history.back();
is(iframeCw.scrollY, 150, "test 5");
iframeCw.history.forward();
is(iframeCw.scrollY, 200, "test 6");
// At this point, the history looks like:
// PATH POSITION
// file_bug590573_1.html 150 <-- oldest
// file_bug590573_1.html?pushed 200 <-- newest, current
// Now test that the scroll position is persisted when we have real
// navigations involved. First, we need to spin the event loop so that the
// navigation doesn't replace our current history entry.
setTimeout(iframeLoad, 0);
}
else if (loads == 2) {
iframe2PopstateCallbackEnabled = true;
iframeCw.location = 'file_bug590573_2.html';
}
else if (loads == 3) {
ok(iframeCw.location.href.match('file_bug590573_2.html$'),
"Location was " + iframeCw.location +
" but should end with file_bug590573_2.html");
is(iframeCw.scrollY, 0, "test 7");
iframeCw.scroll(0, 300);
// We need to spin the event loop again before we go back, otherwise the
// scroll positions don't get updated properly.
setTimeout(iframeLoad, 0);
}
else if (loads == 4) {
iframe1PopstateCallbackEnabled = true;
iframeCw.history.back();
}
else if (loads == 5) {
// Spin the event loop again so that we get the right scroll positions.
setTimeout(iframeLoad, 0);
}
else if (loads == 6) {
is(iframeCw.location.search, "?pushed");
ok(iframeCw.document.getElementById('div1'), 'Iframe should have div1.');
is(iframeCw.scrollY, 200, "test 8");
iframeCw.history.back();
is(iframeCw.scrollY, 150, "test 9");
iframeCw.history.forward();
is(iframeCw.scrollY, 200, "test 10");
// Spin one last time...
setTimeout(iframeLoad, 0);
}
else if (loads == 7) {
iframe2PopstateCallbackEnabled = true;
iframeCw.history.forward();
}
else if (loads == 8) {
is(iframeCw.scrollY, 300, "test 11");
SimpleTest.finish();
}
else {
ok(false, "Got extra load!");
}
}
</script>
</body>
</html>