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"
16 <script src=
"chrome://mochikit/content/chrome-harness.js" />
17 <script type=
"application/javascript" src=
"docshell_helpers.js" />
18 <script type=
"application/javascript"><![CDATA[
19 Services.prefs.setBoolPref(
"browser.navigation.requireUserInteraction", false);
23 async function runTest() {
24 gBrowser = document.getElementById(
"content");
27 // Back/forward between two simple documents. Bfcache will be used.
29 var test1Doc =
"data:text/html,<html><head><title>test1</title></head>" +
30 "<body>test1</body></html>";
32 await promisePageNavigation({
34 eventsToListenFor: [
"load",
"pageshow"],
35 expectedEvents: [{type:
"load", title:
"test1"},
36 {type:
"pageshow", title:
"test1", persisted: false}],
39 var test2Doc =
"data:text/html,<html><head><title>test2</title></head>" +
40 "<body>test2</body></html>";
42 await promisePageNavigation({
44 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
45 expectedEvents: [{type:
"pagehide", title:
"test1", persisted: true},
46 {type:
"load", title:
"test2"},
47 {type:
"pageshow", title:
"test2", persisted: false}],
50 await promisePageNavigation({
52 eventsToListenFor: [
"pageshow",
"pagehide"],
53 expectedEvents: [{type:
"pagehide", title:
"test2", persisted: true},
54 {type:
"pageshow", title:
"test1", persisted: true}],
57 await promisePageNavigation({
59 eventsToListenFor: [
"pageshow",
"pagehide"],
60 expectedEvents: [{type:
"pagehide", title:
"test1", persisted: true},
61 {type:
"pageshow", title:
"test2", persisted: true}],
65 // Back/forward between a two-level deep iframed document and a simple
66 // document. Bfcache will be used and events should be dispatched to
69 var test3Doc =
"data:text/html,<html><head><title>test3</title>" +
71 "<iframe src='data:text/html," +
72 "<html><head><title>test3-nested1</title></head>" +
73 "<body>test3-nested1" +
74 "<iframe src=\"data:text/html,
" +
75 "<html><head><title>test3-nested2
</title></head>" +
76 "<body>test3-nested2
</body></html>\
">" +
82 await promisePageNavigation({
84 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
85 expectedEvents: [{type:
"pagehide", title:
"test2", persisted: true},
86 {type:
"load", title:
"test3-nested2"},
87 {type:
"pageshow", title:
"test3-nested2", persisted: false},
88 {type:
"load", title:
"test3-nested1"},
89 {type:
"pageshow", title:
"test3-nested1", persisted: false},
90 {type:
"load", title:
"test3"},
91 {type:
"pageshow", title:
"test3", persisted: false}],
94 var test4Doc =
"data:text/html,<html><head><title>test4</title></head>" +
95 "<body>test4</body></html>";
97 await promisePageNavigation({
99 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
100 expectedEvents: [{type:
"pagehide", title:
"test3", persisted: true},
101 {type:
"pagehide", title:
"test3-nested1", persisted: true},
102 {type:
"pagehide", title:
"test3-nested2", persisted: true},
103 {type:
"load", title:
"test4"},
104 {type:
"pageshow", title:
"test4", persisted: false}],
107 await promisePageNavigation({
109 eventsToListenFor: [
"pageshow",
"pagehide"],
110 expectedEvents: [{type:
"pagehide", title:
"test4", persisted: true},
111 {type:
"pageshow", title:
"test3-nested2", persisted: true},
112 {type:
"pageshow", title:
"test3-nested1", persisted: true},
113 {type:
"pageshow", title:
"test3", persisted: true}],
116 // This is where the two nested pagehide are not dispatched in bug
364461
117 await promisePageNavigation({
119 eventsToListenFor: [
"pageshow",
"pagehide"],
120 expectedEvents: [{type:
"pagehide", title:
"test3", persisted: true},
121 {type:
"pagehide", title:
"test3-nested1", persisted: true},
122 {type:
"pagehide", title:
"test3-nested2", persisted: true},
123 {type:
"pageshow", title:
"test4", persisted: true}],
127 // Back/forward between a document containing an unload handler and a
128 // a simple document. Bfcache won't be used for the first one (see
129 // http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching).
131 var test5Doc =
"data:text/html,<html><head><title>test5</title></head>" +
132 "<body onunload='while(false) { /* nop */ }'>" +
133 "test5</body></html>";
135 await promisePageNavigation({
137 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
138 expectedEvents: [{type:
"pagehide", title:
"test4", persisted: true},
139 {type:
"load", title:
"test5"},
140 {type:
"pageshow", title:
"test5", persisted: false}],
143 var test6Doc =
"data:text/html,<html><head><title>test6</title></head>" +
144 "<body>test6</body></html>";
146 await promisePageNavigation({
148 eventsToListenFor: [
"load",
"unload",
"pageshow",
"pagehide"],
149 expectedEvents: [{type:
"pagehide", title:
"test5", persisted: false},
150 {type:
"unload", title:
"test5"},
151 {type:
"load", title:
"test6"},
152 {type:
"pageshow", title:
"test6", persisted: false}],
155 await promisePageNavigation({
157 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
158 expectedEvents: [{type:
"pagehide", title:
"test6", persisted: true},
159 {type:
"load", title:
"test5"},
160 {type:
"pageshow", title:
"test5", persisted: false}],
163 await promisePageNavigation({
165 eventsToListenFor: [
"unload",
"pageshow",
"pagehide"],
166 expectedEvents: [{type:
"pagehide", title:
"test5", persisted: false},
167 {type:
"unload", title:
"test5"},
168 {type:
"pageshow", title:
"test6", persisted: true}],
172 // Testcase from https://bugzilla.mozilla.org/show_bug.cgi?id=
384977#c10
173 // Check that navigation is not blocked after a document is restored
176 var test7Doc =
"data:text/html,<html><head><title>test7</title>" +
178 "<iframe src='data:text/html," +
179 "<html><head><title>test7-nested1</title></head>" +
180 "<body>test7-nested1<br/>" +
181 "<a href=\"data:text/plain,aaa\
" target=\"_top\
">" +
182 "Click me, hit back, click me again</a>" +
187 await promisePageNavigation({
189 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
190 expectedEvents: [{type:
"pagehide", title:
"test6", persisted: true},
191 {type:
"load", title:
"test7-nested1"},
192 {type:
"pageshow", title:
"test7-nested1", persisted: false},
193 {type:
"load", title:
"test7"},
194 {type:
"pageshow", title:
"test7", persisted: false}],
197 // Simulates a click on the link inside the iframe
198 function clickIframeLink() {
199 SpecialPowers.spawn(TestWindow.getBrowser(), [], () =
> {
200 var iframe = content.document.getElementsByTagName(
"iframe")[
0];
201 var w = iframe.contentWindow;
202 var d = iframe.contentDocument;
204 var evt = d.createEvent(
"MouseEvents");
205 evt.initMouseEvent(
"click", true, true, w,
206 0,
0,
0,
0,
0, false, false, false, false,
0, null);
207 d.getElementsByTagName(
"a")[
0].dispatchEvent(evt);
211 let clicked = promisePageNavigation({
212 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
213 expectedEvents: [{type:
"pagehide", title:
"test7", persisted: true},
214 {type:
"pagehide", title:
"test7-nested1", persisted: true},
216 {type:
"pageshow", persisted: false}],
217 waitForEventsOnly: true,
222 is(gBrowser.currentURI.spec,
"data:text/plain,aaa",
223 "Navigation is blocked when clicking link");
225 await promisePageNavigation({
227 eventsToListenFor: [
"pageshow",
"pagehide"],
228 expectedEvents: [{type:
"pagehide", persisted: true},
229 {type:
"pageshow", title:
"test7-nested1", persisted: true},
230 {type:
"pageshow", title:
"test7", persisted: true}],
233 clicked = promisePageNavigation({
234 eventsToListenFor: [
"load",
"pageshow",
"pagehide"],
235 expectedEvents: [{type:
"pagehide", title:
"test7", persisted: true},
236 {type:
"pagehide", title:
"test7-nested1", persisted: true},
238 {type:
"pageshow", persisted: false}],
239 waitForEventsOnly: true,
244 is(gBrowser.currentURI.spec,
"data:text/plain,aaa",
245 "Navigation is blocked when clicking link");
247 Services.prefs.clearUserPref(
"browser.navigation.requireUserInteraction");
252 <browser type=
"content" primary=
"true" flex=
"1" id=
"content" remote=
"true" maychangeremoteness=
"true" />