B2G/gecko/accessible/tests/mochitest/text.js
/**
 * Test word count for an element.
 *
 * @param aElement   [in] element identifier
 * @param aCount     [in] Expected word count
 * @param aToDoFlag  [in] kTodo or kOk for returned text
 */
Test word count for an element.
@param aElement   [in] element identifier
@param aCount     [in] Expected word count
@param aToDoFlag  [in] kTodo or kOk for returned text
Test word count for an element . @param aElement [ in ] element identifier @param aCount [ in ] Expected word count @param aToDoFlag [ in ] kTodo or kOk for returned text
function testWordCount(aElement, aCount, aToDoFlag)
{
  var isFunc = (aToDoFlag == kTodo) ? todo_is : is;
  var acc = getAccessible(aElement, nsIAccessibleText);
  var startOffsetObj = {}, endOffsetObj = {};
  var length = acc.characterCount;
  var offset = 0;
  var wordCount = 0;
  while (true) {
    var text = acc.getTextAtOffset(offset, BOUNDARY_WORD_START,
                                   startOffsetObj, endOffsetObj);
    if (offset >= length)
      break;
    wordCount++;
    offset = endOffsetObj.value;
  }
  isFunc(wordCount, aCount,  "wrong words count for '" + acc.getText(0, -1) + "': " +
         wordCount);
}
function testWordCount ( aElement , aCount , aToDoFlag ) { var isFunc = ( aToDoFlag == kTodo ) ? todo_is : is ; var acc = getAccessible ( aElement , nsIAccessibleText ) ; var startOffsetObj = { } , endOffsetObj = { } ; var length = acc . characterCount ; var offset = 0 ; var wordCount = 0 ; while ( true ) { var text = acc . getTextAtOffset ( offset , BOUNDARY_WORD_START , startOffsetObj , endOffsetObj ) ; if ( offset >= length ) break ; wordCount ++ ; offset = endOffsetObj . value ; } isFunc ( wordCount , aCount , "wrong words count for '" + acc . getText ( 0 , - 1 ) + "': " + wordCount ) ; }
Test word count for an element.
Test word count for an element .