1 // //////////////////////////////////////////////////////////////////////////////
4 const MOUSEDOWN_EVENT = 1;
5 const MOUSEUP_EVENT = 2;
7 const COMMAND_EVENT = 8;
8 const FOCUS_EVENT = 16;
10 const CLICK_EVENTS = MOUSEDOWN_EVENT | MOUSEUP_EVENT | CLICK_EVENT;
11 const XUL_EVENTS = CLICK_EVENTS | COMMAND_EVENT;
13 // //////////////////////////////////////////////////////////////////////////////
17 * Test default accessible actions.
19 * Action tester interface is:
22 * // identifier of accessible to perform an action on
25 * // index of the action
26 * get actionIndex() {},
28 * // name of the action
29 * get actionName() {},
31 * // DOM events (see constants defined above)
34 * // [optional] identifier of target DOM events listeners are registered on,
35 * // used with 'events', if missing then 'ID' is used instead.
38 * // [optional] perform checks when 'click' event is handled if 'events'
40 * checkOnClickEvent: function() {},
42 * // [optional] an array of invoker's checker objects (see eventQueue
43 * // constructor events.js)
48 * @param aArray [in] an array of action cheker objects
50 function testActions(aArray) {
51 gActionsQueue = new eventQueue();
53 for (var idx = 0; idx < aArray.length; idx++) {
54 var actionObj = aArray[idx];
55 var accOrElmOrID = actionObj.ID;
56 var actionIndex = actionObj.actionIndex;
57 var actionName = actionObj.actionName;
58 var events = actionObj.events;
59 var accOrElmOrIDOfTarget = actionObj.targetID
65 var elm = getNode(accOrElmOrIDOfTarget);
66 if (events & MOUSEDOWN_EVENT) {
67 eventSeq.push(new checkerOfActionInvoker("mousedown", elm, actionObj));
70 if (events & MOUSEUP_EVENT) {
71 eventSeq.push(new checkerOfActionInvoker("mouseup", elm, actionObj));
74 if (events & CLICK_EVENT) {
75 eventSeq.push(new checkerOfActionInvoker("click", elm, actionObj));
78 if (events & COMMAND_EVENT) {
79 eventSeq.push(new checkerOfActionInvoker("command", elm, actionObj));
82 if (events & FOCUS_EVENT) {
83 eventSeq.push(new focusChecker(elm));
87 if (actionObj.eventSeq) {
88 eventSeq = eventSeq.concat(actionObj.eventSeq);
91 var invoker = new actionInvoker(
97 gActionsQueue.push(invoker);
100 gActionsQueue.invoke();
104 * Test action names and descriptions.
106 function testActionNames(aID, aActions) {
107 var actions = typeof aActions == "string" ? [aActions] : aActions || [];
109 var acc = getAccessible(aID);
110 is(acc.actionCount, actions.length, "Wong number of actions.");
111 for (var i = 0; i < actions.length; i++) {
113 acc.getActionName(i),
115 "Wrong action name at " + i + " index."
118 acc.getActionDescription(0),
119 gActionDescrMap[actions[i]],
120 "Wrong action description at " + i + "index."
125 // //////////////////////////////////////////////////////////////////////////////
128 var gActionsQueue = null;
130 function actionInvoker(aAccOrElmOrId, aActionIndex, aActionName, aEventSeq) {
131 this.invoke = function actionInvoker_invoke() {
132 var acc = getAccessible(aAccOrElmOrId);
134 return INVOKER_ACTION_FAILED;
137 var isThereActions = acc.actionCount > 0;
140 "No actions on the accessible for " + prettyName(aAccOrElmOrId)
143 if (!isThereActions) {
144 return INVOKER_ACTION_FAILED;
148 acc.getActionName(aActionIndex),
150 "Wrong action name of the accessible for " + prettyName(aAccOrElmOrId)
154 acc.doAction(aActionIndex);
156 ok(false, "doAction(" + aActionIndex + ") failed with: " + e.name);
157 return INVOKER_ACTION_FAILED;
162 this.eventSeq = aEventSeq;
164 this.getID = function actionInvoker_getID() {
166 "invoke an action " +
171 prettyName(aAccOrElmOrId)
176 function checkerOfActionInvoker(aType, aTarget, aActionObj) {
179 this.target = aTarget;
181 if (aActionObj && "eventTarget" in aActionObj) {
182 this.eventTarget = aActionObj.eventTarget;
187 this.getID = function getID() {
188 return aType + " event handling";
191 this.check = function check(aEvent) {
192 if (aType == "click" && aActionObj && "checkOnClickEvent" in aActionObj) {
193 aActionObj.checkOnClickEvent(aEvent);
198 var gActionDescrMap = {
208 collapse: "Collapse",
210 activate: "Activate",