4 https://bugzilla.mozilla.org/show_bug.cgi?id=590573
7 <title>Test for Bug
590573</title>
8 <script type=
"application/javascript" src=
"/MochiKit/packed.js"></script>
9 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <script type=
"application/javascript" src=
"/tests/SimpleTest/EventUtils.js"></script>
11 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=590573">Mozilla Bug
590573</a>
16 <script type='application/javascript;version=
1.7'
>
17 SimpleTest.waitForExplicitFinish();
19 // Listen to the first callback, since this indicates that the page loaded.
20 var page1PopstateCallbackEnabled = true;
21 function page1Popstate()
23 if (page1PopstateCallbackEnabled) {
24 page1PopstateCallbackEnabled = false;
25 dump('Got page1 popstate.\n');
29 dump('Ignoring page1 popstate.\n');
33 var page2PopstateCallbackEnabled = false;
34 function page2Popstate()
36 if (page2PopstateCallbackEnabled) {
37 page2PopstateCallbackEnabled = false;
38 dump('Got page2 popstate.\n');
42 dump('Ignoring page2 popstate.\n');
46 function dumpSHistory(theWindow)
48 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
50 const Ci = Components.interfaces;
51 let sh = theWindow.QueryInterface(Ci.nsIInterfaceRequestor)
52 .getInterface(Ci.nsIWebNavigation)
55 dump(
" window has no shistory.\n");
59 dump(
" count: " + sh.count +
"\n");
60 dump(
" index: " + sh.index +
"\n");
61 dump(
" requestedIndex: " + sh.requestedIndex +
"\n");
63 for (let i =
0; i < sh.count; i++) {
64 let shentry = sh.getEntryAtIndex(i, false);
65 dump(
" " + i +
": " + shentry.URI.spec + '\n');
66 shentry.QueryInterface(Ci.nsISHContainer);
67 for (let j =
0; j < shentry.childCount; j++) {
68 let child = shentry.GetChildAt(j);
69 dump(
" child " + j +
": " + child.URI.spec + '\n');
76 var popup = window.open('file_bug590573_1.html');
82 dump('pageLoad(loads=' + loads + ', page location=' + popup.location + ')\n');
87 is(popup.scrollY,
0,
"test 1");
90 popup.history.pushState('', '', '?pushed');
91 is(popup.scrollY,
100,
"test 2");
92 popup.scroll(
0,
200); // set state-
2's position to
200
95 is(popup.scrollY,
100,
"test 3");
96 popup.scroll(
0,
150); // set original page's position to
150
98 popup.history.forward();
99 is(popup.scrollY,
200,
"test 4");
101 popup.history.back();
102 is(popup.scrollY,
150,
"test 5");
104 popup.history.forward();
105 is(popup.scrollY,
200,
"test 6");
107 // At this point, the history looks like:
109 // file_bug590573_1.html
150 <-- oldest
110 // file_bug590573_1.html?pushed
200 <-- newest, current
112 // Now test that the scroll position is persisted when we have real
113 // navigations involved. First, we need to spin the event loop so that the
114 // navigation doesn't replace our current history entry.
116 setTimeout(pageLoad,
0);
118 else if (loads ==
2) {
119 page2PopstateCallbackEnabled = true;
120 popup.location = 'file_bug590573_2.html';
122 else if (loads ==
3) {
123 ok(popup.location.href.match('file_bug590573_2.html$'),
124 "Location was " + popup.location +
125 " but should end with file_bug590573_2.html");
127 is(popup.scrollY,
0,
"test 7");
128 popup.scroll(
0,
300);
130 // We need to spin the event loop again before we go back, otherwise the
131 // scroll positions don't get updated properly.
132 setTimeout(pageLoad,
0);
134 else if (loads ==
4) {
135 page1PopstateCallbackEnabled = true;
136 popup.history.back();
138 else if (loads ==
5) {
139 // Spin the event loop again so that we get the right scroll positions.
140 setTimeout(pageLoad,
0);
142 else if (loads ==
6) {
143 is(popup.location.search,
"?pushed");
144 ok(popup.document.getElementById('div1'), 'page should have div1.');
146 is(popup.scrollY,
200,
"test 8");
147 popup.history.back();
148 is(popup.scrollY,
150,
"test 9");
149 popup.history.forward();
150 is(popup.scrollY,
200,
"test 10");
152 // Spin one last time...
153 setTimeout(pageLoad,
0);
155 else if (loads ==
7) {
156 page2PopstateCallbackEnabled = true;
157 popup.history.forward();
159 else if (loads ==
8) {
160 is(popup.scrollY,
300,
"test 11");
165 ok(false,
"Got extra load!");