Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 4 | type="text/css"?> |
michael@0 | 5 | |
michael@0 | 6 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 7 | title="Accessibility Loading Document Events Test."> |
michael@0 | 8 | |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 11 | <script type="application/javascript" |
michael@0 | 12 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 13 | |
michael@0 | 14 | <script type="application/javascript" |
michael@0 | 15 | src="../common.js"></script> |
michael@0 | 16 | <script type="application/javascript" |
michael@0 | 17 | src="../role.js"></script> |
michael@0 | 18 | <script type="application/javascript" |
michael@0 | 19 | src="../states.js"></script> |
michael@0 | 20 | <script type="application/javascript" |
michael@0 | 21 | src="../events.js"></script> |
michael@0 | 22 | <script type="application/javascript" |
michael@0 | 23 | src="../browser.js"></script> |
michael@0 | 24 | |
michael@0 | 25 | <script type="application/javascript"> |
michael@0 | 26 | <![CDATA[ |
michael@0 | 27 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 28 | // Invoker checkers. |
michael@0 | 29 | function stateBusyChecker(aIsEnabled) |
michael@0 | 30 | { |
michael@0 | 31 | this.type = EVENT_STATE_CHANGE; |
michael@0 | 32 | this.__defineGetter__("target", currentTabDocument); |
michael@0 | 33 | |
michael@0 | 34 | this.check = function stateBusyChecker_check(aEvent) |
michael@0 | 35 | { |
michael@0 | 36 | var event = null; |
michael@0 | 37 | try { |
michael@0 | 38 | var event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent); |
michael@0 | 39 | } catch (e) { |
michael@0 | 40 | ok(false, "State change event was expected"); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (!event) |
michael@0 | 44 | return; |
michael@0 | 45 | |
michael@0 | 46 | is(event.state, STATE_BUSY, "Wrong state of statechange event."); |
michael@0 | 47 | is(event.isEnabled, aIsEnabled, |
michael@0 | 48 | "Wrong value of state of statechange event"); |
michael@0 | 49 | |
michael@0 | 50 | testStates(event.accessible, (aIsEnabled ? STATE_BUSY : 0), 0, |
michael@0 | 51 | (aIsEnabled ? 0 : STATE_BUSY), 0); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function documentReloadChecker(aIsFromUserInput) |
michael@0 | 56 | { |
michael@0 | 57 | this.type = EVENT_DOCUMENT_RELOAD; |
michael@0 | 58 | this.__defineGetter__("target", currentTabDocument); |
michael@0 | 59 | |
michael@0 | 60 | this.check = function documentReloadChecker_check(aEvent) |
michael@0 | 61 | { |
michael@0 | 62 | is(aEvent.isFromUserInput, aIsFromUserInput, |
michael@0 | 63 | "Wrong value of isFromUserInput"); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 68 | // Invokers. |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Load URI. |
michael@0 | 72 | */ |
michael@0 | 73 | function loadURIInvoker(aURI) |
michael@0 | 74 | { |
michael@0 | 75 | this.invoke = function loadURIInvoker_invoke() |
michael@0 | 76 | { |
michael@0 | 77 | tabBrowser().loadURI(aURI); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | this.eventSeq = [ |
michael@0 | 81 | // We don't expect state change event for busy true since things happen |
michael@0 | 82 | // quickly and it's coalesced. |
michael@0 | 83 | new asyncInvokerChecker(EVENT_REORDER, currentBrowser), |
michael@0 | 84 | new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), |
michael@0 | 85 | new stateBusyChecker(false) |
michael@0 | 86 | ]; |
michael@0 | 87 | |
michael@0 | 88 | this.getID = function loadURIInvoker_getID() |
michael@0 | 89 | { |
michael@0 | 90 | return "load uri " + aURI; |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Load the document having sub document. No document loading events for |
michael@0 | 96 | * nested document. |
michael@0 | 97 | */ |
michael@0 | 98 | function loadNestedDocURIInvoker(aNestedDocURI) |
michael@0 | 99 | { |
michael@0 | 100 | this.__proto__ = new loadURIInvoker(aNestedDocURI); |
michael@0 | 101 | |
michael@0 | 102 | // Remove reorder event checker since the event is likely coalesced by |
michael@0 | 103 | // reorder event on Firefox UI (refer to bug 759670 for details). |
michael@0 | 104 | this.eventSeq.shift(); |
michael@0 | 105 | |
michael@0 | 106 | this.unexpectedEventSeq = [ |
michael@0 | 107 | new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, getNestedDoc), |
michael@0 | 108 | new invokerChecker(EVENT_STATE_CHANGE, getNestedDoc) |
michael@0 | 109 | ]; |
michael@0 | 110 | |
michael@0 | 111 | function getNestedDoc() |
michael@0 | 112 | { |
michael@0 | 113 | var iframeNodes = currentTabDocument().getElementsByTagName("iframe"); |
michael@0 | 114 | return iframeNodes && iframeNodes.length > 0 ? |
michael@0 | 115 | iframeNodes[0].firstChild : null; |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Reload the page by F5 (isFromUserInput flag is true). |
michael@0 | 121 | */ |
michael@0 | 122 | function userReloadInvoker() |
michael@0 | 123 | { |
michael@0 | 124 | this.invoke = function userReloadInvoker_invoke() |
michael@0 | 125 | { |
michael@0 | 126 | synthesizeKey("VK_F5", {}, browserWindow()); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | this.eventSeq = [ |
michael@0 | 130 | new documentReloadChecker(true), |
michael@0 | 131 | new asyncInvokerChecker(EVENT_REORDER, currentBrowser), |
michael@0 | 132 | new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), |
michael@0 | 133 | new stateBusyChecker(false) |
michael@0 | 134 | ]; |
michael@0 | 135 | |
michael@0 | 136 | this.getID = function userReloadInvoker_getID() |
michael@0 | 137 | { |
michael@0 | 138 | return "user reload page"; |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Reload the page (isFromUserInput flag is false). |
michael@0 | 144 | */ |
michael@0 | 145 | function reloadInvoker() |
michael@0 | 146 | { |
michael@0 | 147 | this.invoke = function reloadInvoker_invoke() |
michael@0 | 148 | { |
michael@0 | 149 | tabBrowser().reload(); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | this.eventSeq = [ |
michael@0 | 153 | new documentReloadChecker(false), |
michael@0 | 154 | new asyncInvokerChecker(EVENT_REORDER, currentBrowser), |
michael@0 | 155 | new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), |
michael@0 | 156 | new stateBusyChecker(false) |
michael@0 | 157 | ]; |
michael@0 | 158 | |
michael@0 | 159 | this.getID = function reloadInvoker_getID() |
michael@0 | 160 | { |
michael@0 | 161 | return "reload page"; |
michael@0 | 162 | } |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | /** |
michael@0 | 166 | * Load wrong URI what results in error page loading. |
michael@0 | 167 | */ |
michael@0 | 168 | function loadErrorPageInvoker(aURL, aURLDescr) |
michael@0 | 169 | { |
michael@0 | 170 | this.invoke = function loadErrorPageInvoker_invoke() |
michael@0 | 171 | { |
michael@0 | 172 | tabBrowser().loadURI(aURL); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | this.eventSeq = [ |
michael@0 | 176 | // We don't expect state change for busy true, load stopped events since |
michael@0 | 177 | // things happen quickly and it's coalesced. |
michael@0 | 178 | new asyncInvokerChecker(EVENT_REORDER, currentBrowser), |
michael@0 | 179 | new invokerChecker(EVENT_DOCUMENT_LOAD_COMPLETE, currentTabDocument), |
michael@0 | 180 | new stateBusyChecker(false) |
michael@0 | 181 | ]; |
michael@0 | 182 | |
michael@0 | 183 | this.getID = function loadErrorPageInvoker_getID() |
michael@0 | 184 | { |
michael@0 | 185 | return "load error page: '" + aURLDescr + "'"; |
michael@0 | 186 | } |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 190 | // Tests |
michael@0 | 191 | |
michael@0 | 192 | //gA11yEventDumpToConsole = true; // debug |
michael@0 | 193 | //gA11yEventDumpFeature = "parentchain:reorder"; |
michael@0 | 194 | |
michael@0 | 195 | var gQueue = null; |
michael@0 | 196 | function doTests() |
michael@0 | 197 | { |
michael@0 | 198 | gQueue = new eventQueue(); |
michael@0 | 199 | |
michael@0 | 200 | var dataURL = |
michael@0 | 201 | "data:text/html,<html><body><iframe src='http://example.com'></iframe></body></html>"; |
michael@0 | 202 | gQueue.push(new loadNestedDocURIInvoker(dataURL)); |
michael@0 | 203 | |
michael@0 | 204 | gQueue.push(new loadURIInvoker("about:")); |
michael@0 | 205 | gQueue.push(new userReloadInvoker()); |
michael@0 | 206 | gQueue.push(new loadURIInvoker("about:mozilla")); |
michael@0 | 207 | gQueue.push(new reloadInvoker()); |
michael@0 | 208 | gQueue.push(new loadErrorPageInvoker("www.wronguri.wronguri", |
michael@0 | 209 | "Server not found")); |
michael@0 | 210 | gQueue.push(new loadErrorPageInvoker("https://nocert.example.com:443", |
michael@0 | 211 | "Untrusted Connection")); |
michael@0 | 212 | |
michael@0 | 213 | gQueue.onFinish = function() { closeBrowserWindow(); } |
michael@0 | 214 | gQueue.invoke(); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 218 | openBrowserWindow(doTests); |
michael@0 | 219 | ]]> |
michael@0 | 220 | </script> |
michael@0 | 221 | |
michael@0 | 222 | <vbox flex="1" style="overflow: auto;"> |
michael@0 | 223 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 224 | <a target="_blank" |
michael@0 | 225 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=566103" |
michael@0 | 226 | title=" reorganize accessible document handling"> |
michael@0 | 227 | Mozilla Bug 566103 |
michael@0 | 228 | </a> |
michael@0 | 229 | <a target="_blank" |
michael@0 | 230 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=754165" |
michael@0 | 231 | title="Fire document load events on iframes too"> |
michael@0 | 232 | Mozilla Bug 754165 |
michael@0 | 233 | </a> |
michael@0 | 234 | <p id="display"></p> |
michael@0 | 235 | <div id="content" style="display: none"> |
michael@0 | 236 | </div> |
michael@0 | 237 | <pre id="test"> |
michael@0 | 238 | </pre> |
michael@0 | 239 | </body> |
michael@0 | 240 | |
michael@0 | 241 | <vbox id="eventdump"></vbox> |
michael@0 | 242 | </vbox> |
michael@0 | 243 | </window> |