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