2009-05-10 18:32:09 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event constants
|
|
|
|
|
|
|
|
const MOUSEDOWN_EVENT = 1;
|
|
|
|
const MOUSEUP_EVENT = 2;
|
|
|
|
const CLICK_EVENT = 4;
|
|
|
|
const COMMAND_EVENT = 8;
|
2013-05-31 11:16:18 -07:00
|
|
|
const FOCUS_EVENT = 16;
|
2009-05-10 18:32:09 -07:00
|
|
|
|
|
|
|
const CLICK_EVENTS = MOUSEDOWN_EVENT | MOUSEUP_EVENT | CLICK_EVENT;
|
2013-05-31 11:16:18 -07:00
|
|
|
const XUL_EVENTS = CLICK_EVENTS | COMMAND_EVENT;
|
2009-05-10 18:32:09 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Public functions
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test default accessible actions.
|
|
|
|
*
|
|
|
|
* Action tester interface is:
|
|
|
|
*
|
|
|
|
* var actionObj = {
|
2009-08-19 23:45:19 -07:00
|
|
|
* // identifier of accessible to perform an action on
|
2009-05-10 18:32:09 -07:00
|
|
|
* get ID() {},
|
|
|
|
*
|
2009-08-19 23:45:19 -07:00
|
|
|
* // index of the action
|
|
|
|
* get actionIndex() {},
|
|
|
|
*
|
|
|
|
* // name of the action
|
2009-05-10 18:32:09 -07:00
|
|
|
* get actionName() {},
|
|
|
|
*
|
2009-08-19 23:45:19 -07:00
|
|
|
* // DOM events (see constants defined above)
|
|
|
|
* get events() {},
|
|
|
|
*
|
|
|
|
* // [optional] identifier of target DOM events listeners are registered on,
|
|
|
|
* // used with 'events', if missing then 'ID' is used instead.
|
|
|
|
* get targetID() {},
|
|
|
|
*
|
|
|
|
* // [optional] perform checks when 'click' event is handled if 'events'
|
|
|
|
* // is used.
|
|
|
|
* checkOnClickEvent: function() {},
|
2009-05-10 18:32:09 -07:00
|
|
|
*
|
|
|
|
* // [optional] an array of invoker's checker objects (see eventQueue
|
|
|
|
* // constructor events.js)
|
|
|
|
* get eventSeq() {}
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param aArray [in] an array of action cheker objects
|
|
|
|
*/
|
|
|
|
function testActions(aArray)
|
|
|
|
{
|
|
|
|
gActionsQueue = new eventQueue();
|
|
|
|
|
|
|
|
for (var idx = 0; idx < aArray.length; idx++) {
|
|
|
|
|
|
|
|
var actionObj = aArray[idx];
|
|
|
|
var accOrElmOrID = actionObj.ID;
|
2009-08-19 23:45:19 -07:00
|
|
|
var actionIndex = actionObj.actionIndex;
|
2009-05-10 18:32:09 -07:00
|
|
|
var actionName = actionObj.actionName;
|
|
|
|
var events = actionObj.events;
|
2009-08-19 23:45:19 -07:00
|
|
|
var accOrElmOrIDOfTarget = actionObj.targetID ?
|
|
|
|
actionObj.targetID : accOrElmOrID;
|
2009-05-10 18:32:09 -07:00
|
|
|
|
|
|
|
var eventSeq = new Array();
|
|
|
|
if (events) {
|
2009-08-19 23:45:19 -07:00
|
|
|
var elm = getNode(accOrElmOrIDOfTarget);
|
2009-05-10 18:32:09 -07:00
|
|
|
if (events & MOUSEDOWN_EVENT)
|
|
|
|
eventSeq.push(new checkerOfActionInvoker("mousedown", elm));
|
|
|
|
|
|
|
|
if (events & MOUSEUP_EVENT)
|
|
|
|
eventSeq.push(new checkerOfActionInvoker("mouseup", elm));
|
|
|
|
|
|
|
|
if (events & CLICK_EVENT)
|
|
|
|
eventSeq.push(new checkerOfActionInvoker("click", elm, actionObj));
|
|
|
|
|
|
|
|
if (events & COMMAND_EVENT)
|
|
|
|
eventSeq.push(new checkerOfActionInvoker("command", elm));
|
2013-05-31 11:16:18 -07:00
|
|
|
|
|
|
|
if (events & FOCUS_EVENT)
|
|
|
|
eventSeq.push(new focusChecker(elm));
|
2009-05-10 18:32:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (actionObj.eventSeq)
|
|
|
|
eventSeq = eventSeq.concat(actionObj.eventSeq);
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
var invoker = new actionInvoker(accOrElmOrID, actionIndex, actionName,
|
|
|
|
eventSeq);
|
2009-05-10 18:32:09 -07:00
|
|
|
gActionsQueue.push(invoker);
|
|
|
|
}
|
|
|
|
|
|
|
|
gActionsQueue.invoke();
|
|
|
|
}
|
|
|
|
|
2013-12-07 13:37:04 -08:00
|
|
|
/**
|
|
|
|
* Test action names and descriptions.
|
|
|
|
*/
|
|
|
|
function testActionNames(aID, aActions)
|
|
|
|
{
|
|
|
|
var actions = (typeof aActions == "string") ?
|
|
|
|
[ aActions ] : (aActions || []);
|
|
|
|
|
|
|
|
var acc = getAccessible(aID);
|
|
|
|
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.");
|
|
|
|
is(acc.getActionDescription(0), gActionDescrMap[actions[i]],
|
|
|
|
"Wrong action description at " + i + "index.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private
|
|
|
|
|
|
|
|
var gActionsQueue = null;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
function actionInvoker(aAccOrElmOrId, aActionIndex, aActionName, aEventSeq)
|
2009-05-10 18:32:09 -07:00
|
|
|
{
|
|
|
|
this.invoke = function actionInvoker_invoke()
|
|
|
|
{
|
|
|
|
var acc = getAccessible(aAccOrElmOrId);
|
|
|
|
if (!acc)
|
|
|
|
return INVOKER_ACTION_FAILED;
|
|
|
|
|
2012-05-26 08:47:22 -07:00
|
|
|
var isThereActions = acc.actionCount > 0;
|
2009-05-10 18:32:09 -07:00
|
|
|
ok(isThereActions,
|
|
|
|
"No actions on the accessible for " + prettyName(aAccOrElmOrId));
|
|
|
|
|
|
|
|
if (!isThereActions)
|
|
|
|
return INVOKER_ACTION_FAILED;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
is(acc.getActionName(aActionIndex), aActionName,
|
2009-05-10 18:32:09 -07:00
|
|
|
"Wrong action name of the accessible for " + prettyName(aAccOrElmOrId));
|
|
|
|
|
|
|
|
try {
|
2009-08-19 23:45:19 -07:00
|
|
|
acc.doAction(aActionIndex);
|
2009-05-10 18:32:09 -07:00
|
|
|
}
|
|
|
|
catch (e){
|
2009-08-19 23:45:19 -07:00
|
|
|
ok(false, "doAction(" + aActionIndex + ") failed with: " + e.name);
|
2009-05-10 18:32:09 -07:00
|
|
|
return INVOKER_ACTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.eventSeq = aEventSeq;
|
2011-01-19 00:02:59 -08:00
|
|
|
|
|
|
|
this.getID = function actionInvoker_getID()
|
|
|
|
{
|
|
|
|
return "invoke an action " + aActionName + " at index " + aActionIndex +
|
|
|
|
" on " + prettyName(aAccOrElmOrId);
|
|
|
|
}
|
2009-05-10 18:32:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkerOfActionInvoker(aType, aTarget, aActionObj)
|
|
|
|
{
|
|
|
|
this.type = aType;
|
|
|
|
|
|
|
|
this.target = aTarget;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
this.phase = false;
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
this.getID = function getID()
|
|
|
|
{
|
|
|
|
return aType + " event handling";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.check = function check(aEvent)
|
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
if (aActionObj && "checkOnClickEvent" in aActionObj)
|
|
|
|
aActionObj.checkOnClickEvent(aEvent);
|
2009-05-10 18:32:09 -07:00
|
|
|
}
|
|
|
|
}
|
2013-12-07 13:37:04 -08:00
|
|
|
|
|
|
|
var gActionDescrMap =
|
|
|
|
{
|
|
|
|
jump: "Jump",
|
|
|
|
press: "Press",
|
|
|
|
check: "Check",
|
|
|
|
uncheck: "Uncheck",
|
|
|
|
select: "Select",
|
|
|
|
open: "Open",
|
|
|
|
close: "Close",
|
|
|
|
switch: "Switch",
|
|
|
|
click: "Click",
|
|
|
|
collapse: "Collapse",
|
|
|
|
expand: "Expand",
|
|
|
|
activate: "Activate",
|
|
|
|
cycle: "Cycle"
|
|
|
|
};
|