Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 2 | |
michael@0 | 3 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 4 | // Constants |
michael@0 | 5 | |
michael@0 | 6 | const PREFILTER_INVISIBLE = nsIAccessibleTraversalRule.PREFILTER_INVISIBLE; |
michael@0 | 7 | const PREFILTER_ARIA_HIDDEN = nsIAccessibleTraversalRule.PREFILTER_ARIA_HIDDEN; |
michael@0 | 8 | const PREFILTER_TRANSPARENT = nsIAccessibleTraversalRule.PREFILTER_TRANSPARENT; |
michael@0 | 9 | const FILTER_MATCH = nsIAccessibleTraversalRule.FILTER_MATCH; |
michael@0 | 10 | const FILTER_IGNORE = nsIAccessibleTraversalRule.FILTER_IGNORE; |
michael@0 | 11 | const FILTER_IGNORE_SUBTREE = nsIAccessibleTraversalRule.FILTER_IGNORE_SUBTREE; |
michael@0 | 12 | const CHAR_BOUNDARY = nsIAccessiblePivot.CHAR_BOUNDARY; |
michael@0 | 13 | const WORD_BOUNDARY = nsIAccessiblePivot.WORD_BOUNDARY; |
michael@0 | 14 | |
michael@0 | 15 | const NS_ERROR_NOT_IN_TREE = 0x80780026; |
michael@0 | 16 | const NS_ERROR_INVALID_ARG = 0x80070057; |
michael@0 | 17 | |
michael@0 | 18 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 19 | // Traversal rules |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * Rule object to traverse all focusable nodes and text nodes. |
michael@0 | 23 | */ |
michael@0 | 24 | var HeadersTraversalRule = |
michael@0 | 25 | { |
michael@0 | 26 | getMatchRoles: function(aRules) |
michael@0 | 27 | { |
michael@0 | 28 | aRules.value = [ROLE_HEADING]; |
michael@0 | 29 | return aRules.value.length; |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | preFilter: PREFILTER_INVISIBLE, |
michael@0 | 33 | |
michael@0 | 34 | match: function(aAccessible) |
michael@0 | 35 | { |
michael@0 | 36 | return FILTER_MATCH; |
michael@0 | 37 | }, |
michael@0 | 38 | |
michael@0 | 39 | QueryInterface: XPCOMUtils.generateQI([nsIAccessibleTraversalRule]) |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Traversal rule for all focusable nodes or leafs. |
michael@0 | 44 | */ |
michael@0 | 45 | var ObjectTraversalRule = |
michael@0 | 46 | { |
michael@0 | 47 | getMatchRoles: function(aRules) |
michael@0 | 48 | { |
michael@0 | 49 | aRules.value = []; |
michael@0 | 50 | return 0; |
michael@0 | 51 | }, |
michael@0 | 52 | |
michael@0 | 53 | preFilter: PREFILTER_INVISIBLE | PREFILTER_ARIA_HIDDEN | PREFILTER_TRANSPARENT, |
michael@0 | 54 | |
michael@0 | 55 | match: function(aAccessible) |
michael@0 | 56 | { |
michael@0 | 57 | var rv = FILTER_IGNORE; |
michael@0 | 58 | var role = aAccessible.role; |
michael@0 | 59 | if (hasState(aAccessible, STATE_FOCUSABLE) && |
michael@0 | 60 | (role != ROLE_DOCUMENT && role != ROLE_INTERNAL_FRAME)) |
michael@0 | 61 | rv = FILTER_IGNORE_SUBTREE | FILTER_MATCH; |
michael@0 | 62 | else if (aAccessible.childCount == 0 && |
michael@0 | 63 | role != ROLE_STATICTEXT && aAccessible.name.trim()) |
michael@0 | 64 | rv = FILTER_MATCH; |
michael@0 | 65 | |
michael@0 | 66 | return rv; |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | QueryInterface: XPCOMUtils.generateQI([nsIAccessibleTraversalRule]) |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 73 | // Virtual state invokers and checkers |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * A checker for virtual cursor changed events. |
michael@0 | 77 | */ |
michael@0 | 78 | function VCChangedChecker(aDocAcc, aIdOrNameOrAcc, aTextOffsets, aPivotMoveMethod) |
michael@0 | 79 | { |
michael@0 | 80 | this.__proto__ = new invokerChecker(EVENT_VIRTUALCURSOR_CHANGED, aDocAcc); |
michael@0 | 81 | |
michael@0 | 82 | this.match = function VCChangedChecker_check(aEvent) |
michael@0 | 83 | { |
michael@0 | 84 | var event = null; |
michael@0 | 85 | try { |
michael@0 | 86 | event = aEvent.QueryInterface(nsIAccessibleVirtualCursorChangeEvent); |
michael@0 | 87 | } catch (e) { |
michael@0 | 88 | return false; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | var expectedReason = VCChangedChecker.methodReasonMap[aPivotMoveMethod] || |
michael@0 | 92 | nsIAccessiblePivot.REASON_NONE; |
michael@0 | 93 | |
michael@0 | 94 | return event.reason == expectedReason; |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | this.check = function VCChangedChecker_check(aEvent) |
michael@0 | 98 | { |
michael@0 | 99 | SimpleTest.info("VCChangedChecker_check"); |
michael@0 | 100 | |
michael@0 | 101 | var event = null; |
michael@0 | 102 | try { |
michael@0 | 103 | event = aEvent.QueryInterface(nsIAccessibleVirtualCursorChangeEvent); |
michael@0 | 104 | } catch (e) { |
michael@0 | 105 | SimpleTest.ok(false, "Does not support correct interface: " + e); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | var position = aDocAcc.virtualCursor.position; |
michael@0 | 109 | var idMatches = position && position.DOMNode.id == aIdOrNameOrAcc; |
michael@0 | 110 | var nameMatches = position && position.name == aIdOrNameOrAcc; |
michael@0 | 111 | var accMatches = position == aIdOrNameOrAcc; |
michael@0 | 112 | |
michael@0 | 113 | SimpleTest.ok(idMatches || nameMatches || accMatches, "id or name matches", |
michael@0 | 114 | "expecting " + aIdOrNameOrAcc + ", got '" + |
michael@0 | 115 | prettyName(position)); |
michael@0 | 116 | |
michael@0 | 117 | if (aTextOffsets) { |
michael@0 | 118 | SimpleTest.is(aDocAcc.virtualCursor.startOffset, aTextOffsets[0], |
michael@0 | 119 | "wrong start offset"); |
michael@0 | 120 | SimpleTest.is(aDocAcc.virtualCursor.endOffset, aTextOffsets[1], |
michael@0 | 121 | "wrong end offset"); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | var prevPosAndOffset = VCChangedChecker. |
michael@0 | 125 | getPreviousPosAndOffset(aDocAcc.virtualCursor); |
michael@0 | 126 | |
michael@0 | 127 | if (prevPosAndOffset) { |
michael@0 | 128 | SimpleTest.is(event.oldAccessible, prevPosAndOffset.position, |
michael@0 | 129 | "previous position does not match"); |
michael@0 | 130 | SimpleTest.is(event.oldStartOffset, prevPosAndOffset.startOffset, |
michael@0 | 131 | "previous start offset does not match"); |
michael@0 | 132 | SimpleTest.is(event.oldEndOffset, prevPosAndOffset.endOffset, |
michael@0 | 133 | "previous end offset does not match"); |
michael@0 | 134 | } |
michael@0 | 135 | }; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | VCChangedChecker.prevPosAndOffset = {}; |
michael@0 | 139 | |
michael@0 | 140 | VCChangedChecker.storePreviousPosAndOffset = |
michael@0 | 141 | function storePreviousPosAndOffset(aPivot) |
michael@0 | 142 | { |
michael@0 | 143 | VCChangedChecker.prevPosAndOffset[aPivot] = |
michael@0 | 144 | {position: aPivot.position, |
michael@0 | 145 | startOffset: aPivot.startOffset, |
michael@0 | 146 | endOffset: aPivot.endOffset}; |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | VCChangedChecker.getPreviousPosAndOffset = |
michael@0 | 150 | function getPreviousPosAndOffset(aPivot) |
michael@0 | 151 | { |
michael@0 | 152 | return VCChangedChecker.prevPosAndOffset[aPivot]; |
michael@0 | 153 | }; |
michael@0 | 154 | |
michael@0 | 155 | VCChangedChecker.methodReasonMap = { |
michael@0 | 156 | 'moveNext': nsIAccessiblePivot.REASON_NEXT, |
michael@0 | 157 | 'movePrevious': nsIAccessiblePivot.REASON_PREV, |
michael@0 | 158 | 'moveFirst': nsIAccessiblePivot.REASON_FIRST, |
michael@0 | 159 | 'moveLast': nsIAccessiblePivot.REASON_LAST, |
michael@0 | 160 | 'setTextRange': nsIAccessiblePivot.REASON_TEXT, |
michael@0 | 161 | 'moveNextByText': nsIAccessiblePivot.REASON_TEXT, |
michael@0 | 162 | 'movePreviousByText': nsIAccessiblePivot.REASON_TEXT, |
michael@0 | 163 | 'moveToPoint': nsIAccessiblePivot.REASON_POINT |
michael@0 | 164 | }; |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Set a text range in the pivot and wait for virtual cursor change event. |
michael@0 | 168 | * |
michael@0 | 169 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 170 | * @param aTextAccessible [in] accessible to set to virtual cursor's position |
michael@0 | 171 | * @param aTextOffsets [in] start and end offsets of text range to set in |
michael@0 | 172 | * virtual cursor. |
michael@0 | 173 | */ |
michael@0 | 174 | function setVCRangeInvoker(aDocAcc, aTextAccessible, aTextOffsets) |
michael@0 | 175 | { |
michael@0 | 176 | this.invoke = function virtualCursorChangedInvoker_invoke() |
michael@0 | 177 | { |
michael@0 | 178 | VCChangedChecker. |
michael@0 | 179 | storePreviousPosAndOffset(aDocAcc.virtualCursor); |
michael@0 | 180 | SimpleTest.info(prettyName(aTextAccessible) + " " + aTextOffsets); |
michael@0 | 181 | aDocAcc.virtualCursor.setTextRange(aTextAccessible, |
michael@0 | 182 | aTextOffsets[0], |
michael@0 | 183 | aTextOffsets[1]); |
michael@0 | 184 | }; |
michael@0 | 185 | |
michael@0 | 186 | this.getID = function setVCRangeInvoker_getID() |
michael@0 | 187 | { |
michael@0 | 188 | return "Set offset in " + prettyName(aTextAccessible) + |
michael@0 | 189 | " to (" + aTextOffsets[0] + ", " + aTextOffsets[1] + ")"; |
michael@0 | 190 | }; |
michael@0 | 191 | |
michael@0 | 192 | this.eventSeq = [ |
michael@0 | 193 | new VCChangedChecker(aDocAcc, aTextAccessible, aTextOffsets, "setTextRange") |
michael@0 | 194 | ]; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Move the pivot and wait for virtual cursor change event. |
michael@0 | 199 | * |
michael@0 | 200 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 201 | * @param aPivotMoveMethod [in] method to test (ie. "moveNext", "moveFirst", etc.) |
michael@0 | 202 | * @param aRule [in] traversal rule object |
michael@0 | 203 | * @param aIdOrNameOrAcc [in] id, accessible or accessible name to expect |
michael@0 | 204 | * virtual cursor to land on after performing move method. |
michael@0 | 205 | * false if no move is expected. |
michael@0 | 206 | */ |
michael@0 | 207 | function setVCPosInvoker(aDocAcc, aPivotMoveMethod, aRule, aIdOrNameOrAcc) |
michael@0 | 208 | { |
michael@0 | 209 | var expectMove = (aIdOrNameOrAcc != false); |
michael@0 | 210 | this.invoke = function virtualCursorChangedInvoker_invoke() |
michael@0 | 211 | { |
michael@0 | 212 | VCChangedChecker. |
michael@0 | 213 | storePreviousPosAndOffset(aDocAcc.virtualCursor); |
michael@0 | 214 | if (aPivotMoveMethod && aRule) { |
michael@0 | 215 | var moved = aDocAcc.virtualCursor[aPivotMoveMethod](aRule); |
michael@0 | 216 | SimpleTest.is(!!moved, !!expectMove, |
michael@0 | 217 | "moved pivot with " + aPivotMoveMethod + |
michael@0 | 218 | " to " + aIdOrNameOrAcc); |
michael@0 | 219 | } else { |
michael@0 | 220 | aDocAcc.virtualCursor.position = getAccessible(aIdOrNameOrAcc); |
michael@0 | 221 | } |
michael@0 | 222 | }; |
michael@0 | 223 | |
michael@0 | 224 | this.getID = function setVCPosInvoker_getID() |
michael@0 | 225 | { |
michael@0 | 226 | return "Do " + (expectMove ? "" : "no-op ") + aPivotMoveMethod; |
michael@0 | 227 | }; |
michael@0 | 228 | |
michael@0 | 229 | if (expectMove) { |
michael@0 | 230 | this.eventSeq = [ |
michael@0 | 231 | new VCChangedChecker(aDocAcc, aIdOrNameOrAcc, null, aPivotMoveMethod) |
michael@0 | 232 | ]; |
michael@0 | 233 | } else { |
michael@0 | 234 | this.eventSeq = []; |
michael@0 | 235 | this.unexpectedEventSeq = [ |
michael@0 | 236 | new invokerChecker(EVENT_VIRTUALCURSOR_CHANGED, aDocAcc) |
michael@0 | 237 | ]; |
michael@0 | 238 | } |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | /** |
michael@0 | 242 | * Move the pivot by text and wait for virtual cursor change event. |
michael@0 | 243 | * |
michael@0 | 244 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 245 | * @param aPivotMoveMethod [in] method to test (ie. "moveNext", "moveFirst", etc.) |
michael@0 | 246 | * @param aBoundary [in] boundary constant |
michael@0 | 247 | * @param aTextOffsets [in] start and end offsets of text range to set in |
michael@0 | 248 | * virtual cursor. |
michael@0 | 249 | * @param aIdOrNameOrAcc [in] id, accessible or accessible name to expect |
michael@0 | 250 | * virtual cursor to land on after performing move method. |
michael@0 | 251 | * false if no move is expected. |
michael@0 | 252 | */ |
michael@0 | 253 | function setVCTextInvoker(aDocAcc, aPivotMoveMethod, aBoundary, aTextOffsets, aIdOrNameOrAcc) |
michael@0 | 254 | { |
michael@0 | 255 | var expectMove = (aIdOrNameOrAcc != false); |
michael@0 | 256 | this.invoke = function virtualCursorChangedInvoker_invoke() |
michael@0 | 257 | { |
michael@0 | 258 | VCChangedChecker.storePreviousPosAndOffset(aDocAcc.virtualCursor); |
michael@0 | 259 | SimpleTest.info(aDocAcc.virtualCursor.position); |
michael@0 | 260 | var moved = aDocAcc.virtualCursor[aPivotMoveMethod](aBoundary); |
michael@0 | 261 | SimpleTest.is(!!moved, !!expectMove, |
michael@0 | 262 | "moved pivot by text with " + aPivotMoveMethod + |
michael@0 | 263 | " to " + aIdOrNameOrAcc); |
michael@0 | 264 | }; |
michael@0 | 265 | |
michael@0 | 266 | this.getID = function setVCPosInvoker_getID() |
michael@0 | 267 | { |
michael@0 | 268 | return "Do " + (expectMove ? "" : "no-op ") + aPivotMoveMethod + " in " + |
michael@0 | 269 | prettyName(aIdOrNameOrAcc) + ", " + boundaryToString(aBoundary) + |
michael@0 | 270 | ", [" + aTextOffsets + "]"; |
michael@0 | 271 | }; |
michael@0 | 272 | |
michael@0 | 273 | if (expectMove) { |
michael@0 | 274 | this.eventSeq = [ |
michael@0 | 275 | new VCChangedChecker(aDocAcc, aIdOrNameOrAcc, aTextOffsets, aPivotMoveMethod) |
michael@0 | 276 | ]; |
michael@0 | 277 | } else { |
michael@0 | 278 | this.eventSeq = []; |
michael@0 | 279 | this.unexpectedEventSeq = [ |
michael@0 | 280 | new invokerChecker(EVENT_VIRTUALCURSOR_CHANGED, aDocAcc) |
michael@0 | 281 | ]; |
michael@0 | 282 | } |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | |
michael@0 | 286 | /** |
michael@0 | 287 | * Move the pivot to the position under the point. |
michael@0 | 288 | * |
michael@0 | 289 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 290 | * @param aX [in] screen x coordinate |
michael@0 | 291 | * @param aY [in] screen y coordinate |
michael@0 | 292 | * @param aIgnoreNoMatch [in] don't unset position if no object was found at |
michael@0 | 293 | * point. |
michael@0 | 294 | * @param aRule [in] traversal rule object |
michael@0 | 295 | * @param aIdOrNameOrAcc [in] id, accessible or accessible name to expect |
michael@0 | 296 | * virtual cursor to land on after performing move method. |
michael@0 | 297 | * false if no move is expected. |
michael@0 | 298 | */ |
michael@0 | 299 | function moveVCCoordInvoker(aDocAcc, aX, aY, aIgnoreNoMatch, |
michael@0 | 300 | aRule, aIdOrNameOrAcc) |
michael@0 | 301 | { |
michael@0 | 302 | var expectMove = (aIdOrNameOrAcc != false); |
michael@0 | 303 | this.invoke = function virtualCursorChangedInvoker_invoke() |
michael@0 | 304 | { |
michael@0 | 305 | VCChangedChecker. |
michael@0 | 306 | storePreviousPosAndOffset(aDocAcc.virtualCursor); |
michael@0 | 307 | var moved = aDocAcc.virtualCursor.moveToPoint(aRule, aX, aY, |
michael@0 | 308 | aIgnoreNoMatch); |
michael@0 | 309 | SimpleTest.ok((expectMove && moved) || (!expectMove && !moved), |
michael@0 | 310 | "moved pivot"); |
michael@0 | 311 | }; |
michael@0 | 312 | |
michael@0 | 313 | this.getID = function setVCPosInvoker_getID() |
michael@0 | 314 | { |
michael@0 | 315 | return "Do " + (expectMove ? "" : "no-op ") + "moveToPoint " + aIdOrNameOrAcc; |
michael@0 | 316 | }; |
michael@0 | 317 | |
michael@0 | 318 | if (expectMove) { |
michael@0 | 319 | this.eventSeq = [ |
michael@0 | 320 | new VCChangedChecker(aDocAcc, aIdOrNameOrAcc, null, 'moveToPoint') |
michael@0 | 321 | ]; |
michael@0 | 322 | } else { |
michael@0 | 323 | this.eventSeq = []; |
michael@0 | 324 | this.unexpectedEventSeq = [ |
michael@0 | 325 | new invokerChecker(EVENT_VIRTUALCURSOR_CHANGED, aDocAcc) |
michael@0 | 326 | ]; |
michael@0 | 327 | } |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | /** |
michael@0 | 331 | * Change the pivot modalRoot |
michael@0 | 332 | * |
michael@0 | 333 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 334 | * @param aModalRootAcc [in] accessible of the modal root, or null |
michael@0 | 335 | * @param aExpectedResult [in] error result expected. 0 if expecting success |
michael@0 | 336 | */ |
michael@0 | 337 | function setModalRootInvoker(aDocAcc, aModalRootAcc, aExpectedResult) |
michael@0 | 338 | { |
michael@0 | 339 | this.invoke = function setModalRootInvoker_invoke() |
michael@0 | 340 | { |
michael@0 | 341 | var errorResult = 0; |
michael@0 | 342 | try { |
michael@0 | 343 | aDocAcc.virtualCursor.modalRoot = aModalRootAcc; |
michael@0 | 344 | } catch (x) { |
michael@0 | 345 | SimpleTest.ok( |
michael@0 | 346 | x.result, "Unexpected exception when changing modal root: " + x); |
michael@0 | 347 | errorResult = x.result; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | SimpleTest.is(errorResult, aExpectedResult, |
michael@0 | 351 | "Did not get expected result when changing modalRoot"); |
michael@0 | 352 | }; |
michael@0 | 353 | |
michael@0 | 354 | this.getID = function setModalRootInvoker_getID() |
michael@0 | 355 | { |
michael@0 | 356 | return "Set modalRoot to " + prettyName(aModalRootAcc); |
michael@0 | 357 | }; |
michael@0 | 358 | |
michael@0 | 359 | this.eventSeq = []; |
michael@0 | 360 | this.unexpectedEventSeq = [ |
michael@0 | 361 | new invokerChecker(EVENT_VIRTUALCURSOR_CHANGED, aDocAcc) |
michael@0 | 362 | ]; |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | /** |
michael@0 | 366 | * Add invokers to a queue to test a rule and an expected sequence of element ids |
michael@0 | 367 | * or accessible names for that rule in the given document. |
michael@0 | 368 | * |
michael@0 | 369 | * @param aQueue [in] event queue in which to push invoker sequence. |
michael@0 | 370 | * @param aDocAcc [in] the managing document of the virtual cursor we are |
michael@0 | 371 | * testing |
michael@0 | 372 | * @param aRule [in] the traversal rule to use in the invokers |
michael@0 | 373 | * @param aModalRoot [in] a modal root to use in this traversal sequence |
michael@0 | 374 | * @param aSequence [in] a sequence of accessible names or element ids to expect |
michael@0 | 375 | * with the given rule in the given document |
michael@0 | 376 | */ |
michael@0 | 377 | function queueTraversalSequence(aQueue, aDocAcc, aRule, aModalRoot, aSequence) |
michael@0 | 378 | { |
michael@0 | 379 | aDocAcc.virtualCursor.position = null; |
michael@0 | 380 | |
michael@0 | 381 | // Add modal root (if any) |
michael@0 | 382 | aQueue.push(new setModalRootInvoker(aDocAcc, aModalRoot, 0)); |
michael@0 | 383 | |
michael@0 | 384 | aQueue.push(new setVCPosInvoker(aDocAcc, "moveFirst", aRule, aSequence[0])); |
michael@0 | 385 | |
michael@0 | 386 | for (var i = 1; i < aSequence.length; i++) { |
michael@0 | 387 | var invoker = |
michael@0 | 388 | new setVCPosInvoker(aDocAcc, "moveNext", aRule, aSequence[i]); |
michael@0 | 389 | aQueue.push(invoker); |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | // No further more matches for given rule, expect no virtual cursor changes. |
michael@0 | 393 | aQueue.push(new setVCPosInvoker(aDocAcc, "moveNext", aRule, false)); |
michael@0 | 394 | |
michael@0 | 395 | for (var i = aSequence.length-2; i >= 0; i--) { |
michael@0 | 396 | var invoker = |
michael@0 | 397 | new setVCPosInvoker(aDocAcc, "movePrevious", aRule, aSequence[i]); |
michael@0 | 398 | aQueue.push(invoker); |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | // No previous more matches for given rule, expect no virtual cursor changes. |
michael@0 | 402 | aQueue.push(new setVCPosInvoker(aDocAcc, "movePrevious", aRule, false)); |
michael@0 | 403 | |
michael@0 | 404 | aQueue.push(new setVCPosInvoker(aDocAcc, "moveLast", aRule, |
michael@0 | 405 | aSequence[aSequence.length - 1])); |
michael@0 | 406 | |
michael@0 | 407 | // No further more matches for given rule, expect no virtual cursor changes. |
michael@0 | 408 | aQueue.push(new setVCPosInvoker(aDocAcc, "moveNext", aRule, false)); |
michael@0 | 409 | |
michael@0 | 410 | aQueue.push(new setVCPosInvoker(aDocAcc, "moveFirst", aRule, aSequence[0])); |
michael@0 | 411 | |
michael@0 | 412 | // No previous more matches for given rule, expect no virtual cursor changes. |
michael@0 | 413 | aQueue.push(new setVCPosInvoker(aDocAcc, "movePrevious", aRule, false)); |
michael@0 | 414 | |
michael@0 | 415 | // Remove modal root (if any). |
michael@0 | 416 | aQueue.push(new setModalRootInvoker(aDocAcc, null, 0)); |
michael@0 | 417 | } |
michael@0 | 418 | |
michael@0 | 419 | /** |
michael@0 | 420 | * A checker for removing an accessible while the virtual cursor is on it. |
michael@0 | 421 | */ |
michael@0 | 422 | function removeVCPositionChecker(aDocAcc, aHiddenParentAcc) |
michael@0 | 423 | { |
michael@0 | 424 | this.__proto__ = new invokerChecker(EVENT_REORDER, aHiddenParentAcc); |
michael@0 | 425 | |
michael@0 | 426 | this.check = function removeVCPositionChecker_check(aEvent) { |
michael@0 | 427 | var errorResult = 0; |
michael@0 | 428 | try { |
michael@0 | 429 | aDocAcc.virtualCursor.moveNext(ObjectTraversalRule); |
michael@0 | 430 | } catch (x) { |
michael@0 | 431 | errorResult = x.result; |
michael@0 | 432 | } |
michael@0 | 433 | SimpleTest.is( |
michael@0 | 434 | errorResult, NS_ERROR_NOT_IN_TREE, |
michael@0 | 435 | "Expecting NOT_IN_TREE error when moving pivot from invalid position."); |
michael@0 | 436 | }; |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | /** |
michael@0 | 440 | * Put the virtual cursor's position on an object, and then remove it. |
michael@0 | 441 | * |
michael@0 | 442 | * @param aDocAcc [in] document that manages the virtual cursor |
michael@0 | 443 | * @param aPosNode [in] DOM node to hide after virtual cursor's position is |
michael@0 | 444 | * set to it. |
michael@0 | 445 | */ |
michael@0 | 446 | function removeVCPositionInvoker(aDocAcc, aPosNode) |
michael@0 | 447 | { |
michael@0 | 448 | this.accessible = getAccessible(aPosNode); |
michael@0 | 449 | this.invoke = function removeVCPositionInvoker_invoke() |
michael@0 | 450 | { |
michael@0 | 451 | aDocAcc.virtualCursor.position = this.accessible; |
michael@0 | 452 | aPosNode.parentNode.removeChild(aPosNode); |
michael@0 | 453 | }; |
michael@0 | 454 | |
michael@0 | 455 | this.getID = function removeVCPositionInvoker_getID() |
michael@0 | 456 | { |
michael@0 | 457 | return "Bring virtual cursor to accessible, and remove its DOM node."; |
michael@0 | 458 | }; |
michael@0 | 459 | |
michael@0 | 460 | this.eventSeq = [ |
michael@0 | 461 | new removeVCPositionChecker(aDocAcc, this.accessible.parent) |
michael@0 | 462 | ]; |
michael@0 | 463 | } |
michael@0 | 464 | |
michael@0 | 465 | /** |
michael@0 | 466 | * A checker for removing the pivot root and then calling moveFirst, and |
michael@0 | 467 | * checking that an exception is thrown. |
michael@0 | 468 | */ |
michael@0 | 469 | function removeVCRootChecker(aPivot) |
michael@0 | 470 | { |
michael@0 | 471 | this.__proto__ = new invokerChecker(EVENT_REORDER, aPivot.root.parent); |
michael@0 | 472 | |
michael@0 | 473 | this.check = function removeVCRootChecker_check(aEvent) { |
michael@0 | 474 | var errorResult = 0; |
michael@0 | 475 | try { |
michael@0 | 476 | aPivot.moveLast(ObjectTraversalRule); |
michael@0 | 477 | } catch (x) { |
michael@0 | 478 | errorResult = x.result; |
michael@0 | 479 | } |
michael@0 | 480 | SimpleTest.is( |
michael@0 | 481 | errorResult, NS_ERROR_NOT_IN_TREE, |
michael@0 | 482 | "Expecting NOT_IN_TREE error when moving pivot from invalid position."); |
michael@0 | 483 | }; |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | /** |
michael@0 | 487 | * Create a pivot, remove its root, and perform an operation where the root is |
michael@0 | 488 | * needed. |
michael@0 | 489 | * |
michael@0 | 490 | * @param aRootNode [in] DOM node of which accessible will be the root of the |
michael@0 | 491 | * pivot. Should have more than one child. |
michael@0 | 492 | */ |
michael@0 | 493 | function removeVCRootInvoker(aRootNode) |
michael@0 | 494 | { |
michael@0 | 495 | this.pivot = gAccRetrieval.createAccessiblePivot(getAccessible(aRootNode)); |
michael@0 | 496 | this.invoke = function removeVCRootInvoker_invoke() |
michael@0 | 497 | { |
michael@0 | 498 | this.pivot.position = this.pivot.root.firstChild; |
michael@0 | 499 | aRootNode.parentNode.removeChild(aRootNode); |
michael@0 | 500 | }; |
michael@0 | 501 | |
michael@0 | 502 | this.getID = function removeVCRootInvoker_getID() |
michael@0 | 503 | { |
michael@0 | 504 | return "Remove root of pivot from tree."; |
michael@0 | 505 | }; |
michael@0 | 506 | |
michael@0 | 507 | this.eventSeq = [ |
michael@0 | 508 | new removeVCRootChecker(this.pivot) |
michael@0 | 509 | ]; |
michael@0 | 510 | } |
michael@0 | 511 | |
michael@0 | 512 | /** |
michael@0 | 513 | * A debug utility for writing proper sequences for queueTraversalSequence. |
michael@0 | 514 | */ |
michael@0 | 515 | function dumpTraversalSequence(aPivot, aRule) |
michael@0 | 516 | { |
michael@0 | 517 | var sequence = []; |
michael@0 | 518 | if (aPivot.moveFirst(aRule)) { |
michael@0 | 519 | do { |
michael@0 | 520 | sequence.push("'" + prettyName(aPivot.position) + "'"); |
michael@0 | 521 | } while (aPivot.moveNext(aRule)) |
michael@0 | 522 | } |
michael@0 | 523 | SimpleTest.info("\n[" + sequence.join(", ") + "]\n"); |
michael@0 | 524 | } |