2009-02-18 23:06:14 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constants
|
|
|
|
|
2010-08-29 22:09:59 -07:00
|
|
|
const EVENT_ALERT = nsIAccessibleEvent.EVENT_ALERT;
|
2010-01-20 03:16:32 -08:00
|
|
|
const EVENT_DOCUMENT_LOAD_COMPLETE = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_COMPLETE;
|
2010-06-08 09:39:58 -07:00
|
|
|
const EVENT_DOCUMENT_RELOAD = nsIAccessibleEvent.EVENT_DOCUMENT_RELOAD;
|
|
|
|
const EVENT_DOCUMENT_LOAD_STOPPED = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_STOPPED;
|
2009-09-09 02:03:14 -07:00
|
|
|
const EVENT_HIDE = nsIAccessibleEvent.EVENT_HIDE;
|
2009-05-10 18:32:09 -07:00
|
|
|
const EVENT_FOCUS = nsIAccessibleEvent.EVENT_FOCUS;
|
2009-02-27 02:45:21 -08:00
|
|
|
const EVENT_NAME_CHANGE = nsIAccessibleEvent.EVENT_NAME_CHANGE;
|
2010-01-20 03:16:32 -08:00
|
|
|
const EVENT_REORDER = nsIAccessibleEvent.EVENT_REORDER;
|
2009-08-31 19:49:15 -07:00
|
|
|
const EVENT_SCROLLING_START = nsIAccessibleEvent.EVENT_SCROLLING_START;
|
2010-06-15 07:53:27 -07:00
|
|
|
const EVENT_SELECTION_ADD = nsIAccessibleEvent.EVENT_SELECTION_ADD;
|
|
|
|
const EVENT_SELECTION_WITHIN = nsIAccessibleEvent.EVENT_SELECTION_WITHIN;
|
2010-01-20 03:16:32 -08:00
|
|
|
const EVENT_SHOW = nsIAccessibleEvent.EVENT_SHOW;
|
2009-08-19 23:45:19 -07:00
|
|
|
const EVENT_STATE_CHANGE = nsIAccessibleEvent.EVENT_STATE_CHANGE;
|
2010-01-20 03:16:32 -08:00
|
|
|
const EVENT_TEXT_CARET_MOVED = nsIAccessibleEvent.EVENT_TEXT_CARET_MOVED;
|
2010-07-01 18:50:03 -07:00
|
|
|
const EVENT_TEXT_INSERTED = nsIAccessibleEvent.EVENT_TEXT_INSERTED;
|
2010-05-17 09:17:50 -07:00
|
|
|
const EVENT_TEXT_REMOVED = nsIAccessibleEvent.EVENT_TEXT_REMOVED;
|
2010-06-09 20:29:56 -07:00
|
|
|
const EVENT_VALUE_CHANGE = nsIAccessibleEvent.EVENT_VALUE_CHANGE;
|
2009-02-18 23:06:14 -08:00
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
2009-02-04 22:23:18 -08:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump events into DOM.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpID = "";
|
|
|
|
|
2010-06-17 19:44:09 -07:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump event processing into console.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpToConsole = false;
|
|
|
|
|
2009-02-18 23:06:14 -08:00
|
|
|
/**
|
|
|
|
* Executes the function when requested event is handled.
|
|
|
|
*
|
|
|
|
* @param aEventType [in] event type
|
|
|
|
* @param aTarget [in] event target
|
|
|
|
* @param aFunc [in] function to call when event is handled
|
|
|
|
* @param aContext [in, optional] object in which context the function is
|
|
|
|
* called
|
|
|
|
* @param aArg1 [in, optional] argument passed into the function
|
|
|
|
* @param aArg2 [in, optional] argument passed into the function
|
|
|
|
*/
|
|
|
|
function waitForEvent(aEventType, aTarget, aFunc, aContext, aArg1, aArg2)
|
|
|
|
{
|
|
|
|
var handler = {
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
2009-09-18 23:30:07 -07:00
|
|
|
|
|
|
|
if (aTarget) {
|
|
|
|
if (aTarget instanceof nsIAccessible &&
|
|
|
|
aTarget != aEvent.accessible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aTarget instanceof nsIDOMNode &&
|
|
|
|
aTarget != aEvent.DOMNode)
|
|
|
|
return;
|
2009-02-18 23:06:14 -08:00
|
|
|
}
|
2009-09-18 23:30:07 -07:00
|
|
|
|
|
|
|
unregisterA11yEventListener(aEventType, this);
|
|
|
|
|
|
|
|
window.setTimeout(
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
aFunc.call(aContext, aArg1, aArg2);
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2009-02-18 23:06:14 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
registerA11yEventListener(aEventType, handler);
|
|
|
|
}
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
/**
|
|
|
|
* Register accessibility event listener.
|
|
|
|
*
|
|
|
|
* @param aEventType the accessible event type (see nsIAccessibleEvent for
|
|
|
|
* available constants).
|
|
|
|
* @param aEventHandler event listener object, when accessible event of the
|
|
|
|
* given type is handled then 'handleEvent' method of
|
|
|
|
* this object is invoked with nsIAccessibleEvent object
|
|
|
|
* as the first argument.
|
|
|
|
*/
|
|
|
|
function registerA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
listenA11yEvents(true);
|
|
|
|
addA11yEventListener(aEventType, aEventHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister accessibility event listener. Must be called for every registered
|
|
|
|
* event listener (see registerA11yEventListener() function) when the listener
|
|
|
|
* is not needed.
|
|
|
|
*/
|
|
|
|
function unregisterA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
removeA11yEventListener(aEventType, aEventHandler);
|
|
|
|
listenA11yEvents(false);
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
/**
|
|
|
|
* Return value of invoke method of invoker object. Indicates invoker was unable
|
|
|
|
* to prepare action.
|
|
|
|
*/
|
|
|
|
const INVOKER_ACTION_FAILED = 1;
|
|
|
|
|
2009-09-18 23:30:07 -07:00
|
|
|
/**
|
|
|
|
* Return value of eventQueue.onFinish. Indicates eventQueue should not finish
|
|
|
|
* tests.
|
|
|
|
*/
|
|
|
|
const DO_NOT_FINISH_TEST = 1;
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
/**
|
|
|
|
* Creates event queue for the given event type. The queue consists of invoker
|
|
|
|
* objects, each of them generates the event of the event type. When queue is
|
|
|
|
* started then every invoker object is asked to generate event after timeout.
|
2009-06-11 12:57:29 -07:00
|
|
|
* When event is caught then current invoker object is asked to check whether
|
2009-01-24 20:42:21 -08:00
|
|
|
* event was handled correctly.
|
|
|
|
*
|
|
|
|
* Invoker interface is:
|
|
|
|
*
|
|
|
|
* var invoker = {
|
2009-05-10 18:32:09 -07:00
|
|
|
* // Generates accessible event or event sequence. If returns
|
|
|
|
* // INVOKER_ACTION_FAILED constant then stop tests.
|
2009-01-24 20:42:21 -08:00
|
|
|
* invoke: function(){},
|
|
|
|
*
|
2009-02-27 02:45:21 -08:00
|
|
|
* // [optional] Invoker's check of handled event for correctness.
|
2009-01-24 20:42:21 -08:00
|
|
|
* check: function(aEvent){},
|
|
|
|
*
|
2010-06-08 09:39:58 -07:00
|
|
|
* // [optional] Invoker's check before the next invoker is proceeded.
|
|
|
|
* finalCheck: function(aEvent){},
|
|
|
|
*
|
2009-02-27 02:45:21 -08:00
|
|
|
* // [optional] Is called when event of registered type is handled.
|
2009-01-24 20:42:21 -08:00
|
|
|
* debugCheck: function(aEvent){},
|
|
|
|
*
|
2009-02-27 02:45:21 -08:00
|
|
|
* // [ignored if 'eventSeq' is defined] DOM node event is generated for
|
|
|
|
* // (used in the case when invoker expects single event).
|
|
|
|
* DOMNode getter: function() {},
|
2009-01-24 20:42:21 -08:00
|
|
|
*
|
2009-09-02 19:01:18 -07:00
|
|
|
* // Array of checker objects defining expected events on invoker's action.
|
2009-02-27 02:45:21 -08:00
|
|
|
* //
|
2009-09-02 19:01:18 -07:00
|
|
|
* // Checker object interface:
|
2009-02-27 02:45:21 -08:00
|
|
|
* //
|
|
|
|
* // var checker = {
|
|
|
|
* // type getter: function() {}, // DOM or a11y event type
|
|
|
|
* // target getter: function() {}, // DOM node or accessible
|
2009-08-19 23:45:19 -07:00
|
|
|
* // phase getter: function() {}, // DOM event phase (false - bubbling)
|
2009-02-27 02:45:21 -08:00
|
|
|
* // check: function(aEvent) {},
|
|
|
|
* // getID: function() {}
|
|
|
|
* // };
|
2009-01-24 20:42:21 -08:00
|
|
|
* eventSeq getter() {},
|
|
|
|
*
|
2009-09-02 19:01:18 -07:00
|
|
|
* // Array of checker objects defining unexpected events on invoker's
|
|
|
|
* // action.
|
|
|
|
* unexpectedEventSeq getter() {},
|
2009-01-24 20:42:21 -08:00
|
|
|
*
|
|
|
|
* // The ID of invoker.
|
|
|
|
* getID: function(){} // returns invoker ID
|
|
|
|
* };
|
|
|
|
*
|
2009-09-18 23:30:07 -07:00
|
|
|
* @param aEventType [in, optional] the default event type (isn't used if
|
|
|
|
* invoker defines eventSeq property).
|
2009-01-24 20:42:21 -08:00
|
|
|
*/
|
|
|
|
function eventQueue(aEventType)
|
|
|
|
{
|
|
|
|
// public
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add invoker object into queue.
|
|
|
|
*/
|
|
|
|
this.push = function eventQueue_push(aEventInvoker)
|
|
|
|
{
|
|
|
|
this.mInvokers.push(aEventInvoker);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the queue processing.
|
|
|
|
*/
|
|
|
|
this.invoke = function eventQueue_invoke()
|
|
|
|
{
|
|
|
|
listenA11yEvents(true);
|
|
|
|
|
|
|
|
// XXX: Intermittent test_events_caretmove.html fails withouth timeout,
|
|
|
|
// see bug 474952.
|
2009-09-02 19:01:18 -07:00
|
|
|
this.processNextInvokerInTimeout(true);
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
|
2009-08-21 06:20:18 -07:00
|
|
|
/**
|
|
|
|
* This function is called when all events in the queue were handled.
|
|
|
|
* Override it if you need to be notified of this.
|
|
|
|
*/
|
|
|
|
this.onFinish = function eventQueue_finish()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
// private
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process next invoker.
|
|
|
|
*/
|
|
|
|
this.processNextInvoker = function eventQueue_processNextInvoker()
|
|
|
|
{
|
2010-02-05 12:30:14 -08:00
|
|
|
// Finish processing of the current invoker.
|
2009-01-24 20:42:21 -08:00
|
|
|
var testFailed = false;
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if (invoker) {
|
2009-09-02 19:01:18 -07:00
|
|
|
if ("finalCheck" in invoker)
|
|
|
|
invoker.finalCheck();
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
if (invoker.wasCaught) {
|
2009-02-27 02:45:21 -08:00
|
|
|
for (var idx = 0; idx < invoker.wasCaught.length; idx++) {
|
|
|
|
var id = this.getEventID(idx);
|
|
|
|
var type = this.getEventType(idx);
|
2009-09-02 19:01:18 -07:00
|
|
|
var unexpected = this.mEventSeq[idx].unexpected;
|
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
var typeStr = (typeof type == "string") ?
|
|
|
|
type : gAccRetrieval.getStringEventType(type);
|
2009-01-24 20:42:21 -08:00
|
|
|
|
|
|
|
var msg = "test with ID = '" + id + "' failed. ";
|
2009-09-02 19:01:18 -07:00
|
|
|
if (unexpected) {
|
2009-02-27 02:45:21 -08:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-24 20:42:21 -08:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = wasCaught;
|
|
|
|
|
|
|
|
ok(!wasCaught,
|
|
|
|
msg + "There is unexpected " + typeStr + " event.");
|
|
|
|
|
|
|
|
} else {
|
2009-02-27 02:45:21 -08:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-24 20:42:21 -08:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = !wasCaught;
|
|
|
|
|
|
|
|
ok(wasCaught,
|
|
|
|
msg + "No " + typeStr + " event.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
testFailed = true;
|
2009-02-27 02:45:21 -08:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var id = this.getEventID(idx);
|
|
|
|
ok(false,
|
|
|
|
"test with ID = '" + id + "' failed. No events were registered.");
|
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler();
|
|
|
|
|
|
|
|
// Check if need to stop the test.
|
|
|
|
if (testFailed || this.mIndex == this.mInvokers.length - 1) {
|
|
|
|
listenA11yEvents(false);
|
|
|
|
|
2009-09-18 23:30:07 -07:00
|
|
|
var res = this.onFinish();
|
|
|
|
if (res != DO_NOT_FINISH_TEST)
|
|
|
|
SimpleTest.finish();
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start processing of next invoker.
|
|
|
|
invoker = this.getNextInvoker();
|
|
|
|
|
|
|
|
this.setEventHandler(invoker);
|
|
|
|
|
2010-06-17 19:44:09 -07:00
|
|
|
if (gA11yEventDumpToConsole)
|
|
|
|
dump("\nEvent queue: \n invoke: " + invoker.getID() + "\n");
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
if (invoker.invoke() == INVOKER_ACTION_FAILED) {
|
|
|
|
// Invoker failed to prepare action, fail and finish tests.
|
|
|
|
this.processNextInvoker();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
if (this.areAllEventsUnexpected())
|
|
|
|
this.processNextInvokerInTimeout(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.processNextInvokerInTimeout = function eventQueue_processNextInvokerInTimeout(aUncondProcess)
|
|
|
|
{
|
|
|
|
if (!aUncondProcess && this.areAllEventsExpected()) {
|
|
|
|
// We need delay to avoid events coalesce from different invokers.
|
|
|
|
var queue = this;
|
|
|
|
SimpleTest.executeSoon(function() { queue.processNextInvoker(); });
|
|
|
|
return;
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
2009-09-02 19:01:18 -07:00
|
|
|
|
|
|
|
// Check in timeout invoker didn't fire registered events.
|
|
|
|
window.setTimeout(function(aQueue) { aQueue.processNextInvoker(); }, 500,
|
|
|
|
this);
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle events for the current invoker.
|
|
|
|
*/
|
|
|
|
this.handleEvent = function eventQueue_handleEvent(aEvent)
|
|
|
|
{
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if (!invoker) // skip events before test was started
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!this.mEventSeq) {
|
|
|
|
// Bad invoker object, error will be reported before processing of next
|
|
|
|
// invoker in the queue.
|
|
|
|
this.processNextInvoker();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("debugCheck" in invoker)
|
|
|
|
invoker.debugCheck(aEvent);
|
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
// Search through unexpected events to ensure no one of them was handled.
|
2010-08-29 22:08:00 -07:00
|
|
|
var idx = 0;
|
|
|
|
for (; idx < this.mEventSeq.length; idx++) {
|
2009-09-02 19:01:18 -07:00
|
|
|
if (this.mEventSeq[idx].unexpected && this.compareEvents(idx, aEvent))
|
|
|
|
invoker.wasCaught[idx] = true;
|
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
|
2010-08-29 22:08:00 -07:00
|
|
|
// We've handled all expected events, next invoker processing is pending.
|
|
|
|
if (this.mEventSeqIdx == this.mEventSeq.length)
|
|
|
|
return;
|
2009-02-04 22:23:18 -08:00
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
// Compute next expected event index.
|
2010-08-29 22:08:00 -07:00
|
|
|
for (idx = this.mEventSeqIdx + 1;
|
|
|
|
idx < this.mEventSeq.length && this.mEventSeq[idx].unexpected;
|
|
|
|
idx++);
|
2009-01-24 20:42:21 -08:00
|
|
|
|
2010-08-29 22:08:00 -07:00
|
|
|
// No expected events were registered, proceed to next invoker to ensure
|
|
|
|
// unexpected events for current invoker won't be handled.
|
2009-09-02 19:01:18 -07:00
|
|
|
if (idx == this.mEventSeq.length) {
|
2010-08-29 22:08:00 -07:00
|
|
|
this.mEventSeqIdx = idx;
|
2009-09-02 19:01:18 -07:00
|
|
|
this.processNextInvokerInTimeout();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
|
2010-08-29 22:08:00 -07:00
|
|
|
// Check if handled event matches expected event.
|
2009-09-02 19:01:18 -07:00
|
|
|
var matched = this.compareEvents(idx, aEvent);
|
|
|
|
this.dumpEventToDOM(aEvent, idx, matched);
|
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
this.checkEvent(idx, aEvent);
|
|
|
|
invoker.wasCaught[idx] = true;
|
2010-08-29 22:08:00 -07:00
|
|
|
this.mEventSeqIdx = idx;
|
2009-09-02 19:01:18 -07:00
|
|
|
|
2010-08-29 22:08:00 -07:00
|
|
|
// Get next expected event index.
|
|
|
|
while (++idx < this.mEventSeq.length && this.mEventSeq[idx].unexpected);
|
|
|
|
|
|
|
|
// If the last expected event was processed, proceed next invoker in
|
|
|
|
// timeout to ensure unexpected events for current invoker won't be
|
|
|
|
// handled.
|
|
|
|
if (idx == this.mEventSeq.length) {
|
|
|
|
this.mEventSeqIdx = idx;
|
2009-09-02 19:01:18 -07:00
|
|
|
this.processNextInvokerInTimeout();
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
this.getInvoker = function eventQueue_getInvoker()
|
|
|
|
{
|
|
|
|
return this.mInvokers[this.mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getNextInvoker = function eventQueue_getNextInvoker()
|
|
|
|
{
|
|
|
|
return this.mInvokers[++this.mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setEventHandler = function eventQueue_setEventHandler(aInvoker)
|
|
|
|
{
|
2009-09-02 19:01:18 -07:00
|
|
|
// Create unique event sequence concatenating expected and unexpected
|
|
|
|
// events.
|
2009-01-24 20:42:21 -08:00
|
|
|
this.mEventSeq = ("eventSeq" in aInvoker) ?
|
2009-07-27 19:28:06 -07:00
|
|
|
aInvoker.eventSeq :
|
|
|
|
[ new invokerChecker(this.mDefEventType, aInvoker.DOMNode) ];
|
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++)
|
|
|
|
this.mEventSeq[idx].unexpected = false;
|
|
|
|
|
|
|
|
var unexpectedSeq = aInvoker.unexpectedEventSeq;
|
|
|
|
if (unexpectedSeq) {
|
|
|
|
for (var idx = 0; idx < unexpectedSeq.length; idx++)
|
|
|
|
unexpectedSeq[idx].unexpected = true;
|
|
|
|
|
|
|
|
this.mEventSeq = this.mEventSeq.concat(unexpectedSeq);
|
|
|
|
}
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
this.mEventSeqIdx = -1;
|
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
// Register event listeners
|
2009-01-24 20:42:21 -08:00
|
|
|
if (this.mEventSeq) {
|
|
|
|
aInvoker.wasCaught = new Array(this.mEventSeq.length);
|
2009-02-04 22:23:18 -08:00
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2009-08-21 06:20:18 -07:00
|
|
|
if (typeof eventType == "string") {
|
|
|
|
// DOM event
|
|
|
|
var target = this.getEventTarget(idx);
|
|
|
|
var phase = this.getEventPhase(idx);
|
|
|
|
target.ownerDocument.addEventListener(eventType, this, phase);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// A11y event
|
2009-02-27 02:45:21 -08:00
|
|
|
addA11yEventListener(eventType, this);
|
2009-08-21 06:20:18 -07:00
|
|
|
}
|
2009-02-27 02:45:21 -08:00
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler = function eventQueue_clearEventHandler()
|
|
|
|
{
|
|
|
|
if (this.mEventSeq) {
|
2009-02-27 02:45:21 -08:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2009-08-21 06:20:18 -07:00
|
|
|
if (typeof eventType == "string") {
|
|
|
|
// DOM event
|
|
|
|
var target = this.getEventTarget(idx);
|
|
|
|
var phase = this.getEventPhase(idx);
|
|
|
|
target.ownerDocument.removeEventListener(eventType, this, phase);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// A11y event
|
2009-02-27 02:45:21 -08:00
|
|
|
removeA11yEventListener(eventType, this);
|
2009-08-21 06:20:18 -07:00
|
|
|
}
|
2009-02-27 02:45:21 -08:00
|
|
|
}
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
this.mEventSeq = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
this.getEventType = function eventQueue_getEventType(aIdx)
|
|
|
|
{
|
2009-07-27 19:28:06 -07:00
|
|
|
return this.mEventSeq[aIdx].type;
|
2009-02-27 02:45:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.getEventTarget = function eventQueue_getEventTarget(aIdx)
|
|
|
|
{
|
2009-07-27 19:28:06 -07:00
|
|
|
return this.mEventSeq[aIdx].target;
|
2009-02-27 02:45:21 -08:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
this.getEventPhase = function eventQueue_getEventPhase(aIdx)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("phase" in eventItem)
|
|
|
|
return eventItem.phase;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
this.getEventID = function eventQueue_getEventID(aIdx)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("getID" in eventItem)
|
|
|
|
return eventItem.getID();
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
return invoker.getID();
|
|
|
|
}
|
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
this.compareEvents = function eventQueue_compareEvents(aIdx, aEvent)
|
|
|
|
{
|
|
|
|
var eventType1 = this.getEventType(aIdx);
|
|
|
|
|
|
|
|
var eventType2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
aEvent.type : aEvent.eventType;
|
|
|
|
|
|
|
|
if (eventType1 != eventType2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var target1 = this.getEventTarget(aIdx);
|
|
|
|
if (target1 instanceof nsIAccessible) {
|
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
getAccessible(aEvent.target) : aEvent.accessible;
|
|
|
|
|
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
// If original target isn't suitable then extend interface to support target
|
|
|
|
// (original target is used in test_elm_media.html).
|
2009-02-27 02:45:21 -08:00
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
2009-05-10 18:32:09 -07:00
|
|
|
aEvent.originalTarget : aEvent.DOMNode;
|
2009-02-27 02:45:21 -08:00
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.checkEvent = function eventQueue_checkEvent(aIdx, aEvent)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("check" in eventItem)
|
|
|
|
eventItem.check(aEvent);
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if ("check" in invoker)
|
|
|
|
invoker.check(aEvent);
|
|
|
|
}
|
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
this.areAllEventsExpected = function eventQueue_areAllEventsExpected()
|
2009-02-27 02:45:21 -08:00
|
|
|
{
|
2009-09-02 19:01:18 -07:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
if (this.mEventSeq[idx].unexpected)
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-27 02:45:21 -08:00
|
|
|
|
2009-09-02 19:01:18 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.areAllEventsUnexpected = function eventQueue_areAllEventsUnxpected()
|
|
|
|
{
|
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
if (!this.mEventSeq[idx].unexpected)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-02-27 02:45:21 -08:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
this.dumpEventToDOM = function eventQueue_dumpEventToDOM(aOrigEvent,
|
|
|
|
aExpectedEventIdx,
|
|
|
|
aMatch)
|
|
|
|
{
|
|
|
|
if (!gA11yEventDumpID) // debug stuff
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Dump DOM event information. Skip a11y event since it is dumped by
|
|
|
|
// gA11yEventObserver.
|
|
|
|
if (aOrigEvent instanceof nsIDOMEvent) {
|
|
|
|
var info = "Event type: " + aOrigEvent.type;
|
|
|
|
info += ". Target: " + prettyName(aOrigEvent.originalTarget);
|
|
|
|
dumpInfoToDOM(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
var currType = this.getEventType(aExpectedEventIdx);
|
|
|
|
var currTarget = this.getEventTarget(aExpectedEventIdx);
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
var containerTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"div" : "description";
|
|
|
|
var inlineTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"span" : "description";
|
|
|
|
|
|
|
|
var container = document.createElement(containerTagName);
|
|
|
|
container.setAttribute("style", "padding-left: 10px;");
|
|
|
|
|
|
|
|
var text1 = document.createTextNode("EQ: ");
|
|
|
|
container.appendChild(text1);
|
|
|
|
|
|
|
|
var styledNode = document.createElement(inlineTagName);
|
|
|
|
if (aMatch) {
|
|
|
|
styledNode.setAttribute("style", "color: blue;");
|
|
|
|
styledNode.textContent = "matched";
|
|
|
|
|
|
|
|
// Dump matched events into console.
|
|
|
|
dump("\n*****\nEQ matched: " + eventTypeToString(currType) + "\n*****\n");
|
|
|
|
} else {
|
|
|
|
styledNode.textContent = "expected";
|
|
|
|
}
|
|
|
|
container.appendChild(styledNode);
|
|
|
|
|
|
|
|
var info = " event, type: ";
|
2009-08-19 23:45:19 -07:00
|
|
|
info += (typeof currType == "string") ?
|
|
|
|
currType : eventTypeToString(currType);
|
|
|
|
info += ". Target: " + prettyName(currTarget);
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
var text1 = document.createTextNode(info);
|
|
|
|
container.appendChild(text1);
|
|
|
|
|
|
|
|
dumpInfoToDOM(container);
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
this.mDefEventType = aEventType;
|
|
|
|
|
|
|
|
this.mInvokers = new Array();
|
|
|
|
this.mIndex = -1;
|
|
|
|
|
|
|
|
this.mEventSeq = null;
|
|
|
|
this.mEventSeqIdx = -1;
|
|
|
|
}
|
|
|
|
|
2009-09-18 23:30:07 -07:00
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Action sequence
|
|
|
|
|
2009-09-18 23:30:07 -07:00
|
|
|
/**
|
|
|
|
* Deal with action sequence. Used when you need to execute couple of actions
|
|
|
|
* each after other one.
|
|
|
|
*/
|
|
|
|
function sequence()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Append new sequence item.
|
|
|
|
*
|
|
|
|
* @param aProcessor [in] object implementing interface
|
|
|
|
* {
|
|
|
|
* // execute item action
|
|
|
|
* process: function() {},
|
|
|
|
* // callback, is called when item was processed
|
|
|
|
* onProcessed: function() {}
|
|
|
|
* };
|
|
|
|
* @param aEventType [in] event type of expected event on item action
|
|
|
|
* @param aTarget [in] event target of expected event on item action
|
|
|
|
* @param aItemID [in] identifier of item
|
|
|
|
*/
|
|
|
|
this.append = function sequence_append(aProcessor, aEventType, aTarget,
|
|
|
|
aItemID)
|
|
|
|
{
|
|
|
|
var item = new sequenceItem(aProcessor, aEventType, aTarget, aItemID);
|
|
|
|
this.items.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process next sequence item.
|
|
|
|
*/
|
|
|
|
this.processNext = function sequence_processNext()
|
|
|
|
{
|
|
|
|
this.idx++;
|
|
|
|
if (this.idx >= this.items.length) {
|
|
|
|
ok(false, "End of sequence: nothing to process!");
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items[this.idx].startProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = new Array();
|
|
|
|
this.idx = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue invokers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokers defined below take a checker object implementing 'check' method
|
|
|
|
* which will be called when proper event is handled. Invokers listen default
|
2010-01-20 03:16:32 -08:00
|
|
|
* event type registered in event queue object until it is passed explicetly.
|
2009-10-06 00:50:47 -07:00
|
|
|
*
|
2010-03-12 20:24:51 -08:00
|
|
|
* Note, checker object is optional.
|
2009-10-06 00:50:47 -07:00
|
|
|
* Note, you don't need to initialize 'target' and 'type' members of checker
|
|
|
|
* object. The 'target' member will be initialized by invoker object and you are
|
|
|
|
* free to use it in 'check' method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthClick(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.invoke = function synthClick_invoke()
|
|
|
|
{
|
|
|
|
// Scroll the node into view, otherwise synth click may fail.
|
2010-03-17 22:44:57 -07:00
|
|
|
if (this.DOMNode instanceof nsIDOMNSHTMLElement)
|
|
|
|
this.DOMNode.scrollIntoView(true);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
synthesizeMouse(this.DOMNode, 1, 1, {});
|
|
|
|
}
|
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
this.getID = function synthClick_getID()
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " click";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 22:44:57 -07:00
|
|
|
/**
|
|
|
|
* Mouse move invoker.
|
|
|
|
*/
|
|
|
|
function synthMouseMove(aNodeOrID, aChecker, aEventType)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
|
|
|
|
|
|
|
|
this.invoke = function synthMouseMove_invoke()
|
|
|
|
{
|
|
|
|
synthesizeMouse(this.DOMNode, 1, 1, { type: "mousemove" });
|
|
|
|
synthesizeMouse(this.DOMNode, 2, 2, { type: "mousemove" });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthMouseMove_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " mouse move";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
/**
|
|
|
|
* General key press invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthKey(aNodeOrID, aKey, aArgs, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.invoke = function synthKey_invoke()
|
|
|
|
{
|
|
|
|
synthesizeKey(this.mKey, this.mArgs);
|
|
|
|
}
|
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
this.getID = function synthKey_getID()
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " '" + this.mKey + "' key";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mKey = aKey;
|
|
|
|
this.mArgs = aArgs ? aArgs : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tab key invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthTab(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB", { shiftKey: false },
|
2010-01-20 03:16:32 -08:00
|
|
|
aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
this.getID = function synthTab_getID()
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " tab";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shift tab key invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthShiftTab(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB", { shiftKey: true },
|
2010-01-20 03:16:32 -08:00
|
|
|
aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.getID = function synthTabTest_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " shift tab";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Down arrow key invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthDownKey(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_DOWN", null, aChecker,
|
|
|
|
aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.getID = function synthDownKey_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " key down";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Right arrow key invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthRightKey(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_RIGHT", null, aChecker,
|
|
|
|
aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.getID = function synthRightKey_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " key right";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
/**
|
|
|
|
* Home key invoker.
|
|
|
|
*/
|
|
|
|
function synthHomeKey(aNodeOrID, aChecker, aEventType)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_HOME", null, aChecker,
|
|
|
|
aEventType);
|
|
|
|
|
|
|
|
this.getID = function synthHomeKey_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " key home";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
/**
|
|
|
|
* Focus invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthFocus(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.invoke = function synthFocus_invoke()
|
|
|
|
{
|
|
|
|
this.DOMNode.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthFocus_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " focus";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 22:44:57 -07:00
|
|
|
/**
|
|
|
|
* Focus invoker. Focus the HTML body of content document of iframe.
|
|
|
|
*/
|
|
|
|
function synthFocusOnFrame(aNodeOrID, aChecker, aEventType)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthAction(getNode(aNodeOrID).contentDocument,
|
|
|
|
aChecker, aEventType);
|
|
|
|
|
|
|
|
this.invoke = function synthFocus_invoke()
|
|
|
|
{
|
|
|
|
this.DOMNode.body.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthFocus_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " frame document focus";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
/**
|
|
|
|
* Select all invoker.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthSelectAll(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
2010-01-20 03:16:32 -08:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
this.invoke = function synthSelectAll_invoke()
|
|
|
|
{
|
|
|
|
if (this.DOMNode instanceof Components.interfaces.nsIDOMHTMLInputElement)
|
|
|
|
this.DOMNode.select();
|
|
|
|
else
|
|
|
|
window.getSelection().selectAllChildren(this.DOMNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthSelectAll_getID()
|
|
|
|
{
|
|
|
|
return aNodeOrID + " selectall";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue checkers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common invoker checker (see eventSeq of eventQueue).
|
|
|
|
*/
|
2010-06-08 09:39:58 -07:00
|
|
|
function invokerChecker(aEventType, aTargetOrFunc, aTargetFuncArg)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
this.type = aEventType;
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
this.__defineGetter__("target", invokerChecker_targetGetter);
|
|
|
|
this.__defineSetter__("target", invokerChecker_targetSetter);
|
|
|
|
|
|
|
|
// implementation details
|
|
|
|
function invokerChecker_targetGetter()
|
|
|
|
{
|
|
|
|
if (typeof this.mTarget == "function")
|
|
|
|
return this.mTarget.call(null, this.mTargetFuncArg);
|
|
|
|
|
|
|
|
return this.mTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
function invokerChecker_targetSetter(aValue)
|
|
|
|
{
|
|
|
|
this.mTarget = aValue;
|
|
|
|
return this.mTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mTarget = aTargetOrFunc;
|
|
|
|
this.mTargetFuncArg = aTargetFuncArg;
|
2009-10-06 00:50:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private implementation details.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
|
|
|
var gA11yEventListeners = {};
|
|
|
|
var gA11yEventApplicantsCount = 0;
|
|
|
|
|
|
|
|
var gA11yEventObserver =
|
|
|
|
{
|
2010-02-04 10:15:03 -08:00
|
|
|
// The service reference needs to live in the observer, instead of as a global var,
|
|
|
|
// to be available in observe() catch case too.
|
2010-02-05 12:30:14 -08:00
|
|
|
observerService :
|
|
|
|
Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(nsIObserverService),
|
2010-02-04 10:15:03 -08:00
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
observe: function observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic != "accessible-event")
|
|
|
|
return;
|
|
|
|
|
2010-02-04 10:15:03 -08:00
|
|
|
var event;
|
|
|
|
try {
|
|
|
|
event = aSubject.QueryInterface(nsIAccessibleEvent);
|
|
|
|
} catch (ex) {
|
|
|
|
// After a test is aborted (i.e. timed out by the harness), this exception is soon triggered.
|
|
|
|
// Remove the leftover observer, otherwise it "leaks" to all the following tests.
|
|
|
|
this.observerService.removeObserver(this, "accessible-event");
|
|
|
|
// Forward the exception, with added explanation.
|
|
|
|
throw "[accessible/events.js, gA11yEventObserver.observe] This is expected if a previous test has been aborted... Initial exception was: [ " + ex + " ]";
|
|
|
|
}
|
2009-01-24 20:42:21 -08:00
|
|
|
var listenersArray = gA11yEventListeners[event.eventType];
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
var eventFromDumpArea = false;
|
2009-01-24 20:42:21 -08:00
|
|
|
if (gA11yEventDumpID) { // debug stuff
|
2010-06-08 09:39:58 -07:00
|
|
|
eventFromDumpArea = true;
|
|
|
|
|
2009-01-24 20:42:21 -08:00
|
|
|
var target = event.DOMNode;
|
2009-02-04 22:23:18 -08:00
|
|
|
var dumpElm = document.getElementById(gA11yEventDumpID);
|
2009-01-24 20:42:21 -08:00
|
|
|
|
|
|
|
var parent = target;
|
|
|
|
while (parent && parent != dumpElm)
|
|
|
|
parent = parent.parentNode;
|
|
|
|
|
|
|
|
if (parent != dumpElm) {
|
2009-02-27 02:45:21 -08:00
|
|
|
var type = eventTypeToString(event.eventType);
|
|
|
|
var info = "Event type: " + type;
|
2010-07-01 18:50:03 -07:00
|
|
|
|
|
|
|
if (event instanceof nsIAccessibleTextChangeEvent) {
|
|
|
|
info += ", start: " + event.start + ", length: " + event.length +
|
|
|
|
", " + (event.isInserted() ? "inserted" : "removed") +
|
|
|
|
" text: " + event.modifiedText;
|
|
|
|
}
|
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
info += ". Target: " + prettyName(event.accessible);
|
2009-01-24 20:42:21 -08:00
|
|
|
|
2009-02-04 22:23:18 -08:00
|
|
|
if (listenersArray)
|
|
|
|
info += ". Listeners count: " + listenersArray.length;
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
eventFromDumpArea = false;
|
2009-02-04 22:23:18 -08:00
|
|
|
dumpInfoToDOM(info);
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
// Do not notify listeners if event is result of event log changes.
|
|
|
|
if (!listenersArray || eventFromDumpArea)
|
2009-01-24 20:42:21 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (var index = 0; index < listenersArray.length; index++)
|
|
|
|
listenersArray[index].handleEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function listenA11yEvents(aStartToListen)
|
|
|
|
{
|
2010-02-05 12:30:14 -08:00
|
|
|
if (aStartToListen) {
|
|
|
|
// Add observer when adding the first applicant only.
|
|
|
|
if (!(gA11yEventApplicantsCount++))
|
|
|
|
gA11yEventObserver.observerService
|
|
|
|
.addObserver(gA11yEventObserver, "accessible-event", false);
|
|
|
|
} else {
|
|
|
|
// Remove observer when there are no more applicants only.
|
|
|
|
// '< 0' case should not happen, but just in case: removeObserver() will throw.
|
|
|
|
if (--gA11yEventApplicantsCount <= 0)
|
|
|
|
gA11yEventObserver.observerService
|
|
|
|
.removeObserver(gA11yEventObserver, "accessible-event");
|
2009-01-24 20:42:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
if (!(aEventType in gA11yEventListeners))
|
|
|
|
gA11yEventListeners[aEventType] = new Array();
|
|
|
|
|
|
|
|
gA11yEventListeners[aEventType].push(aEventHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
var listenersArray = gA11yEventListeners[aEventType];
|
|
|
|
if (!listenersArray)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var index = listenersArray.indexOf(aEventHandler);
|
|
|
|
if (index == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
listenersArray.splice(index, 1);
|
|
|
|
|
|
|
|
if (!listenersArray.length) {
|
|
|
|
gA11yEventListeners[aEventType] = null;
|
|
|
|
delete gA11yEventListeners[aEventType];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-04 22:23:18 -08:00
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
/**
|
|
|
|
* Dumps message to DOM.
|
|
|
|
*
|
2010-06-08 09:39:58 -07:00
|
|
|
* @param aInfo [in] the message or DOM node to dump
|
2009-05-10 18:32:09 -07:00
|
|
|
* @param aDumpNode [in, optional] host DOM node for dumped message, if ommited
|
|
|
|
* then global variable gA11yEventDumpID is used
|
|
|
|
*/
|
|
|
|
function dumpInfoToDOM(aInfo, aDumpNode)
|
2009-02-04 22:23:18 -08:00
|
|
|
{
|
2009-05-10 18:32:09 -07:00
|
|
|
var dumpID = gA11yEventDumpID ? gA11yEventDumpID : aDumpNode;
|
|
|
|
if (!dumpID)
|
2009-02-18 23:06:14 -08:00
|
|
|
return;
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2009-05-10 18:32:09 -07:00
|
|
|
var dumpElm = document.getElementById(dumpID);
|
2010-01-20 03:16:32 -08:00
|
|
|
if (!dumpElm) {
|
|
|
|
ok(false, "No dump element '" + dumpID + "' within the document!");
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
var containerTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"div" : "description";
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2009-02-27 02:45:21 -08:00
|
|
|
var container = document.createElement(containerTagName);
|
2010-06-08 09:39:58 -07:00
|
|
|
if (aInfo instanceof nsIDOMNode)
|
|
|
|
container.appendChild(aInfo);
|
|
|
|
else
|
|
|
|
container.textContent = aInfo;
|
2009-02-27 02:45:21 -08:00
|
|
|
|
|
|
|
dumpElm.appendChild(container);
|
2009-02-04 22:23:18 -08:00
|
|
|
}
|
2009-09-18 23:30:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Sequence
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class of sequence item.
|
|
|
|
*/
|
|
|
|
function sequenceItem(aProcessor, aEventType, aTarget, aItemID)
|
|
|
|
{
|
|
|
|
// private
|
|
|
|
|
|
|
|
this.startProcess = function sequenceItem_startProcess()
|
|
|
|
{
|
|
|
|
this.queue.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
var item = this;
|
|
|
|
|
|
|
|
this.queue = new eventQueue();
|
|
|
|
this.queue.onFinish = function()
|
|
|
|
{
|
|
|
|
aProcessor.onProcessed();
|
|
|
|
return DO_NOT_FINISH_TEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
var invoker = {
|
|
|
|
invoke: function invoker_invoke() {
|
|
|
|
return aProcessor.process();
|
|
|
|
},
|
|
|
|
getID: function invoker_getID()
|
|
|
|
{
|
|
|
|
return aItemID;
|
|
|
|
},
|
|
|
|
eventSeq: [ new invokerChecker(aEventType, aTarget) ]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.queue.push(invoker);
|
|
|
|
}
|
2009-10-06 00:50:47 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue invokers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoker base class for prepare an action.
|
|
|
|
*/
|
2010-01-20 03:16:32 -08:00
|
|
|
function synthAction(aNodeOrID, aChecker, aEventType)
|
2009-10-06 00:50:47 -07:00
|
|
|
{
|
|
|
|
this.DOMNode = getNode(aNodeOrID);
|
2010-03-12 20:24:51 -08:00
|
|
|
if (aChecker)
|
|
|
|
aChecker.target = this.DOMNode;
|
2009-10-06 00:50:47 -07:00
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
if (aEventType)
|
|
|
|
this.eventSeq = [ new invokerChecker(aEventType, this.DOMNode) ];
|
|
|
|
|
2009-10-06 00:50:47 -07:00
|
|
|
this.check = function synthAction_check(aEvent)
|
|
|
|
{
|
2010-03-12 20:24:51 -08:00
|
|
|
if (aChecker)
|
|
|
|
aChecker.check(aEvent);
|
2009-10-06 00:50:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthAction_getID() { return aNodeOrID + " action"; }
|
|
|
|
}
|