Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <?xml version="1.0"?>
3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
4 - License, v. 2.0. If a copy of the MPL was not distributed with this
5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
9 <window id="364461Test"
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
11 width="600"
12 height="600"
13 onload="onLoad();"
14 title="364461 test">
16 <script type="application/javascript"><![CDATA[
18 const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
20 var gBrowser;
21 var gTestsIterator;
22 var gExpected = [];
24 function ok(condition, message) {
25 window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
26 }
27 function is(a, b, message) {
28 window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
29 }
30 function finish() {
31 for each (let eventType in LISTEN_EVENTS) {
32 gBrowser.removeEventListener(eventType, eventListener, true);
33 }
35 window.close();
36 window.opener.wrappedJSObject.SimpleTest.finish();
37 }
39 function onLoad() {
40 gBrowser = document.getElementById("content");
42 for each (let eventType in LISTEN_EVENTS) {
43 gBrowser.addEventListener(eventType, eventListener, true);
44 }
46 gTestsIterator = testsIterator();
47 nextTest();
48 }
50 function eventListener(event) {
51 ok(gExpected.length >= 1, "Unexpected event " + event.type);
52 if (gExpected.length == 0) {
53 // in case of unexpected event, try to continue anyway
54 setTimeout(nextTest, 0);
55 return;
56 }
58 var exp = gExpected.shift();
59 is(event.type, exp.type, "Invalid event received");
60 if (typeof(exp.persisted) != "undefined") {
61 is(event.persisted, exp.persisted, "Invalid persisted state");
62 }
63 if (exp.title) {
64 ok(event.originalTarget instanceof HTMLDocument,
65 "originalTarget not a HTMLDocument");
66 is(event.originalTarget.title, exp.title, "titles don't match");
67 }
69 if (gExpected.length == 0) {
70 setTimeout(nextTest, 0);
71 }
72 }
74 function nextTest() {
75 try {
76 gTestsIterator.next();
77 } catch (err if err instanceof StopIteration) {
78 finish();
79 }
80 }
82 function testsIterator() {
84 // Tests 1 + 2:
85 // Back/forward between two simple documents. Bfcache will be used.
87 var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
88 "<body>test1</body></html>";
90 gExpected = [{type: "pagehide", persisted: true},
92 {type: "load", title: "test1"},
93 {type: "pageshow", title: "test1", persisted: false}];
94 gBrowser.loadURI(test1Doc);
95 yield undefined;
97 var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
98 "<body>test2</body></html>";
100 gExpected = [{type: "pagehide", title: "test1", persisted: true},
101 {type: "load", title: "test2"},
102 {type: "pageshow", title: "test2", persisted: false}];
103 gBrowser.loadURI(test2Doc);
104 yield undefined;
106 gExpected = [{type: "pagehide", title: "test2", persisted: true},
107 {type: "pageshow", title: "test1", persisted: true}];
108 gBrowser.goBack();
109 yield undefined;
111 gExpected = [{type: "pagehide", title: "test1", persisted: true},
112 {type: "pageshow", title: "test2", persisted: true}];
113 gBrowser.goForward();
114 yield undefined;
116 // Tests 3 + 4:
117 // Back/forward between a two-level deep iframed document and a simple
118 // document. Bfcache will be used and events should be dispatched to
119 // all frames.
121 var test3Doc = "data:text/html,<html><head><title>test3</title>" +
122 "</head><body>" +
123 "<iframe src='data:text/html," +
124 "<html><head><title>test3-nested1</title></head>" +
125 "<body>test3-nested1" +
126 "<iframe src=\"data:text/html," +
127 "<html><head><title>test3-nested2</title></head>" +
128 "<body>test3-nested2</body></html>\">" +
129 "</iframe>" +
130 "</body></html>'>" +
131 "</iframe>" +
132 "</body></html>";
134 gExpected = [{type: "pagehide", title: "test2", persisted: true},
135 {type: "load", title: "test3-nested2"},
136 {type: "pageshow", title: "test3-nested2", persisted: false},
137 {type: "load", title: "test3-nested1"},
138 {type: "pageshow", title: "test3-nested1", persisted: false},
139 {type: "load", title: "test3"},
140 {type: "pageshow", title: "test3", persisted: false}];
141 gBrowser.loadURI(test3Doc);
142 yield undefined;
144 var test4Doc = "data:text/html,<html><head><title>test4</title></head>" +
145 "<body>test4</body></html>";
147 gExpected = [{type: "pagehide", title: "test3", persisted: true},
148 {type: "pagehide", title: "test3-nested1", persisted: true},
149 {type: "pagehide", title: "test3-nested2", persisted: true},
150 {type: "load", title: "test4"},
151 {type: "pageshow", title: "test4", persisted: false}];
152 gBrowser.loadURI(test4Doc);
153 yield undefined;
155 gExpected = [{type: "pagehide", title: "test4", persisted: true},
156 {type: "pageshow", title: "test3-nested2", persisted: true},
157 {type: "pageshow", title: "test3-nested1", persisted: true},
158 {type: "pageshow", title: "test3", persisted: true}];
159 gBrowser.goBack();
160 yield undefined;
162 // This is where the two nested pagehide are not dispatched in bug 364461
163 gExpected = [{type: "pagehide", title: "test3", persisted: true},
164 {type: "pagehide", title: "test3-nested1", persisted: true},
165 {type: "pagehide", title: "test3-nested2", persisted: true},
166 {type: "pageshow", title: "test4", persisted: true}];
167 gBrowser.goForward();
168 yield undefined;
170 // Tests 5 + 6:
171 // Back/forward between a document containing an unload handler and a
172 // a simple document. Bfcache won't be used for the first one (see
173 // http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching).
175 var test5Doc = "data:text/html,<html><head><title>test5</title></head>" +
176 "<body onunload='while(false) { /* nop */ }'>" +
177 "test5</body></html>";
179 gExpected = [{type: "pagehide", title: "test4", persisted: true},
180 {type: "load", title: "test5"},
181 {type: "pageshow", title: "test5", persisted: false}];
182 gBrowser.loadURI(test5Doc);
183 yield undefined;
185 var test6Doc = "data:text/html,<html><head><title>test6</title></head>" +
186 "<body>test6</body></html>";
188 gExpected = [{type: "pagehide", title: "test5", persisted: false},
189 {type: "unload", title: "test5"},
190 {type: "load", title: "test6"},
191 {type: "pageshow", title: "test6", persisted: false}];
192 gBrowser.loadURI(test6Doc);
193 yield undefined;
195 gExpected = [{type: "pagehide", title: "test6", persisted: true},
196 {type: "load", title: "test5"},
197 {type: "pageshow", title: "test5", persisted: false}];
198 gBrowser.goBack();
199 yield undefined;
201 gExpected = [{type: "pagehide", title: "test5", persisted: false},
202 {type: "unload", title: "test5"},
203 {type: "pageshow", title: "test6", persisted: true}];
204 gBrowser.goForward();
205 yield undefined;
207 // Test 7:
208 // Testcase from https://bugzilla.mozilla.org/show_bug.cgi?id=384977#c10
209 // Check that navigation is not blocked after a document is restored
210 // from bfcache
212 var test7Doc = "data:text/html,<html><head><title>test7</title>" +
213 "</head><body>" +
214 "<iframe src='data:text/html," +
215 "<html><head><title>test7-nested1</title></head>" +
216 "<body>test7-nested1<br/>" +
217 "<a href=\"data:text/plain,aaa\" target=\"_main\">" +
218 "Click me, hit back, click me again</a>" +
219 "</body></html>'>" +
220 "</iframe>" +
221 "</body></html>";
223 gExpected = [{type: "pagehide", title: "test6", persisted: true},
224 {type: "load", title: "test7-nested1"},
225 {type: "pageshow", title: "test7-nested1", persisted: false},
226 {type: "load", title: "test7"},
227 {type: "pageshow", title: "test7", persisted: false}];
228 gBrowser.loadURI(test7Doc);
229 yield undefined;
231 // Simulates a click on the link inside the iframe
232 function clickIframeLink() {
233 var iframe = gBrowser.contentDocument.getElementsByTagName("iframe")[0];
234 var w = iframe.contentWindow;
235 var d = iframe.contentDocument;
237 var evt = d.createEvent("MouseEvents");
238 evt.initMouseEvent("click", true, true, w,
239 0, 0, 0, 0, 0, false, false, false, false, 0, null);
240 d.getElementsByTagName("a")[0].dispatchEvent(evt);
241 }
243 gExpected = [{type: "pagehide", title: "test7", persisted: true},
244 {type: "pagehide", title: "test7-nested1", persisted: true},
245 {type: "load"},
246 {type: "pageshow", persisted: false}];
247 clickIframeLink();
248 yield undefined;
250 is(gBrowser.currentURI.spec, "data:text/plain,aaa",
251 "Navigation is blocked when clicking link");
253 gExpected = [{type: "pagehide", persisted: true},
254 {type: "pageshow", title: "test7-nested1", persisted: true},
255 {type: "pageshow", title: "test7", persisted: true}];
256 gBrowser.goBack();
257 yield undefined;
259 gExpected = [{type: "pagehide", title: "test7", persisted: true},
260 {type: "pagehide", title: "test7-nested1", persisted: true},
261 {type: "load"},
262 {type: "pageshow", persisted: false}];
263 clickIframeLink();
264 yield undefined;
266 is(gBrowser.currentURI.spec, "data:text/plain,aaa",
267 "Navigation is blocked when clicking link");
269 // nextTest has to be called from here, as no events are fired in this
270 // step
271 setTimeout(nextTest, 0);
272 yield undefined;
273 }
274 ]]></script>
276 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
277 </window>