2009-06-24 19:12:38 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helper functions for accessible states testing.
|
|
|
|
//
|
|
|
|
// requires:
|
|
|
|
// common.js
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-10-20 08:04:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// State constants
|
|
|
|
|
|
|
|
// const STATE_BUSY is defined in common.js
|
|
|
|
const STATE_CHECKED = nsIAccessibleStates.STATE_CHECKED;
|
|
|
|
const STATE_CHECKABLE = nsIAccessibleStates.STATE_CHECKABLE;
|
|
|
|
const STATE_COLLAPSED = nsIAccessibleStates.STATE_COLLAPSED;
|
|
|
|
const STATE_EXPANDED = nsIAccessibleStates.STATE_EXPANDED;
|
|
|
|
const STATE_EXTSELECTABLE = nsIAccessibleStates.STATE_EXTSELECTABLE;
|
|
|
|
const STATE_FOCUSABLE = nsIAccessibleStates.STATE_FOCUSABLE;
|
|
|
|
const STATE_FOCUSED = nsIAccessibleStates.STATE_FOCUSED;
|
|
|
|
const STATE_HASPOPUP = nsIAccessibleStates.STATE_HASPOPUP;
|
|
|
|
const STATE_INVALID = nsIAccessibleStates.STATE_INVALID;
|
2011-01-27 21:15:31 -08:00
|
|
|
const STATE_INVISIBLE = nsIAccessibleStates.STATE_INVISIBLE;
|
2010-10-20 08:04:18 -07:00
|
|
|
const STATE_LINKED = nsIAccessibleStates.STATE_LINKED;
|
|
|
|
const STATE_MIXED = nsIAccessibleStates.STATE_MIXED;
|
|
|
|
const STATE_MULTISELECTABLE = nsIAccessibleStates.STATE_MULTISELECTABLE;
|
|
|
|
const STATE_OFFSCREEN = nsIAccessibleStates.STATE_OFFSCREEN;
|
|
|
|
const STATE_PRESSED = nsIAccessibleStates.STATE_PRESSED;
|
|
|
|
const STATE_READONLY = nsIAccessibleStates.STATE_READONLY;
|
|
|
|
const STATE_REQUIRED = nsIAccessibleStates.STATE_REQUIRED;
|
|
|
|
const STATE_SELECTABLE = nsIAccessibleStates.STATE_SELECTABLE;
|
|
|
|
const STATE_SELECTED = nsIAccessibleStates.STATE_SELECTED;
|
|
|
|
const STATE_TRAVERSED = nsIAccessibleStates.STATE_TRAVERSED;
|
|
|
|
const STATE_UNAVAILABLE = nsIAccessibleStates.STATE_UNAVAILABLE;
|
|
|
|
|
|
|
|
const EXT_STATE_ACTIVE = nsIAccessibleStates.EXT_STATE_ACTIVE;
|
|
|
|
const EXT_STATE_DEFUNCT = nsIAccessibleStates.EXT_STATE_DEFUNCT;
|
|
|
|
const EXT_STATE_EDITABLE = nsIAccessibleStates.EXT_STATE_EDITABLE;
|
|
|
|
const EXT_STATE_EXPANDABLE = nsIAccessibleStates.EXT_STATE_EXPANDABLE;
|
|
|
|
const EXT_STATE_HORIZONTAL = nsIAccessibleStates.EXT_STATE_HORIZONTAL;
|
|
|
|
const EXT_STATE_MULTI_LINE = nsIAccessibleStates.EXT_STATE_MULTI_LINE;
|
|
|
|
const EXT_STATE_SINGLE_LINE = nsIAccessibleStates.EXT_STATE_SINGLE_LINE;
|
2010-11-05 21:11:08 -07:00
|
|
|
const EXT_STATE_STALE = nsIAccessibleStates.EXT_STATE_STALE;
|
2010-10-20 08:04:18 -07:00
|
|
|
const EXT_STATE_SUPPORTS_AUTOCOMPLETION =
|
|
|
|
nsIAccessibleStates.EXT_STATE_SUPPORTS_AUTOCOMPLETION;
|
|
|
|
const EXT_STATE_VERTICAL = nsIAccessibleStates.EXT_STATE_VERTICAL;
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test functions
|
|
|
|
|
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);
|
|
|
|
|
2009-05-22 09:09:51 -07:00
|
|
|
var id = prettyName(aAccOrElmOrID);
|
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
// Primary test.
|
|
|
|
isState(state & aState, aState, false,
|
|
|
|
"wrong state bits for " + id + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (aExtraState)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(extraState & aExtraState, aExtraState, true,
|
|
|
|
"wrong extra state bits for " + id + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (aAbsentState)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & aAbsentState, 0, false,
|
|
|
|
"state bits should not be present in ID " + id + "!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
2009-01-06 06:04:28 -08:00
|
|
|
if (aAbsentExtraState)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(extraState & aAbsentExtraState, 0, true,
|
|
|
|
"extraState bits should not be present in ID " + id + "!");
|
|
|
|
|
|
|
|
// Additional test.
|
2009-01-06 06:04:28 -08:00
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
// readonly/editable
|
2008-10-07 22:27:24 -07:00
|
|
|
if (state & STATE_READONLY)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(extraState & EXT_STATE_EDITABLE, 0, true,
|
|
|
|
"Read-only " + id + " cannot be editable!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (extraState & EXT_STATE_EDITABLE)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_READONLY, 0, true,
|
|
|
|
"Editable " + id + " cannot be readonly!");
|
|
|
|
|
|
|
|
// multiline/singleline
|
|
|
|
if (extraState & EXT_STATE_MULTI_LINE)
|
|
|
|
isState(extraState & EXT_STATE_SINGLE_LINE, 0, true,
|
|
|
|
"Multiline " + id + " cannot be singleline!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
if (extraState & EXT_STATE_SINGLE_LINE)
|
|
|
|
isState(extraState & EXT_STATE_MULTI_LINE, 0, true,
|
|
|
|
"Singleline " + id + " cannot be multiline!");
|
|
|
|
|
|
|
|
// expanded/collapsed/expandable
|
2008-10-07 22:27:24 -07:00
|
|
|
if (state & STATE_COLLAPSED || state & STATE_EXPANDED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(extraState & EXT_STATE_EXPANDABLE, EXT_STATE_EXPANDABLE, true,
|
|
|
|
"Collapsed or expanded " + id + " should be expandable!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (state & STATE_COLLAPSED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_EXPANDED, 0, false,
|
|
|
|
"Collapsed " + id + " cannot be expanded!");
|
2008-10-07 22:27:24 -07:00
|
|
|
|
|
|
|
if (state & STATE_EXPANDED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_COLLAPSED, 0, false,
|
|
|
|
"Expanded " + id + " cannot be collapsed!");
|
2009-03-03 02:42:00 -08:00
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
// checked/mixed/checkable
|
2009-03-09 23:03:21 -07:00
|
|
|
if (state & STATE_CHECKED || state & STATE_MIXED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_CHECKABLE, STATE_CHECKABLE, false,
|
|
|
|
"Checked or mixed element must be checkable!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
|
|
|
if (state & STATE_CHECKED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_MIXED, 0, false,
|
|
|
|
"Checked element cannot be state mixed!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
|
|
|
if (state & STATE_MIXED)
|
2009-06-24 19:12:38 -07:00
|
|
|
isState(state & STATE_CHECKED, 0, false,
|
|
|
|
"Mixed element cannot be state checked!");
|
2009-03-09 23:03:21 -07:00
|
|
|
|
2009-07-01 01:10:15 -07:00
|
|
|
// selected/selectable
|
|
|
|
if (state & STATE_SELECTED) {
|
|
|
|
isState(state & STATE_SELECTABLE, STATE_SELECTABLE, false,
|
|
|
|
"Selected element should be selectable!");
|
|
|
|
}
|
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];
|
|
|
|
}
|
2009-06-24 19:12:38 -07:00
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
/**
|
|
|
|
* Return true if the accessible has given states.
|
|
|
|
*/
|
|
|
|
function hasState(aAccOrElmOrID, aState, aExtraState)
|
|
|
|
{
|
|
|
|
var [state, exstate] = getStates(aAccOrElmOrID);
|
|
|
|
return (aState ? state & aState : true) &&
|
|
|
|
(aExtraState ? exstate & aExtraState : true);
|
|
|
|
}
|
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private implementation details
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Analogy of SimpleTest.is function used to compare states.
|
|
|
|
*/
|
|
|
|
function isState(aState1, aState2, aIsExtraStates, aMsg)
|
|
|
|
{
|
|
|
|
if (aState1 == aState2) {
|
|
|
|
ok(true, aMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var got = "0";
|
|
|
|
if (aState1) {
|
|
|
|
got = statesToString(aIsExtraStates ? 0 : aState1,
|
|
|
|
aIsExtraStates ? aState1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var expected = "0";
|
|
|
|
if (aState2) {
|
|
|
|
expected = statesToString(aIsExtraStates ? 0 : aState2,
|
|
|
|
aIsExtraStates ? aState2 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(false, aMsg + "got '" + got + "', expected '" + expected + "'");
|
|
|
|
}
|