bug364461_window.xhtml (11183B)
1 <?xml version="1.0"?> 2 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/. --> 6 7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 8 9 <window id="364461Test" 10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 11 width="600" 12 height="600" 13 onload="runTest();" 14 title="364461 test"> 15 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); 20 21 var gBrowser; 22 23 async function runTest() { 24 gBrowser = document.getElementById("content"); 25 26 // Tests 1 + 2: 27 // Back/forward between two simple documents. Bfcache will be used. 28 29 var test1Doc = "data:text/html,<html><head><title>test1</title></head>" + 30 "<body>test1</body></html>"; 31 32 await promisePageNavigation({ 33 uri: test1Doc, 34 eventsToListenFor: ["load", "pageshow"], 35 expectedEvents: [{type: "load", title: "test1"}, 36 {type: "pageshow", title: "test1", persisted: false}], 37 }); 38 39 var test2Doc = "data:text/html,<html><head><title>test2</title></head>" + 40 "<body>test2</body></html>"; 41 42 await promisePageNavigation({ 43 uri: test2Doc, 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}], 48 }); 49 50 await promisePageNavigation({ 51 back: true, 52 eventsToListenFor: ["pageshow", "pagehide"], 53 expectedEvents: [{type: "pagehide", title: "test2", persisted: true}, 54 {type: "pageshow", title: "test1", persisted: true}], 55 }); 56 57 await promisePageNavigation({ 58 forward: true, 59 eventsToListenFor: ["pageshow", "pagehide"], 60 expectedEvents: [{type: "pagehide", title: "test1", persisted: true}, 61 {type: "pageshow", title: "test2", persisted: true}], 62 }); 63 64 // Tests 3 + 4: 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 67 // all frames. 68 69 var test3Doc = "data:text/html,<html><head><title>test3</title>" + 70 "</head><body>" + 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>\">" + 77 "</iframe>" + 78 "</body></html>'>" + 79 "</iframe>" + 80 "</body></html>"; 81 82 await promisePageNavigation({ 83 uri: test3Doc, 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}], 92 }); 93 94 var test4Doc = "data:text/html,<html><head><title>test4</title></head>" + 95 "<body>test4</body></html>"; 96 97 await promisePageNavigation({ 98 uri: test4Doc, 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}], 105 }); 106 107 await promisePageNavigation({ 108 back: true, 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}], 114 }); 115 116 // This is where the two nested pagehide are not dispatched in bug 364461 117 await promisePageNavigation({ 118 forward: true, 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}], 124 }); 125 126 // Tests 5 + 6: 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). 130 131 var test5Doc = "data:text/html,<html><head><title>test5</title></head>" + 132 "<body onunload='while(false) { /* nop */ }'>" + 133 "test5</body></html>"; 134 135 await promisePageNavigation({ 136 uri: test5Doc, 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}], 141 }); 142 143 var test6Doc = "data:text/html,<html><head><title>test6</title></head>" + 144 "<body>test6</body></html>"; 145 146 await promisePageNavigation({ 147 uri: test6Doc, 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}], 153 }); 154 155 await promisePageNavigation({ 156 back: true, 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}], 161 }); 162 163 await promisePageNavigation({ 164 forward: true, 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}], 169 }); 170 171 // Test 7: 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 174 // from bfcache 175 176 var test7Doc = "data:text/html,<html><head><title>test7</title>" + 177 "</head><body>" + 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>" + 183 "</body></html>'>" + 184 "</iframe>" + 185 "</body></html>"; 186 187 await promisePageNavigation({ 188 uri: test7Doc, 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}], 195 }); 196 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; 203 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); 208 }); 209 } 210 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}, 215 {type: "load"}, 216 {type: "pageshow", persisted: false}], 217 waitForEventsOnly: true, 218 }); 219 clickIframeLink(); 220 await clicked; 221 222 is(gBrowser.currentURI.spec, "data:text/plain,aaa", 223 "Navigation is blocked when clicking link"); 224 225 await promisePageNavigation({ 226 back: true, 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}], 231 }); 232 233 clicked = promisePageNavigation({ 234 eventsToListenFor: ["load", "pageshow", "pagehide"], 235 expectedEvents: [{type: "pagehide", title: "test7", persisted: true}, 236 {type: "pagehide", title: "test7-nested1", persisted: true}, 237 {type: "load"}, 238 {type: "pageshow", persisted: false}], 239 waitForEventsOnly: true, 240 }); 241 clickIframeLink(); 242 await clicked; 243 244 is(gBrowser.currentURI.spec, "data:text/plain,aaa", 245 "Navigation is blocked when clicking link"); 246 247 Services.prefs.clearUserPref("browser.navigation.requireUserInteraction"); 248 finish(); 249 } 250 ]]></script> 251 252 <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" /> 253 </window>