accessible/tests/mochitest/text.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 ////////////////////////////////////////////////////////////////////////////////
michael@0 2 // Public
michael@0 3
michael@0 4 const BOUNDARY_CHAR = nsIAccessibleText.BOUNDARY_CHAR;
michael@0 5 const BOUNDARY_WORD_START = nsIAccessibleText.BOUNDARY_WORD_START;
michael@0 6 const BOUNDARY_WORD_END = nsIAccessibleText.BOUNDARY_WORD_END;
michael@0 7 const BOUNDARY_LINE_START = nsIAccessibleText.BOUNDARY_LINE_START;
michael@0 8 const BOUNDARY_LINE_END = nsIAccessibleText.BOUNDARY_LINE_END;
michael@0 9
michael@0 10 const kTextEndOffset = nsIAccessibleText.TEXT_OFFSET_END_OF_TEXT;
michael@0 11 const kCaretOffset = nsIAccessibleText.TEXT_OFFSET_CARET;
michael@0 12
michael@0 13 const kTodo = 1; // a test is expected to fail
michael@0 14 const kOk = 2; // a test doesn't fail
michael@0 15
michael@0 16 /**
michael@0 17 * Test characterCount for the given array of accessibles.
michael@0 18 *
michael@0 19 * @param aCount [in] the expected character count
michael@0 20 * @param aIDs [in] array of accessible identifiers to test
michael@0 21 * @param aTodoFlag [in, optional] either kOk or kTodo
michael@0 22 */
michael@0 23 function testCharacterCount(aIDs, aCount, aTodoFlag)
michael@0 24 {
michael@0 25 var ids = (aIDs instanceof Array) ? aIDs : [ aIDs ];
michael@0 26 var isFunc = (aTodoFlag == kTodo) ? todo_is : is;
michael@0 27 for (var i = 0; i < ids.length; i++) {
michael@0 28 var textacc = getAccessible(ids[i], [nsIAccessibleText]);
michael@0 29 isFunc(textacc.characterCount, aCount,
michael@0 30 "Wrong character count for " + prettyName(ids[i]));
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 /**
michael@0 35 * Test text between two given offsets.
michael@0 36 *
michael@0 37 * @param aIDs [in] an array of accessible IDs to test
michael@0 38 * @param aStartOffset [in] the start offset within the text to test
michael@0 39 * @param aEndOffset [in] the end offset up to which the text is tested
michael@0 40 * @param aText [in] the expected result from the test
michael@0 41 * @param aTodoFlag [in, optional] either kOk or kTodo
michael@0 42 */
michael@0 43 function testText(aIDs, aStartOffset, aEndOffset, aText, aTodoFlag)
michael@0 44 {
michael@0 45 var ids = (aIDs instanceof Array) ? aIDs : [ aIDs ];
michael@0 46 var isFunc = (aTodoFlag == kTodo) ? todo_is : is;
michael@0 47 for (var i = 0; i < ids.length; i++) {
michael@0 48 var acc = getAccessible(ids[i], nsIAccessibleText);
michael@0 49 try {
michael@0 50 isFunc(acc.getText(aStartOffset, aEndOffset), aText,
michael@0 51 "getText: wrong text between start and end offsets '" +
michael@0 52 aStartOffset + "', '" + aEndOffset + " for '" +
michael@0 53 prettyName(ids[i]) + "'");
michael@0 54 } catch (e) {
michael@0 55 ok(false,
michael@0 56 "getText fails between start and end offsets '" + aStartOffset +
michael@0 57 "', '" + aEndOffset + " for '" + prettyName(ids[i]) + "'");
michael@0 58 }
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 /**
michael@0 63 * Test password text between two given offsets
michael@0 64 *
michael@0 65 * @param aIDs [in] an array of accessible IDs to test
michael@0 66 * @param aStartOffset [in] the start offset within the text to test
michael@0 67 * @param aEndOffset [in] the end offset up to which the text is tested
michael@0 68 * @param aText [in] the expected result from the test
michael@0 69 *
michael@0 70 * @note All this function does is test that getText doe snot expose the
michael@0 71 * password text itself, but something else.
michael@0 72 */
michael@0 73 function testPasswordText(aIDs, aStartOffset, aEndOffset, aText)
michael@0 74 {
michael@0 75 for (var i = 0; i < aIDs.length; i++)
michael@0 76 {
michael@0 77 var acc = getAccessible(aIDs[i], nsIAccessibleText);
michael@0 78 try {
michael@0 79 isnot(acc.getText(aStartOffset, aEndOffset), aText,
michael@0 80 "getText: plain text between start and end offsets '" + aStartOffset +
michael@0 81 "', '" + aEndOffset + " for '" + prettyName(aIDs[i]) + "'");
michael@0 82 } catch (e) {
michael@0 83 ok(false,
michael@0 84 "getText fails between start and end offsets '" + aStartOffset +
michael@0 85 "', '" + aEndOffset + " for '" + prettyName(aIDs[i]) + "'");
michael@0 86 }
michael@0 87 }
michael@0 88 }
michael@0 89
michael@0 90 /**
michael@0 91 * Test getTextAtOffset for BOUNDARY_CHAR over different elements.
michael@0 92 *
michael@0 93 * @param aIDs [in] the accessible identifier or array of accessible
michael@0 94 * identifiers
michael@0 95 * @param aOffset [in] the offset to get a character at it
michael@0 96 * @param aChar [in] the expected character
michael@0 97 * @param aStartOffset [in] expected start offset of the character
michael@0 98 * @param aEndOffset [in] expected end offset of the character
michael@0 99 */
michael@0 100 function testCharAtOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
michael@0 101 {
michael@0 102 var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
michael@0 103 for (var i = 0; i < IDs.length; i++) {
michael@0 104 var acc = getAccessible(IDs[i], nsIAccessibleText);
michael@0 105 testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
michael@0 106 aChar, aStartOffset, aEndOffset,
michael@0 107 kOk, kOk, kOk,
michael@0 108 acc.getTextAtOffset, "getTextAtOffset ");
michael@0 109 }
michael@0 110 }
michael@0 111
michael@0 112 /**
michael@0 113 * Test getTextAtOffset function over different elements.
michael@0 114 *
michael@0 115 * @param aIDs [in] ID or array of IDs
michael@0 116 * @param aBoundaryType [in] boundary type for text to be retrieved
michael@0 117 * @param aTestList [in] array of sets:
michael@0 118 * offset1 and offset2 defining the offset range
michael@0 119 * the text in the range
michael@0 120 * start offset of the text in the range
michael@0 121 * end offset of the text in the range
michael@0 122 *
michael@0 123 * or
michael@0 124 *
michael@0 125 * @param aOffset [in] the offset to get the text at
michael@0 126 * @param aBoundaryType [in] Boundary type for text to be retrieved
michael@0 127 * @param aText [in] expected return text for getTextAtOffset
michael@0 128 * @param aStartOffset [in] expected return start offset for getTextAtOffset
michael@0 129 * @param aEndOffset [in] expected return end offset for getTextAtOffset
michael@0 130 * @param ... [in] list of ids or list of tuples made of:
michael@0 131 * element identifier
michael@0 132 * kTodo or kOk for returned text
michael@0 133 * kTodo or kOk for returned start offset
michael@0 134 * kTodo or kOk for returned offset result
michael@0 135 */
michael@0 136 function testTextAtOffset()
michael@0 137 {
michael@0 138 testTextSuperHelper("getTextAtOffset", arguments);
michael@0 139 }
michael@0 140
michael@0 141 /**
michael@0 142 * Test getTextAfterOffset for BOUNDARY_CHAR over different elements.
michael@0 143 *
michael@0 144 * @param aIDs [in] the accessible identifier or array of accessible
michael@0 145 * identifiers
michael@0 146 * @param aOffset [in] the offset to get a character after it
michael@0 147 * @param aChar [in] the expected character
michael@0 148 * @param aStartOffset [in] expected start offset of the character
michael@0 149 * @param aEndOffset [in] expected end offset of the character
michael@0 150 */
michael@0 151 function testCharAfterOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
michael@0 152 {
michael@0 153 var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
michael@0 154 for (var i = 0; i < IDs.length; i++) {
michael@0 155 var acc = getAccessible(IDs[i], nsIAccessibleText);
michael@0 156 testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
michael@0 157 aChar, aStartOffset, aEndOffset,
michael@0 158 kOk, kOk, kOk,
michael@0 159 acc.getTextAfterOffset, "getTextAfterOffset ");
michael@0 160 }
michael@0 161 }
michael@0 162
michael@0 163 /**
michael@0 164 * Test getTextAfterOffset function over different elements
michael@0 165 *
michael@0 166 * @param aIDs [in] ID or array of IDs
michael@0 167 * @param aBoundaryType [in] boundary type for text to be retrieved
michael@0 168 * @param aTestList [in] array of sets:
michael@0 169 * offset1 and offset2 defining the offset range
michael@0 170 * the text in the range
michael@0 171 * start offset of the text in the range
michael@0 172 * end offset of the text in the range
michael@0 173 *
michael@0 174 * or
michael@0 175 *
michael@0 176 * @param aOffset [in] the offset to get the text after
michael@0 177 * @param aBoundaryType [in] Boundary type for text to be retrieved
michael@0 178 * @param aText [in] expected return text for getTextAfterOffset
michael@0 179 * @param aStartOffset [in] expected return start offset for getTextAfterOffset
michael@0 180 * @param aEndOffset [in] expected return end offset for getTextAfterOffset
michael@0 181 * @param ... [in] list of ids or list of tuples made of:
michael@0 182 * element identifier
michael@0 183 * kTodo or kOk for returned text
michael@0 184 * kTodo or kOk for returned start offset
michael@0 185 * kTodo or kOk for returned offset result
michael@0 186 */
michael@0 187 function testTextAfterOffset(aOffset, aBoundaryType,
michael@0 188 aText, aStartOffset, aEndOffset)
michael@0 189 {
michael@0 190 testTextSuperHelper("getTextAfterOffset", arguments);
michael@0 191 }
michael@0 192
michael@0 193 /**
michael@0 194 * Test getTextBeforeOffset for BOUNDARY_CHAR over different elements.
michael@0 195 *
michael@0 196 * @param aIDs [in] the accessible identifier or array of accessible
michael@0 197 * identifiers
michael@0 198 * @param aOffset [in] the offset to get a character before it
michael@0 199 * @param aChar [in] the expected character
michael@0 200 * @param aStartOffset [in] expected start offset of the character
michael@0 201 * @param aEndOffset [in] expected end offset of the character
michael@0 202 */
michael@0 203 function testCharBeforeOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
michael@0 204 {
michael@0 205 var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
michael@0 206 for (var i = 0; i < IDs.length; i++) {
michael@0 207 var acc = getAccessible(IDs[i], nsIAccessibleText);
michael@0 208 testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
michael@0 209 aChar, aStartOffset, aEndOffset,
michael@0 210 kOk, kOk, kOk,
michael@0 211 acc.getTextBeforeOffset, "getTextBeforeOffset ");
michael@0 212 }
michael@0 213 }
michael@0 214
michael@0 215 /**
michael@0 216 * Test getTextBeforeOffset function over different elements
michael@0 217 *
michael@0 218 * @param aIDs [in] ID or array of IDs
michael@0 219 * @param aBoundaryType [in] boundary type for text to be retrieved
michael@0 220 * @param aTestList [in] array of sets:
michael@0 221 * offset1 and offset2 defining the offset range
michael@0 222 * the text in the range
michael@0 223 * start offset of the text in the range
michael@0 224 * end offset of the text in the range
michael@0 225 *
michael@0 226 * or
michael@0 227 *
michael@0 228 * @param aOffset [in] the offset to get the text before
michael@0 229 * @param aBoundaryType [in] Boundary type for text to be retrieved
michael@0 230 * @param aText [in] expected return text for getTextBeforeOffset
michael@0 231 * @param aStartOffset [in] expected return start offset for getTextBeforeOffset
michael@0 232 * @param aEndOffset [in] expected return end offset for getTextBeforeOffset
michael@0 233 * @param ... [in] list of ids or list of tuples made of:
michael@0 234 * element identifier
michael@0 235 * kTodo or kOk for returned text
michael@0 236 * kTodo or kOk for returned start offset
michael@0 237 * kTodo or kOk for returned offset result
michael@0 238 */
michael@0 239 function testTextBeforeOffset(aOffset, aBoundaryType,
michael@0 240 aText, aStartOffset, aEndOffset)
michael@0 241 {
michael@0 242 testTextSuperHelper("getTextBeforeOffset", arguments);
michael@0 243 }
michael@0 244
michael@0 245 /**
michael@0 246 * Test word count for an element.
michael@0 247 *
michael@0 248 * @param aElement [in] element identifier
michael@0 249 * @param aCount [in] Expected word count
michael@0 250 * @param aToDoFlag [in] kTodo or kOk for returned text
michael@0 251 */
michael@0 252 function testWordCount(aElement, aCount, aToDoFlag)
michael@0 253 {
michael@0 254 var isFunc = (aToDoFlag == kTodo) ? todo_is : is;
michael@0 255 var acc = getAccessible(aElement, nsIAccessibleText);
michael@0 256 var startOffsetObj = {}, endOffsetObj = {};
michael@0 257 var length = acc.characterCount;
michael@0 258 var offset = 0;
michael@0 259 var wordCount = 0;
michael@0 260 while (true) {
michael@0 261 var text = acc.getTextAtOffset(offset, BOUNDARY_WORD_START,
michael@0 262 startOffsetObj, endOffsetObj);
michael@0 263 if (offset >= length)
michael@0 264 break;
michael@0 265
michael@0 266 wordCount++;
michael@0 267 offset = endOffsetObj.value;
michael@0 268 }
michael@0 269 isFunc(wordCount, aCount,
michael@0 270 "wrong words count for '" + acc.getText(0, -1) + "': " + wordCount +
michael@0 271 " in " + prettyName(aElement));
michael@0 272 }
michael@0 273
michael@0 274 /**
michael@0 275 * Test word at a position for an element.
michael@0 276 *
michael@0 277 * @param aElement [in] element identifier
michael@0 278 * @param aWordIndex [in] index of the word to test
michael@0 279 * @param aText [in] expected text for that word
michael@0 280 * @param aToDoFlag [in] kTodo or kOk for returned text
michael@0 281 */
michael@0 282 function testWordAt(aElement, aWordIndex, aText, aToDoFlag)
michael@0 283 {
michael@0 284 var isFunc = (aToDoFlag == kTodo) ? todo_is : is;
michael@0 285 var acc = getAccessible(aElement, nsIAccessibleText);
michael@0 286
michael@0 287 var textLength = acc.characterCount;
michael@0 288 var wordIdx = aWordIndex;
michael@0 289 var startOffsetObj = { value: 0 }, endOffsetObj = { value: 0 };
michael@0 290 for (offset = 0; offset < textLength; offset = endOffsetObj.value) {
michael@0 291 acc.getTextAtOffset(offset, BOUNDARY_WORD_START,
michael@0 292 startOffsetObj, endOffsetObj);
michael@0 293
michael@0 294 wordIdx--;
michael@0 295 if (wordIdx < 0)
michael@0 296 break;
michael@0 297 }
michael@0 298
michael@0 299 if (wordIdx >= 0) {
michael@0 300 ok(false,
michael@0 301 "the given word index '" + aWordIndex + "' exceeds words amount in " +
michael@0 302 prettyName(aElement));
michael@0 303
michael@0 304 return;
michael@0 305 }
michael@0 306
michael@0 307 var startWordOffset = startOffsetObj.value;
michael@0 308 var endWordOffset = endOffsetObj.value;
michael@0 309
michael@0 310 // Calculate the end word offset.
michael@0 311 acc.getTextAtOffset(endOffsetObj.value, BOUNDARY_WORD_END,
michael@0 312 startOffsetObj, endOffsetObj);
michael@0 313 if (startOffsetObj.value != textLength)
michael@0 314 endWordOffset = startOffsetObj.value
michael@0 315
michael@0 316 if (endWordOffset <= startWordOffset) {
michael@0 317 todo(false,
michael@0 318 "wrong start and end offset for word at index '" + aWordIndex + "': " +
michael@0 319 " of text '" + acc.getText(0, -1) + "' in " + prettyName(aElement));
michael@0 320
michael@0 321 return;
michael@0 322 }
michael@0 323
michael@0 324 text = acc.getText(startWordOffset, endWordOffset);
michael@0 325 isFunc(text, aText, "wrong text for word at index '" + aWordIndex + "': " +
michael@0 326 " of text '" + acc.getText(0, -1) + "' in " + prettyName(aElement));
michael@0 327 }
michael@0 328
michael@0 329 /**
michael@0 330 * Test words in a element.
michael@0 331 *
michael@0 332 * @param aElement [in] element identifier
michael@0 333 * @param aWords [in] array of expected words
michael@0 334 * @param aToDoFlag [in, optional] kTodo or kOk for returned text
michael@0 335 */
michael@0 336 function testWords(aElement, aWords, aToDoFlag)
michael@0 337 {
michael@0 338 if (aToDoFlag == null)
michael@0 339 aToDoFlag = kOk;
michael@0 340
michael@0 341 testWordCount(aElement, aWords.length, aToDoFlag);
michael@0 342
michael@0 343 for (var i = 0; i < aWords.length; i++) {
michael@0 344 testWordAt(aElement, i, aWords[i], aToDoFlag);
michael@0 345 }
michael@0 346 }
michael@0 347
michael@0 348 /**
michael@0 349 * Remove all selections.
michael@0 350 *
michael@0 351 * @param aID [in] Id, DOM node, or acc obj
michael@0 352 */
michael@0 353 function cleanTextSelections(aID)
michael@0 354 {
michael@0 355 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 356
michael@0 357 while (acc.selectionCount > 0)
michael@0 358 acc.removeSelection(0);
michael@0 359 }
michael@0 360
michael@0 361 /**
michael@0 362 * Test addSelection method.
michael@0 363 *
michael@0 364 * @param aID [in] Id, DOM node, or acc obj
michael@0 365 * @param aStartOffset [in] start offset for the new selection
michael@0 366 * @param aEndOffset [in] end offset for the new selection
michael@0 367 * @param aSelectionsCount [in] expected number of selections after addSelection
michael@0 368 */
michael@0 369 function testTextAddSelection(aID, aStartOffset, aEndOffset, aSelectionsCount)
michael@0 370 {
michael@0 371 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 372 var text = acc.getText(0, -1);
michael@0 373
michael@0 374 acc.addSelection(aStartOffset, aEndOffset);
michael@0 375
michael@0 376 ok(acc.selectionCount, aSelectionsCount,
michael@0 377 text + ": failed to add selection from offset '" + aStartOffset +
michael@0 378 "' to offset '" + aEndOffset + "': selectionCount after");
michael@0 379 }
michael@0 380
michael@0 381 /**
michael@0 382 * Test removeSelection method.
michael@0 383 *
michael@0 384 * @param aID [in] Id, DOM node, or acc obj
michael@0 385 * @param aSelectionIndex [in] index of the selection to be removed
michael@0 386 * @param aSelectionsCount [in] expected number of selections after
michael@0 387 * removeSelection
michael@0 388 */
michael@0 389 function testTextRemoveSelection(aID, aSelectionIndex, aSelectionsCount)
michael@0 390 {
michael@0 391 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 392 var text = acc.getText(0, -1);
michael@0 393
michael@0 394 acc.removeSelection(aSelectionIndex);
michael@0 395
michael@0 396 ok(acc.selectionCount, aSelectionsCount,
michael@0 397 text + ": failed to remove selection at index '" +
michael@0 398 aSelectionIndex + "': selectionCount after");
michael@0 399 }
michael@0 400
michael@0 401 /**
michael@0 402 * Test setSelectionBounds method.
michael@0 403 *
michael@0 404 * @param aID [in] Id, DOM node, or acc obj
michael@0 405 * @param aStartOffset [in] new start offset for the selection
michael@0 406 * @param aEndOffset [in] new end offset for the selection
michael@0 407 * @param aSelectionIndex [in] index of the selection to set
michael@0 408 * @param aSelectionsCount [in] expected number of selections after
michael@0 409 * setSelectionBounds
michael@0 410 */
michael@0 411 function testTextSetSelection(aID, aStartOffset, aEndOffset,
michael@0 412 aSelectionIndex, aSelectionsCount)
michael@0 413 {
michael@0 414 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 415 var text = acc.getText(0, -1);
michael@0 416
michael@0 417 acc.setSelectionBounds(aSelectionIndex, aStartOffset, aEndOffset);
michael@0 418
michael@0 419 is(acc.selectionCount, aSelectionsCount,
michael@0 420 text + ": failed to set selection at index '" +
michael@0 421 aSelectionIndex + "': selectionCount after");
michael@0 422 }
michael@0 423
michael@0 424 /**
michael@0 425 * Test selectionCount method.
michael@0 426 *
michael@0 427 * @param aID [in] Id, DOM node, or acc obj
michael@0 428 * @param aCount [in] expected selection count
michael@0 429 */
michael@0 430 function testTextSelectionCount(aID, aCount)
michael@0 431 {
michael@0 432 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 433 var text = acc.getText(0, -1);
michael@0 434
michael@0 435 is(acc.selectionCount, aCount, text + ": wrong selectionCount: ");
michael@0 436 }
michael@0 437
michael@0 438 /**
michael@0 439 * Test getSelectionBounds method.
michael@0 440 *
michael@0 441 * @param aID [in] Id, DOM node, or acc obj
michael@0 442 * @param aStartOffset [in] expected start offset for the selection
michael@0 443 * @param aEndOffset [in] expected end offset for the selection
michael@0 444 * @param aSelectionIndex [in] index of the selection to get
michael@0 445 */
michael@0 446 function testTextGetSelection(aID, aStartOffset, aEndOffset, aSelectionIndex)
michael@0 447 {
michael@0 448 var acc = getAccessible(aID, [nsIAccessibleText]);
michael@0 449 var text = acc.getText(0, -1);
michael@0 450
michael@0 451 var startObj = {}, endObj = {};
michael@0 452 acc.getSelectionBounds(aSelectionIndex, startObj, endObj);
michael@0 453
michael@0 454 is(startObj.value, aStartOffset, text + ": wrong start offset for index '" +
michael@0 455 aSelectionIndex + "'");
michael@0 456 is(endObj.value, aEndOffset, text + ": wrong end offset for index '" +
michael@0 457 aSelectionIndex + "'");
michael@0 458 }
michael@0 459
michael@0 460 function testTextRange(aRange, aStartContainer, aStartOffset,
michael@0 461 aEndContainer, aEndOffset)
michael@0 462 {
michael@0 463 is(aRange.startContainer, getAccessible(aStartContainer),
michael@0 464 "Wrong start container");
michael@0 465 is(aRange.startOffset, aStartOffset,
michael@0 466 "Wrong start offset");
michael@0 467 is(aRange.endContainer, getAccessible(aEndContainer),
michael@0 468 "Wrong end container");
michael@0 469 is(aRange.endOffset, aEndOffset,
michael@0 470 "Wrong end offset");
michael@0 471 }
michael@0 472
michael@0 473 ////////////////////////////////////////////////////////////////////////////////
michael@0 474 // Private
michael@0 475
michael@0 476 function testTextSuperHelper(aFuncName, aArgs)
michael@0 477 {
michael@0 478 // List of tests.
michael@0 479 if (aArgs[2] instanceof Array) {
michael@0 480 var ids = (aArgs[0] instanceof Array) ? aArgs[0] : [ aArgs[0] ];
michael@0 481 var boundaryType = aArgs[1];
michael@0 482 var list = aArgs[2];
michael@0 483 for (var i = 0; i < list.length; i++) {
michael@0 484 var offset1 = list[i][0], offset2 = list[i][1];
michael@0 485 var text = list[i][2], startOffset = list[i][3], endOffset = list[i][4];
michael@0 486 var failureList = list[i][5];
michael@0 487 for (var offset = offset1; offset <= offset2; offset++) {
michael@0 488 for (var idIdx = 0; idIdx < ids.length; idIdx++) {
michael@0 489 var id = ids[idIdx];
michael@0 490
michael@0 491 var flagOk1 = kOk, flagOk2 = kOk, flagOk3 = kOk;
michael@0 492 if (failureList) {
michael@0 493 for (var fIdx = 0; fIdx < failureList.length; fIdx++) {
michael@0 494 if (offset == failureList[fIdx][0] && id == failureList[fIdx][1]) {
michael@0 495 flagOk1 = failureList[fIdx][2];
michael@0 496 flagOk2 = failureList[fIdx][3];
michael@0 497 flagOk3 = failureList[fIdx][4];
michael@0 498 break;
michael@0 499 }
michael@0 500 }
michael@0 501 }
michael@0 502
michael@0 503 var acc = getAccessible(id, nsIAccessibleText);
michael@0 504 testTextHelper(id, offset, boundaryType,
michael@0 505 text, startOffset, endOffset,
michael@0 506 flagOk1, flagOk2, flagOk3,
michael@0 507 acc[aFuncName], aFuncName + " ");
michael@0 508 }
michael@0 509 }
michael@0 510 }
michael@0 511 return;
michael@0 512 }
michael@0 513
michael@0 514 // Test at single offset. List of IDs.
michael@0 515 var offset = aArgs[0];
michael@0 516 var boundaryType = aArgs[1];
michael@0 517 var text = aArgs[2];
michael@0 518 var startOffset = aArgs[3];
michael@0 519 var endOffset = aArgs[4];
michael@0 520 if (aArgs[5] instanceof Array) {
michael@0 521 var ids = aArgs[5];
michael@0 522 for (var i = 0; i < ids.length; i++) {
michael@0 523 var acc = getAccessible(ids[i], nsIAccessibleText);
michael@0 524 testTextHelper(ids[i], offset, boundaryType,
michael@0 525 text, startOffset, endOffset,
michael@0 526 kOk, kOk, kOk,
michael@0 527 acc[aFuncName], aFuncName + " ");
michael@0 528 }
michael@0 529
michael@0 530 return;
michael@0 531 }
michael@0 532
michael@0 533 // Each ID is tested separately.
michael@0 534 for (var i = 5; i < aArgs.length; i = i + 4) {
michael@0 535 var ID = aArgs[i];
michael@0 536 var acc = getAccessible(ID, nsIAccessibleText);
michael@0 537 var toDoFlag1 = aArgs[i + 1];
michael@0 538 var toDoFlag2 = aArgs[i + 2];
michael@0 539 var toDoFlag3 = aArgs[i + 3];
michael@0 540
michael@0 541 testTextHelper(ID, offset, boundaryType,
michael@0 542 text, startOffset, endOffset,
michael@0 543 toDoFlag1, toDoFlag2, toDoFlag3,
michael@0 544 acc[aFuncName], aFuncName + " ");
michael@0 545 }
michael@0 546 }
michael@0 547
michael@0 548 function testTextHelper(aID, aOffset, aBoundaryType,
michael@0 549 aText, aStartOffset, aEndOffset,
michael@0 550 aToDoFlag1, aToDoFlag2, aToDoFlag3,
michael@0 551 aTextFunc, aTextFuncName)
michael@0 552 {
michael@0 553 var exceptionFlag = aToDoFlag1 == undefined ||
michael@0 554 aToDoFlag2 == undefined ||
michael@0 555 aToDoFlag3 == undefined;
michael@0 556
michael@0 557 var startMsg = aTextFuncName + "(" + boundaryToString(aBoundaryType) + "): ";
michael@0 558 var endMsg = ", id: " + prettyName(aID) + ";";
michael@0 559
michael@0 560 try {
michael@0 561 var startOffsetObj = {}, endOffsetObj = {};
michael@0 562 var text = aTextFunc(aOffset, aBoundaryType,
michael@0 563 startOffsetObj, endOffsetObj);
michael@0 564
michael@0 565 if (exceptionFlag) {
michael@0 566 ok(false, startMsg + "no expected failure at offset " + aOffset + endMsg);
michael@0 567 return;
michael@0 568 }
michael@0 569
michael@0 570 var isFunc1 = (aToDoFlag1 == kTodo) ? todo : ok;
michael@0 571 var isFunc2 = (aToDoFlag2 == kTodo) ? todo : ok;
michael@0 572 var isFunc3 = (aToDoFlag3 == kTodo) ? todo : ok;
michael@0 573
michael@0 574 isFunc1(text == aText,
michael@0 575 startMsg + "wrong text " +
michael@0 576 "(got '" + text + "', expected: '" + aText + "')" +
michael@0 577 ", offset: " + aOffset + endMsg);
michael@0 578 isFunc2(startOffsetObj.value == aStartOffset,
michael@0 579 startMsg + "wrong start offset" +
michael@0 580 "(got '" + startOffsetObj.value + "', expected: '" + aStartOffset + "')" +
michael@0 581 ", offset: " + aOffset + endMsg);
michael@0 582 isFunc3(endOffsetObj.value == aEndOffset,
michael@0 583 startMsg + "wrong end offset" +
michael@0 584 "(got '" + endOffsetObj.value + "', expected: '" + aEndOffset + "')" +
michael@0 585 ", offset: " + aOffset + endMsg);
michael@0 586
michael@0 587 } catch (e) {
michael@0 588 var okFunc = exceptionFlag ? todo : ok;
michael@0 589 okFunc(false, startMsg + "failed at offset " + aOffset + endMsg +
michael@0 590 ", exception: " + e);
michael@0 591 }
michael@0 592 }
michael@0 593
michael@0 594 function boundaryToString(aBoundaryType)
michael@0 595 {
michael@0 596 switch (aBoundaryType) {
michael@0 597 case BOUNDARY_CHAR:
michael@0 598 return "char";
michael@0 599 case BOUNDARY_WORD_START:
michael@0 600 return "word start";
michael@0 601 case BOUNDARY_WORD_END:
michael@0 602 return "word end";
michael@0 603 case BOUNDARY_LINE_START:
michael@0 604 return "line start";
michael@0 605 case BOUNDARY_LINE_END:
michael@0 606 return "line end";
michael@0 607 }
michael@0 608 }

mercurial