1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/events/test_docload.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,243 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 + 1.9 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + title="Accessibility Loading Document Events Test."> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.14 + <script type="application/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.16 + 1.17 + <script type="application/javascript" 1.18 + src="../common.js"></script> 1.19 + <script type="application/javascript" 1.20 + src="../role.js"></script> 1.21 + <script type="application/javascript" 1.22 + src="../states.js"></script> 1.23 + <script type="application/javascript" 1.24 + src="../events.js"></script> 1.25 + <script type="application/javascript" 1.26 + src="../browser.js"></script> 1.27 + 1.28 + <script type="application/javascript"> 1.29 + <![CDATA[ 1.30 + //////////////////////////////////////////////////////////////////////////// 1.31 + // Invoker checkers. 1.32 + function stateBusyChecker(aIsEnabled) 1.33 + { 1.34 + this.type = EVENT_STATE_CHANGE; 1.35 + this.__defineGetter__("target", currentTabDocument); 1.36 + 1.37 + this.check = function stateBusyChecker_check(aEvent) 1.38 + { 1.39 + var event = null; 1.40 + try { 1.41 + var event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent); 1.42 + } catch (e) { 1.43 + ok(false, "State change event was expected"); 1.44 + } 1.45 + 1.46 + if (!event) 1.47 + return; 1.48 + 1.49 + is(event.state, STATE_BUSY, "Wrong state of statechange event."); 1.50 + is(event.isEnabled, aIsEnabled, 1.51 + "Wrong value of state of statechange event"); 1.52 + 1.53 + testStates(event.accessible, (aIsEnabled ? STATE_BUSY : 0), 0, 1.54 + (aIsEnabled ? 0 : STATE_BUSY), 0); 1.55 + } 1.56 + } 1.57 + 1.58 + function documentReloadChecker(aIsFromUserInput) 1.59 + { 1.60 + this.type = EVENT_DOCUMENT_RELOAD; 1.61 + this.__defineGetter__("target", currentTabDocument); 1.62 + 1.63 + this.check = function documentReloadChecker_check(aEvent) 1.64 + { 1.65 + is(aEvent.isFromUserInput, aIsFromUserInput, 1.66 + "Wrong value of isFromUserInput"); 1.67 + } 1.68 + } 1.69 + 1.70 + //////////////////////////////////////////////////////////////////////////// 1.71 + // Invokers. 1.72 + 1.73 + /** 1.74 + * Load URI. 1.75 + */ 1.76 + function loadURIInvoker(aURI) 1.77 + { 1.78 + this.invoke = function loadURIInvoker_invoke() 1.79 + { 1.80 + tabBrowser().loadURI(aURI); 1.81 + } 1.82 + 1.83 + this.eventSeq = [ 1.84 + // We don't expect state change event for busy true since things happen 1.85 + // quickly and it's coalesced. 1.86 + new asyncInvokerChecker(EVENT_REORDER, currentBrowser), 1.87 + new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), 1.88 + new stateBusyChecker(false) 1.89 + ]; 1.90 + 1.91 + this.getID = function loadURIInvoker_getID() 1.92 + { 1.93 + return "load uri " + aURI; 1.94 + } 1.95 + } 1.96 + 1.97 + /** 1.98 + * Load the document having sub document. No document loading events for 1.99 + * nested document. 1.100 + */ 1.101 + function loadNestedDocURIInvoker(aNestedDocURI) 1.102 + { 1.103 + this.__proto__ = new loadURIInvoker(aNestedDocURI); 1.104 + 1.105 + // Remove reorder event checker since the event is likely coalesced by 1.106 + // reorder event on Firefox UI (refer to bug 759670 for details). 1.107 + this.eventSeq.shift(); 1.108 + 1.109 + this.unexpectedEventSeq = [ 1.110 + new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getNestedDoc), 1.111 + new invokerChecker(EVENT_STATE_CHANGE, getNestedDoc) 1.112 + ]; 1.113 + 1.114 + function getNestedDoc() 1.115 + { 1.116 + var iframeNodes = currentTabDocument().getElementsByTagName("iframe"); 1.117 + return iframeNodes && iframeNodes.length > 0 ? 1.118 + iframeNodes[0].firstChild : null; 1.119 + } 1.120 + } 1.121 + 1.122 + /** 1.123 + * Reload the page by F5 (isFromUserInput flag is true). 1.124 + */ 1.125 + function userReloadInvoker() 1.126 + { 1.127 + this.invoke = function userReloadInvoker_invoke() 1.128 + { 1.129 + synthesizeKey("VK_F5", {}, browserWindow()); 1.130 + } 1.131 + 1.132 + this.eventSeq = [ 1.133 + new documentReloadChecker(true), 1.134 + new asyncInvokerChecker(EVENT_REORDER, currentBrowser), 1.135 + new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), 1.136 + new stateBusyChecker(false) 1.137 + ]; 1.138 + 1.139 + this.getID = function userReloadInvoker_getID() 1.140 + { 1.141 + return "user reload page"; 1.142 + } 1.143 + } 1.144 + 1.145 + /** 1.146 + * Reload the page (isFromUserInput flag is false). 1.147 + */ 1.148 + function reloadInvoker() 1.149 + { 1.150 + this.invoke = function reloadInvoker_invoke() 1.151 + { 1.152 + tabBrowser().reload(); 1.153 + } 1.154 + 1.155 + this.eventSeq = [ 1.156 + new documentReloadChecker(false), 1.157 + new asyncInvokerChecker(EVENT_REORDER, currentBrowser), 1.158 + new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), 1.159 + new stateBusyChecker(false) 1.160 + ]; 1.161 + 1.162 + this.getID = function reloadInvoker_getID() 1.163 + { 1.164 + return "reload page"; 1.165 + } 1.166 + } 1.167 + 1.168 + /** 1.169 + * Load wrong URI what results in error page loading. 1.170 + */ 1.171 + function loadErrorPageInvoker(aURL, aURLDescr) 1.172 + { 1.173 + this.invoke = function loadErrorPageInvoker_invoke() 1.174 + { 1.175 + tabBrowser().loadURI(aURL); 1.176 + } 1.177 + 1.178 + this.eventSeq = [ 1.179 + // We don't expect state change for busy true, load stopped events since 1.180 + // things happen quickly and it's coalesced. 1.181 + new asyncInvokerChecker(EVENT_REORDER, currentBrowser), 1.182 + new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), 1.183 + new stateBusyChecker(false) 1.184 + ]; 1.185 + 1.186 + this.getID = function loadErrorPageInvoker_getID() 1.187 + { 1.188 + return "load error page: '" + aURLDescr + "'"; 1.189 + } 1.190 + } 1.191 + 1.192 + //////////////////////////////////////////////////////////////////////////// 1.193 + // Tests 1.194 + 1.195 + //gA11yEventDumpToConsole = true; // debug 1.196 + //gA11yEventDumpFeature = "parentchain:reorder"; 1.197 + 1.198 + var gQueue = null; 1.199 + function doTests() 1.200 + { 1.201 + gQueue = new eventQueue(); 1.202 + 1.203 + var dataURL = 1.204 + "data:text/html,<html><body><iframe src='http://example.com'></iframe></body></html>"; 1.205 + gQueue.push(new loadNestedDocURIInvoker(dataURL)); 1.206 + 1.207 + gQueue.push(new loadURIInvoker("about:")); 1.208 + gQueue.push(new userReloadInvoker()); 1.209 + gQueue.push(new loadURIInvoker("about:mozilla")); 1.210 + gQueue.push(new reloadInvoker()); 1.211 + gQueue.push(new loadErrorPageInvoker("www.wronguri.wronguri", 1.212 + "Server not found")); 1.213 + gQueue.push(new loadErrorPageInvoker("https://nocert.example.com:443", 1.214 + "Untrusted Connection")); 1.215 + 1.216 + gQueue.onFinish = function() { closeBrowserWindow(); } 1.217 + gQueue.invoke(); 1.218 + } 1.219 + 1.220 + SimpleTest.waitForExplicitFinish(); 1.221 + openBrowserWindow(doTests); 1.222 + ]]> 1.223 + </script> 1.224 + 1.225 + <vbox flex="1" style="overflow: auto;"> 1.226 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.227 + <a target="_blank" 1.228 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103" 1.229 + title=" reorganize accessible document handling"> 1.230 + Mozilla Bug 566103 1.231 + </a> 1.232 + <a target="_blank" 1.233 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165" 1.234 + title="Fire document load events on iframes too"> 1.235 + Mozilla Bug 754165 1.236 + </a> 1.237 + <p id="display"></p> 1.238 + <div id="content" style="display: none"> 1.239 + </div> 1.240 + <pre id="test"> 1.241 + </pre> 1.242 + </body> 1.243 + 1.244 + <vbox id="eventdump"></vbox> 1.245 + </vbox> 1.246 +</window>