2008-08-28 07:48:41 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Interfaces
|
|
|
|
|
|
|
|
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
|
|
|
|
|
|
|
|
const nsIAccessibleEvent = Components.interfaces.nsIAccessibleEvent;
|
2008-12-03 01:04:02 -08:00
|
|
|
const nsIAccessibleStateChangeEvent =
|
|
|
|
Components.interfaces.nsIAccessibleStateChangeEvent;
|
2008-12-16 02:14:20 -08:00
|
|
|
const nsIAccessibleCaretMoveEvent =
|
|
|
|
Components.interfaces.nsIAccessibleCaretMoveEvent;
|
2010-05-17 09:17:50 -07:00
|
|
|
const nsIAccessibleTextChangeEvent =
|
|
|
|
Components.interfaces.nsIAccessibleTextChangeEvent;
|
2012-03-09 17:52:13 -08:00
|
|
|
const nsIAccessibleVirtualCursorChangeEvent =
|
|
|
|
Components.interfaces.nsIAccessibleVirtualCursorChangeEvent;
|
2008-12-03 01:04:02 -08:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
const nsIAccessibleStates = Components.interfaces.nsIAccessibleStates;
|
|
|
|
const nsIAccessibleRole = Components.interfaces.nsIAccessibleRole;
|
2011-09-27 18:46:11 -07:00
|
|
|
const nsIAccessibleScrollType = Components.interfaces.nsIAccessibleScrollType;
|
|
|
|
const nsIAccessibleCoordinateType = Components.interfaces.nsIAccessibleCoordinateType;
|
2008-08-28 07:48:41 -07:00
|
|
|
|
|
|
|
const nsIAccessibleRelation = Components.interfaces.nsIAccessibleRelation;
|
|
|
|
|
|
|
|
const nsIAccessible = Components.interfaces.nsIAccessible;
|
|
|
|
|
|
|
|
const nsIAccessibleDocument = Components.interfaces.nsIAccessibleDocument;
|
2010-03-18 11:49:39 -07:00
|
|
|
const nsIAccessibleApplication = Components.interfaces.nsIAccessibleApplication;
|
2008-08-28 07:48:41 -07:00
|
|
|
|
|
|
|
const nsIAccessibleText = Components.interfaces.nsIAccessibleText;
|
|
|
|
const nsIAccessibleEditableText = Components.interfaces.nsIAccessibleEditableText;
|
|
|
|
|
|
|
|
const nsIAccessibleHyperLink = Components.interfaces.nsIAccessibleHyperLink;
|
|
|
|
const nsIAccessibleHyperText = Components.interfaces.nsIAccessibleHyperText;
|
|
|
|
|
2012-02-01 22:14:51 -08:00
|
|
|
const nsIAccessibleCursorable = Components.interfaces.nsIAccessibleCursorable;
|
2008-08-28 07:48:41 -07:00
|
|
|
const nsIAccessibleImage = Components.interfaces.nsIAccessibleImage;
|
2012-02-01 22:14:51 -08:00
|
|
|
const nsIAccessiblePivot = Components.interfaces.nsIAccessiblePivot;
|
2008-08-28 07:48:41 -07:00
|
|
|
const nsIAccessibleSelectable = Components.interfaces.nsIAccessibleSelectable;
|
|
|
|
const nsIAccessibleTable = Components.interfaces.nsIAccessibleTable;
|
2009-09-10 18:07:56 -07:00
|
|
|
const nsIAccessibleTableCell = Components.interfaces.nsIAccessibleTableCell;
|
2012-02-01 22:14:51 -08:00
|
|
|
const nsIAccessibleTraversalRule = Components.interfaces.nsIAccessibleTraversalRule;
|
2008-08-28 07:48:41 -07:00
|
|
|
const nsIAccessibleValue = Components.interfaces.nsIAccessibleValue;
|
|
|
|
|
|
|
|
const nsIObserverService = Components.interfaces.nsIObserverService;
|
|
|
|
|
2009-02-04 21:43:46 -08:00
|
|
|
const nsIDOMDocument = Components.interfaces.nsIDOMDocument;
|
2009-02-27 02:45:21 -08:00
|
|
|
const nsIDOMEvent = Components.interfaces.nsIDOMEvent;
|
|
|
|
const nsIDOMHTMLDocument = Components.interfaces.nsIDOMHTMLDocument;
|
2008-08-28 07:48:41 -07:00
|
|
|
const nsIDOMNode = Components.interfaces.nsIDOMNode;
|
2011-10-29 13:03:55 -07:00
|
|
|
const nsIDOMHTMLElement = Components.interfaces.nsIDOMHTMLElement;
|
2009-02-04 21:43:46 -08:00
|
|
|
const nsIDOMWindow = Components.interfaces.nsIDOMWindow;
|
2009-05-11 03:57:28 -07:00
|
|
|
const nsIDOMXULElement = Components.interfaces.nsIDOMXULElement;
|
2009-02-04 21:43:46 -08:00
|
|
|
|
2008-10-28 04:54:57 -07:00
|
|
|
const nsIPropertyElement = Components.interfaces.nsIPropertyElement;
|
2008-08-28 07:48:41 -07:00
|
|
|
|
2009-01-24 23:01:24 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// OS detect
|
2012-02-19 20:25:17 -08:00
|
|
|
|
|
|
|
const MAC = (navigator.platform.indexOf("Mac") != -1);
|
|
|
|
const LINUX = (navigator.platform.indexOf("Linux") != -1);
|
|
|
|
const SOLARIS = (navigator.platform.indexOf("SunOS") != -1);
|
|
|
|
const WIN = (navigator.platform.indexOf("Win") != -1);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Application detect
|
|
|
|
// Firefox is assumed by default.
|
|
|
|
|
|
|
|
const SEAMONKEY = navigator.userAgent.match(/ SeaMonkey\//);
|
2009-01-24 23:01:24 -08:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-08-31 18:52:40 -07:00
|
|
|
// Accessible general
|
2008-08-28 07:48:41 -07:00
|
|
|
|
2010-10-20 08:04:18 -07:00
|
|
|
const STATE_BUSY = nsIAccessibleStates.STATE_BUSY;
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
const SCROLL_TYPE_ANYWHERE = nsIAccessibleScrollType.SCROLL_TYPE_ANYWHERE;
|
|
|
|
|
2012-10-19 08:10:28 -07:00
|
|
|
const COORDTYPE_SCREEN_RELATIVE = nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE;
|
|
|
|
const COORDTYPE_WINDOW_RELATIVE = nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE;
|
|
|
|
const COORDTYPE_PARENT_RELATIVE = nsIAccessibleCoordinateType.COORDTYPE_PARENT_RELATIVE;
|
|
|
|
|
2010-07-01 18:49:42 -07:00
|
|
|
const kEmbedChar = String.fromCharCode(0xfffc);
|
|
|
|
|
2011-03-28 06:59:54 -07:00
|
|
|
const kDiscBulletText = String.fromCharCode(0x2022) + " ";
|
|
|
|
const kCircleBulletText = String.fromCharCode(0x25e6) + " ";
|
|
|
|
const kSquareBulletText = String.fromCharCode(0x25aa) + " ";
|
|
|
|
|
2012-10-22 22:04:43 -07:00
|
|
|
const MAX_TRIM_LENGTH = 100;
|
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
/**
|
2011-09-27 18:46:11 -07:00
|
|
|
* nsIAccessibleRetrieval service.
|
2008-08-28 07:48:41 -07:00
|
|
|
*/
|
2011-09-27 18:46:11 -07:00
|
|
|
var gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
|
|
|
|
getService(nsIAccessibleRetrieval);
|
2008-08-28 07:48:41 -07:00
|
|
|
|
2012-06-01 18:58:44 -07:00
|
|
|
/**
|
|
|
|
* Enable/disable logging.
|
|
|
|
*/
|
|
|
|
function enableLogging(aModules)
|
|
|
|
{
|
|
|
|
gAccRetrieval.setLogging(aModules);
|
|
|
|
}
|
|
|
|
function disableLogging()
|
|
|
|
{
|
|
|
|
gAccRetrieval.setLogging("");
|
|
|
|
}
|
2012-11-03 19:19:56 -07:00
|
|
|
function isLogged(aModule)
|
|
|
|
{
|
|
|
|
return gAccRetrieval.isLogged(aModule);
|
|
|
|
}
|
2012-06-01 18:58:44 -07:00
|
|
|
|
2008-12-16 23:10:41 -08:00
|
|
|
/**
|
2009-09-23 07:21:47 -07:00
|
|
|
* Invokes the given function when document is loaded and focused. Preferable
|
|
|
|
* to mochitests 'addLoadEvent' function -- additionally ensures state of the
|
|
|
|
* document accessible is not busy.
|
2008-12-16 23:10:41 -08:00
|
|
|
*
|
|
|
|
* @param aFunc the function to invoke
|
|
|
|
*/
|
2011-09-27 18:46:11 -07:00
|
|
|
function addA11yLoadEvent(aFunc, aWindow)
|
2008-12-16 23:10:41 -08:00
|
|
|
{
|
|
|
|
function waitForDocLoad()
|
|
|
|
{
|
|
|
|
window.setTimeout(
|
|
|
|
function()
|
|
|
|
{
|
2011-09-27 18:46:11 -07:00
|
|
|
var targetDocument = aWindow ? aWindow.document : document;
|
|
|
|
var accDoc = getAccessible(targetDocument);
|
2008-12-16 23:10:41 -08:00
|
|
|
var state = {};
|
|
|
|
accDoc.getState(state, {});
|
2009-06-24 19:12:38 -07:00
|
|
|
if (state.value & STATE_BUSY)
|
2008-12-16 23:10:41 -08:00
|
|
|
return waitForDocLoad();
|
|
|
|
|
2011-05-26 20:26:48 -07:00
|
|
|
window.setTimeout(aFunc, 0);
|
2008-12-16 23:10:41 -08:00
|
|
|
},
|
2009-12-18 07:47:15 -08:00
|
|
|
0
|
2008-12-16 23:10:41 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
SimpleTest.waitForFocus(waitForDocLoad, aWindow);
|
2008-12-16 23:10:41 -08:00
|
|
|
}
|
|
|
|
|
2012-03-26 05:19:07 -07:00
|
|
|
/**
|
|
|
|
* Analogy of SimpleTest.is function used to compare objects.
|
|
|
|
*/
|
|
|
|
function isObject(aObj, aExpectedObj, aMsg)
|
|
|
|
{
|
|
|
|
if (aObj == aExpectedObj) {
|
|
|
|
ok(true, aMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(false,
|
|
|
|
aMsg + " - got '" + prettyName(aObj) +
|
|
|
|
"', expected '" + prettyName(aExpectedObj) + "'");
|
|
|
|
}
|
|
|
|
|
2008-12-16 23:10:41 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-12-18 07:47:15 -08:00
|
|
|
// Helpers for getting DOM node/accessible
|
2008-12-16 23:10:41 -08:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
/**
|
2009-05-10 18:32:09 -07:00
|
|
|
* Return the DOM node by identifier (may be accessible, DOM node or ID).
|
2008-12-16 02:14:20 -08:00
|
|
|
*/
|
2009-05-10 18:32:09 -07:00
|
|
|
function getNode(aAccOrNodeOrID)
|
2008-12-16 02:14:20 -08:00
|
|
|
{
|
2009-05-10 18:32:09 -07:00
|
|
|
if (!aAccOrNodeOrID)
|
2008-12-16 02:14:20 -08:00
|
|
|
return null;
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
if (aAccOrNodeOrID instanceof nsIDOMNode)
|
|
|
|
return aAccOrNodeOrID;
|
2008-12-16 02:14:20 -08:00
|
|
|
|
2012-02-07 05:18:33 -08:00
|
|
|
if (aAccOrNodeOrID instanceof nsIAccessible)
|
2009-05-10 18:32:09 -07:00
|
|
|
return aAccOrNodeOrID.DOMNode;
|
2008-12-16 02:14:20 -08:00
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
node = document.getElementById(aAccOrNodeOrID);
|
|
|
|
if (!node) {
|
|
|
|
ok(false, "Can't get DOM element for " + aAccOrNodeOrID);
|
|
|
|
return null;
|
2008-12-16 02:14:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
/**
|
|
|
|
* Constants indicates getAccessible doesn't fail if there is no accessible.
|
|
|
|
*/
|
|
|
|
const DONOTFAIL_IF_NO_ACC = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants indicates getAccessible won't fail if accessible doesn't implement
|
|
|
|
* the requested interfaces.
|
|
|
|
*/
|
|
|
|
const DONOTFAIL_IF_NO_INTERFACE = 2;
|
|
|
|
|
2008-12-16 02:14:20 -08:00
|
|
|
/**
|
2009-01-20 07:08:38 -08:00
|
|
|
* Return accessible for the given identifier (may be ID attribute or DOM
|
2009-08-18 08:06:54 -07:00
|
|
|
* element or accessible object) or null.
|
2008-08-28 07:48:41 -07:00
|
|
|
*
|
2009-01-20 07:08:38 -08:00
|
|
|
* @param aAccOrElmOrID [in] identifier to get an accessible implementing
|
|
|
|
* the given interfaces
|
|
|
|
* @param aInterfaces [in, optional] the interface or an array interfaces
|
|
|
|
* to query it/them from obtained accessible
|
|
|
|
* @param aElmObj [out, optional] object to store DOM element which
|
|
|
|
* accessible is obtained for
|
2009-02-27 02:45:21 -08:00
|
|
|
* @param aDoNotFailIf [in, optional] no error for special cases (see
|
|
|
|
* constants above)
|
2008-08-28 07:48:41 -07:00
|
|
|
*/
|
2009-02-27 02:45:21 -08:00
|
|
|
function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj, aDoNotFailIf)
|
2008-08-28 07:48:41 -07:00
|
|
|
{
|
2009-02-18 23:06:14 -08:00
|
|
|
if (!aAccOrElmOrID)
|
2009-08-18 08:06:54 -07:00
|
|
|
return null;
|
2009-02-18 23:06:14 -08:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
var elm = null;
|
|
|
|
|
2008-08-31 18:52:40 -07:00
|
|
|
if (aAccOrElmOrID instanceof nsIAccessible) {
|
|
|
|
elm = aAccOrElmOrID.DOMNode;
|
|
|
|
|
|
|
|
} else if (aAccOrElmOrID instanceof nsIDOMNode) {
|
|
|
|
elm = aAccOrElmOrID;
|
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
} else {
|
2010-06-08 12:17:54 -07:00
|
|
|
elm = document.getElementById(aAccOrElmOrID);
|
2008-08-28 07:48:41 -07:00
|
|
|
if (!elm) {
|
2008-10-14 01:27:02 -07:00
|
|
|
ok(false, "Can't get DOM element for " + aAccOrElmOrID);
|
2008-08-28 07:48:41 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aElmObj && (typeof aElmObj == "object"))
|
|
|
|
aElmObj.value = elm;
|
|
|
|
|
2008-08-31 18:52:40 -07:00
|
|
|
var acc = (aAccOrElmOrID instanceof nsIAccessible) ? aAccOrElmOrID : null;
|
2008-08-28 07:48:41 -07:00
|
|
|
if (!acc) {
|
2008-08-31 18:52:40 -07:00
|
|
|
try {
|
|
|
|
acc = gAccRetrieval.getAccessibleFor(elm);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2008-09-17 06:09:34 -07:00
|
|
|
|
2008-08-31 18:52:40 -07:00
|
|
|
if (!acc) {
|
2009-02-27 02:45:21 -08:00
|
|
|
if (!(aDoNotFailIf & DONOTFAIL_IF_NO_ACC))
|
2009-01-20 07:08:38 -08:00
|
|
|
ok(false, "Can't get accessible for " + aAccOrElmOrID);
|
|
|
|
|
2008-08-31 18:52:40 -07:00
|
|
|
return null;
|
|
|
|
}
|
2008-08-28 07:48:41 -07:00
|
|
|
}
|
2008-09-17 06:09:34 -07:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
if (!aInterfaces)
|
|
|
|
return acc;
|
2008-09-17 06:09:34 -07:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
if (aInterfaces instanceof Array) {
|
|
|
|
for (var index = 0; index < aInterfaces.length; index++) {
|
|
|
|
try {
|
|
|
|
acc.QueryInterface(aInterfaces[index]);
|
|
|
|
} catch (e) {
|
2009-02-27 02:45:21 -08:00
|
|
|
if (!(aDoNotFailIf & DONOTFAIL_IF_NO_INTERFACE))
|
2009-05-05 20:16:36 -07:00
|
|
|
ok(false, "Can't query " + aInterfaces[index] + " for " + aAccOrElmOrID);
|
2009-02-27 02:45:21 -08:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
acc.QueryInterface(aInterfaces);
|
|
|
|
} catch (e) {
|
2009-05-05 20:16:36 -07:00
|
|
|
ok(false, "Can't query " + aInterfaces + " for " + aAccOrElmOrID);
|
2008-08-28 07:48:41 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2009-01-20 07:08:38 -08:00
|
|
|
/**
|
2009-03-05 04:55:54 -08:00
|
|
|
* Return true if the given identifier has an accessible, or exposes the wanted
|
|
|
|
* interfaces.
|
2009-01-20 07:08:38 -08:00
|
|
|
*/
|
2009-03-05 04:55:54 -08:00
|
|
|
function isAccessible(aAccOrElmOrID, aInterfaces)
|
2009-01-20 07:08:38 -08:00
|
|
|
{
|
2009-03-05 04:55:54 -08:00
|
|
|
return getAccessible(aAccOrElmOrID, aInterfaces, null,
|
|
|
|
DONOTFAIL_IF_NO_ACC | DONOTFAIL_IF_NO_INTERFACE) ?
|
2009-02-27 02:45:21 -08:00
|
|
|
true : false;
|
2009-01-20 07:08:38 -08:00
|
|
|
}
|
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
/**
|
|
|
|
* Return an accessible that contains the DOM node for the given identifier.
|
|
|
|
*/
|
|
|
|
function getContainerAccessible(aAccOrElmOrID)
|
|
|
|
{
|
|
|
|
var node = getNode(aAccOrElmOrID);
|
|
|
|
if (!node)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
while ((node = node.parentNode) && !isAccessible(node));
|
|
|
|
return node ? getAccessible(node) : null;
|
|
|
|
}
|
|
|
|
|
2009-08-21 06:20:18 -07:00
|
|
|
/**
|
|
|
|
* Return root accessible for the given identifier.
|
|
|
|
*/
|
|
|
|
function getRootAccessible(aAccOrElmOrID)
|
|
|
|
{
|
2012-02-07 05:18:33 -08:00
|
|
|
var acc = getAccessible(aAccOrElmOrID ? aAccOrElmOrID : document);
|
2010-03-18 11:50:31 -07:00
|
|
|
return acc ? acc.rootDocument.QueryInterface(nsIAccessible) : null;
|
2009-08-21 06:20:18 -07:00
|
|
|
}
|
|
|
|
|
2010-10-20 08:04:18 -07:00
|
|
|
/**
|
|
|
|
* Return tab document accessible the given accessible is contained by.
|
|
|
|
*/
|
|
|
|
function getTabDocAccessible(aAccOrElmOrID)
|
|
|
|
{
|
2012-02-07 05:18:33 -08:00
|
|
|
var acc = getAccessible(aAccOrElmOrID ? aAccOrElmOrID : document);
|
2010-10-20 08:04:18 -07:00
|
|
|
|
|
|
|
var docAcc = acc.document.QueryInterface(nsIAccessible);
|
2012-02-07 05:18:33 -08:00
|
|
|
var containerDocAcc = docAcc.parent.document;
|
2010-10-20 08:04:18 -07:00
|
|
|
|
|
|
|
// Test is running is stand-alone mode.
|
|
|
|
if (acc.rootDocument == containerDocAcc)
|
|
|
|
return docAcc;
|
|
|
|
|
|
|
|
// In the case of running all tests together.
|
|
|
|
return containerDocAcc.QueryInterface(nsIAccessible);
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/**
|
|
|
|
* Return application accessible.
|
|
|
|
*/
|
|
|
|
function getApplicationAccessible()
|
|
|
|
{
|
2010-03-18 11:49:39 -07:00
|
|
|
return gAccRetrieval.getApplicationAccessible().
|
|
|
|
QueryInterface(nsIAccessibleApplication);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2009-04-20 00:09:21 -07:00
|
|
|
/**
|
|
|
|
* Compare expected and actual accessibles trees.
|
2009-09-10 18:07:56 -07:00
|
|
|
*
|
|
|
|
* @param aAccOrElmOrID [in] accessible identifier
|
|
|
|
* @param aAccTree [in] JS object, each field corresponds to property of
|
|
|
|
* accessible object. Additionally special properties
|
|
|
|
* are presented:
|
|
|
|
* children - an array of JS objects representing
|
|
|
|
* children of accessible
|
|
|
|
* states - an object having states and extraStates
|
|
|
|
* fields
|
2009-04-20 00:09:21 -07:00
|
|
|
*/
|
|
|
|
function testAccessibleTree(aAccOrElmOrID, aAccTree)
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aAccOrElmOrID);
|
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
2010-11-13 09:49:26 -08:00
|
|
|
var accTree = aAccTree;
|
|
|
|
|
|
|
|
// Support of simplified accessible tree object.
|
|
|
|
var key = Object.keys(accTree)[0];
|
|
|
|
var roleName = "ROLE_" + key;
|
|
|
|
if (roleName in nsIAccessibleRole) {
|
|
|
|
accTree = {
|
|
|
|
role: nsIAccessibleRole[roleName],
|
|
|
|
children: accTree[key]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test accessible properties.
|
|
|
|
for (var prop in accTree) {
|
2009-09-10 18:07:56 -07:00
|
|
|
var msg = "Wrong value of property '" + prop + "' for " + prettyName(acc) + ".";
|
2009-05-22 09:09:51 -07:00
|
|
|
if (prop == "role") {
|
2010-11-13 09:49:26 -08:00
|
|
|
is(roleToString(acc[prop]), roleToString(accTree[prop]), msg);
|
2009-05-22 09:09:51 -07:00
|
|
|
|
|
|
|
} else if (prop == "states") {
|
2010-11-13 09:49:26 -08:00
|
|
|
var statesObj = accTree[prop];
|
2009-05-22 09:09:51 -07:00
|
|
|
testStates(acc, statesObj.states, statesObj.extraStates,
|
|
|
|
statesObj.absentStates, statesObj.absentExtraStates);
|
|
|
|
|
2012-11-29 23:33:01 -08:00
|
|
|
} else if (prop == "tagName") {
|
|
|
|
is(accTree[prop], acc.DOMNode.tagName, msg);
|
|
|
|
|
2009-05-22 09:09:51 -07:00
|
|
|
} else if (prop != "children") {
|
2010-11-13 09:49:26 -08:00
|
|
|
is(acc[prop], accTree[prop], msg);
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
2009-04-20 00:09:21 -07:00
|
|
|
}
|
|
|
|
|
2010-11-13 09:49:26 -08:00
|
|
|
// Test children.
|
|
|
|
if ("children" in accTree && accTree["children"] instanceof Array) {
|
2009-04-20 00:09:21 -07:00
|
|
|
var children = acc.children;
|
2010-11-13 09:49:26 -08:00
|
|
|
is(children.length, accTree.children.length,
|
2009-05-22 09:09:51 -07:00
|
|
|
"Different amount of expected children of " + prettyName(acc) + ".");
|
2009-04-20 00:09:21 -07:00
|
|
|
|
2010-11-13 09:49:26 -08:00
|
|
|
if (accTree.children.length == children.length) {
|
2009-07-27 19:28:06 -07:00
|
|
|
var childCount = children.length;
|
|
|
|
|
|
|
|
// nsIAccessible::firstChild
|
|
|
|
var expectedFirstChild = childCount > 0 ?
|
|
|
|
children.queryElementAt(0, nsIAccessible) : null;
|
|
|
|
var firstChild = null;
|
|
|
|
try { firstChild = acc.firstChild; } catch (e) {}
|
|
|
|
is(firstChild, expectedFirstChild,
|
|
|
|
"Wrong first child of " + prettyName(acc));
|
|
|
|
|
|
|
|
// nsIAccessible::lastChild
|
|
|
|
var expectedLastChild = childCount > 0 ?
|
|
|
|
children.queryElementAt(childCount - 1, nsIAccessible) : null;
|
|
|
|
var lastChild = null;
|
|
|
|
try { lastChild = acc.lastChild; } catch (e) {}
|
|
|
|
is(lastChild, expectedLastChild,
|
|
|
|
"Wrong last child of " + prettyName(acc));
|
|
|
|
|
2009-04-20 00:09:21 -07:00
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var child = children.queryElementAt(i, nsIAccessible);
|
2009-07-27 19:28:06 -07:00
|
|
|
|
|
|
|
// nsIAccessible::parent
|
|
|
|
var parent = null;
|
|
|
|
try { parent = child.parent; } catch (e) {}
|
|
|
|
is(parent, acc, "Wrong parent of " + prettyName(child));
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
// nsIAccessible::indexInParent
|
|
|
|
var indexInParent = -1;
|
|
|
|
try { indexInParent = child.indexInParent; } catch(e) {}
|
|
|
|
is(indexInParent, i,
|
|
|
|
"Wrong index in parent of " + prettyName(child));
|
|
|
|
|
2009-07-27 19:28:06 -07:00
|
|
|
// nsIAccessible::nextSibling
|
|
|
|
var expectedNextSibling = (i < childCount - 1) ?
|
|
|
|
children.queryElementAt(i + 1, nsIAccessible) : null;
|
|
|
|
var nextSibling = null;
|
|
|
|
try { nextSibling = child.nextSibling; } catch (e) {}
|
|
|
|
is(nextSibling, expectedNextSibling,
|
|
|
|
"Wrong next sibling of " + prettyName(child));
|
|
|
|
|
|
|
|
// nsIAccessible::previousSibling
|
|
|
|
var expectedPrevSibling = (i > 0) ?
|
|
|
|
children.queryElementAt(i - 1, nsIAccessible) : null;
|
|
|
|
var prevSibling = null;
|
|
|
|
try { prevSibling = child.previousSibling; } catch (e) {}
|
|
|
|
is(prevSibling, expectedPrevSibling,
|
|
|
|
"Wrong previous sibling of " + prettyName(child));
|
|
|
|
|
|
|
|
// Go down through subtree
|
2010-11-13 09:49:26 -08:00
|
|
|
testAccessibleTree(child, accTree.children[i]);
|
2009-04-20 00:09:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 19:43:58 -07:00
|
|
|
/**
|
|
|
|
* Return true if accessible for the given node is in cache.
|
|
|
|
*/
|
|
|
|
function isAccessibleInCache(aNodeOrId)
|
|
|
|
{
|
|
|
|
var node = getNode(aNodeOrId);
|
|
|
|
return gAccRetrieval.getAccessibleFromCache(node) ? true : false;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/**
|
|
|
|
* Test accessible tree for defunct accessible.
|
|
|
|
*
|
|
|
|
* @param aAcc [in] the defunct accessible
|
|
|
|
* @param aNodeOrId [in] the DOM node identifier for the defunct accessible
|
|
|
|
*/
|
|
|
|
function testDefunctAccessible(aAcc, aNodeOrId)
|
|
|
|
{
|
|
|
|
if (aNodeOrId)
|
|
|
|
ok(!isAccessible(aNodeOrId),
|
|
|
|
"Accessible for " + aNodeOrId + " wasn't properly shut down!");
|
|
|
|
|
|
|
|
var msg = " doesn't fail for shut down accessible " + prettyName(aNodeOrId) + "!";
|
|
|
|
|
|
|
|
// firstChild
|
|
|
|
var success = false;
|
|
|
|
try {
|
|
|
|
aAcc.firstChild;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE)
|
|
|
|
}
|
|
|
|
ok(success, "firstChild" + msg);
|
|
|
|
|
|
|
|
// lastChild
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.lastChild;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE)
|
|
|
|
}
|
|
|
|
ok(success, "lastChild" + msg);
|
|
|
|
|
|
|
|
// childCount
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.childCount;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE)
|
|
|
|
}
|
|
|
|
ok(success, "childCount" + msg);
|
|
|
|
|
|
|
|
// children
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.children;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE)
|
|
|
|
}
|
|
|
|
ok(success, "children" + msg);
|
|
|
|
|
|
|
|
// nextSibling
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.nextSibling;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
ok(success, "nextSibling" + msg);
|
|
|
|
|
|
|
|
// previousSibling
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.previousSibling;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
ok(success, "previousSibling" + msg);
|
|
|
|
|
|
|
|
// parent
|
|
|
|
success = false;
|
|
|
|
try {
|
|
|
|
aAcc.parent;
|
|
|
|
} catch (e) {
|
|
|
|
success = (e.result == Components.results.NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
ok(success, "parent" + msg);
|
|
|
|
}
|
|
|
|
|
2009-01-27 09:27:51 -08:00
|
|
|
/**
|
|
|
|
* Convert role to human readable string.
|
|
|
|
*/
|
|
|
|
function roleToString(aRole)
|
|
|
|
{
|
|
|
|
return gAccRetrieval.getStringRole(aRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert states to human readable string.
|
|
|
|
*/
|
|
|
|
function statesToString(aStates, aExtraStates)
|
|
|
|
{
|
|
|
|
var list = gAccRetrieval.getStringStates(aStates, aExtraStates);
|
|
|
|
|
|
|
|
var str = "";
|
2009-06-24 19:12:38 -07:00
|
|
|
for (var index = 0; index < list.length - 1; index++)
|
2009-01-27 09:27:51 -08:00
|
|
|
str += list.item(index) + ", ";
|
|
|
|
|
2009-06-24 19:12:38 -07:00
|
|
|
if (list.length != 0)
|
|
|
|
str += list.item(index)
|
|
|
|
|
2009-01-27 09:27:51 -08:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert event type to human readable string.
|
|
|
|
*/
|
|
|
|
function eventTypeToString(aEventType)
|
|
|
|
{
|
2009-04-24 20:32:47 -07:00
|
|
|
return gAccRetrieval.getStringEventType(aEventType);
|
2009-01-27 09:27:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert relation type to human readable string.
|
|
|
|
*/
|
|
|
|
function relationTypeToString(aRelationType)
|
|
|
|
{
|
|
|
|
return gAccRetrieval.getStringRelationType(aRelationType);
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:14:01 -07:00
|
|
|
function getLoadContext() {
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
|
|
|
}
|
|
|
|
|
2010-12-15 13:23:19 -08:00
|
|
|
/**
|
|
|
|
* Return text from clipboard.
|
|
|
|
*/
|
|
|
|
function getTextFromClipboard()
|
|
|
|
{
|
|
|
|
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Components.interfaces.nsIClipboard);
|
|
|
|
if (!clip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var trans = Components.classes["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Components.interfaces.nsITransferable);
|
2012-04-16 19:14:01 -07:00
|
|
|
trans.init(getLoadContext());
|
2010-12-15 13:23:19 -08:00
|
|
|
if (!trans)
|
|
|
|
return;
|
|
|
|
|
|
|
|
trans.addDataFlavor("text/unicode");
|
|
|
|
clip.getData(trans, clip.kGlobalClipboard);
|
|
|
|
|
|
|
|
var str = new Object();
|
|
|
|
var strLength = new Object();
|
|
|
|
trans.getTransferData("text/unicode", str, strLength);
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
|
|
|
|
if (str)
|
|
|
|
return str.data.substring(0, strLength.value / 2);
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
/**
|
|
|
|
* Return pretty name for identifier, it may be ID, DOM node or accessible.
|
|
|
|
*/
|
|
|
|
function prettyName(aIdentifier)
|
|
|
|
{
|
|
|
|
if (aIdentifier instanceof nsIAccessible) {
|
2012-02-07 05:18:33 -08:00
|
|
|
var acc = getAccessible(aIdentifier);
|
2010-06-08 09:39:58 -07:00
|
|
|
var msg = "[" + getNodePrettyName(acc.DOMNode);
|
|
|
|
try {
|
|
|
|
msg += ", role: " + roleToString(acc.role);
|
|
|
|
if (acc.name)
|
2012-10-22 22:04:43 -07:00
|
|
|
msg += ", name: '" + shortenString(acc.name) + "'";
|
2010-06-08 09:39:58 -07:00
|
|
|
} catch (e) {
|
|
|
|
msg += "defunct";
|
|
|
|
}
|
2010-10-20 21:16:10 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
if (acc)
|
|
|
|
msg += ", address: " + getObjAddress(acc);
|
2009-05-13 22:27:40 -07:00
|
|
|
msg += "]";
|
|
|
|
|
|
|
|
return msg;
|
2009-02-10 02:03:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aIdentifier instanceof nsIDOMNode)
|
2011-09-27 18:46:11 -07:00
|
|
|
return "[ " + getNodePrettyName(aIdentifier) + " ]";
|
2009-02-10 02:03:30 -08:00
|
|
|
|
|
|
|
return " '" + aIdentifier + "' ";
|
|
|
|
}
|
|
|
|
|
2012-10-22 22:04:43 -07:00
|
|
|
/**
|
|
|
|
* Shorten a long string if it exceeds MAX_TRIM_LENGTH.
|
|
|
|
* @param aString the string to shorten.
|
|
|
|
* @returns the shortened string.
|
|
|
|
*/
|
|
|
|
function shortenString(aString, aMaxLength)
|
|
|
|
{
|
|
|
|
if (aString.length <= MAX_TRIM_LENGTH)
|
|
|
|
return aString;
|
|
|
|
|
|
|
|
// Trim the string if its length is > MAX_TRIM_LENGTH characters.
|
|
|
|
var trimOffset = MAX_TRIM_LENGTH / 2;
|
|
|
|
return aString.substring(0, trimOffset - 1) + "..." +
|
|
|
|
aString.substring(aString.length - trimOffset, aString.length);
|
|
|
|
}
|
2012-10-09 17:14:44 -07:00
|
|
|
|
2008-08-28 07:48:41 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-08-31 18:52:40 -07:00
|
|
|
// Accessible general
|
2008-08-28 07:48:41 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
function getNodePrettyName(aNode)
|
|
|
|
{
|
2009-05-10 18:32:09 -07:00
|
|
|
try {
|
2011-09-27 18:46:11 -07:00
|
|
|
var tag = "";
|
|
|
|
if (aNode.nodeType == nsIDOMNode.DOCUMENT_NODE) {
|
|
|
|
tag = "document";
|
|
|
|
} else {
|
|
|
|
tag = aNode.localName;
|
|
|
|
if (aNode.nodeType == nsIDOMNode.ELEMENT_NODE && aNode.hasAttribute("id"))
|
|
|
|
tag += "@id=\"" + aNode.getAttribute("id") + "\"";
|
|
|
|
}
|
2010-10-20 21:16:10 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
return "'" + tag + " node', address: " + getObjAddress(aNode);
|
2009-05-10 18:32:09 -07:00
|
|
|
} catch (e) {
|
2010-10-20 21:16:10 -07:00
|
|
|
return "' no node info '";
|
2009-05-10 18:32:09 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
function getObjAddress(aObj)
|
|
|
|
{
|
|
|
|
var exp = /native\s*@\s*(0x[a-f0-9]+)/g;
|
2012-03-07 10:19:50 -08:00
|
|
|
var match = exp.exec(aObj.toString());
|
2011-09-27 18:46:11 -07:00
|
|
|
if (match)
|
|
|
|
return match[1];
|
|
|
|
|
2012-03-07 10:19:50 -08:00
|
|
|
return aObj.toString();
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|