B2G/gecko/accessible/tests/mochitest/relations.js
/**
 * Test the accessible relation.
 *
 * @param aIdentifier          [in] identifier to get an accessible, may be ID
 *                             attribute or DOM element or accessible object
 * @param aRelType             [in] relation type (see constants above)
 * @param aRelatedIdentifiers  [in] identifier or array of identifiers of
 *                             expected related accessibles
 */
Test the accessible relation.
@param aIdentifier          [in] identifier to get an accessible, may be ID
attribute or DOM element or accessible object
@param aRelType             [in] relation type
@param aRelatedIdentifiers  [in] identifier or array of identifiers of
expected related accessibles
Test the accessible relation . @param aIdentifier [ in ] identifier to get an accessible may be ID attribute or DOM element or accessible object @param aRelType [ in ] relation type @param aRelatedIdentifiers [ in ] identifier or array of identifiers of expected related accessibles
function testRelation(aIdentifier, aRelType, aRelatedIdentifiers)
{
  var relation = getRelationByType(aIdentifier, aRelType);
  var relDescr = getRelationErrorMsg(aIdentifier, aRelType);
  var relDescrStart = getRelationErrorMsg(aIdentifier, aRelType, true);
  if (!relation || !relation.targetsCount) {
    if (!aRelatedIdentifiers) {
      ok(true, "No" + relDescr);
      return;
    }
    var msg = relDescrStart + "has no expected targets: '" +
      prettyName(aRelatedIdentifiers) + "'";
    ok(false, msg);
    return;
  } else if (!aRelatedIdentifiers) {
    ok(false, "There are unexpected targets of " + relDescr);
    return;
  }
  var relatedIds = (aRelatedIdentifiers instanceof Array) ?
  aRelatedIdentifiers : [aRelatedIdentifiers];
  var targets = [];
   for (var idx = 0; idx < relatedIds.length; idx++)
     targets.push(getAccessible(relatedIds[idx]));
  if (targets.length != relatedIds.length)
    return;
  var actualTargets = relation.getTargets();
  for (var idx = 0; idx < targets.length; idx++) {
    var isFound = false;
    var enumerate = actualTargets.enumerate();
    while (enumerate.hasMoreElements()) {
      var relatedAcc = enumerate.getNext().QueryInterface(nsIAccessible);
      if (targets[idx] == relatedAcc) {
        isFound = true;
        break;
      }
    }
    ok(isFound, prettyName(relatedIds[idx]) + " is not a target of" + relDescr);
  }
  var enumerate = actualTargets.enumerate();
  while (enumerate.hasMoreElements()) {
    var relatedAcc = enumerate.getNext().QueryInterface(nsIAccessible);
    for (var idx = 0; idx < targets.length && relatedAcc != targets[idx]; idx++);
    if (idx == targets.length)
      ok(false, "There is unexpected target" + prettyName(relatedAcc) + "of" + relDescr);
  }
}
function testRelation ( aIdentifier , aRelType , aRelatedIdentifiers ) { var relation = getRelationByType ( aIdentifier , aRelType ) ; var relDescr = getRelationErrorMsg ( aIdentifier , aRelType ) ; var relDescrStart = getRelationErrorMsg ( aIdentifier , aRelType , true ) ; if ( ! relation || ! relation . targetsCount ) { if ( ! aRelatedIdentifiers ) { ok ( true , "No" + relDescr ) ; return ; } var msg = relDescrStart + "has no expected targets: '" + prettyName ( aRelatedIdentifiers ) + "'" ; ok ( false , msg ) ; return ; } else if ( ! aRelatedIdentifiers ) { ok ( false , "There are unexpected targets of " + relDescr ) ; return ; } var relatedIds = ( aRelatedIdentifiers instanceof Array ) ? aRelatedIdentifiers : [ aRelatedIdentifiers ] ; var targets = [ ] ; for ( var idx = 0 ; idx < relatedIds . length ; idx ++ ) targets . push ( getAccessible ( relatedIds [ idx ] ) ) ; if ( targets . length != relatedIds . length ) return ; var actualTargets = relation . getTargets ( ) ; for ( var idx = 0 ; idx < targets . length ; idx ++ ) { var isFound = false ; var enumerate = actualTargets . enumerate ( ) ; while ( enumerate . hasMoreElements ( ) ) { var relatedAcc = enumerate . getNext ( ) . QueryInterface ( nsIAccessible ) ; if ( targets [ idx ] == relatedAcc ) { isFound = true ; break ; } } ok ( isFound , prettyName ( relatedIds [ idx ] ) + " is not a target of" + relDescr ) ; } var enumerate = actualTargets . enumerate ( ) ; while ( enumerate . hasMoreElements ( ) ) { var relatedAcc = enumerate . getNext ( ) . QueryInterface ( nsIAccessible ) ; for ( var idx = 0 ; idx < targets . length && relatedAcc != targets [ idx ] ; idx ++ ) ; if ( idx == targets . length ) ok ( false , "There is unexpected target" + prettyName ( relatedAcc ) + "of" + relDescr ) ; } }
Test the accessible relation.
Test the accessible relation .
// Check if all given related accessibles are targets of obtained relation. // Check if all obtained targets are given related accessibles.