1 ////////////////////////////////////////////////////////////////////////////////
4 const MOUSEDOWN_EVENT
= 1;
5 const MOUSEUP_EVENT
= 2;
7 const COMMAND_EVENT
= 8;
9 const CLICK_EVENTS
= MOUSEDOWN_EVENT
| MOUSEUP_EVENT
| CLICK_EVENT
;
10 const ALL_EVENTS
= CLICK_EVENTS
| COMMAND_EVENT
;
12 ////////////////////////////////////////////////////////////////////////////////
15 function testActions(aArray
, aIndex
)
20 if (aIndex
== aArray
.length
) {
25 var accOrElmOrID
= aArray
[aIndex
].ID
;
26 var actionName
= aArray
[aIndex
].actionName
;
27 var events
= aArray
[aIndex
].events
;
30 var acc
= getAccessible(accOrElmOrID
, null, elmObj
);
31 var elm
= elmObj
.value
;
33 var isThereActions
= acc
.numActions
> 0;
35 "No actions on the accessible for " + accOrElmOrID
);
37 if (!isThereActions
) {
42 is(acc
.getActionName(0), actionName
,
43 "Wrong action name of the accessible for " + accOrElmOrID
);
45 gEventHandler
.initialize(accOrElmOrID
, elm
, events
);
52 gEventHandler
.checkEvents();
53 testActions(aArray
, aIndex
+ 1);
59 ////////////////////////////////////////////////////////////////////////////////
64 initialize: function(aID
, aElm
, aExpectedEvents
)
68 this.mExpectedEvents
= aExpectedEvents
;
69 this.mFiredEvents
= 0;
71 if (this.mExpectedEvents
& MOUSEDOWN_EVENT
)
72 aElm
.addEventListener("mousedown", this, false);
74 if (this.mExpectedEvents
& MOUSEUP_EVENT
)
75 aElm
.addEventListener("mouseup", this, false);
77 if (this.mExpectedEvents
& CLICK_EVENT
)
78 aElm
.addEventListener("click", this, false);
80 if (this.mExpectedEvents
& COMMAND_EVENT
)
81 aElm
.addEventListener("command", this, false);
84 checkEvents: function()
86 if (this.mExpectedEvents
& MOUSEDOWN_EVENT
) {
87 ok(this.mFiredEvents
& MOUSEDOWN_EVENT
,
88 "mousedown hasn't been fired for " + this.ID
);
89 this.element
.removeEventListener("mousedown", this, false);
92 if (this.mExpectedEvents
& MOUSEUP_EVENT
) {
93 ok(this.mFiredEvents
& MOUSEUP_EVENT
,
94 "mouseup hasn't been fired for " + this.ID
);
95 this.element
.removeEventListener("mouseup", this, false);
98 if (this.mExpectedEvents
& CLICK_EVENT
) {
99 ok(this.mFiredEvents
& CLICK_EVENT
,
100 "click hasn't been fired for " + this.ID
);
101 this.element
.removeEventListener("click", this, false);
104 if (this.mExpectedEvents
& COMMAND_EVENT
) {
105 ok(this.mFiredEvents
& COMMAND_EVENT
,
106 "command hasn't been fired for " + this.ID
);
107 this.element
.removeEventListener("command", this, false);
114 handleEvent : function(aEvent
)
116 if (aEvent
.type
== "mousedown")
117 this.mFiredEvents
|= MOUSEDOWN_EVENT
;
118 else if(aEvent
.type
== "mouseup")
119 this.mFiredEvents
|= MOUSEUP_EVENT
;
120 else if(aEvent
.type
== "click")
121 this.mFiredEvents
|= CLICK_EVENT
;
122 else if(aEvent
.type
== "command")
123 this.mFiredEvents
|= COMMAND_EVENT
;