|
1 //////////////////////////////////////////////////////////////////////////////// |
|
2 // Event constants |
|
3 |
|
4 const MOUSEDOWN_EVENT = 1; |
|
5 const MOUSEUP_EVENT = 2; |
|
6 const CLICK_EVENT = 4; |
|
7 const COMMAND_EVENT = 8; |
|
8 const FOCUS_EVENT = 16; |
|
9 |
|
10 const CLICK_EVENTS = MOUSEDOWN_EVENT | MOUSEUP_EVENT | CLICK_EVENT; |
|
11 const XUL_EVENTS = CLICK_EVENTS | COMMAND_EVENT; |
|
12 |
|
13 //////////////////////////////////////////////////////////////////////////////// |
|
14 // Public functions |
|
15 |
|
16 /** |
|
17 * Test default accessible actions. |
|
18 * |
|
19 * Action tester interface is: |
|
20 * |
|
21 * var actionObj = { |
|
22 * // identifier of accessible to perform an action on |
|
23 * get ID() {}, |
|
24 * |
|
25 * // index of the action |
|
26 * get actionIndex() {}, |
|
27 * |
|
28 * // name of the action |
|
29 * get actionName() {}, |
|
30 * |
|
31 * // DOM events (see constants defined above) |
|
32 * get events() {}, |
|
33 * |
|
34 * // [optional] identifier of target DOM events listeners are registered on, |
|
35 * // used with 'events', if missing then 'ID' is used instead. |
|
36 * get targetID() {}, |
|
37 * |
|
38 * // [optional] perform checks when 'click' event is handled if 'events' |
|
39 * // is used. |
|
40 * checkOnClickEvent: function() {}, |
|
41 * |
|
42 * // [optional] an array of invoker's checker objects (see eventQueue |
|
43 * // constructor events.js) |
|
44 * get eventSeq() {} |
|
45 * }; |
|
46 * |
|
47 * |
|
48 * @param aArray [in] an array of action cheker objects |
|
49 */ |
|
50 function testActions(aArray) |
|
51 { |
|
52 gActionsQueue = new eventQueue(); |
|
53 |
|
54 for (var idx = 0; idx < aArray.length; idx++) { |
|
55 |
|
56 var actionObj = aArray[idx]; |
|
57 var accOrElmOrID = actionObj.ID; |
|
58 var actionIndex = actionObj.actionIndex; |
|
59 var actionName = actionObj.actionName; |
|
60 var events = actionObj.events; |
|
61 var accOrElmOrIDOfTarget = actionObj.targetID ? |
|
62 actionObj.targetID : accOrElmOrID; |
|
63 |
|
64 var eventSeq = new Array(); |
|
65 if (events) { |
|
66 var elm = getNode(accOrElmOrIDOfTarget); |
|
67 if (events & MOUSEDOWN_EVENT) |
|
68 eventSeq.push(new checkerOfActionInvoker("mousedown", elm)); |
|
69 |
|
70 if (events & MOUSEUP_EVENT) |
|
71 eventSeq.push(new checkerOfActionInvoker("mouseup", elm)); |
|
72 |
|
73 if (events & CLICK_EVENT) |
|
74 eventSeq.push(new checkerOfActionInvoker("click", elm, actionObj)); |
|
75 |
|
76 if (events & COMMAND_EVENT) |
|
77 eventSeq.push(new checkerOfActionInvoker("command", elm)); |
|
78 |
|
79 if (events & FOCUS_EVENT) |
|
80 eventSeq.push(new focusChecker(elm)); |
|
81 } |
|
82 |
|
83 if (actionObj.eventSeq) |
|
84 eventSeq = eventSeq.concat(actionObj.eventSeq); |
|
85 |
|
86 var invoker = new actionInvoker(accOrElmOrID, actionIndex, actionName, |
|
87 eventSeq); |
|
88 gActionsQueue.push(invoker); |
|
89 } |
|
90 |
|
91 gActionsQueue.invoke(); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Test action names and descriptions. |
|
96 */ |
|
97 function testActionNames(aID, aActions) |
|
98 { |
|
99 var actions = (typeof aActions == "string") ? |
|
100 [ aActions ] : (aActions || []); |
|
101 |
|
102 var acc = getAccessible(aID); |
|
103 is(acc.actionCount, actions.length, "Wong number of actions."); |
|
104 for (var i = 0; i < actions.length; i++ ) { |
|
105 is(acc.getActionName(i), actions[i], "Wrong action name at " + i + " index."); |
|
106 is(acc.getActionDescription(0), gActionDescrMap[actions[i]], |
|
107 "Wrong action description at " + i + "index."); |
|
108 } |
|
109 } |
|
110 |
|
111 //////////////////////////////////////////////////////////////////////////////// |
|
112 // Private |
|
113 |
|
114 var gActionsQueue = null; |
|
115 |
|
116 function actionInvoker(aAccOrElmOrId, aActionIndex, aActionName, aEventSeq) |
|
117 { |
|
118 this.invoke = function actionInvoker_invoke() |
|
119 { |
|
120 var acc = getAccessible(aAccOrElmOrId); |
|
121 if (!acc) |
|
122 return INVOKER_ACTION_FAILED; |
|
123 |
|
124 var isThereActions = acc.actionCount > 0; |
|
125 ok(isThereActions, |
|
126 "No actions on the accessible for " + prettyName(aAccOrElmOrId)); |
|
127 |
|
128 if (!isThereActions) |
|
129 return INVOKER_ACTION_FAILED; |
|
130 |
|
131 is(acc.getActionName(aActionIndex), aActionName, |
|
132 "Wrong action name of the accessible for " + prettyName(aAccOrElmOrId)); |
|
133 |
|
134 try { |
|
135 acc.doAction(aActionIndex); |
|
136 } |
|
137 catch (e){ |
|
138 ok(false, "doAction(" + aActionIndex + ") failed with: " + e.name); |
|
139 return INVOKER_ACTION_FAILED; |
|
140 } |
|
141 } |
|
142 |
|
143 this.eventSeq = aEventSeq; |
|
144 |
|
145 this.getID = function actionInvoker_getID() |
|
146 { |
|
147 return "invoke an action " + aActionName + " at index " + aActionIndex + |
|
148 " on " + prettyName(aAccOrElmOrId); |
|
149 } |
|
150 } |
|
151 |
|
152 function checkerOfActionInvoker(aType, aTarget, aActionObj) |
|
153 { |
|
154 this.type = aType; |
|
155 |
|
156 this.target = aTarget; |
|
157 |
|
158 this.phase = false; |
|
159 |
|
160 this.getID = function getID() |
|
161 { |
|
162 return aType + " event handling"; |
|
163 } |
|
164 |
|
165 this.check = function check(aEvent) |
|
166 { |
|
167 if (aActionObj && "checkOnClickEvent" in aActionObj) |
|
168 aActionObj.checkOnClickEvent(aEvent); |
|
169 } |
|
170 } |
|
171 |
|
172 var gActionDescrMap = |
|
173 { |
|
174 jump: "Jump", |
|
175 press: "Press", |
|
176 check: "Check", |
|
177 uncheck: "Uncheck", |
|
178 select: "Select", |
|
179 open: "Open", |
|
180 close: "Close", |
|
181 switch: "Switch", |
|
182 click: "Click", |
|
183 collapse: "Collapse", |
|
184 expand: "Expand", |
|
185 activate: "Activate", |
|
186 cycle: "Cycle" |
|
187 }; |