Bug 905215 - Add a test sheet for HTML elements, r=davidb

This commit is contained in:
Alexander Surkov 2013-08-19 18:50:14 -04:00
parent 21880a4f7a
commit e588494720
9 changed files with 1704 additions and 17 deletions

View File

@ -328,6 +328,11 @@ function getApplicationAccessible()
QueryInterface(nsIAccessibleApplication);
}
/**
* Flags used for testAccessibleTree
*/
const kSkipTreeFullCheck = 1;
/**
* Compare expected and actual accessibles trees.
*
@ -339,8 +344,9 @@ function getApplicationAccessible()
* children of accessible
* states - an object having states and extraStates
* fields
* @param aFlags [in, optional] flags, see constants above
*/
function testAccessibleTree(aAccOrElmOrID, aAccTree)
function testAccessibleTree(aAccOrElmOrID, aAccTree, aFlags)
{
var acc = getAccessible(aAccOrElmOrID);
if (!acc)
@ -361,30 +367,101 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
// Test accessible properties.
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);
switch (prop) {
case "actions": {
var actions = (typeof accTree.actions == "string") ?
[ accTree.actions ] : (accTree.actions || []);
is(acc.actionCount, actions.length, "Wong number of actions.");
for (var i = 0; i < actions.length; i++ )
is(acc.getActionName(i), actions[i], "Wrong action name at " + i + " index.");
break;
}
} else if (prop == "tagName") {
case "attributes":
testAttrs(acc, accTree[prop], true);
break;
case "absentAttributes":
testAbsentAttrs(acc, accTree[prop]);
break;
case "interfaces": {
var ifaces = (accTree[prop] instanceof Array) ?
accTree[prop] : [ accTree[prop] ];
for (var i = 0; i < ifaces.length; i++) {
ok((acc instanceof ifaces[i]),
"No " + ifaces[i] + " interface on " + prettyName(acc));
}
break;
}
case "relations": {
for (var rel in accTree[prop])
testRelation(acc, window[rel], accTree[prop][rel]);
break;
}
case "role":
isRole(acc, accTree[prop], msg);
break;
case "states":
case "extraStates":
case "absentStates":
case "absentExtraStates": {
testStates(acc, accTree["states"], accTree["extraStates"],
accTree["absentStates"], accTree["absentExtraStates"]);
break;
}
case "tagName":
is(accTree[prop], acc.DOMNode.tagName, msg);
break;
} else if (prop != "children") {
is(acc[prop], accTree[prop], msg);
case "textAttrs": {
var prevOffset = -1;
for (var offset in accTree[prop]) {
if (prevOffset !=- 1) {
var attrs = accTree[prop][prevOffset];
testTextAttrs(acc, prevOffset, attrs, { }, prevOffset, offset, true);
}
prevOffset = offset;
}
if (prevOffset != -1) {
var charCount = getAccessible(acc, [nsIAccessibleText]).characterCount;
var attrs = accTree[prop][prevOffset];
testTextAttrs(acc, prevOffset, attrs, { }, prevOffset, charCount, true);
}
break;
}
default:
if (prop.indexOf("todo_") == 0)
todo(false, msg);
else if (prop != "children")
is(acc[prop], accTree[prop], msg);
}
}
// Test children.
if ("children" in accTree && accTree["children"] instanceof Array) {
var children = acc.children;
is(children.length, accTree.children.length,
var childCount = children.length;
is(childCount, accTree.children.length,
"Different amount of expected children of " + prettyName(acc) + ".");
if (accTree.children.length == children.length) {
var childCount = children.length;
if (accTree.children.length == childCount) {
if (aFlags & kSkipTreeFullCheck) {
for (var i = 0; i < childCount; i++) {
var child = children.queryElementAt(i, nsIAccessible);
testAccessibleTree(child, accTree.children[i], aFlags);
}
return;
}
// nsIAccessible::firstChild
var expectedFirstChild = childCount > 0 ?
@ -402,7 +479,7 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
is(lastChild, expectedLastChild,
"Wrong last child of " + prettyName(acc));
for (var i = 0; i < children.length; i++) {
for (var i = 0; i < childCount; i++) {
var child = children.queryElementAt(i, nsIAccessible);
// nsIAccessible::parent
@ -433,7 +510,7 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
"Wrong previous sibling of " + prettyName(child));
// Go down through subtree
testAccessibleTree(child, accTree.children[i]);
testAccessibleTree(child, accTree.children[i], aFlags);
}
}
}

View File

@ -13,6 +13,7 @@ include $(DEPTH)/config/autoconf.mk
MOCHITEST_A11Y_FILES =\
test_figure.html \
test_HTMLSpec.html \
test_listbox.xul \
test_nsApplicationAcc.html \
test_plugin.html \

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ const ROLE_DIALOG = nsIAccessibleRole.ROLE_DIALOG;
const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT;
const ROLE_EMBEDDED_OBJECT = nsIAccessibleRole.ROLE_EMBEDDED_OBJECT;
const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY;
const ROLE_EQUATION = nsIAccessibleRole.ROLE_EQUATION;
const ROLE_FIGURE = nsIAccessibleRole.ROLE_FIGURE;
const ROLE_FOOTER = nsIAccessibleRole.ROLE_FOOTER;
const ROLE_FLAT_EQUATION = nsIAccessibleRole.ROLE_FLAT_EQUATION;

View File

@ -78,8 +78,10 @@ function testStates(aAccOrElmOrID, aState, aExtraState, aAbsentState,
var id = prettyName(aAccOrElmOrID) + (aTestName ? " [" + aTestName + "]": "");
// Primary test.
isState(state & aState, aState, false,
"wrong state bits for " + id + "!");
if (aState) {
isState(state & aState, aState, false,
"wrong state bits for " + id + "!");
}
if (aExtraState)
isState(extraState & aExtraState, aExtraState, true,

View File

@ -11,6 +11,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -20,6 +20,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -10,6 +10,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -10,6 +10,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>