2010-05-20 00:40:25 -07:00
|
|
|
/**
|
|
|
|
* Test selection getter methods of nsIAccessibleSelectable.
|
|
|
|
*
|
|
|
|
* @param aIdentifier [in] selectable container accessible
|
|
|
|
* @param aSelectedChildren [in] array of selected children
|
|
|
|
*/
|
2010-09-01 17:46:59 -07:00
|
|
|
function testSelectableSelection(aIdentifier, aSelectedChildren, aMsg)
|
2010-05-20 00:40:25 -07:00
|
|
|
{
|
|
|
|
var acc = getAccessible(aIdentifier, [nsIAccessibleSelectable]);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
var msg = aMsg ? aMsg : "";
|
2010-05-20 00:40:25 -07:00
|
|
|
var len = aSelectedChildren.length;
|
|
|
|
|
|
|
|
// getSelectedChildren
|
2013-11-02 18:56:59 -07:00
|
|
|
var selectedChildren = acc.selectedItems;
|
2010-09-01 17:46:59 -07:00
|
|
|
is(selectedChildren ? selectedChildren.length : 0, len,
|
|
|
|
msg + "getSelectedChildren: wrong selected children count for " +
|
|
|
|
prettyName(aIdentifier));
|
2010-05-20 00:40:25 -07:00
|
|
|
|
|
|
|
for (var idx = 0; idx < len; idx++) {
|
|
|
|
var expectedAcc = getAccessible(aSelectedChildren[idx]);
|
2010-09-01 17:46:59 -07:00
|
|
|
var actualAcc = selectedChildren.queryElementAt(idx, nsIAccessible);
|
|
|
|
is(actualAcc, expectedAcc,
|
|
|
|
msg + "getSelectedChildren: wrong selected child at index " + idx +
|
|
|
|
" for " + prettyName(aIdentifier) + " { actual : " +
|
|
|
|
prettyName(actualAcc) + ", expected: " + prettyName(expectedAcc) + "}");
|
2010-05-20 00:40:25 -07:00
|
|
|
}
|
|
|
|
|
2013-11-02 18:56:59 -07:00
|
|
|
// selectedItemCount
|
|
|
|
is(acc.selectedItemCount, aSelectedChildren.length,
|
|
|
|
"selectedItemCount: wrong selected children count for " + prettyName(aIdentifier));
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2013-11-02 18:56:59 -07:00
|
|
|
// getSelectedItemAt
|
2010-05-20 00:40:25 -07:00
|
|
|
for (var idx = 0; idx < len; idx++) {
|
|
|
|
var expectedAcc = getAccessible(aSelectedChildren[idx]);
|
2013-11-02 18:56:59 -07:00
|
|
|
is(acc.getSelectedItemAt(idx), expectedAcc,
|
|
|
|
msg + "getSelectedItemAt: wrong selected child at index " + idx + " for " +
|
2010-09-01 17:46:59 -07:00
|
|
|
prettyName(aIdentifier));
|
|
|
|
}
|
|
|
|
|
2013-11-02 18:56:59 -07:00
|
|
|
// isItemSelected
|
|
|
|
testIsItemSelected(acc, acc, { value: 0 }, aSelectedChildren, msg);
|
2010-09-01 17:46:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-02 18:56:59 -07:00
|
|
|
* Test isItemSelected method, helper for testSelectableSelection
|
2010-09-01 17:46:59 -07:00
|
|
|
*/
|
2013-11-02 18:56:59 -07:00
|
|
|
function testIsItemSelected(aSelectAcc, aTraversedAcc, aIndexObj, aSelectedChildren, aMsg)
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
var childCount = aTraversedAcc.childCount;
|
|
|
|
for (var idx = 0; idx < childCount; idx++) {
|
|
|
|
var child = aTraversedAcc.getChildAt(idx);
|
|
|
|
var [state, extraState] = getStates(child);
|
|
|
|
if (state & STATE_SELECTABLE) {
|
|
|
|
var isSelected = false;
|
|
|
|
var len = aSelectedChildren.length;
|
|
|
|
for (var jdx = 0; jdx < len; jdx++) {
|
|
|
|
if (child == getAccessible(aSelectedChildren[jdx])) {
|
|
|
|
isSelected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-02 18:56:59 -07:00
|
|
|
// isItemSelected
|
|
|
|
is(aSelectAcc.isItemSelected(aIndexObj.value++), isSelected,
|
|
|
|
aMsg + "isItemSelected: wrong selected child " + prettyName(child) +
|
2010-09-01 17:46:59 -07:00
|
|
|
" for " + prettyName(aSelectAcc));
|
|
|
|
|
|
|
|
// selected state
|
|
|
|
testStates(child, isSelected ? STATE_SELECTED : 0, 0,
|
|
|
|
!isSelected ? STATE_SELECTED : 0 , 0);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-02 18:56:59 -07:00
|
|
|
testIsItemSelected(aSelectAcc, child, aIndexObj, aSelectedChildren);
|
2010-05-20 00:40:25 -07:00
|
|
|
}
|
|
|
|
}
|