|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window id="301397Test" |
|
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
6 width="600" |
|
7 height="600" |
|
8 onload="setTimeout(nextTest,0);" |
|
9 title="bug 301397 test"> |
|
10 |
|
11 <script type="text/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> |
|
13 <script type="text/javascript" |
|
14 src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> |
|
15 <script type="text/javascript" |
|
16 src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> |
|
17 <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> |
|
18 <script type="application/javascript" src="docshell_helpers.js" /> |
|
19 <script type="application/javascript"><![CDATA[ |
|
20 |
|
21 // Define the generator-iterator for the tests. |
|
22 var tests = testIterator(); |
|
23 |
|
24 //// |
|
25 // Execute the next test in the generator function. |
|
26 // |
|
27 function nextTest() { |
|
28 tests.next(); |
|
29 } |
|
30 |
|
31 //// |
|
32 // Return the document element with the specified id. |
|
33 // |
|
34 function $(id) { return TestWindow.getDocument().getElementById(id); } |
|
35 |
|
36 //// |
|
37 // Verifies that the given string exists in the innerHTML of the iframe |
|
38 // content. |
|
39 // |
|
40 function verifyIframeInnerHtml(string) { |
|
41 var iframeInnerHtml = $("iframe").contentDocument.body.innerHTML; |
|
42 ok(iframeInnerHtml.indexOf(string) != -1, |
|
43 "iframe contains wrong document: " + iframeInnerHtml); |
|
44 } |
|
45 |
|
46 //// |
|
47 // Generator function for test steps for bug 301397: |
|
48 // The correct page should be displayed in an iframe when |
|
49 // navigating back and forwards, when the parent page |
|
50 // occupies multiple spots in the session history. |
|
51 // |
|
52 function testIterator() |
|
53 { |
|
54 // Make sure the bfcache is enabled. |
|
55 enableBFCache(8); |
|
56 |
|
57 // Load a dummy page. |
|
58 doPageNavigation({ |
|
59 uri: getHttpUrl("generic.html"), |
|
60 onNavComplete: nextTest |
|
61 }); |
|
62 yield undefined; |
|
63 |
|
64 // Load a page containing an iframe. |
|
65 doPageNavigation({ |
|
66 uri: getHttpUrl("bug301397_1.html"), |
|
67 eventsToListenFor: ["pageshow", "pagehide"], |
|
68 expectedEvents: [ { type: "pagehide", |
|
69 title: "generic page", |
|
70 persisted: true }, |
|
71 { type: "pageshow", |
|
72 title: "iframe content #1", |
|
73 persisted: false }, // false on initial load |
|
74 { type: "pageshow", |
|
75 title: "iframe parent", |
|
76 persisted: false } ], // false on initial load |
|
77 onNavComplete: nextTest |
|
78 }); |
|
79 yield undefined; |
|
80 |
|
81 // Click a link in the iframe to cause the iframe to navigate |
|
82 // to a new page, and wait until the related pagehide/pageshow |
|
83 // events have occurred. |
|
84 waitForPageEvents({ |
|
85 eventsToListenFor: ["pageshow", "pagehide"], |
|
86 expectedEvents: [ { type: "pagehide", |
|
87 title: "iframe content #1", |
|
88 persisted: false }, // false, subframe nav |
|
89 { type: "pageshow", |
|
90 title: "iframe content #2", |
|
91 persisted: false } ], // false on initial load |
|
92 onNavComplete: nextTest |
|
93 }); |
|
94 var link = $("iframe").contentDocument.getElementById("link"); |
|
95 var event = $("iframe").contentDocument.createEvent("MouseEvents"); |
|
96 event.initMouseEvent("click", true, true, $("iframe").contentWindow, |
|
97 0, 0, 0, 0, 0, |
|
98 false, false, false, false, |
|
99 0, null); |
|
100 link.dispatchEvent(event); |
|
101 yield undefined; |
|
102 |
|
103 // Load another dummy page. Verify that both the outgoing parent and |
|
104 // iframe pages are stored in the bfcache. |
|
105 doPageNavigation({ |
|
106 uri: getHttpUrl("bug301397_4.html"), |
|
107 eventsToListenFor: ["pageshow", "pagehide"], |
|
108 expectedEvents: [ { type: "pagehide", |
|
109 title: "iframe parent", |
|
110 persisted: true }, |
|
111 { type: "pagehide", |
|
112 title: "iframe content #2", |
|
113 persisted: true }, |
|
114 { type: "pageshow", |
|
115 title: "dummy page, no iframe", |
|
116 persisted: false } ], // false on initial load |
|
117 onNavComplete: nextTest |
|
118 }); |
|
119 yield undefined; |
|
120 |
|
121 // Go back. The iframe should show the second page loaded in it. |
|
122 // Both the parent and the iframe pages should be loaded from |
|
123 // the bfcache. |
|
124 doPageNavigation({ |
|
125 back: true, |
|
126 eventsToListenFor: ["pageshow", "pagehide"], |
|
127 expectedEvents: [ { type: "pagehide", |
|
128 title: "dummy page, no iframe", |
|
129 persisted: true }, |
|
130 { type: "pageshow", |
|
131 persisted: true, |
|
132 title: "iframe content #2" }, |
|
133 { type: "pageshow", |
|
134 persisted: true, |
|
135 title: "iframe parent" } ], |
|
136 onNavComplete: nextTest |
|
137 }); |
|
138 yield undefined; |
|
139 |
|
140 verifyIframeInnerHtml("You made it"); |
|
141 |
|
142 // Go gack again. The iframe should show the first page loaded in it. |
|
143 doPageNavigation({ |
|
144 back: true, |
|
145 eventsToListenFor: ["pageshow", "pagehide"], |
|
146 expectedEvents: [ { type: "pagehide", |
|
147 title: "iframe content #2", |
|
148 persisted: false }, // false, subframe nav |
|
149 { type: "pageshow", |
|
150 title: "iframe content #1", |
|
151 // false since this page was never stored |
|
152 // in the bfcache in the first place |
|
153 persisted: false } ], |
|
154 onNavComplete: nextTest |
|
155 }); |
|
156 yield undefined; |
|
157 |
|
158 verifyIframeInnerHtml("go to next page"); |
|
159 |
|
160 // Go back to the generic page. Now go forward to the last page, |
|
161 // again verifying that the iframe shows the first and second |
|
162 // pages in order. |
|
163 doPageNavigation({ |
|
164 back: true, |
|
165 eventsToListenFor: ["pageshow", "pagehide"], |
|
166 expectedEvents: [ { type: "pagehide", |
|
167 title: "iframe parent", |
|
168 persisted: true }, |
|
169 { type: "pagehide", |
|
170 title: "iframe content #1", |
|
171 persisted: true }, |
|
172 { type: "pageshow", |
|
173 title: "generic page", |
|
174 persisted: true } ], |
|
175 onNavComplete: nextTest |
|
176 }); |
|
177 yield undefined; |
|
178 |
|
179 doPageNavigation({ |
|
180 forward: true, |
|
181 eventsToListenFor: ["pageshow"], |
|
182 expectedEvents: [ {type: "pageshow", |
|
183 title: "iframe content #1", |
|
184 persisted: true}, |
|
185 {type: "pageshow", |
|
186 title: "iframe parent", |
|
187 persisted: true} ], |
|
188 onNavComplete: nextTest |
|
189 }); |
|
190 yield undefined; |
|
191 |
|
192 verifyIframeInnerHtml("go to next page"); |
|
193 |
|
194 doPageNavigation({ |
|
195 forward: true, |
|
196 eventsToListenFor: ["pageshow", "pagehide"], |
|
197 expectedEvents: [ { type: "pagehide", |
|
198 title: "iframe content #1", |
|
199 persisted: false }, // false, subframe nav |
|
200 { type: "pageshow", |
|
201 title: "iframe content #2", |
|
202 // false because the page wasn't stored in |
|
203 // bfcache last time it was unloaded |
|
204 persisted: false } ], |
|
205 onNavComplete: nextTest |
|
206 }); |
|
207 yield undefined; |
|
208 |
|
209 verifyIframeInnerHtml("You made it"); |
|
210 |
|
211 doPageNavigation({ |
|
212 forward: true, |
|
213 eventsToListenFor: ["pageshow", "pagehide"], |
|
214 expectedEvents: [ { type: "pagehide", |
|
215 title: "iframe parent", |
|
216 persisted: true }, |
|
217 { type: "pagehide", |
|
218 title: "iframe content #2", |
|
219 persisted: true }, |
|
220 { type: "pageshow", |
|
221 title: "dummy page, no iframe", |
|
222 persisted: true } ], |
|
223 onNavComplete: nextTest |
|
224 }); |
|
225 yield undefined; |
|
226 |
|
227 // Go back once more, and again verify that the iframe shows the |
|
228 // second page loaded in it. |
|
229 doPageNavigation({ |
|
230 back: true, |
|
231 eventsToListenFor: ["pageshow", "pagehide"], |
|
232 expectedEvents: [ { type: "pagehide", |
|
233 title: "dummy page, no iframe", |
|
234 persisted: true }, |
|
235 { type: "pageshow", |
|
236 persisted: true, |
|
237 title: "iframe content #2" }, |
|
238 { type: "pageshow", |
|
239 persisted: true, |
|
240 title: "iframe parent" } ], |
|
241 onNavComplete: nextTest |
|
242 }); |
|
243 yield undefined; |
|
244 |
|
245 verifyIframeInnerHtml("You made it"); |
|
246 |
|
247 // Tell the framework the test is finished. Include the final 'yield' |
|
248 // statement to prevent a StopIteration exception from being thrown. |
|
249 finish(); |
|
250 yield undefined; |
|
251 } |
|
252 |
|
253 ]]></script> |
|
254 |
|
255 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
256 </window> |