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