|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=590573 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 590573</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=590573">Mozilla Bug 590573</a> |
|
14 |
|
15 <script type='application/javascript;version=1.7'> |
|
16 SimpleTest.waitForExplicitFinish(); |
|
17 |
|
18 // Listen to the first callback, since this indicates that the page loaded. |
|
19 var page1LoadCallbackEnabled = true; |
|
20 function page1Load() |
|
21 { |
|
22 if (page1LoadCallbackEnabled) { |
|
23 page1LoadCallbackEnabled = false; |
|
24 dump('Got page1 load.\n'); |
|
25 pageLoad(); |
|
26 } |
|
27 else { |
|
28 dump('Ignoring page1 load.\n'); |
|
29 } |
|
30 } |
|
31 |
|
32 var page1PopstateCallbackEnabled = false; |
|
33 function page1Popstate() |
|
34 { |
|
35 if (page1PopstateCallbackEnabled) { |
|
36 page1PopstateCallbackEnabled = false; |
|
37 dump('Got page1 popstate.\n'); |
|
38 pageLoad(); |
|
39 } |
|
40 else { |
|
41 dump('Ignoring page1 popstate.\n'); |
|
42 } |
|
43 } |
|
44 |
|
45 var page1PageShowCallbackEnabled = false; |
|
46 function page1PageShow() |
|
47 { |
|
48 if (page1PageShowCallbackEnabled) { |
|
49 page1PageShowCallbackEnabled = false; |
|
50 dump('Got page1 pageshow.\n'); |
|
51 pageLoad(); |
|
52 } |
|
53 else { |
|
54 dump('Ignoring page1 pageshow.\n'); |
|
55 } |
|
56 } |
|
57 |
|
58 var page2LoadCallbackEnabled = false; |
|
59 function page2Load() |
|
60 { |
|
61 if (page2LoadCallbackEnabled) { |
|
62 page2LoadCallbackEnabled = false; |
|
63 dump('Got page2 popstate.\n'); |
|
64 pageLoad(); |
|
65 } |
|
66 else { |
|
67 dump('Ignoring page2 popstate.\n'); |
|
68 } |
|
69 } |
|
70 |
|
71 var page2PopstateCallbackEnabled = false; |
|
72 function page2Popstate() |
|
73 { |
|
74 if (page2PopstateCallbackEnabled) { |
|
75 page2PopstateCallbackEnabled = false; |
|
76 dump('Got page2 popstate.\n'); |
|
77 pageLoad(); |
|
78 } |
|
79 else { |
|
80 dump('Ignoring page2 popstate.\n'); |
|
81 } |
|
82 } |
|
83 |
|
84 var page2PageShowCallbackEnabled = false; |
|
85 function page2PageShow() |
|
86 { |
|
87 if (page2PageShowCallbackEnabled) { |
|
88 page2PageShowCallbackEnabled = false; |
|
89 dump('Got page2 pageshow.\n'); |
|
90 pageLoad(); |
|
91 } |
|
92 else { |
|
93 dump('Ignoring page2 pageshow.\n'); |
|
94 } |
|
95 } |
|
96 |
|
97 function dumpSHistory(theWindow) |
|
98 { |
|
99 let sh = SpecialPowers.wrap(theWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) |
|
100 .getInterface(SpecialPowers.Ci.nsIWebNavigation) |
|
101 .sessionHistory; |
|
102 if (!sh) { |
|
103 dump(" window has no shistory.\n"); |
|
104 return; |
|
105 } |
|
106 |
|
107 dump(" count: " + sh.count + "\n"); |
|
108 dump(" index: " + sh.index + "\n"); |
|
109 dump(" requestedIndex: " + sh.requestedIndex + "\n"); |
|
110 |
|
111 for (let i = 0; i < sh.count; i++) { |
|
112 let shentry = sh.getEntryAtIndex(i, false); |
|
113 dump(" " + i + ": " + shentry.URI.spec + '\n'); |
|
114 shentry.QueryInterface(SpecialPowers.Ci.nsISHContainer); |
|
115 for (let j = 0; j < shentry.childCount; j++) { |
|
116 let child = shentry.GetChildAt(j); |
|
117 dump(" child " + j + ": " + child.URI.spec + '\n'); |
|
118 } |
|
119 } |
|
120 |
|
121 return sh; |
|
122 } |
|
123 |
|
124 var popup = window.open('file_bug590573_1.html'); |
|
125 |
|
126 var loads = 0; |
|
127 function pageLoad() |
|
128 { |
|
129 loads++; |
|
130 dump('pageLoad(loads=' + loads + ', page location=' + popup.location + ')\n'); |
|
131 |
|
132 dumpSHistory(window); |
|
133 |
|
134 if (loads == 1) { |
|
135 is(popup.scrollY, 0, "test 1"); |
|
136 popup.scroll(0, 100); |
|
137 |
|
138 popup.history.pushState('', '', '?pushed'); |
|
139 is(popup.scrollY, 100, "test 2"); |
|
140 popup.scroll(0, 200); // set state-2's position to 200 |
|
141 |
|
142 popup.history.back(); |
|
143 is(popup.scrollY, 100, "test 3"); |
|
144 popup.scroll(0, 150); // set original page's position to 150 |
|
145 |
|
146 popup.history.forward(); |
|
147 is(popup.scrollY, 200, "test 4"); |
|
148 |
|
149 popup.history.back(); |
|
150 is(popup.scrollY, 150, "test 5"); |
|
151 |
|
152 popup.history.forward(); |
|
153 is(popup.scrollY, 200, "test 6"); |
|
154 |
|
155 // At this point, the history looks like: |
|
156 // PATH POSITION |
|
157 // file_bug590573_1.html 150 <-- oldest |
|
158 // file_bug590573_1.html?pushed 200 <-- newest, current |
|
159 |
|
160 // Now test that the scroll position is persisted when we have real |
|
161 // navigations involved. First, we need to spin the event loop so that the |
|
162 // navigation doesn't replace our current history entry. |
|
163 |
|
164 setTimeout(pageLoad, 0); |
|
165 } |
|
166 else if (loads == 2) { |
|
167 page2LoadCallbackEnabled = true; |
|
168 popup.location = 'file_bug590573_2.html'; |
|
169 } |
|
170 else if (loads == 3) { |
|
171 ok(popup.location.href.match('file_bug590573_2.html$'), |
|
172 "Location was " + popup.location + |
|
173 " but should end with file_bug590573_2.html"); |
|
174 |
|
175 is(popup.scrollY, 0, "test 7"); |
|
176 popup.scroll(0, 300); |
|
177 |
|
178 // We need to spin the event loop again before we go back, otherwise the |
|
179 // scroll positions don't get updated properly. |
|
180 setTimeout(pageLoad, 0); |
|
181 } |
|
182 else if (loads == 4) { |
|
183 page1PageShowCallbackEnabled = true; |
|
184 popup.history.back(); |
|
185 } |
|
186 else if (loads == 5) { |
|
187 // Spin the event loop again so that we get the right scroll positions. |
|
188 setTimeout(pageLoad, 0); |
|
189 } |
|
190 else if (loads == 6) { |
|
191 is(popup.location.search, "?pushed"); |
|
192 ok(popup.document.getElementById('div1'), 'page should have div1.'); |
|
193 |
|
194 // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200 |
|
195 if (popup.scrollY >= 199 && popup.scrollY <= 200) { |
|
196 is(1, 1, "test 8"); |
|
197 } else { |
|
198 is(1, 0, "test 8, got " + popup.scrollY + " for popup.scrollY instead of 199|200"); |
|
199 } |
|
200 |
|
201 popup.history.back(); |
|
202 is(popup.scrollY, 150, "test 9"); |
|
203 popup.history.forward(); |
|
204 |
|
205 // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200 |
|
206 if (popup.scrollY >= 199 && popup.scrollY <= 200) { |
|
207 is(1, 1, "test 10"); |
|
208 } else { |
|
209 is(1, 0, "test 10, got " + popup.scrollY + " for popup.scrollY instead of 199|200"); |
|
210 } |
|
211 |
|
212 // Spin one last time... |
|
213 setTimeout(pageLoad, 0); |
|
214 } |
|
215 else if (loads == 7) { |
|
216 page2PageShowCallbackEnabled = true; |
|
217 popup.history.forward(); |
|
218 } |
|
219 else if (loads == 8) { |
|
220 // Bug 821821, on Android tegras we get 299 instead of 300 sometimes |
|
221 if (popup.scrollY >= 299 && popup.scrollY <= 300) { |
|
222 is(1, 1, "test 11"); |
|
223 } else { |
|
224 is(1, 0, "test 11, got " + popup.scrollY + " for popup.scrollY instead of 299|300"); |
|
225 } |
|
226 popup.close(); |
|
227 SimpleTest.finish(); |
|
228 } |
|
229 else { |
|
230 ok(false, "Got extra load!"); |
|
231 } |
|
232 } |
|
233 </script> |
|
234 |
|
235 </body> |
|
236 </html> |