2010-08-28 01:19:45 +04:00
|
|
|
<!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>
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
<script type='application/javascript;version=1.7'>
|
2010-08-28 01:19:45 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
// Listen to the first callback, since this indicates that the page loaded.
|
|
|
|
var page1PopstateCallbackEnabled = true;
|
|
|
|
function page1Popstate()
|
2010-08-28 01:19:45 +04:00
|
|
|
{
|
2010-09-22 05:10:31 +04:00
|
|
|
if (page1PopstateCallbackEnabled) {
|
|
|
|
page1PopstateCallbackEnabled = false;
|
|
|
|
dump('Got page1 popstate.\n');
|
|
|
|
pageLoad();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dump('Ignoring page1 popstate.\n');
|
|
|
|
}
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
var page2PopstateCallbackEnabled = false;
|
|
|
|
function page2Popstate()
|
2010-08-28 01:19:45 +04:00
|
|
|
{
|
2010-09-22 05:10:31 +04:00
|
|
|
if (page2PopstateCallbackEnabled) {
|
|
|
|
page2PopstateCallbackEnabled = false;
|
|
|
|
dump('Got page2 popstate.\n');
|
|
|
|
pageLoad();
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-09-22 05:10:31 +04:00
|
|
|
dump('Ignoring page2 popstate.\n');
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
function dumpSHistory(theWindow)
|
2010-08-28 01:19:45 +04:00
|
|
|
{
|
2010-09-22 05:10:31 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
let sh = theWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.sessionHistory;
|
|
|
|
if (!sh) {
|
|
|
|
dump(" window has no shistory.\n");
|
|
|
|
return;
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
2010-09-22 05:10:31 +04:00
|
|
|
|
|
|
|
dump(" count: " + sh.count + "\n");
|
|
|
|
dump(" index: " + sh.index + "\n");
|
|
|
|
dump(" requestedIndex: " + sh.requestedIndex + "\n");
|
|
|
|
|
|
|
|
for (let i = 0; i < sh.count; i++) {
|
|
|
|
let shentry = sh.getEntryAtIndex(i, false);
|
|
|
|
dump(" " + i + ": " + shentry.URI.spec + '\n');
|
|
|
|
shentry.QueryInterface(Ci.nsISHContainer);
|
|
|
|
for (let j = 0; j < shentry.childCount; j++) {
|
|
|
|
let child = shentry.GetChildAt(j);
|
|
|
|
dump(" child " + j + ": " + child.URI.spec + '\n');
|
|
|
|
}
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
2010-09-22 05:10:31 +04:00
|
|
|
|
|
|
|
return sh;
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
var popup = window.open('file_bug590573_1.html');
|
|
|
|
|
2010-08-28 01:19:45 +04:00
|
|
|
var loads = 0;
|
2010-09-22 05:10:31 +04:00
|
|
|
function pageLoad()
|
2010-08-28 01:19:45 +04:00
|
|
|
{
|
|
|
|
loads++;
|
2010-09-22 05:10:31 +04:00
|
|
|
dump('pageLoad(loads=' + loads + ', page location=' + popup.location + ')\n');
|
|
|
|
|
|
|
|
dumpSHistory(window);
|
2010-08-28 01:19:45 +04:00
|
|
|
|
|
|
|
if (loads == 1) {
|
2010-09-22 05:10:31 +04:00
|
|
|
is(popup.scrollY, 0, "test 1");
|
|
|
|
popup.scroll(0, 100);
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
popup.history.pushState('', '', '?pushed');
|
|
|
|
is(popup.scrollY, 100, "test 2");
|
|
|
|
popup.scroll(0, 200); // set state-2's position to 200
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
popup.history.back();
|
|
|
|
is(popup.scrollY, 100, "test 3");
|
|
|
|
popup.scroll(0, 150); // set original page's position to 150
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
popup.history.forward();
|
|
|
|
is(popup.scrollY, 200, "test 4");
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
popup.history.back();
|
|
|
|
is(popup.scrollY, 150, "test 5");
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
popup.history.forward();
|
|
|
|
is(popup.scrollY, 200, "test 6");
|
2010-08-28 01:19:45 +04:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
setTimeout(pageLoad, 0);
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 2) {
|
2010-09-22 05:10:31 +04:00
|
|
|
page2PopstateCallbackEnabled = true;
|
|
|
|
popup.location = 'file_bug590573_2.html';
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 3) {
|
2010-09-22 05:10:31 +04:00
|
|
|
ok(popup.location.href.match('file_bug590573_2.html$'),
|
|
|
|
"Location was " + popup.location +
|
2010-08-28 01:19:45 +04:00
|
|
|
" but should end with file_bug590573_2.html");
|
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
is(popup.scrollY, 0, "test 7");
|
|
|
|
popup.scroll(0, 300);
|
2010-08-28 01:19:45 +04:00
|
|
|
|
|
|
|
// We need to spin the event loop again before we go back, otherwise the
|
|
|
|
// scroll positions don't get updated properly.
|
2010-09-22 05:10:31 +04:00
|
|
|
setTimeout(pageLoad, 0);
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 4) {
|
2010-09-22 05:10:31 +04:00
|
|
|
page1PopstateCallbackEnabled = true;
|
|
|
|
popup.history.back();
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 5) {
|
|
|
|
// Spin the event loop again so that we get the right scroll positions.
|
2010-09-22 05:10:31 +04:00
|
|
|
setTimeout(pageLoad, 0);
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 6) {
|
2010-09-22 05:10:31 +04:00
|
|
|
is(popup.location.search, "?pushed");
|
|
|
|
ok(popup.document.getElementById('div1'), 'page should have div1.');
|
2010-08-28 01:19:45 +04:00
|
|
|
|
2010-09-22 05:10:31 +04:00
|
|
|
is(popup.scrollY, 200, "test 8");
|
|
|
|
popup.history.back();
|
|
|
|
is(popup.scrollY, 150, "test 9");
|
|
|
|
popup.history.forward();
|
|
|
|
is(popup.scrollY, 200, "test 10");
|
2010-08-28 01:19:45 +04:00
|
|
|
|
|
|
|
// Spin one last time...
|
2010-09-22 05:10:31 +04:00
|
|
|
setTimeout(pageLoad, 0);
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 7) {
|
2010-09-22 05:10:31 +04:00
|
|
|
page2PopstateCallbackEnabled = true;
|
|
|
|
popup.history.forward();
|
2010-08-28 01:19:45 +04:00
|
|
|
}
|
|
|
|
else if (loads == 8) {
|
2010-09-22 05:10:31 +04:00
|
|
|
is(popup.scrollY, 300, "test 11");
|
|
|
|
popup.close();
|
2010-08-28 01:19:45 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(false, "Got extra load!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|