B2G/gecko/accessible/tests/mochitest/states.js
/**
 * Tests the states and extra states of the given accessible.
 * Also tests for unwanted states and extra states.
 * In addition, the function performs a few plausibility checks derived from the
 * sstates and extra states passed in.
 *
 * @param aAccOrElmOrID      The accessible, DOM element or ID to be tested.
 * @param aState             The state bits that are wanted.
 * @param aExtraState        The extra state bits that are wanted.
 * @param aAbsentState       State bits that are not wanted.
 * @param aAbsentExtraState  Extra state bits that are not wanted.
 * @param aTestName          The test name.
 */
Tests the states and extra states of the given accessible.
Also tests for unwanted states and extra states.
In addition, the function performs a few plausibility checks derived from the
sstates and extra states passed in.

@param aAccOrElmOrID      The accessible, DOM element or ID to be tested.
@param aState             The state bits that are wanted.
@param aExtraState        The extra state bits that are wanted.
@param aAbsentState       State bits that are not wanted.
@param aAbsentExtraState  Extra state bits that are not wanted.
@param aTestName          The test name.
Tests the states and extra states of the given accessible . Also tests for unwanted states and extra states . In addition the function performs a few plausibility checks derived from the sstates and extra states passed in . @param aAccOrElmOrID The accessible DOM element or ID to be tested . @param aState The state bits that are wanted . @param aExtraState The extra state bits that are wanted . @param aAbsentState State bits that are not wanted . @param aAbsentExtraState Extra state bits that are not wanted . @param aTestName The test name .
function testStates(aAccOrElmOrID, aState, aExtraState, aAbsentState,
                    aAbsentExtraState, aTestName)
{
  var [state, extraState] = getStates(aAccOrElmOrID);
  var role = getRole(aAccOrElmOrID);
  var id = prettyName(aAccOrElmOrID) + (aTestName ? " [" + aTestName + "]": "");
  isState(state & aState, aState, false,
          "wrong state bits for " + id + "!");
  if (aExtraState)
    isState(extraState & aExtraState, aExtraState, true,
            "wrong extra state bits for " + id + "!");
  if (aAbsentState)
    isState(state & aAbsentState, 0, false,
            "state bits should not be present in ID " + id + "!");
  if (aAbsentExtraState)
    isState(extraState & aAbsentExtraState, 0, true,
            "extraState bits should not be present in ID " + id + "!");
  if (state & STATE_FOCUSED)
    isState(state & STATE_FOCUSABLE, STATE_FOCUSABLE, false,
            "Focussed " + id + " must be focusable!");
  if (aAbsentState && (aAbsentState & STATE_FOCUSABLE)) {
    isState(state & STATE_FOCUSED, 0, false,
              "Not focusable " + id + " must be not focused!");
  }
  if (extraState & EXT_STATE_MULTI_LINE)
    isState(extraState & EXT_STATE_SINGLE_LINE, 0, true,
            "Multiline " + id + " cannot be singleline!");
  if (extraState & EXT_STATE_SINGLE_LINE)
    isState(extraState & EXT_STATE_MULTI_LINE, 0, true,
            "Singleline " + id + " cannot be multiline!");
  if (state & STATE_COLLAPSED || state & STATE_EXPANDED)
    isState(extraState & EXT_STATE_EXPANDABLE, EXT_STATE_EXPANDABLE, true,
            "Collapsed or expanded " + id + " must be expandable!");
  if (state & STATE_COLLAPSED)
    isState(state & STATE_EXPANDED, 0, false,
            "Collapsed " + id + " cannot be expanded!");
  if (state & STATE_EXPANDED)
    isState(state & STATE_COLLAPSED, 0, false,
            "Expanded " + id + " cannot be collapsed!");
  if (aAbsentState && (extraState & EXT_STATE_EXPANDABLE)) {
    if (aAbsentState & STATE_EXPANDED) {
      isState(state & STATE_COLLAPSED, STATE_COLLAPSED, false,
              "Not expanded " + id + " must be collapsed!");
    } else if (aAbsentState & STATE_COLLAPSED) {
      isState(state & STATE_EXPANDED, STATE_EXPANDED, false,
              "Not collapsed " + id + " must be expanded!");
    }
  }
  if (state & STATE_CHECKED || state & STATE_MIXED && role != ROLE_PROGRESSBAR)
    isState(state & STATE_CHECKABLE, STATE_CHECKABLE, false,
            "Checked or mixed element must be checkable!");
  if (state & STATE_CHECKED)
    isState(state & STATE_MIXED, 0, false,
            "Checked element cannot be state mixed!");
  if (state & STATE_MIXED)
    isState(state & STATE_CHECKED, 0, false,
            "Mixed element cannot be state checked!");
  if (state & STATE_SELECTED) {
    isState(state & STATE_SELECTABLE, STATE_SELECTABLE, false,
            "Selected element must be selectable!");
  }
}
function testStates ( aAccOrElmOrID , aState , aExtraState , aAbsentState , aAbsentExtraState , aTestName ) { var [ state , extraState ] = getStates ( aAccOrElmOrID ) ; var role = getRole ( aAccOrElmOrID ) ; var id = prettyName ( aAccOrElmOrID ) + ( aTestName ? " [" + aTestName + "]" : "" ) ; isState ( state & aState , aState , false , "wrong state bits for " + id + "!" ) ; if ( aExtraState ) isState ( extraState & aExtraState , aExtraState , true , "wrong extra state bits for " + id + "!" ) ; if ( aAbsentState ) isState ( state & aAbsentState , 0 , false , "state bits should not be present in ID " + id + "!" ) ; if ( aAbsentExtraState ) isState ( extraState & aAbsentExtraState , 0 , true , "extraState bits should not be present in ID " + id + "!" ) ; if ( state & STATE_FOCUSED ) isState ( state & STATE_FOCUSABLE , STATE_FOCUSABLE , false , "Focussed " + id + " must be focusable!" ) ; if ( aAbsentState && ( aAbsentState & STATE_FOCUSABLE ) ) { isState ( state & STATE_FOCUSED , 0 , false , "Not focusable " + id + " must be not focused!" ) ; } if ( extraState & EXT_STATE_MULTI_LINE ) isState ( extraState & EXT_STATE_SINGLE_LINE , 0 , true , "Multiline " + id + " cannot be singleline!" ) ; if ( extraState & EXT_STATE_SINGLE_LINE ) isState ( extraState & EXT_STATE_MULTI_LINE , 0 , true , "Singleline " + id + " cannot be multiline!" ) ; if ( state & STATE_COLLAPSED || state & STATE_EXPANDED ) isState ( extraState & EXT_STATE_EXPANDABLE , EXT_STATE_EXPANDABLE , true , "Collapsed or expanded " + id + " must be expandable!" ) ; if ( state & STATE_COLLAPSED ) isState ( state & STATE_EXPANDED , 0 , false , "Collapsed " + id + " cannot be expanded!" ) ; if ( state & STATE_EXPANDED ) isState ( state & STATE_COLLAPSED , 0 , false , "Expanded " + id + " cannot be collapsed!" ) ; if ( aAbsentState && ( extraState & EXT_STATE_EXPANDABLE ) ) { if ( aAbsentState & STATE_EXPANDED ) { isState ( state & STATE_COLLAPSED , STATE_COLLAPSED , false , "Not expanded " + id + " must be collapsed!" ) ; } else if ( aAbsentState & STATE_COLLAPSED ) { isState ( state & STATE_EXPANDED , STATE_EXPANDED , false , "Not collapsed " + id + " must be expanded!" ) ; } } if ( state & STATE_CHECKED || state & STATE_MIXED && role != ROLE_PROGRESSBAR ) isState ( state & STATE_CHECKABLE , STATE_CHECKABLE , false , "Checked or mixed element must be checkable!" ) ; if ( state & STATE_CHECKED ) isState ( state & STATE_MIXED , 0 , false , "Checked element cannot be state mixed!" ) ; if ( state & STATE_MIXED ) isState ( state & STATE_CHECKED , 0 , false , "Mixed element cannot be state checked!" ) ; if ( state & STATE_SELECTED ) { isState ( state & STATE_SELECTABLE , STATE_SELECTABLE , false , "Selected element must be selectable!" ) ; } }
Tests the states and extra states of the given accessible.
Tests the states and extra states of the given accessible .
// Primary test. // Additional test. // focused/focusable // multiline/singleline // expanded/collapsed/expandable // checked/mixed/checkable // selected/selectable