Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <html> |
michael@0 | 2 | |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Accessible events testing for document</title> |
michael@0 | 5 | |
michael@0 | 6 | <link rel="stylesheet" type="text/css" |
michael@0 | 7 | href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 8 | |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | |
michael@0 | 12 | <script type="application/javascript" |
michael@0 | 13 | src="../common.js"></script> |
michael@0 | 14 | <script type="application/javascript" |
michael@0 | 15 | src="../role.js"></script> |
michael@0 | 16 | <script type="application/javascript" |
michael@0 | 17 | src="../states.js"></script> |
michael@0 | 18 | |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | // Front end stuff sometimes likes to stuff things in the hidden window(s) |
michael@0 | 21 | // in which case there's accessibles for that content. |
michael@0 | 22 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 23 | |
michael@0 | 24 | // Force the creation of an accessible for the hidden window's document. |
michael@0 | 25 | var doc = Services.appShell.hiddenDOMWindow.document; |
michael@0 | 26 | gAccRetrieval.getAccessibleFor(doc); |
michael@0 | 27 | |
michael@0 | 28 | // The private hidden window will be lazily created that's why we need to do |
michael@0 | 29 | // it here *before* loading '../events.js' or else we'll have a duplicate |
michael@0 | 30 | // reorder event. |
michael@0 | 31 | var privateDoc = Services.appShell.hiddenPrivateDOMWindow.document; |
michael@0 | 32 | |
michael@0 | 33 | // Force the creation of an accessible for the private hidden window's doc. |
michael@0 | 34 | gAccRetrieval.getAccessibleFor(privateDoc); |
michael@0 | 35 | </script> |
michael@0 | 36 | |
michael@0 | 37 | <script type="application/javascript" |
michael@0 | 38 | src="../events.js"></script> |
michael@0 | 39 | |
michael@0 | 40 | <script type="application/javascript"> |
michael@0 | 41 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 42 | // Invokers |
michael@0 | 43 | |
michael@0 | 44 | function changeIframeSrc(aIdentifier, aURL) |
michael@0 | 45 | { |
michael@0 | 46 | this.DOMNode = getNode(aIdentifier); |
michael@0 | 47 | |
michael@0 | 48 | this.eventSeq = [ |
michael@0 | 49 | new invokerChecker(EVENT_REORDER, getAccessible(this.DOMNode)), |
michael@0 | 50 | new asyncInvokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getIframeDoc) |
michael@0 | 51 | ]; |
michael@0 | 52 | |
michael@0 | 53 | this.invoke = function changeIframeSrc_invoke() |
michael@0 | 54 | { |
michael@0 | 55 | this.DOMNode.src = aURL; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | this.finalCheck = function changeIframeSrc_finalCheck() |
michael@0 | 59 | { |
michael@0 | 60 | var accTree = { |
michael@0 | 61 | role: ROLE_INTERNAL_FRAME, |
michael@0 | 62 | children: [ |
michael@0 | 63 | { |
michael@0 | 64 | role: ROLE_DOCUMENT, |
michael@0 | 65 | name: aURL == "about:" ? "About:" : aURL |
michael@0 | 66 | } |
michael@0 | 67 | ] |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | testAccessibleTree(this.DOMNode, accTree); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | this.getID = function changeIframeSrc_getID() |
michael@0 | 74 | { |
michael@0 | 75 | return "change iframe src on " + aURL; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function getIframeDoc() |
michael@0 | 79 | { |
michael@0 | 80 | return getAccessible(getNode(aIdentifier).contentDocument); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | const kHide = 1; |
michael@0 | 85 | const kShow = 2; |
michael@0 | 86 | const kRemove = 3; |
michael@0 | 87 | function morphIFrame(aIdentifier, aAction) |
michael@0 | 88 | { |
michael@0 | 89 | this.DOMNode = getNode(aIdentifier); |
michael@0 | 90 | this.IFrameContainerDOMNode = this.DOMNode.parentNode; |
michael@0 | 91 | |
michael@0 | 92 | this.eventSeq = []; |
michael@0 | 93 | |
michael@0 | 94 | var checker = null; |
michael@0 | 95 | if (aAction == kShow) |
michael@0 | 96 | checker = new invokerChecker(EVENT_SHOW, this.DOMNode); |
michael@0 | 97 | else |
michael@0 | 98 | checker = new invokerChecker(EVENT_HIDE, this.DOMNode); |
michael@0 | 99 | this.eventSeq.push(checker); |
michael@0 | 100 | |
michael@0 | 101 | var reorderChecker = |
michael@0 | 102 | new invokerChecker(EVENT_REORDER, this.IFrameContainerDOMNode); |
michael@0 | 103 | this.eventSeq.push(reorderChecker); |
michael@0 | 104 | |
michael@0 | 105 | this.invoke = function morphIFrame_invoke() |
michael@0 | 106 | { |
michael@0 | 107 | if (aAction == kHide) { |
michael@0 | 108 | this.DOMNode.style.display = "none"; |
michael@0 | 109 | } else if (aAction == kShow) { |
michael@0 | 110 | this.DOMNode.style.display = "block"; |
michael@0 | 111 | } else { |
michael@0 | 112 | this.IFrameContainerDOMNode.removeChild(this.DOMNode); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | this.finalCheck = function morphIFrame_finalCheck() |
michael@0 | 117 | { |
michael@0 | 118 | var accTree = { |
michael@0 | 119 | role: ROLE_SECTION, |
michael@0 | 120 | children: (aAction == kHide || aAction == kRemove) ? [ ] : |
michael@0 | 121 | [ |
michael@0 | 122 | { |
michael@0 | 123 | role: ROLE_INTERNAL_FRAME, |
michael@0 | 124 | children: [ |
michael@0 | 125 | { role: ROLE_DOCUMENT } |
michael@0 | 126 | ] |
michael@0 | 127 | } |
michael@0 | 128 | ] |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | testAccessibleTree(this.IFrameContainerDOMNode, accTree); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | this.getID = function morphIFrame_getID() |
michael@0 | 135 | { |
michael@0 | 136 | if (aAction == kRemove) |
michael@0 | 137 | return "remove iframe"; |
michael@0 | 138 | |
michael@0 | 139 | return "change display style of iframe to " + |
michael@0 | 140 | ((aAction == kHide) ? "none" : "block"); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function makeIFrameVisible(aID) |
michael@0 | 145 | { |
michael@0 | 146 | this.DOMNode = getNode(aID); |
michael@0 | 147 | |
michael@0 | 148 | this.eventSeq = [ |
michael@0 | 149 | new invokerChecker(EVENT_REORDER, this.DOMNode.parentNode) |
michael@0 | 150 | ]; |
michael@0 | 151 | |
michael@0 | 152 | this.invoke = function makeIFrameVisible_invoke() |
michael@0 | 153 | { |
michael@0 | 154 | this.DOMNode.style.visibility = "visible"; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | this.getID = function makeIFrameVisible_getID() |
michael@0 | 158 | { |
michael@0 | 159 | return "The accessible for DOM document loaded before it's shown shouldn't have busy state."; |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | function openDialogWnd(aURL) |
michael@0 | 164 | { |
michael@0 | 165 | // Get application root accessible. |
michael@0 | 166 | var docAcc = getAccessible(document); |
michael@0 | 167 | while (docAcc) { |
michael@0 | 168 | this.mRootAcc = docAcc; |
michael@0 | 169 | try { |
michael@0 | 170 | docAcc = docAcc.parent; |
michael@0 | 171 | } catch (e) { |
michael@0 | 172 | ok(false, "Can't get parent for " + prettyName(docAcc)); |
michael@0 | 173 | throw e; |
michael@0 | 174 | } |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | this.eventSeq = [ |
michael@0 | 178 | new invokerChecker(EVENT_REORDER, this.mRootAcc) |
michael@0 | 179 | ]; |
michael@0 | 180 | |
michael@0 | 181 | this.invoke = function openDialogWnd_invoke() |
michael@0 | 182 | { |
michael@0 | 183 | this.mDialog = window.openDialog(aURL); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | this.finalCheck = function openDialogWnd_finalCheck() |
michael@0 | 187 | { |
michael@0 | 188 | this.finalCheckImpl(); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | this.finalCheckImpl = function openDialogWnd_finalCheckImpl() |
michael@0 | 192 | { |
michael@0 | 193 | var accTree = { |
michael@0 | 194 | role: ROLE_APP_ROOT, |
michael@0 | 195 | children: [ |
michael@0 | 196 | { |
michael@0 | 197 | role: ROLE_CHROME_WINDOW |
michael@0 | 198 | }, |
michael@0 | 199 | { |
michael@0 | 200 | role: ROLE_CHROME_WINDOW |
michael@0 | 201 | }, |
michael@0 | 202 | { |
michael@0 | 203 | role: ROLE_CHROME_WINDOW |
michael@0 | 204 | }, |
michael@0 | 205 | { |
michael@0 | 206 | role: ROLE_CHROME_WINDOW |
michael@0 | 207 | } |
michael@0 | 208 | ] |
michael@0 | 209 | }; |
michael@0 | 210 | |
michael@0 | 211 | testAccessibleTree(this.mRootAcc, accTree); |
michael@0 | 212 | |
michael@0 | 213 | var dlgDoc = this.mDialog.document; |
michael@0 | 214 | ok(isAccessibleInCache(dlgDoc), |
michael@0 | 215 | "The document accessible for '" + aURL + "' is not in cache!"); |
michael@0 | 216 | |
michael@0 | 217 | this.mDialog.close(); |
michael@0 | 218 | |
michael@0 | 219 | // close() is asynchronous. |
michael@0 | 220 | SimpleTest.executeSoon(function() { |
michael@0 | 221 | ok(!isAccessibleInCache(dlgDoc), |
michael@0 | 222 | "The document accessible for '" + aURL + "' is in cache still!"); |
michael@0 | 223 | }); |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | this.getID = function openDialogWnd_getID() |
michael@0 | 227 | { |
michael@0 | 228 | return "open dialog '" + aURL + "'"; |
michael@0 | 229 | } |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | function openWndShutdownDoc() |
michael@0 | 233 | { |
michael@0 | 234 | this.__proto__ = |
michael@0 | 235 | new openDialogWnd("../events/docload_wnd.html"); |
michael@0 | 236 | |
michael@0 | 237 | var thisObj = this; |
michael@0 | 238 | var docChecker = { |
michael@0 | 239 | type: EVENT_HIDE, |
michael@0 | 240 | get target() |
michael@0 | 241 | { |
michael@0 | 242 | var iframe = this.invoker.mDialog.document.getElementById("iframe"); |
michael@0 | 243 | this.invoker.iframeDoc = iframe.contentDocument; |
michael@0 | 244 | return iframe; |
michael@0 | 245 | }, |
michael@0 | 246 | get targetDescr() |
michael@0 | 247 | { |
michael@0 | 248 | return "inner iframe of docload_wnd.html document"; |
michael@0 | 249 | }, |
michael@0 | 250 | invoker: thisObj |
michael@0 | 251 | }; |
michael@0 | 252 | |
michael@0 | 253 | this.eventSeq.push(docChecker); |
michael@0 | 254 | |
michael@0 | 255 | this.finalCheck = function openWndShutdownDoc_finalCheck() |
michael@0 | 256 | { |
michael@0 | 257 | // After timeout after event hide for iframe was handled the document |
michael@0 | 258 | // accessible for iframe's document is in cache still. |
michael@0 | 259 | ok(!isAccessibleInCache(this.iframeDoc), |
michael@0 | 260 | "The document accessible for iframe is in cache still after iframe hide!"); |
michael@0 | 261 | |
michael@0 | 262 | this.finalCheckImpl(); |
michael@0 | 263 | |
michael@0 | 264 | // After the window is closed all alive subdocument accessibles should |
michael@0 | 265 | // be shut down. |
michael@0 | 266 | ok(!isAccessibleInCache(this.iframeDoc), |
michael@0 | 267 | "The document accessible for iframe is in cache still!"); |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 272 | // Do tests |
michael@0 | 273 | |
michael@0 | 274 | var gQueue = null; |
michael@0 | 275 | |
michael@0 | 276 | // Debug stuff. |
michael@0 | 277 | // gA11yEventDumpID = "eventdump"; |
michael@0 | 278 | //gA11yEventDumpToConsole = true; |
michael@0 | 279 | |
michael@0 | 280 | function doTests() |
michael@0 | 281 | { |
michael@0 | 282 | gQueue = new eventQueue(); |
michael@0 | 283 | |
michael@0 | 284 | gQueue.push(new changeIframeSrc("iframe", "about:")); |
michael@0 | 285 | gQueue.push(new changeIframeSrc("iframe", "about:buildconfig")); |
michael@0 | 286 | gQueue.push(new morphIFrame("iframe", kHide)); |
michael@0 | 287 | gQueue.push(new morphIFrame("iframe", kShow)); |
michael@0 | 288 | gQueue.push(new morphIFrame("iframe", kRemove)); |
michael@0 | 289 | gQueue.push(new makeIFrameVisible("iframe2")); |
michael@0 | 290 | gQueue.push(new openDialogWnd("about:")); |
michael@0 | 291 | gQueue.push(new openWndShutdownDoc()); |
michael@0 | 292 | |
michael@0 | 293 | gQueue.onFinish = doLastCallTests; |
michael@0 | 294 | |
michael@0 | 295 | gQueue.invoke(); // Will call SimpleTest.finish(); |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | function doLastCallTests() |
michael@0 | 299 | { |
michael@0 | 300 | ////////////////////////////////////////////////////////////////////////// |
michael@0 | 301 | // makeIFrameVisible() test, part2 |
michael@0 | 302 | |
michael@0 | 303 | // The document shouldn't have busy state (the DOM document was loaded |
michael@0 | 304 | // before its accessible was created). Do this test lately to make sure |
michael@0 | 305 | // the content of document accessible was created initially, prior to this |
michael@0 | 306 | // the document accessible keeps busy state. The initial creation happens |
michael@0 | 307 | // asynchronously after document creation, there are no events we could |
michael@0 | 308 | // use to catch it. |
michael@0 | 309 | var iframeDoc = getAccessible("iframe2").firstChild; |
michael@0 | 310 | testStates(iframeDoc, 0, 0, STATE_BUSY); |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 314 | addA11yLoadEvent(doTests); |
michael@0 | 315 | </script> |
michael@0 | 316 | </head> |
michael@0 | 317 | |
michael@0 | 318 | <body> |
michael@0 | 319 | |
michael@0 | 320 | <a target="_blank" |
michael@0 | 321 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=420845" |
michael@0 | 322 | title="Fire event_reorder on any embedded frames/iframes whos document has just loaded"> |
michael@0 | 323 | Mozilla Bug 420845 |
michael@0 | 324 | </a><br> |
michael@0 | 325 | <a target="_blank" |
michael@0 | 326 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=506206" |
michael@0 | 327 | title="Fire event_reorder application root accessible"> |
michael@0 | 328 | Mozilla Bug 506206 |
michael@0 | 329 | </a><br> |
michael@0 | 330 | <a target="_blank" |
michael@0 | 331 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103" |
michael@0 | 332 | title="Reorganize accessible document handling"> |
michael@0 | 333 | Mozilla Bug 566103 |
michael@0 | 334 | </a><br> |
michael@0 | 335 | <a target="_blank" |
michael@0 | 336 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=571459" |
michael@0 | 337 | title="Shutdown document accessible when presshell goes away"> |
michael@0 | 338 | Mozilla Bug 571459 |
michael@0 | 339 | </a> |
michael@0 | 340 | <a target="_blank" |
michael@0 | 341 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=658185" |
michael@0 | 342 | title="The DOM document loaded before it's shown shouldn't have busy state"> |
michael@0 | 343 | Mozilla Bug 658185 |
michael@0 | 344 | </a> |
michael@0 | 345 | <a target="_blank" |
michael@0 | 346 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165" |
michael@0 | 347 | title="Fire document load events on iframes too"> |
michael@0 | 348 | Mozilla Bug 754165 |
michael@0 | 349 | </a> |
michael@0 | 350 | |
michael@0 | 351 | <p id="display"></p> |
michael@0 | 352 | <div id="content" style="display: none"></div> |
michael@0 | 353 | <pre id="test"> |
michael@0 | 354 | </pre> |
michael@0 | 355 | |
michael@0 | 356 | <div id="testContainer"><iframe id="iframe"></iframe></div> |
michael@0 | 357 | <div id="testContainer2"><iframe id="iframe2" src="about:" style="visibility: hidden;"></iframe></div> |
michael@0 | 358 | <div id="eventdump"></div> |
michael@0 | 359 | </body> |
michael@0 | 360 | </html> |