accessible/tests/mochitest/text.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/text.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,608 @@
     1.4 +////////////////////////////////////////////////////////////////////////////////
     1.5 +// Public
     1.6 +
     1.7 +const BOUNDARY_CHAR = nsIAccessibleText.BOUNDARY_CHAR;
     1.8 +const BOUNDARY_WORD_START = nsIAccessibleText.BOUNDARY_WORD_START;
     1.9 +const BOUNDARY_WORD_END = nsIAccessibleText.BOUNDARY_WORD_END;
    1.10 +const BOUNDARY_LINE_START = nsIAccessibleText.BOUNDARY_LINE_START;
    1.11 +const BOUNDARY_LINE_END = nsIAccessibleText.BOUNDARY_LINE_END;
    1.12 +
    1.13 +const kTextEndOffset = nsIAccessibleText.TEXT_OFFSET_END_OF_TEXT;
    1.14 +const kCaretOffset = nsIAccessibleText.TEXT_OFFSET_CARET;
    1.15 +
    1.16 +const kTodo = 1; // a test is expected to fail
    1.17 +const kOk = 2; // a test doesn't fail
    1.18 +
    1.19 +/**
    1.20 + * Test characterCount for the given array of accessibles.
    1.21 + *
    1.22 + * @param aCount    [in] the expected character count
    1.23 + * @param aIDs      [in] array of accessible identifiers to test
    1.24 + * @param aTodoFlag [in, optional] either kOk or kTodo
    1.25 + */
    1.26 +function testCharacterCount(aIDs, aCount, aTodoFlag)
    1.27 +{
    1.28 +  var ids = (aIDs instanceof Array) ? aIDs : [ aIDs ];
    1.29 +  var isFunc = (aTodoFlag == kTodo) ? todo_is : is;
    1.30 +  for (var i = 0; i < ids.length; i++) {
    1.31 +    var textacc = getAccessible(ids[i], [nsIAccessibleText]);
    1.32 +    isFunc(textacc.characterCount, aCount,
    1.33 +           "Wrong character count for " + prettyName(ids[i]));
    1.34 +  }
    1.35 +}
    1.36 +
    1.37 +/**
    1.38 + * Test text between two given offsets.
    1.39 + *
    1.40 + * @param aIDs          [in] an array of accessible IDs to test
    1.41 + * @param aStartOffset  [in] the start offset within the text to test
    1.42 + * @param aEndOffset    [in] the end offset up to which the text is tested
    1.43 + * @param aText         [in] the expected result from the test
    1.44 + * @param aTodoFlag     [in, optional] either kOk or kTodo
    1.45 + */
    1.46 +function testText(aIDs, aStartOffset, aEndOffset, aText, aTodoFlag)
    1.47 +{
    1.48 +  var ids = (aIDs instanceof Array) ? aIDs : [ aIDs ];
    1.49 +  var isFunc = (aTodoFlag == kTodo) ? todo_is : is;
    1.50 +  for (var i = 0; i < ids.length; i++) {
    1.51 +    var acc = getAccessible(ids[i], nsIAccessibleText);
    1.52 +    try {
    1.53 +      isFunc(acc.getText(aStartOffset, aEndOffset), aText,
    1.54 +             "getText: wrong text between start and end offsets '" +
    1.55 +             aStartOffset + "', '" + aEndOffset + " for '" +
    1.56 +             prettyName(ids[i]) + "'");
    1.57 +    } catch (e) {
    1.58 +      ok(false,
    1.59 +        "getText fails between start and end offsets '" + aStartOffset +
    1.60 +        "', '" + aEndOffset + " for '" + prettyName(ids[i]) + "'");
    1.61 +    }
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +/**
    1.66 + * Test password text between two given offsets
    1.67 + *
    1.68 + * @param aIDs          [in] an array of accessible IDs to test
    1.69 + * @param aStartOffset  [in] the start offset within the text to test
    1.70 + * @param aEndOffset    [in] the end offset up to which the text is tested
    1.71 + * @param aText         [in] the expected result from the test
    1.72 + *
    1.73 + * @note  All this function does is test that getText doe snot expose the
    1.74 + *        password text itself, but something else.
    1.75 + */
    1.76 +function testPasswordText(aIDs, aStartOffset, aEndOffset, aText)
    1.77 +{
    1.78 +  for (var i = 0; i < aIDs.length; i++)
    1.79 +  {
    1.80 +    var acc = getAccessible(aIDs[i], nsIAccessibleText);
    1.81 +    try {
    1.82 +      isnot(acc.getText(aStartOffset, aEndOffset), aText,
    1.83 +         "getText: plain text between start and end offsets '" + aStartOffset +
    1.84 +         "', '" + aEndOffset + " for '" + prettyName(aIDs[i]) + "'");
    1.85 +    } catch (e) {
    1.86 +      ok(false,
    1.87 +         "getText fails between start and end offsets '" + aStartOffset +
    1.88 +         "', '" + aEndOffset + " for '" + prettyName(aIDs[i]) + "'");
    1.89 +    }
    1.90 +  }
    1.91 +}
    1.92 +
    1.93 +/**
    1.94 + * Test getTextAtOffset for BOUNDARY_CHAR over different elements.
    1.95 + *
    1.96 + * @param aIDs          [in] the accessible identifier or array of accessible
    1.97 + *                        identifiers
    1.98 + * @param aOffset       [in] the offset to get a character at it
    1.99 + * @param aChar         [in] the expected character
   1.100 + * @param aStartOffset  [in] expected start offset of the character
   1.101 + * @param aEndOffset    [in] expected end offset of the character
   1.102 + */
   1.103 +function testCharAtOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
   1.104 +{
   1.105 +  var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
   1.106 +  for (var i = 0; i < IDs.length; i++) {
   1.107 +    var acc = getAccessible(IDs[i], nsIAccessibleText);
   1.108 +    testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
   1.109 +                   aChar, aStartOffset, aEndOffset,
   1.110 +                   kOk, kOk, kOk,
   1.111 +                   acc.getTextAtOffset, "getTextAtOffset ");
   1.112 +  }
   1.113 +}
   1.114 +
   1.115 +/**
   1.116 + * Test getTextAtOffset function over different elements.
   1.117 + *
   1.118 + * @param aIDs            [in] ID or array of IDs
   1.119 + * @param aBoundaryType   [in] boundary type for text to be retrieved
   1.120 + * @param aTestList       [in] array of sets:
   1.121 + *                              offset1 and offset2 defining the offset range
   1.122 + *                              the text in the range
   1.123 + *                              start offset of the text in the range
   1.124 + *                              end offset of the text in the range
   1.125 + *
   1.126 + * or
   1.127 + *
   1.128 + * @param aOffset         [in] the offset to get the text at
   1.129 + * @param aBoundaryType   [in] Boundary type for text to be retrieved
   1.130 + * @param aText           [in] expected return text for getTextAtOffset
   1.131 + * @param aStartOffset    [in] expected return start offset for getTextAtOffset
   1.132 + * @param aEndOffset      [in] expected return end offset for getTextAtOffset
   1.133 + * @param ...             [in] list of ids or list of tuples made of:
   1.134 + *                              element identifier
   1.135 + *                              kTodo or kOk for returned text
   1.136 + *                              kTodo or kOk for returned start offset
   1.137 + *                              kTodo or kOk for returned offset result
   1.138 + */
   1.139 +function testTextAtOffset()
   1.140 +{
   1.141 +  testTextSuperHelper("getTextAtOffset", arguments);
   1.142 +}
   1.143 +
   1.144 +/**
   1.145 + * Test getTextAfterOffset for BOUNDARY_CHAR over different elements.
   1.146 + *
   1.147 + * @param aIDs          [in] the accessible identifier or array of accessible
   1.148 + *                        identifiers
   1.149 + * @param aOffset       [in] the offset to get a character after it
   1.150 + * @param aChar         [in] the expected character
   1.151 + * @param aStartOffset  [in] expected start offset of the character
   1.152 + * @param aEndOffset    [in] expected end offset of the character
   1.153 + */
   1.154 +function testCharAfterOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
   1.155 +{
   1.156 +  var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
   1.157 +  for (var i = 0; i < IDs.length; i++) {
   1.158 +    var acc = getAccessible(IDs[i], nsIAccessibleText);
   1.159 +    testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
   1.160 +                   aChar, aStartOffset, aEndOffset,
   1.161 +                   kOk, kOk, kOk,
   1.162 +                   acc.getTextAfterOffset, "getTextAfterOffset ");
   1.163 +  }
   1.164 +}
   1.165 +
   1.166 +/**
   1.167 + * Test getTextAfterOffset function over different elements
   1.168 + *
   1.169 + * @param aIDs            [in] ID or array of IDs
   1.170 + * @param aBoundaryType   [in] boundary type for text to be retrieved
   1.171 + * @param aTestList       [in] array of sets:
   1.172 + *                              offset1 and offset2 defining the offset range
   1.173 + *                              the text in the range
   1.174 + *                              start offset of the text in the range
   1.175 + *                              end offset of the text in the range
   1.176 + *
   1.177 + * or
   1.178 + *
   1.179 + * @param aOffset         [in] the offset to get the text after
   1.180 + * @param aBoundaryType   [in] Boundary type for text to be retrieved
   1.181 + * @param aText           [in] expected return text for getTextAfterOffset
   1.182 + * @param aStartOffset    [in] expected return start offset for getTextAfterOffset
   1.183 + * @param aEndOffset      [in] expected return end offset for getTextAfterOffset
   1.184 + * @param ...             [in] list of ids or list of tuples made of:
   1.185 + *                              element identifier
   1.186 + *                              kTodo or kOk for returned text
   1.187 + *                              kTodo or kOk for returned start offset
   1.188 + *                              kTodo or kOk for returned offset result
   1.189 + */
   1.190 +function testTextAfterOffset(aOffset, aBoundaryType,
   1.191 +                             aText, aStartOffset, aEndOffset)
   1.192 +{
   1.193 +  testTextSuperHelper("getTextAfterOffset", arguments);
   1.194 +}
   1.195 +
   1.196 +/**
   1.197 + * Test getTextBeforeOffset for BOUNDARY_CHAR over different elements.
   1.198 + *
   1.199 + * @param aIDs          [in] the accessible identifier or array of accessible
   1.200 + *                        identifiers
   1.201 + * @param aOffset       [in] the offset to get a character before it
   1.202 + * @param aChar         [in] the expected character
   1.203 + * @param aStartOffset  [in] expected start offset of the character
   1.204 + * @param aEndOffset    [in] expected end offset of the character
   1.205 + */
   1.206 +function testCharBeforeOffset(aIDs, aOffset, aChar, aStartOffset, aEndOffset)
   1.207 +{
   1.208 +  var IDs = (aIDs instanceof Array) ? aIDs : [ aIDs ];
   1.209 +  for (var i = 0; i < IDs.length; i++) {
   1.210 +    var acc = getAccessible(IDs[i], nsIAccessibleText);
   1.211 +    testTextHelper(IDs[i], aOffset, BOUNDARY_CHAR,
   1.212 +                   aChar, aStartOffset, aEndOffset,
   1.213 +                   kOk, kOk, kOk,
   1.214 +                   acc.getTextBeforeOffset, "getTextBeforeOffset ");
   1.215 +  }
   1.216 +}
   1.217 +
   1.218 +/**
   1.219 + * Test getTextBeforeOffset function over different elements
   1.220 + *
   1.221 + * @param aIDs            [in] ID or array of IDs
   1.222 + * @param aBoundaryType   [in] boundary type for text to be retrieved
   1.223 + * @param aTestList       [in] array of sets:
   1.224 + *                              offset1 and offset2 defining the offset range
   1.225 + *                              the text in the range
   1.226 + *                              start offset of the text in the range
   1.227 + *                              end offset of the text in the range
   1.228 + *
   1.229 + * or
   1.230 + *
   1.231 + * @param aOffset         [in] the offset to get the text before
   1.232 + * @param aBoundaryType   [in] Boundary type for text to be retrieved
   1.233 + * @param aText           [in] expected return text for getTextBeforeOffset
   1.234 + * @param aStartOffset    [in] expected return start offset for getTextBeforeOffset
   1.235 + * @param aEndOffset      [in] expected return end offset for getTextBeforeOffset
   1.236 + * @param ...             [in] list of ids or list of tuples made of:
   1.237 + *                              element identifier
   1.238 + *                              kTodo or kOk for returned text
   1.239 + *                              kTodo or kOk for returned start offset
   1.240 + *                              kTodo or kOk for returned offset result
   1.241 + */
   1.242 +function testTextBeforeOffset(aOffset, aBoundaryType,
   1.243 +                              aText, aStartOffset, aEndOffset)
   1.244 +{
   1.245 +  testTextSuperHelper("getTextBeforeOffset", arguments);
   1.246 +}
   1.247 +
   1.248 +/**
   1.249 + * Test word count for an element.
   1.250 + *
   1.251 + * @param aElement   [in] element identifier
   1.252 + * @param aCount     [in] Expected word count
   1.253 + * @param aToDoFlag  [in] kTodo or kOk for returned text
   1.254 + */
   1.255 +function testWordCount(aElement, aCount, aToDoFlag)
   1.256 +{
   1.257 +  var isFunc = (aToDoFlag == kTodo) ? todo_is : is;
   1.258 +  var acc = getAccessible(aElement, nsIAccessibleText);
   1.259 +  var startOffsetObj = {}, endOffsetObj = {};
   1.260 +  var length = acc.characterCount;
   1.261 +  var offset = 0;
   1.262 +  var wordCount = 0;
   1.263 +  while (true) {
   1.264 +    var text = acc.getTextAtOffset(offset, BOUNDARY_WORD_START,
   1.265 +                                   startOffsetObj, endOffsetObj);
   1.266 +    if (offset >= length)
   1.267 +      break;
   1.268 +
   1.269 +    wordCount++;
   1.270 +    offset = endOffsetObj.value;
   1.271 +  }
   1.272 +  isFunc(wordCount, aCount,
   1.273 +        "wrong words count for '" + acc.getText(0, -1) + "': " + wordCount +
   1.274 +        " in " + prettyName(aElement));
   1.275 +}
   1.276 +
   1.277 +/**
   1.278 + * Test word at a position for an element.
   1.279 + *
   1.280 + * @param aElement    [in] element identifier
   1.281 + * @param aWordIndex  [in] index of the word to test
   1.282 + * @param aText       [in] expected text for that word
   1.283 + * @param aToDoFlag   [in] kTodo or kOk for returned text
   1.284 + */
   1.285 +function testWordAt(aElement, aWordIndex, aText, aToDoFlag)
   1.286 +{
   1.287 +  var isFunc = (aToDoFlag == kTodo) ? todo_is : is;
   1.288 +  var acc = getAccessible(aElement, nsIAccessibleText);
   1.289 +
   1.290 +  var textLength = acc.characterCount;
   1.291 +  var wordIdx = aWordIndex;
   1.292 +  var startOffsetObj = { value: 0 }, endOffsetObj = { value: 0 };
   1.293 +  for (offset = 0; offset < textLength; offset = endOffsetObj.value) {
   1.294 +    acc.getTextAtOffset(offset, BOUNDARY_WORD_START,
   1.295 +                        startOffsetObj, endOffsetObj);
   1.296 +
   1.297 +    wordIdx--;
   1.298 +    if (wordIdx < 0)
   1.299 +      break;
   1.300 +  }
   1.301 +
   1.302 +  if (wordIdx >= 0) {
   1.303 +    ok(false,
   1.304 +       "the given word index '" + aWordIndex + "' exceeds words amount in " +
   1.305 +       prettyName(aElement));
   1.306 +
   1.307 +    return;
   1.308 +  }
   1.309 +
   1.310 +  var startWordOffset = startOffsetObj.value;
   1.311 +  var endWordOffset = endOffsetObj.value;
   1.312 +
   1.313 +  // Calculate the end word offset.
   1.314 +  acc.getTextAtOffset(endOffsetObj.value, BOUNDARY_WORD_END,
   1.315 +                      startOffsetObj, endOffsetObj);
   1.316 +  if (startOffsetObj.value != textLength)
   1.317 +    endWordOffset = startOffsetObj.value
   1.318 +
   1.319 +  if (endWordOffset <= startWordOffset) {
   1.320 +    todo(false,
   1.321 +         "wrong start and end offset for word at index '" + aWordIndex + "': " +
   1.322 +         " of text '" + acc.getText(0, -1) + "' in " + prettyName(aElement));
   1.323 +
   1.324 +    return;
   1.325 +  }
   1.326 +
   1.327 +  text = acc.getText(startWordOffset, endWordOffset);
   1.328 +  isFunc(text, aText,  "wrong text for word at index '" + aWordIndex + "': " +
   1.329 +         " of text '" + acc.getText(0, -1) + "' in " + prettyName(aElement));
   1.330 +}
   1.331 +
   1.332 +/**
   1.333 + * Test words in a element.
   1.334 + *
   1.335 + * @param aElement   [in]           element identifier
   1.336 + * @param aWords     [in]           array of expected words
   1.337 + * @param aToDoFlag  [in, optional] kTodo or kOk for returned text
   1.338 + */
   1.339 +function testWords(aElement, aWords, aToDoFlag)
   1.340 +{
   1.341 +  if (aToDoFlag == null)
   1.342 +    aToDoFlag = kOk;
   1.343 +
   1.344 +  testWordCount(aElement, aWords.length, aToDoFlag);
   1.345 +
   1.346 +  for (var i = 0; i < aWords.length; i++) {
   1.347 +    testWordAt(aElement, i, aWords[i], aToDoFlag);
   1.348 +  }
   1.349 +}
   1.350 +
   1.351 +/**
   1.352 + * Remove all selections.
   1.353 + *
   1.354 + * @param aID  [in] Id, DOM node, or acc obj
   1.355 + */
   1.356 +function cleanTextSelections(aID)
   1.357 +{
   1.358 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.359 +
   1.360 +  while (acc.selectionCount > 0)
   1.361 +    acc.removeSelection(0);
   1.362 +}
   1.363 +
   1.364 +/**
   1.365 + * Test addSelection method.
   1.366 + *
   1.367 + * @param aID               [in] Id, DOM node, or acc obj
   1.368 + * @param aStartOffset      [in] start offset for the new selection
   1.369 + * @param aEndOffset        [in] end offset for the new selection
   1.370 + * @param aSelectionsCount  [in] expected number of selections after addSelection
   1.371 + */
   1.372 +function testTextAddSelection(aID, aStartOffset, aEndOffset, aSelectionsCount)
   1.373 +{
   1.374 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.375 +  var text = acc.getText(0, -1);
   1.376 +
   1.377 +  acc.addSelection(aStartOffset, aEndOffset);
   1.378 +
   1.379 +  ok(acc.selectionCount, aSelectionsCount,
   1.380 +     text + ": failed to add selection from offset '" + aStartOffset +
   1.381 +     "' to offset '" + aEndOffset + "': selectionCount after");
   1.382 +}
   1.383 +
   1.384 +/**
   1.385 + * Test removeSelection method.
   1.386 + *
   1.387 + * @param aID               [in] Id, DOM node, or acc obj
   1.388 + * @param aSelectionIndex   [in] index of the selection to be removed
   1.389 + * @param aSelectionsCount  [in] expected number of selections after
   1.390 + *                               removeSelection
   1.391 + */
   1.392 +function testTextRemoveSelection(aID, aSelectionIndex, aSelectionsCount)
   1.393 +{
   1.394 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.395 +  var text = acc.getText(0, -1);
   1.396 +
   1.397 +  acc.removeSelection(aSelectionIndex);
   1.398 +
   1.399 +  ok(acc.selectionCount, aSelectionsCount, 
   1.400 +     text + ": failed to remove selection at index '" + 
   1.401 +     aSelectionIndex + "': selectionCount after");
   1.402 +}
   1.403 +
   1.404 +/**
   1.405 + * Test setSelectionBounds method.
   1.406 + *
   1.407 + * @param aID               [in] Id, DOM node, or acc obj
   1.408 + * @param aStartOffset      [in] new start offset for the selection
   1.409 + * @param aEndOffset        [in] new end offset for the selection
   1.410 + * @param aSelectionIndex   [in] index of the selection to set
   1.411 + * @param aSelectionsCount  [in] expected number of selections after
   1.412 + *                               setSelectionBounds
   1.413 + */
   1.414 +function testTextSetSelection(aID, aStartOffset, aEndOffset,
   1.415 +                              aSelectionIndex, aSelectionsCount)
   1.416 +{
   1.417 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.418 +  var text = acc.getText(0, -1);
   1.419 +
   1.420 +  acc.setSelectionBounds(aSelectionIndex, aStartOffset, aEndOffset);
   1.421 +
   1.422 +  is(acc.selectionCount, aSelectionsCount, 
   1.423 +     text + ": failed to set selection at index '" + 
   1.424 +     aSelectionIndex + "': selectionCount after");
   1.425 +}
   1.426 +
   1.427 +/**
   1.428 + * Test selectionCount method.
   1.429 + *
   1.430 + * @param aID        [in] Id, DOM node, or acc obj
   1.431 + * @param aCount     [in] expected selection count
   1.432 + */
   1.433 +function testTextSelectionCount(aID, aCount)
   1.434 +{
   1.435 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.436 +  var text = acc.getText(0, -1);
   1.437 +
   1.438 +  is(acc.selectionCount, aCount, text + ": wrong selectionCount: ");
   1.439 +}
   1.440 +
   1.441 +/**
   1.442 + * Test getSelectionBounds method.
   1.443 + *
   1.444 + * @param aID              [in] Id, DOM node, or acc obj
   1.445 + * @param aStartOffset     [in] expected start offset for the selection
   1.446 + * @param aEndOffset       [in] expected end offset for the selection
   1.447 + * @param aSelectionIndex  [in] index of the selection to get
   1.448 + */
   1.449 +function testTextGetSelection(aID, aStartOffset, aEndOffset, aSelectionIndex)
   1.450 +{
   1.451 +  var acc = getAccessible(aID, [nsIAccessibleText]);
   1.452 +  var text = acc.getText(0, -1);
   1.453 +
   1.454 +  var startObj = {}, endObj = {};
   1.455 +  acc.getSelectionBounds(aSelectionIndex, startObj, endObj);
   1.456 +
   1.457 +  is(startObj.value, aStartOffset, text + ": wrong start offset for index '" +
   1.458 +     aSelectionIndex + "'");
   1.459 +  is(endObj.value, aEndOffset, text + ": wrong end offset for index '" +
   1.460 +     aSelectionIndex + "'");
   1.461 +}
   1.462 +
   1.463 +function testTextRange(aRange, aStartContainer, aStartOffset,
   1.464 +                       aEndContainer, aEndOffset)
   1.465 +{
   1.466 +  is(aRange.startContainer, getAccessible(aStartContainer),
   1.467 +     "Wrong start container");
   1.468 +  is(aRange.startOffset, aStartOffset,
   1.469 +     "Wrong start offset");
   1.470 +  is(aRange.endContainer, getAccessible(aEndContainer),
   1.471 +     "Wrong end container");
   1.472 +  is(aRange.endOffset, aEndOffset,
   1.473 +     "Wrong end offset");
   1.474 +}
   1.475 +
   1.476 +////////////////////////////////////////////////////////////////////////////////
   1.477 +// Private
   1.478 +
   1.479 +function testTextSuperHelper(aFuncName, aArgs)
   1.480 +{
   1.481 +  // List of tests.
   1.482 +  if (aArgs[2] instanceof Array) {
   1.483 +    var ids = (aArgs[0] instanceof Array) ? aArgs[0] : [ aArgs[0] ];
   1.484 +    var boundaryType = aArgs[1];
   1.485 +    var list = aArgs[2];
   1.486 +    for (var i = 0; i < list.length; i++) {
   1.487 +      var offset1 = list[i][0], offset2 = list[i][1];
   1.488 +      var text = list[i][2], startOffset = list[i][3], endOffset = list[i][4];
   1.489 +      var failureList = list[i][5];
   1.490 +      for (var offset = offset1; offset <= offset2; offset++) {
   1.491 +        for (var idIdx = 0; idIdx < ids.length; idIdx++) {
   1.492 +          var id = ids[idIdx];
   1.493 +
   1.494 +          var flagOk1 = kOk, flagOk2 = kOk, flagOk3 = kOk;
   1.495 +          if (failureList) {
   1.496 +            for (var fIdx = 0; fIdx < failureList.length; fIdx++) {
   1.497 +              if (offset == failureList[fIdx][0] && id == failureList[fIdx][1]) {
   1.498 +                flagOk1 = failureList[fIdx][2];
   1.499 +                flagOk2 = failureList[fIdx][3];
   1.500 +                flagOk3 = failureList[fIdx][4];
   1.501 +                break;
   1.502 +              }
   1.503 +            }
   1.504 +          }
   1.505 +
   1.506 +          var acc = getAccessible(id, nsIAccessibleText);
   1.507 +          testTextHelper(id, offset, boundaryType,
   1.508 +                         text, startOffset, endOffset,
   1.509 +                         flagOk1, flagOk2, flagOk3,
   1.510 +                         acc[aFuncName], aFuncName + " ");
   1.511 +        }
   1.512 +      }
   1.513 +    }
   1.514 +    return;
   1.515 +  }
   1.516 +
   1.517 +  // Test at single offset. List of IDs.
   1.518 +  var offset = aArgs[0];
   1.519 +  var boundaryType = aArgs[1];
   1.520 +  var text = aArgs[2];
   1.521 +  var startOffset = aArgs[3];
   1.522 +  var endOffset = aArgs[4];
   1.523 +  if (aArgs[5] instanceof Array) {
   1.524 +    var ids = aArgs[5];
   1.525 +    for (var i = 0; i < ids.length; i++) {
   1.526 +      var acc = getAccessible(ids[i], nsIAccessibleText);
   1.527 +      testTextHelper(ids[i], offset, boundaryType,
   1.528 +                     text, startOffset, endOffset,
   1.529 +                     kOk, kOk, kOk,
   1.530 +                     acc[aFuncName], aFuncName + " ");
   1.531 +    }
   1.532 +
   1.533 +    return;
   1.534 +  }
   1.535 +
   1.536 +  // Each ID is tested separately.
   1.537 +  for (var i = 5; i < aArgs.length; i = i + 4) {
   1.538 +    var ID = aArgs[i];
   1.539 +    var acc = getAccessible(ID, nsIAccessibleText);
   1.540 +    var toDoFlag1 = aArgs[i + 1];
   1.541 +    var toDoFlag2 = aArgs[i + 2];
   1.542 +    var toDoFlag3 = aArgs[i + 3];
   1.543 +
   1.544 +    testTextHelper(ID, offset, boundaryType,
   1.545 +                   text, startOffset, endOffset,
   1.546 +                   toDoFlag1, toDoFlag2, toDoFlag3,
   1.547 +                   acc[aFuncName], aFuncName + " ");
   1.548 +  }
   1.549 +}
   1.550 +
   1.551 +function testTextHelper(aID, aOffset, aBoundaryType,
   1.552 +                        aText, aStartOffset, aEndOffset,
   1.553 +                        aToDoFlag1, aToDoFlag2, aToDoFlag3,
   1.554 +                        aTextFunc, aTextFuncName)
   1.555 +{
   1.556 +  var exceptionFlag = aToDoFlag1 == undefined ||
   1.557 +                      aToDoFlag2 == undefined ||
   1.558 +                      aToDoFlag3 == undefined;
   1.559 +
   1.560 +  var startMsg = aTextFuncName + "(" + boundaryToString(aBoundaryType) + "): ";
   1.561 +  var endMsg = ", id: " + prettyName(aID) + ";";
   1.562 +
   1.563 +  try {
   1.564 +    var startOffsetObj = {}, endOffsetObj = {};
   1.565 +    var text = aTextFunc(aOffset, aBoundaryType,
   1.566 +                         startOffsetObj, endOffsetObj);
   1.567 +
   1.568 +    if (exceptionFlag) {
   1.569 +      ok(false, startMsg + "no expected failure at offset " + aOffset + endMsg);
   1.570 +      return;
   1.571 +    }
   1.572 +
   1.573 +    var isFunc1 = (aToDoFlag1 == kTodo) ? todo : ok;
   1.574 +    var isFunc2 = (aToDoFlag2 == kTodo) ? todo : ok;
   1.575 +    var isFunc3 = (aToDoFlag3 == kTodo) ? todo : ok;
   1.576 +
   1.577 +    isFunc1(text == aText,
   1.578 +            startMsg + "wrong text " +
   1.579 +            "(got '" + text + "', expected: '" + aText + "')" +
   1.580 +            ", offset: " + aOffset + endMsg);
   1.581 +    isFunc2(startOffsetObj.value == aStartOffset,
   1.582 +            startMsg + "wrong start offset" +
   1.583 +            "(got '" + startOffsetObj.value + "', expected: '" + aStartOffset + "')" +
   1.584 +            ", offset: " + aOffset + endMsg);
   1.585 +    isFunc3(endOffsetObj.value == aEndOffset,
   1.586 +            startMsg + "wrong end offset" +
   1.587 +            "(got '" + endOffsetObj.value + "', expected: '" + aEndOffset + "')" +
   1.588 +            ", offset: " + aOffset + endMsg);
   1.589 +
   1.590 +  } catch (e) {
   1.591 +    var okFunc = exceptionFlag ? todo : ok;
   1.592 +    okFunc(false, startMsg + "failed at offset " + aOffset + endMsg +
   1.593 +           ", exception: " + e);
   1.594 +  }
   1.595 +}
   1.596 +
   1.597 +function boundaryToString(aBoundaryType)
   1.598 +{
   1.599 +  switch (aBoundaryType) {
   1.600 +    case BOUNDARY_CHAR:
   1.601 +      return "char";
   1.602 +    case BOUNDARY_WORD_START:
   1.603 +      return "word start";
   1.604 +    case BOUNDARY_WORD_END:
   1.605 +      return "word end";
   1.606 +    case BOUNDARY_LINE_START:
   1.607 +      return "line start";
   1.608 +    case BOUNDARY_LINE_END:
   1.609 +      return "line end";
   1.610 +  }
   1.611 +}

mercurial