2009-03-03 02:42:00 -08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-01-06 06:04:28 -08:00
|
|
|
function testStates(aAccOrElmOrID, aState, aExtraState, aAbsentState,
|
|
|
|
aAbsentExtraState)
|
2008-10-07 22:27:24 -07:00
|
|
|
{
|
|
|
|
var [state, extraState] = getStates(aAccOrElmOrID);
|
|
|
|
|
|
|
|
is(state & aState, aState,
|
2009-05-11 08:20:03 -07:00
|
|
|
"wrong state bits for " + aAccOrElmOrID + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (aExtraState)
|
|
|
|
is(extraState & aExtraState, aExtraState,
|
2009-05-11 08:20:03 -07:00
|
|
|
"wrong extra state bits for " + aAccOrElmOrID + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (aAbsentState)
|
|
|
|
is(state & aAbsentState, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"state bits should not be present in ID " + aAccOrElmOrID + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
2009-01-06 06:04:28 -08:00
|
|
|
if (aAbsentExtraState)
|
|
|
|
is(extraState & aAbsentExtraState, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"extraState bits should not be present in ID " + aAccOrElmOrID + "!");
|
2009-01-06 06:04:28 -08:00
|
|
|
|
2008-10-07 22:27:24 -07:00
|
|
|
if (state & STATE_READONLY)
|
|
|
|
is(extraState & EXT_STATE_EDITABLE, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Read-only " + aAccOrElmOrID + " cannot be editable!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (extraState & EXT_STATE_EDITABLE)
|
|
|
|
is(state & STATE_READONLY, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Editable " + aAccOrElmOrID + " cannot be readonly!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (state & STATE_COLLAPSED || state & STATE_EXPANDED)
|
|
|
|
is(extraState & EXT_STATE_EXPANDABLE, EXT_STATE_EXPANDABLE,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Collapsed or expanded " + aAccOrElmOrID + " should be expandable!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (state & STATE_COLLAPSED)
|
|
|
|
is(state & STATE_EXPANDED, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Collapsed " + aAccOrElmOrID + " cannot be expanded!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (state & STATE_EXPANDED)
|
|
|
|
is(state & STATE_COLLAPSED, 0,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Expanded " + aAccOrElmOrID + " cannot be collapsed!");
|
2009-03-03 02:42:00 -08:00
|
|
|
|
2009-03-09 23:03:21 -07:00
|
|
|
if (state & STATE_CHECKED || state & STATE_MIXED)
|
|
|
|
is(state & STATE_CHECKABLE, STATE_CHECKABLE,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Checked or mixed element must be checkable!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
|
|
|
if (state & STATE_CHECKED)
|
2009-05-11 08:20:03 -07:00
|
|
|
is(state & STATE_MIXED, 0, "Checked element cannot be state mixed!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
|
|
|
if (state & STATE_MIXED)
|
2009-05-11 08:20:03 -07:00
|
|
|
is(state & STATE_CHECKED, 0, "Mixed element cannot be state checked!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
2009-05-11 08:20:03 -07:00
|
|
|
if ((state & STATE_UNAVAILABLE)
|
2009-03-03 02:42:00 -08:00
|
|
|
&& (getRole(aAccOrElmOrID) != ROLE_GROUPING))
|
|
|
|
is(state & STATE_FOCUSABLE, STATE_FOCUSABLE,
|
2009-05-11 08:20:03 -07:00
|
|
|
"Disabled " + aAccOrElmOrID + " must be focusable!");
|
2009-03-03 02:42:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests an acessible and its sub tree for the passed in state bits.
|
|
|
|
* Used to make sure that states are propagated to descendants, for example the
|
|
|
|
* STATE_UNAVAILABLE from a container to its children.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
function testStatesInSubtree(aAccOrElmOrID, aState, aExtraState, aAbsentState)
|
|
|
|
{
|
|
|
|
// test accessible and its subtree for propagated states.
|
|
|
|
var acc = getAccessible(aAccOrElmOrID);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
2009-03-07 03:23:25 -08:00
|
|
|
if (getRole(acc) != ROLE_TEXT_LEAF)
|
2009-03-03 02:42:00 -08:00
|
|
|
// Right now, text leafs don't get tested because the states are not being
|
|
|
|
// propagated.
|
|
|
|
testStates(acc, aState, aExtraState, aAbsentState);
|
|
|
|
|
|
|
|
// Iterate over its children to see if the state got propagated.
|
|
|
|
var children = null;
|
|
|
|
try {
|
|
|
|
children = acc.children;
|
|
|
|
} catch(e) {}
|
|
|
|
ok(children, "Could not get children for " + aAccOrElmOrID +"!");
|
|
|
|
|
|
|
|
if (children) {
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var childAcc = children.queryElementAt(i, nsIAccessible);
|
|
|
|
testStatesInSubtree(childAcc, aState, aExtraState, aAbsentState);
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 22:27:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getStringStates(aAccOrElmOrID)
|
|
|
|
{
|
|
|
|
var [state, extraState] = getStates(aAccOrElmOrID);
|
2009-01-27 09:27:51 -08:00
|
|
|
return statesToString(state, extraState);
|
2008-10-07 22:27:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getStates(aAccOrElmOrID)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aAccOrElmOrID);
|
|
|
|
if (!acc)
|
|
|
|
return [0, 0];
|
|
|
|
|
|
|
|
var state = {}, extraState = {};
|
2008-11-03 19:37:46 -08:00
|
|
|
acc.getState(state, extraState);
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
return [state.value, extraState.value];
|
|
|
|
}
|