1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/events/test_docload.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,360 @@ 1.4 +<html> 1.5 + 1.6 +<head> 1.7 + <title>Accessible events testing for document</title> 1.8 + 1.9 + <link rel="stylesheet" type="text/css" 1.10 + href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + 1.15 + <script type="application/javascript" 1.16 + src="../common.js"></script> 1.17 + <script type="application/javascript" 1.18 + src="../role.js"></script> 1.19 + <script type="application/javascript" 1.20 + src="../states.js"></script> 1.21 + 1.22 + <script type="application/javascript"> 1.23 + // Front end stuff sometimes likes to stuff things in the hidden window(s) 1.24 + // in which case there's accessibles for that content. 1.25 + Components.utils.import("resource://gre/modules/Services.jsm"); 1.26 + 1.27 + // Force the creation of an accessible for the hidden window's document. 1.28 + var doc = Services.appShell.hiddenDOMWindow.document; 1.29 + gAccRetrieval.getAccessibleFor(doc); 1.30 + 1.31 + // The private hidden window will be lazily created that's why we need to do 1.32 + // it here *before* loading '../events.js' or else we'll have a duplicate 1.33 + // reorder event. 1.34 + var privateDoc = Services.appShell.hiddenPrivateDOMWindow.document; 1.35 + 1.36 + // Force the creation of an accessible for the private hidden window's doc. 1.37 + gAccRetrieval.getAccessibleFor(privateDoc); 1.38 + </script> 1.39 + 1.40 + <script type="application/javascript" 1.41 + src="../events.js"></script> 1.42 + 1.43 + <script type="application/javascript"> 1.44 + //////////////////////////////////////////////////////////////////////////// 1.45 + // Invokers 1.46 + 1.47 + function changeIframeSrc(aIdentifier, aURL) 1.48 + { 1.49 + this.DOMNode = getNode(aIdentifier); 1.50 + 1.51 + this.eventSeq = [ 1.52 + new invokerChecker(EVENT_REORDER, getAccessible(this.DOMNode)), 1.53 + new asyncInvokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getIframeDoc) 1.54 + ]; 1.55 + 1.56 + this.invoke = function changeIframeSrc_invoke() 1.57 + { 1.58 + this.DOMNode.src = aURL; 1.59 + } 1.60 + 1.61 + this.finalCheck = function changeIframeSrc_finalCheck() 1.62 + { 1.63 + var accTree = { 1.64 + role: ROLE_INTERNAL_FRAME, 1.65 + children: [ 1.66 + { 1.67 + role: ROLE_DOCUMENT, 1.68 + name: aURL == "about:" ? "About:" : aURL 1.69 + } 1.70 + ] 1.71 + }; 1.72 + 1.73 + testAccessibleTree(this.DOMNode, accTree); 1.74 + } 1.75 + 1.76 + this.getID = function changeIframeSrc_getID() 1.77 + { 1.78 + return "change iframe src on " + aURL; 1.79 + } 1.80 + 1.81 + function getIframeDoc() 1.82 + { 1.83 + return getAccessible(getNode(aIdentifier).contentDocument); 1.84 + } 1.85 + } 1.86 + 1.87 + const kHide = 1; 1.88 + const kShow = 2; 1.89 + const kRemove = 3; 1.90 + function morphIFrame(aIdentifier, aAction) 1.91 + { 1.92 + this.DOMNode = getNode(aIdentifier); 1.93 + this.IFrameContainerDOMNode = this.DOMNode.parentNode; 1.94 + 1.95 + this.eventSeq = []; 1.96 + 1.97 + var checker = null; 1.98 + if (aAction == kShow) 1.99 + checker = new invokerChecker(EVENT_SHOW, this.DOMNode); 1.100 + else 1.101 + checker = new invokerChecker(EVENT_HIDE, this.DOMNode); 1.102 + this.eventSeq.push(checker); 1.103 + 1.104 + var reorderChecker = 1.105 + new invokerChecker(EVENT_REORDER, this.IFrameContainerDOMNode); 1.106 + this.eventSeq.push(reorderChecker); 1.107 + 1.108 + this.invoke = function morphIFrame_invoke() 1.109 + { 1.110 + if (aAction == kHide) { 1.111 + this.DOMNode.style.display = "none"; 1.112 + } else if (aAction == kShow) { 1.113 + this.DOMNode.style.display = "block"; 1.114 + } else { 1.115 + this.IFrameContainerDOMNode.removeChild(this.DOMNode); 1.116 + } 1.117 + } 1.118 + 1.119 + this.finalCheck = function morphIFrame_finalCheck() 1.120 + { 1.121 + var accTree = { 1.122 + role: ROLE_SECTION, 1.123 + children: (aAction == kHide || aAction == kRemove) ? [ ] : 1.124 + [ 1.125 + { 1.126 + role: ROLE_INTERNAL_FRAME, 1.127 + children: [ 1.128 + { role: ROLE_DOCUMENT } 1.129 + ] 1.130 + } 1.131 + ] 1.132 + }; 1.133 + 1.134 + testAccessibleTree(this.IFrameContainerDOMNode, accTree); 1.135 + } 1.136 + 1.137 + this.getID = function morphIFrame_getID() 1.138 + { 1.139 + if (aAction == kRemove) 1.140 + return "remove iframe"; 1.141 + 1.142 + return "change display style of iframe to " + 1.143 + ((aAction == kHide) ? "none" : "block"); 1.144 + } 1.145 + } 1.146 + 1.147 + function makeIFrameVisible(aID) 1.148 + { 1.149 + this.DOMNode = getNode(aID); 1.150 + 1.151 + this.eventSeq = [ 1.152 + new invokerChecker(EVENT_REORDER, this.DOMNode.parentNode) 1.153 + ]; 1.154 + 1.155 + this.invoke = function makeIFrameVisible_invoke() 1.156 + { 1.157 + this.DOMNode.style.visibility = "visible"; 1.158 + } 1.159 + 1.160 + this.getID = function makeIFrameVisible_getID() 1.161 + { 1.162 + return "The accessible for DOM document loaded before it's shown shouldn't have busy state."; 1.163 + } 1.164 + } 1.165 + 1.166 + function openDialogWnd(aURL) 1.167 + { 1.168 + // Get application root accessible. 1.169 + var docAcc = getAccessible(document); 1.170 + while (docAcc) { 1.171 + this.mRootAcc = docAcc; 1.172 + try { 1.173 + docAcc = docAcc.parent; 1.174 + } catch (e) { 1.175 + ok(false, "Can't get parent for " + prettyName(docAcc)); 1.176 + throw e; 1.177 + } 1.178 + } 1.179 + 1.180 + this.eventSeq = [ 1.181 + new invokerChecker(EVENT_REORDER, this.mRootAcc) 1.182 + ]; 1.183 + 1.184 + this.invoke = function openDialogWnd_invoke() 1.185 + { 1.186 + this.mDialog = window.openDialog(aURL); 1.187 + } 1.188 + 1.189 + this.finalCheck = function openDialogWnd_finalCheck() 1.190 + { 1.191 + this.finalCheckImpl(); 1.192 + } 1.193 + 1.194 + this.finalCheckImpl = function openDialogWnd_finalCheckImpl() 1.195 + { 1.196 + var accTree = { 1.197 + role: ROLE_APP_ROOT, 1.198 + children: [ 1.199 + { 1.200 + role: ROLE_CHROME_WINDOW 1.201 + }, 1.202 + { 1.203 + role: ROLE_CHROME_WINDOW 1.204 + }, 1.205 + { 1.206 + role: ROLE_CHROME_WINDOW 1.207 + }, 1.208 + { 1.209 + role: ROLE_CHROME_WINDOW 1.210 + } 1.211 + ] 1.212 + }; 1.213 + 1.214 + testAccessibleTree(this.mRootAcc, accTree); 1.215 + 1.216 + var dlgDoc = this.mDialog.document; 1.217 + ok(isAccessibleInCache(dlgDoc), 1.218 + "The document accessible for '" + aURL + "' is not in cache!"); 1.219 + 1.220 + this.mDialog.close(); 1.221 + 1.222 + // close() is asynchronous. 1.223 + SimpleTest.executeSoon(function() { 1.224 + ok(!isAccessibleInCache(dlgDoc), 1.225 + "The document accessible for '" + aURL + "' is in cache still!"); 1.226 + }); 1.227 + } 1.228 + 1.229 + this.getID = function openDialogWnd_getID() 1.230 + { 1.231 + return "open dialog '" + aURL + "'"; 1.232 + } 1.233 + } 1.234 + 1.235 + function openWndShutdownDoc() 1.236 + { 1.237 + this.__proto__ = 1.238 + new openDialogWnd("../events/docload_wnd.html"); 1.239 + 1.240 + var thisObj = this; 1.241 + var docChecker = { 1.242 + type: EVENT_HIDE, 1.243 + get target() 1.244 + { 1.245 + var iframe = this.invoker.mDialog.document.getElementById("iframe"); 1.246 + this.invoker.iframeDoc = iframe.contentDocument; 1.247 + return iframe; 1.248 + }, 1.249 + get targetDescr() 1.250 + { 1.251 + return "inner iframe of docload_wnd.html document"; 1.252 + }, 1.253 + invoker: thisObj 1.254 + }; 1.255 + 1.256 + this.eventSeq.push(docChecker); 1.257 + 1.258 + this.finalCheck = function openWndShutdownDoc_finalCheck() 1.259 + { 1.260 + // After timeout after event hide for iframe was handled the document 1.261 + // accessible for iframe's document is in cache still. 1.262 + ok(!isAccessibleInCache(this.iframeDoc), 1.263 + "The document accessible for iframe is in cache still after iframe hide!"); 1.264 + 1.265 + this.finalCheckImpl(); 1.266 + 1.267 + // After the window is closed all alive subdocument accessibles should 1.268 + // be shut down. 1.269 + ok(!isAccessibleInCache(this.iframeDoc), 1.270 + "The document accessible for iframe is in cache still!"); 1.271 + } 1.272 + } 1.273 + 1.274 + //////////////////////////////////////////////////////////////////////////// 1.275 + // Do tests 1.276 + 1.277 + var gQueue = null; 1.278 + 1.279 + // Debug stuff. 1.280 + // gA11yEventDumpID = "eventdump"; 1.281 + //gA11yEventDumpToConsole = true; 1.282 + 1.283 + function doTests() 1.284 + { 1.285 + gQueue = new eventQueue(); 1.286 + 1.287 + gQueue.push(new changeIframeSrc("iframe", "about:")); 1.288 + gQueue.push(new changeIframeSrc("iframe", "about:buildconfig")); 1.289 + gQueue.push(new morphIFrame("iframe", kHide)); 1.290 + gQueue.push(new morphIFrame("iframe", kShow)); 1.291 + gQueue.push(new morphIFrame("iframe", kRemove)); 1.292 + gQueue.push(new makeIFrameVisible("iframe2")); 1.293 + gQueue.push(new openDialogWnd("about:")); 1.294 + gQueue.push(new openWndShutdownDoc()); 1.295 + 1.296 + gQueue.onFinish = doLastCallTests; 1.297 + 1.298 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.299 + } 1.300 + 1.301 + function doLastCallTests() 1.302 + { 1.303 + ////////////////////////////////////////////////////////////////////////// 1.304 + // makeIFrameVisible() test, part2 1.305 + 1.306 + // The document shouldn't have busy state (the DOM document was loaded 1.307 + // before its accessible was created). Do this test lately to make sure 1.308 + // the content of document accessible was created initially, prior to this 1.309 + // the document accessible keeps busy state. The initial creation happens 1.310 + // asynchronously after document creation, there are no events we could 1.311 + // use to catch it. 1.312 + var iframeDoc = getAccessible("iframe2").firstChild; 1.313 + testStates(iframeDoc, 0, 0, STATE_BUSY); 1.314 + } 1.315 + 1.316 + SimpleTest.waitForExplicitFinish(); 1.317 + addA11yLoadEvent(doTests); 1.318 + </script> 1.319 +</head> 1.320 + 1.321 +<body> 1.322 + 1.323 + <a target="_blank" 1.324 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=420845" 1.325 + title="Fire event_reorder on any embedded frames/iframes whos document has just loaded"> 1.326 + Mozilla Bug 420845 1.327 + </a><br> 1.328 + <a target="_blank" 1.329 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=506206" 1.330 + title="Fire event_reorder application root accessible"> 1.331 + Mozilla Bug 506206 1.332 + </a><br> 1.333 + <a target="_blank" 1.334 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103" 1.335 + title="Reorganize accessible document handling"> 1.336 + Mozilla Bug 566103 1.337 + </a><br> 1.338 + <a target="_blank" 1.339 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=571459" 1.340 + title="Shutdown document accessible when presshell goes away"> 1.341 + Mozilla Bug 571459 1.342 + </a> 1.343 + <a target="_blank" 1.344 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=658185" 1.345 + title="The DOM document loaded before it's shown shouldn't have busy state"> 1.346 + Mozilla Bug 658185 1.347 + </a> 1.348 + <a target="_blank" 1.349 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165" 1.350 + title="Fire document load events on iframes too"> 1.351 + Mozilla Bug 754165 1.352 + </a> 1.353 + 1.354 + <p id="display"></p> 1.355 + <div id="content" style="display: none"></div> 1.356 + <pre id="test"> 1.357 + </pre> 1.358 + 1.359 + <div id="testContainer"><iframe id="iframe"></iframe></div> 1.360 + <div id="testContainer2"><iframe id="iframe2" src="about:" style="visibility: hidden;"></iframe></div> 1.361 + <div id="eventdump"></div> 1.362 +</body> 1.363 +</html>