B2G/gecko/accessible/tests/mochitest/common.js
/**
 * Compare expected and actual accessibles trees.
 *
 * @param  aAccOrElmOrID  [in] accessible identifier
 * @param  aAccTree       [in] JS object, each field corresponds to property of
 *                         accessible object. Additionally special properties
 *                         are presented:
 *                          children - an array of JS objects representing
 *                                      children of accessible
 *                          states   - an object having states and extraStates
 *                                      fields
 */
Compare expected and actual accessibles trees.
@param  aAccOrElmOrID  [in] accessible identifier
@param  aAccTree       [in] JS object, each field corresponds to property of
accessible object. Additionally special properties
are presented:
children - an array of JS objects representing
children of accessible
states   - an object having states and extraStates
fields
Compare expected and actual accessibles trees . @param aAccOrElmOrID [ in ] accessible identifier @param aAccTree [ in ] JS object each field corresponds to property of accessible object . Additionally special properties are presented : children - an array of JS objects representing children of accessible states - an object having states and extraStates fields
function testAccessibleTree(aAccOrElmOrID, aAccTree)
{
  var acc = getAccessible(aAccOrElmOrID);
  if (!acc)
    return;
  var accTree = aAccTree;
  var key = Object.keys(accTree)[0];
  var roleName = "ROLE_" + key;
  if (roleName in nsIAccessibleRole) {
    accTree = {
      role: nsIAccessibleRole[roleName],
      children: accTree[key]
    };
  }
  for (var prop in accTree) {
    var msg = "Wrong value of property '" + prop + "' for " + prettyName(acc) + ".";
    if (prop == "role") {
      is(roleToString(acc[prop]), roleToString(accTree[prop]), msg);
    } else if (prop == "states") {
      var statesObj = accTree[prop];
      testStates(acc, statesObj.states, statesObj.extraStates,
                 statesObj.absentStates, statesObj.absentExtraStates);
    } else if (prop != "children") {
      is(acc[prop], accTree[prop], msg);
    }
  }
  if ("children" in accTree && accTree["children"] instanceof Array) {
    var children = acc.children;
    is(children.length, accTree.children.length,
       "Different amount of expected children of " + prettyName(acc) + ".");
    if (accTree.children.length == children.length) {
      var childCount = children.length;
      var expectedFirstChild = childCount > 0 ?
        children.queryElementAt(0, nsIAccessible) : null;
      var firstChild = null;
      try { firstChild = acc.firstChild; } catch (e) {}
      is(firstChild, expectedFirstChild,
         "Wrong first child of " + prettyName(acc));
      var expectedLastChild = childCount > 0 ?
        children.queryElementAt(childCount - 1, nsIAccessible) : null;
      var lastChild = null;
      try { lastChild = acc.lastChild; } catch (e) {}
      is(lastChild, expectedLastChild,
         "Wrong last child of " + prettyName(acc));
      for (var i = 0; i < children.length; i++) {
        var child = children.queryElementAt(i, nsIAccessible);
        var parent = null;
        try { parent = child.parent; } catch (e) {}
        is(parent, acc, "Wrong parent of " + prettyName(child));
        var indexInParent = -1;
        try { indexInParent = child.indexInParent; } catch(e) {}
        is(indexInParent, i,
           "Wrong index in parent of " + prettyName(child));
        var expectedNextSibling = (i < childCount - 1) ?
          children.queryElementAt(i + 1, nsIAccessible) : null;
        var nextSibling = null;
        try { nextSibling = child.nextSibling; } catch (e) {}
        is(nextSibling, expectedNextSibling,
           "Wrong next sibling of " + prettyName(child));
        var expectedPrevSibling = (i > 0) ?
          children.queryElementAt(i - 1, nsIAccessible) : null;
        var prevSibling = null;
        try { prevSibling = child.previousSibling; } catch (e) {}
        is(prevSibling, expectedPrevSibling,
           "Wrong previous sibling of " + prettyName(child));
        testAccessibleTree(child, accTree.children[i]);
      }
    }
  }
}
function testAccessibleTree ( aAccOrElmOrID , aAccTree ) { var acc = getAccessible ( aAccOrElmOrID ) ; if ( ! acc ) return ; var accTree = aAccTree ; var key = Object . keys ( accTree ) [ 0 ] ; var roleName = "ROLE_" + key ; if ( roleName in nsIAccessibleRole ) { accTree = { role : nsIAccessibleRole [ roleName ] , children : accTree [ key ] } ; } for ( var prop in accTree ) { var msg = "Wrong value of property '" + prop + "' for " + prettyName ( acc ) + "." ; if ( prop == "role" ) { is ( roleToString ( acc [ prop ] ) , roleToString ( accTree [ prop ] ) , msg ) ; } else if ( prop == "states" ) { var statesObj = accTree [ prop ] ; testStates ( acc , statesObj . states , statesObj . extraStates , statesObj . absentStates , statesObj . absentExtraStates ) ; } else if ( prop != "children" ) { is ( acc [ prop ] , accTree [ prop ] , msg ) ; } } if ( "children" in accTree && accTree [ "children" ] instanceof Array ) { var children = acc . children ; is ( children . length , accTree . children . length , "Different amount of expected children of " + prettyName ( acc ) + "." ) ; if ( accTree . children . length == children . length ) { var childCount = children . length ; var expectedFirstChild = childCount > 0 ? children . queryElementAt ( 0 , nsIAccessible ) : null ; var firstChild = null ; try { firstChild = acc . firstChild ; } catch ( e ) { } is ( firstChild , expectedFirstChild , "Wrong first child of " + prettyName ( acc ) ) ; var expectedLastChild = childCount > 0 ? children . queryElementAt ( childCount - 1 , nsIAccessible ) : null ; var lastChild = null ; try { lastChild = acc . lastChild ; } catch ( e ) { } is ( lastChild , expectedLastChild , "Wrong last child of " + prettyName ( acc ) ) ; for ( var i = 0 ; i < children . length ; i ++ ) { var child = children . queryElementAt ( i , nsIAccessible ) ; var parent = null ; try { parent = child . parent ; } catch ( e ) { } is ( parent , acc , "Wrong parent of " + prettyName ( child ) ) ; var indexInParent = - 1 ; try { indexInParent = child . indexInParent ; } catch ( e ) { } is ( indexInParent , i , "Wrong index in parent of " + prettyName ( child ) ) ; var expectedNextSibling = ( i < childCount - 1 ) ? children . queryElementAt ( i + 1 , nsIAccessible ) : null ; var nextSibling = null ; try { nextSibling = child . nextSibling ; } catch ( e ) { } is ( nextSibling , expectedNextSibling , "Wrong next sibling of " + prettyName ( child ) ) ; var expectedPrevSibling = ( i > 0 ) ? children . queryElementAt ( i - 1 , nsIAccessible ) : null ; var prevSibling = null ; try { prevSibling = child . previousSibling ; } catch ( e ) { } is ( prevSibling , expectedPrevSibling , "Wrong previous sibling of " + prettyName ( child ) ) ; testAccessibleTree ( child , accTree . children [ i ] ) ; } } } }
Compare expected and actual accessibles trees.
Compare expected and actual accessibles trees .
// Support of simplified accessible tree object. // Test accessible properties. // Test children. // nsIAccessible::firstChild // nsIAccessible::lastChild // nsIAccessible::parent // nsIAccessible::indexInParent // nsIAccessible::nextSibling // nsIAccessible::previousSibling // Go down through subtree