2009-02-19 07:06:14 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constants
|
|
|
|
|
2010-08-30 05:09:59 +00:00
|
|
|
const EVENT_ALERT = nsIAccessibleEvent.EVENT_ALERT;
|
2010-01-20 11:16:32 +00:00
|
|
|
const EVENT_DOCUMENT_LOAD_COMPLETE = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_COMPLETE;
|
2010-06-08 16:39:58 +00:00
|
|
|
const EVENT_DOCUMENT_RELOAD = nsIAccessibleEvent.EVENT_DOCUMENT_RELOAD;
|
|
|
|
const EVENT_DOCUMENT_LOAD_STOPPED = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_STOPPED;
|
2009-09-09 09:03:14 +00:00
|
|
|
const EVENT_HIDE = nsIAccessibleEvent.EVENT_HIDE;
|
2009-05-11 01:32:09 +00:00
|
|
|
const EVENT_FOCUS = nsIAccessibleEvent.EVENT_FOCUS;
|
2009-02-27 10:45:21 +00:00
|
|
|
const EVENT_NAME_CHANGE = nsIAccessibleEvent.EVENT_NAME_CHANGE;
|
2010-12-03 10:49:20 +00:00
|
|
|
const EVENT_MENU_START = nsIAccessibleEvent.EVENT_MENU_START;
|
|
|
|
const EVENT_MENU_END = nsIAccessibleEvent.EVENT_MENU_END;
|
2010-10-21 04:16:10 +00:00
|
|
|
const EVENT_MENUPOPUP_START = nsIAccessibleEvent.EVENT_MENUPOPUP_START;
|
|
|
|
const EVENT_MENUPOPUP_END = nsIAccessibleEvent.EVENT_MENUPOPUP_END;
|
2011-01-28 05:15:31 +00:00
|
|
|
const EVENT_OBJECT_ATTRIBUTE_CHANGED = nsIAccessibleEvent.EVENT_OBJECT_ATTRIBUTE_CHANGED;
|
2010-01-20 11:16:32 +00:00
|
|
|
const EVENT_REORDER = nsIAccessibleEvent.EVENT_REORDER;
|
2009-09-01 02:49:15 +00:00
|
|
|
const EVENT_SCROLLING_START = nsIAccessibleEvent.EVENT_SCROLLING_START;
|
2011-11-01 00:52:27 +00:00
|
|
|
const EVENT_SELECTION = nsIAccessibleEvent.EVENT_SELECTION;
|
2010-06-15 14:53:27 +00:00
|
|
|
const EVENT_SELECTION_ADD = nsIAccessibleEvent.EVENT_SELECTION_ADD;
|
2011-11-01 00:52:27 +00:00
|
|
|
const EVENT_SELECTION_REMOVE = nsIAccessibleEvent.EVENT_SELECTION_REMOVE;
|
2010-06-15 14:53:27 +00:00
|
|
|
const EVENT_SELECTION_WITHIN = nsIAccessibleEvent.EVENT_SELECTION_WITHIN;
|
2010-01-20 11:16:32 +00:00
|
|
|
const EVENT_SHOW = nsIAccessibleEvent.EVENT_SHOW;
|
2009-08-20 06:45:19 +00:00
|
|
|
const EVENT_STATE_CHANGE = nsIAccessibleEvent.EVENT_STATE_CHANGE;
|
2010-11-25 15:58:15 +00:00
|
|
|
const EVENT_TEXT_ATTRIBUTE_CHANGED = nsIAccessibleEvent.EVENT_TEXT_ATTRIBUTE_CHANGED;
|
2010-01-20 11:16:32 +00:00
|
|
|
const EVENT_TEXT_CARET_MOVED = nsIAccessibleEvent.EVENT_TEXT_CARET_MOVED;
|
2010-07-02 01:50:03 +00:00
|
|
|
const EVENT_TEXT_INSERTED = nsIAccessibleEvent.EVENT_TEXT_INSERTED;
|
2010-05-17 16:17:50 +00:00
|
|
|
const EVENT_TEXT_REMOVED = nsIAccessibleEvent.EVENT_TEXT_REMOVED;
|
2011-10-12 07:39:58 +00:00
|
|
|
const EVENT_TEXT_SELECTION_CHANGED = nsIAccessibleEvent.EVENT_TEXT_SELECTION_CHANGED;
|
2010-06-10 03:29:56 +00:00
|
|
|
const EVENT_VALUE_CHANGE = nsIAccessibleEvent.EVENT_VALUE_CHANGE;
|
2009-02-19 07:06:14 +00:00
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
2009-02-05 06:23:18 +00:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump events into DOM.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpID = "";
|
|
|
|
|
2010-06-18 02:44:09 +00:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump event processing into console.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpToConsole = false;
|
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump event processing into error console.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpToAppConsole = false;
|
|
|
|
|
2009-02-19 07:06:14 +00: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-19 06:30:07 +00:00
|
|
|
|
|
|
|
if (aTarget) {
|
|
|
|
if (aTarget instanceof nsIAccessible &&
|
|
|
|
aTarget != aEvent.accessible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aTarget instanceof nsIDOMNode &&
|
|
|
|
aTarget != aEvent.DOMNode)
|
|
|
|
return;
|
2009-02-19 07:06:14 +00:00
|
|
|
}
|
2009-09-19 06:30:07 +00:00
|
|
|
|
|
|
|
unregisterA11yEventListener(aEventType, this);
|
|
|
|
|
|
|
|
window.setTimeout(
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
aFunc.call(aContext, aArg1, aArg2);
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2009-02-19 07:06:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
registerA11yEventListener(aEventType, handler);
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00: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 07:50:47 +00:00
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue
|
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
/**
|
|
|
|
* Return value of invoke method of invoker object. Indicates invoker was unable
|
|
|
|
* to prepare action.
|
|
|
|
*/
|
|
|
|
const INVOKER_ACTION_FAILED = 1;
|
|
|
|
|
2009-09-19 06:30:07 +00:00
|
|
|
/**
|
|
|
|
* Return value of eventQueue.onFinish. Indicates eventQueue should not finish
|
|
|
|
* tests.
|
|
|
|
*/
|
|
|
|
const DO_NOT_FINISH_TEST = 1;
|
|
|
|
|
2009-01-25 04:42:21 +00: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 19:57:29 +00:00
|
|
|
* When event is caught then current invoker object is asked to check whether
|
2009-01-25 04:42:21 +00:00
|
|
|
* event was handled correctly.
|
|
|
|
*
|
|
|
|
* Invoker interface is:
|
|
|
|
*
|
|
|
|
* var invoker = {
|
2009-05-11 01:32:09 +00:00
|
|
|
* // Generates accessible event or event sequence. If returns
|
|
|
|
* // INVOKER_ACTION_FAILED constant then stop tests.
|
2009-01-25 04:42:21 +00:00
|
|
|
* invoke: function(){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [optional] Invoker's check of handled event for correctness.
|
2009-01-25 04:42:21 +00:00
|
|
|
* check: function(aEvent){},
|
|
|
|
*
|
2010-06-08 16:39:58 +00:00
|
|
|
* // [optional] Invoker's check before the next invoker is proceeded.
|
|
|
|
* finalCheck: function(aEvent){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [optional] Is called when event of registered type is handled.
|
2009-01-25 04:42:21 +00:00
|
|
|
* debugCheck: function(aEvent){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00: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-25 04:42:21 +00:00
|
|
|
*
|
2009-09-03 02:01:18 +00:00
|
|
|
* // Array of checker objects defining expected events on invoker's action.
|
2009-02-27 10:45:21 +00:00
|
|
|
* //
|
2009-09-03 02:01:18 +00:00
|
|
|
* // Checker object interface:
|
2009-02-27 10:45:21 +00:00
|
|
|
* //
|
|
|
|
* // var checker = {
|
2011-07-19 08:30:32 +00:00
|
|
|
* // * DOM or a11y event type. *
|
|
|
|
* // type getter: function() {},
|
|
|
|
* //
|
|
|
|
* // * DOM node or accessible. *
|
|
|
|
* // target getter: function() {},
|
|
|
|
* //
|
|
|
|
* // * DOM event phase (false - bubbling). *
|
|
|
|
* // phase getter: function() {},
|
|
|
|
* //
|
2011-09-28 01:46:11 +00:00
|
|
|
* // * Callback, called to match handled event. *
|
|
|
|
* // match : function() {},
|
|
|
|
* //
|
2011-07-19 08:30:32 +00:00
|
|
|
* // * Callback, called when event is handled
|
2009-02-27 10:45:21 +00:00
|
|
|
* // check: function(aEvent) {},
|
2011-07-19 08:30:32 +00:00
|
|
|
* //
|
|
|
|
* // * Checker ID *
|
|
|
|
* // getID: function() {},
|
|
|
|
* //
|
|
|
|
* // * Event that don't have predefined order relative other events. *
|
2011-09-28 01:46:11 +00:00
|
|
|
* // async getter: function() {},
|
|
|
|
* //
|
|
|
|
* // * Event that is not expected. *
|
|
|
|
* // unexpected getter: function() {},
|
|
|
|
* //
|
|
|
|
* // * No other event of the same type is not allowed. *
|
|
|
|
* // unique getter: function() {}
|
2009-02-27 10:45:21 +00:00
|
|
|
* // };
|
2009-01-25 04:42:21 +00:00
|
|
|
* eventSeq getter() {},
|
|
|
|
*
|
2009-09-03 02:01:18 +00:00
|
|
|
* // Array of checker objects defining unexpected events on invoker's
|
|
|
|
* // action.
|
|
|
|
* unexpectedEventSeq getter() {},
|
2009-01-25 04:42:21 +00:00
|
|
|
*
|
|
|
|
* // The ID of invoker.
|
|
|
|
* getID: function(){} // returns invoker ID
|
|
|
|
* };
|
|
|
|
*
|
2009-09-19 06:30:07 +00:00
|
|
|
* @param aEventType [in, optional] the default event type (isn't used if
|
|
|
|
* invoker defines eventSeq property).
|
2009-01-25 04:42:21 +00: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-03 02:01:18 +00:00
|
|
|
this.processNextInvokerInTimeout(true);
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 13:20:18 +00: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-25 04:42:21 +00:00
|
|
|
// private
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process next invoker.
|
|
|
|
*/
|
|
|
|
this.processNextInvoker = function eventQueue_processNextInvoker()
|
|
|
|
{
|
2010-02-05 20:30:14 +00:00
|
|
|
// Finish processing of the current invoker.
|
2009-01-25 04:42:21 +00:00
|
|
|
var testFailed = false;
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if (invoker) {
|
2009-09-03 02:01:18 +00:00
|
|
|
if ("finalCheck" in invoker)
|
|
|
|
invoker.finalCheck();
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
if (invoker.wasCaught) {
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < invoker.wasCaught.length; idx++) {
|
|
|
|
var id = this.getEventID(idx);
|
|
|
|
var type = this.getEventType(idx);
|
2009-09-03 02:01:18 +00:00
|
|
|
var unexpected = this.mEventSeq[idx].unexpected;
|
|
|
|
|
2010-12-15 21:22:51 +00:00
|
|
|
var typeStr = this.getEventTypeAsString(idx);
|
2009-01-25 04:42:21 +00:00
|
|
|
|
|
|
|
var msg = "test with ID = '" + id + "' failed. ";
|
2009-09-03 02:01:18 +00:00
|
|
|
if (unexpected) {
|
2009-02-27 10:45:21 +00:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-25 04:42:21 +00:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = wasCaught;
|
|
|
|
|
|
|
|
ok(!wasCaught,
|
|
|
|
msg + "There is unexpected " + typeStr + " event.");
|
|
|
|
|
|
|
|
} else {
|
2009-02-27 10:45:21 +00:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-25 04:42:21 +00:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = !wasCaught;
|
|
|
|
|
|
|
|
ok(wasCaught,
|
|
|
|
msg + "No " + typeStr + " event.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
testFailed = true;
|
2009-02-27 10:45:21 +00: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-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler();
|
|
|
|
|
|
|
|
// Check if need to stop the test.
|
|
|
|
if (testFailed || this.mIndex == this.mInvokers.length - 1) {
|
|
|
|
listenA11yEvents(false);
|
|
|
|
|
2009-09-19 06:30:07 +00:00
|
|
|
var res = this.onFinish();
|
|
|
|
if (res != DO_NOT_FINISH_TEST)
|
|
|
|
SimpleTest.finish();
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start processing of next invoker.
|
|
|
|
invoker = this.getNextInvoker();
|
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
if (gLogger.isEnabled()) {
|
|
|
|
gLogger.logToConsole("Event queue: \n invoke: " + invoker.getID());
|
|
|
|
gLogger.logToDOM("EQ: invoke: " + invoker.getID(), true);
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
this.setEventHandler(invoker);
|
2010-06-18 02:44:09 +00:00
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
if (invoker.invoke() == INVOKER_ACTION_FAILED) {
|
|
|
|
// Invoker failed to prepare action, fail and finish tests.
|
|
|
|
this.processNextInvoker();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2009-09-03 02:01:18 +00: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-25 04:42:21 +00:00
|
|
|
}
|
2009-09-03 02:01:18 +00:00
|
|
|
|
|
|
|
// Check in timeout invoker didn't fire registered events.
|
2011-12-08 06:24:17 +00:00
|
|
|
window.setTimeout(function(aQueue) { aQueue.processNextInvoker(); }, 300,
|
2009-09-03 02:01:18 +00:00
|
|
|
this);
|
2009-01-25 04:42:21 +00: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);
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Search through handled expected events to report error if one of them is
|
|
|
|
// handled for a second time.
|
2010-08-30 05:08:00 +00:00
|
|
|
var idx = 0;
|
|
|
|
for (; idx < this.mEventSeq.length; idx++) {
|
2011-07-19 08:30:32 +00:00
|
|
|
if (this.isEventExpected(idx) && (invoker.wasCaught[idx] == true) &&
|
2011-09-28 01:46:11 +00:00
|
|
|
this.isSameEvent(idx, aEvent)) {
|
2010-12-15 21:22:51 +00:00
|
|
|
|
|
|
|
var msg = "Doubled event { event type: " +
|
|
|
|
this.getEventTypeAsString(idx) + ", target: " +
|
2011-09-28 01:46:11 +00:00
|
|
|
this.getEventTargetDescr(idx) + "} in test with ID = '" +
|
2010-12-15 21:22:51 +00:00
|
|
|
this.getEventID(idx) + "'.";
|
|
|
|
ok(false, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Search through unexpected events, any matches result in error report
|
|
|
|
// after this invoker processing.
|
2010-12-15 21:22:51 +00:00
|
|
|
for (idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
if (this.isEventUnexpected(idx) && this.compareEvents(idx, aEvent))
|
2009-09-03 02:01:18 +00:00
|
|
|
invoker.wasCaught[idx] = true;
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Nothing left, proceed next invoker in timeout. Otherwise check if
|
|
|
|
// handled event is matched.
|
|
|
|
var idxObj = {};
|
|
|
|
if (!this.prepareForExpectedEvent(invoker, idxObj))
|
2010-08-30 05:08:00 +00:00
|
|
|
return;
|
2009-02-05 06:23:18 +00:00
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Check if handled event matches expected sync event.
|
|
|
|
var matched = false;
|
|
|
|
idx = idxObj.value;
|
|
|
|
if (idx < this.mEventSeq.length) {
|
|
|
|
matched = this.compareEvents(idx, aEvent);
|
|
|
|
if (matched)
|
|
|
|
this.mEventSeqIdx = idx;
|
2009-09-03 02:01:18 +00:00
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Check if handled event matches any expected async events.
|
|
|
|
if (!matched) {
|
|
|
|
for (idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
if (this.mEventSeq[idx].async) {
|
|
|
|
matched = this.compareEvents(idx, aEvent);
|
|
|
|
if (matched)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 02:01:18 +00:00
|
|
|
this.dumpEventToDOM(aEvent, idx, matched);
|
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
this.checkEvent(idx, aEvent);
|
|
|
|
invoker.wasCaught[idx] = true;
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
this.prepareForExpectedEvent(invoker);
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 05:08:00 +00:00
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
// Helpers
|
|
|
|
this.prepareForExpectedEvent =
|
|
|
|
function eventQueue_prepareForExpectedEvent(aInvoker, aIdxObj)
|
|
|
|
{
|
|
|
|
// Nothing left, wait for next invoker.
|
|
|
|
if (this.mEventSeqFinished)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compute next expected sync event index.
|
|
|
|
for (var idx = this.mEventSeqIdx + 1;
|
|
|
|
idx < this.mEventSeq.length &&
|
|
|
|
(this.mEventSeq[idx].unexpected || this.mEventSeq[idx].async);
|
|
|
|
idx++);
|
|
|
|
|
|
|
|
// If no expected events were left, proceed to next invoker in timeout
|
|
|
|
// to make sure unexpected events for current invoker aren't be handled.
|
|
|
|
if (idx == this.mEventSeq.length) {
|
|
|
|
var allHandled = true;
|
|
|
|
for (var jdx = 0; jdx < this.mEventSeq.length; jdx++) {
|
|
|
|
if (this.isEventExpected(jdx) && !aInvoker.wasCaught[jdx])
|
|
|
|
allHandled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allHandled) {
|
|
|
|
this.mEventSeqIdx = this.mEventSeq.length;
|
|
|
|
this.mEventFinished = true;
|
2009-09-03 02:01:18 +00:00
|
|
|
this.processNextInvokerInTimeout();
|
2011-07-19 08:30:32 +00:00
|
|
|
return false;
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-19 08:30:32 +00:00
|
|
|
|
|
|
|
if (aIdxObj)
|
|
|
|
aIdxObj.value = idx;
|
|
|
|
|
|
|
|
return true;
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
// Create unified event sequence concatenating expected and unexpected
|
2009-09-03 02:01:18 +00:00
|
|
|
// events.
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mEventSeq = ("eventSeq" in aInvoker) ?
|
2009-07-28 02:28:06 +00:00
|
|
|
aInvoker.eventSeq :
|
|
|
|
[ new invokerChecker(this.mDefEventType, aInvoker.DOMNode) ];
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
var len = this.mEventSeq.length;
|
|
|
|
for (var idx = 0; idx < len; idx++) {
|
|
|
|
var seqItem = this.mEventSeq[idx];
|
|
|
|
// Allow unexpected events in primary event sequence.
|
|
|
|
if (!("unexpected" in this.mEventSeq[idx]))
|
|
|
|
seqItem.unexpected = false;
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
if (!("async" in this.mEventSeq[idx]))
|
2011-09-28 01:46:11 +00:00
|
|
|
seqItem.async = false;
|
|
|
|
|
|
|
|
// If the event is of unique type (regardless whether it's expected or
|
|
|
|
// not) then register additional unexpected event that matches to any
|
|
|
|
// event of the same type with any target different from registered
|
|
|
|
// expected events.
|
|
|
|
if (("unique" in seqItem) && seqItem.unique) {
|
|
|
|
var uniquenessChecker = {
|
|
|
|
type: seqItem.type,
|
|
|
|
unexpected: true,
|
|
|
|
match: function uniquenessChecker_match(aEvent)
|
|
|
|
{
|
|
|
|
// The handled event is matched if its target doesn't match to any
|
|
|
|
// registered expected event.
|
|
|
|
var matched = true;
|
|
|
|
for (var idx = 0; idx < this.queue.mEventSeq.length; idx++) {
|
|
|
|
if (this.queue.isEventExpected(idx) &&
|
|
|
|
this.queue.compareEvents(idx, aEvent)) {
|
|
|
|
matched = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
},
|
|
|
|
targetDescr: "any target different from expected events",
|
|
|
|
queue: this
|
|
|
|
};
|
|
|
|
this.mEventSeq.push(uniquenessChecker);
|
|
|
|
}
|
2011-07-19 08:30:32 +00:00
|
|
|
}
|
2009-09-03 02:01:18 +00:00
|
|
|
|
|
|
|
var unexpectedSeq = aInvoker.unexpectedEventSeq;
|
|
|
|
if (unexpectedSeq) {
|
2011-07-19 08:30:32 +00:00
|
|
|
for (var idx = 0; idx < unexpectedSeq.length; idx++) {
|
2009-09-03 02:01:18 +00:00
|
|
|
unexpectedSeq[idx].unexpected = true;
|
2011-07-19 08:30:32 +00:00
|
|
|
unexpectedSeq[idx].async = false;
|
|
|
|
}
|
2009-09-03 02:01:18 +00:00
|
|
|
|
|
|
|
this.mEventSeq = this.mEventSeq.concat(unexpectedSeq);
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mEventSeqIdx = -1;
|
2011-07-19 08:30:32 +00:00
|
|
|
this.mEventSeqFinished = false;
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2009-09-03 02:01:18 +00:00
|
|
|
// Register event listeners
|
2009-01-25 04:42:21 +00:00
|
|
|
if (this.mEventSeq) {
|
|
|
|
aInvoker.wasCaught = new Array(this.mEventSeq.length);
|
2009-02-05 06:23:18 +00:00
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2010-12-03 10:49:08 +00:00
|
|
|
|
|
|
|
if (gLogger.isEnabled()) {
|
|
|
|
var msg = "registered";
|
|
|
|
if (this.isEventUnexpected(idx))
|
|
|
|
msg += " unexpected";
|
|
|
|
|
2010-12-15 21:22:51 +00:00
|
|
|
msg += ": event type: " + this.getEventTypeAsString(idx) +
|
2011-09-28 01:46:11 +00:00
|
|
|
", target: " + this.getEventTargetDescr(idx, true);
|
2010-12-03 10:49:08 +00:00
|
|
|
|
|
|
|
gLogger.logToConsole(msg);
|
|
|
|
gLogger.logToDOM(msg, true);
|
|
|
|
}
|
|
|
|
|
2009-08-21 13:20:18 +00:00
|
|
|
if (typeof eventType == "string") {
|
|
|
|
// DOM event
|
|
|
|
var target = this.getEventTarget(idx);
|
2011-09-28 01:46:11 +00:00
|
|
|
if (!target) {
|
|
|
|
ok(false, "no target for DOM event!");
|
|
|
|
return;
|
|
|
|
}
|
2009-08-21 13:20:18 +00:00
|
|
|
var phase = this.getEventPhase(idx);
|
|
|
|
target.ownerDocument.addEventListener(eventType, this, phase);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// A11y event
|
2009-02-27 10:45:21 +00:00
|
|
|
addA11yEventListener(eventType, this);
|
2009-08-21 13:20:18 +00:00
|
|
|
}
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler = function eventQueue_clearEventHandler()
|
|
|
|
{
|
|
|
|
if (this.mEventSeq) {
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2009-08-21 13:20:18 +00: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 10:45:21 +00:00
|
|
|
removeA11yEventListener(eventType, this);
|
2009-08-21 13:20:18 +00:00
|
|
|
}
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mEventSeq = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
this.getEventType = function eventQueue_getEventType(aIdx)
|
|
|
|
{
|
2009-07-28 02:28:06 +00:00
|
|
|
return this.mEventSeq[aIdx].type;
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 21:22:51 +00:00
|
|
|
this.getEventTypeAsString = function eventQueue_getEventTypeAsString(aIdx)
|
|
|
|
{
|
|
|
|
var type = this.mEventSeq[aIdx].type;
|
|
|
|
return (typeof type == "string") ? type : eventTypeToString(type);
|
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
this.getEventTarget = function eventQueue_getEventTarget(aIdx)
|
|
|
|
{
|
2009-07-28 02:28:06 +00:00
|
|
|
return this.mEventSeq[aIdx].target;
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
this.getEventTargetDescr =
|
|
|
|
function eventQueue_getEventTargetDescr(aIdx, aDontForceTarget)
|
2011-01-26 06:35:51 +00:00
|
|
|
{
|
|
|
|
var descr = this.mEventSeq[aIdx].targetDescr;
|
2011-09-28 01:46:11 +00:00
|
|
|
if (descr)
|
|
|
|
return descr;
|
|
|
|
|
|
|
|
if (aDontForceTarget)
|
|
|
|
return "no target description";
|
|
|
|
|
|
|
|
var target = ("target" in this.mEventSeq[aIdx]) ?
|
|
|
|
this.mEventSeq[aIdx].target : null;
|
|
|
|
return prettyName(target);
|
2011-01-26 06:35:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
this.getEventPhase = function eventQueue_getEventPhase(aIdx)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("phase" in eventItem)
|
|
|
|
return eventItem.phase;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-03 02:01:18 +00: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();
|
|
|
|
}
|
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
this.isEventUnexpected = function eventQueue_isEventUnexpected(aIdx)
|
|
|
|
{
|
|
|
|
return this.mEventSeq[aIdx].unexpected;
|
|
|
|
}
|
2011-07-19 08:30:32 +00:00
|
|
|
this.isEventExpected = function eventQueue_isEventExpected(aIdx)
|
|
|
|
{
|
|
|
|
return !this.mEventSeq[aIdx].unexpected;
|
|
|
|
}
|
2010-12-03 10:49:08 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
this.compareEventTypes = function eventQueue_compareEventTypes(aIdx, aEvent)
|
2009-02-27 10:45:21 +00:00
|
|
|
{
|
|
|
|
var eventType1 = this.getEventType(aIdx);
|
|
|
|
var eventType2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
aEvent.type : aEvent.eventType;
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
return eventType1 == eventType2;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.compareEvents = function eventQueue_compareEvents(aIdx, aEvent)
|
|
|
|
{
|
|
|
|
if (!this.compareEventTypes(aIdx, aEvent))
|
2009-02-27 10:45:21 +00:00
|
|
|
return false;
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
// If checker provides "match" function then allow the checker to decide
|
|
|
|
// whether event is matched.
|
|
|
|
if ("match" in this.mEventSeq[aIdx])
|
|
|
|
return this.mEventSeq[aIdx].match(aEvent);
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
var target1 = this.getEventTarget(aIdx);
|
|
|
|
if (target1 instanceof nsIAccessible) {
|
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
getAccessible(aEvent.target) : aEvent.accessible;
|
|
|
|
|
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
2009-05-11 01:32:09 +00: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 10:45:21 +00:00
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
2009-05-11 01:32:09 +00:00
|
|
|
aEvent.originalTarget : aEvent.DOMNode;
|
2009-02-27 10:45:21 +00:00
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
this.isSameEvent = function eventQueue_isSameEvent(aIdx, aEvent)
|
2011-02-08 04:48:41 +00:00
|
|
|
{
|
|
|
|
// We don't have stored info about handled event other than its type and
|
2011-08-11 11:45:36 +00:00
|
|
|
// target, thus we should filter text change and state change events since
|
|
|
|
// they may occur on the same element because of complex changes.
|
2011-02-08 04:48:41 +00:00
|
|
|
return this.compareEvents(aIdx, aEvent) &&
|
2011-08-11 11:45:36 +00:00
|
|
|
!(aEvent instanceof nsIAccessibleTextChangeEvent) &&
|
|
|
|
!(aEvent instanceof nsIAccessibleStateChangeEvent);
|
2011-02-08 04:48:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
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-03 02:01:18 +00:00
|
|
|
this.areAllEventsExpected = function eventQueue_areAllEventsExpected()
|
2009-02-27 10:45:21 +00:00
|
|
|
{
|
2009-09-03 02:01:18 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
if (this.mEventSeq[idx].unexpected)
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-27 10:45:21 +00:00
|
|
|
|
2009-09-03 02:01:18 +00: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 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
this.dumpEventToDOM = function eventQueue_dumpEventToDOM(aOrigEvent,
|
|
|
|
aExpectedEventIdx,
|
|
|
|
aMatch)
|
|
|
|
{
|
2010-12-03 10:49:08 +00:00
|
|
|
if (!gLogger.isEnabled()) // debug stuff
|
2009-08-20 06:45:19 +00:00
|
|
|
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);
|
2010-12-03 10:49:08 +00:00
|
|
|
gLogger.logToDOM(info);
|
2009-08-20 06:45:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
if (!aMatch)
|
|
|
|
return;
|
2009-08-20 06:45:19 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
var msg = "EQ: ";
|
2011-07-19 08:30:32 +00:00
|
|
|
var emphText = "matched ";
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
var currType = this.getEventTypeAsString(aExpectedEventIdx);
|
2011-09-28 01:46:11 +00:00
|
|
|
var currTargetDescr = this.getEventTargetDescr(aExpectedEventIdx);
|
2011-07-19 08:30:32 +00:00
|
|
|
var consoleMsg = "*****\nEQ matched: " + currType + "\n*****";
|
|
|
|
gLogger.logToConsole(consoleMsg);
|
2010-10-21 04:16:10 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
msg += " event, type: " + currType + ", target: " + currTargetDescr;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
gLogger.logToDOM(msg, true, emphText);
|
2009-08-20 06:45:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mDefEventType = aEventType;
|
|
|
|
|
|
|
|
this.mInvokers = new Array();
|
|
|
|
this.mIndex = -1;
|
|
|
|
|
|
|
|
this.mEventSeq = null;
|
|
|
|
this.mEventSeqIdx = -1;
|
2011-07-19 08:30:32 +00:00
|
|
|
this.mEventSeqFinished = false;
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
2009-09-19 06:30:07 +00:00
|
|
|
|
2009-10-06 07:50:47 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Action sequence
|
|
|
|
|
2009-09-19 06:30:07 +00: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 07:50:47 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue invokers
|
|
|
|
|
|
|
|
/**
|
2011-09-28 01:46:11 +00:00
|
|
|
* Invokers defined below take a checker object (or array of checker objects).
|
|
|
|
* An invoker listens for default event type registered in event queue object
|
|
|
|
* until its checker is provided.
|
2009-10-06 07:50:47 +00:00
|
|
|
*
|
2010-12-03 10:49:20 +00:00
|
|
|
* Note, checker object or array of checker objects is optional.
|
2009-10-06 07:50:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthClick(aNodeOrID, aCheckerOrEventSeq, aArgs)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
|
|
|
|
this.invoke = function synthClick_invoke()
|
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
var targetNode = this.DOMNode;
|
|
|
|
if (targetNode instanceof nsIDOMDocument) {
|
|
|
|
targetNode =
|
|
|
|
this.DOMNode.body ? this.DOMNode.body : this.DOMNode.documentElement;
|
|
|
|
}
|
|
|
|
|
2009-10-06 07:50:47 +00:00
|
|
|
// Scroll the node into view, otherwise synth click may fail.
|
2011-10-29 20:03:55 +00:00
|
|
|
if (targetNode instanceof nsIDOMHTMLElement) {
|
2011-09-28 01:46:11 +00:00
|
|
|
targetNode.scrollIntoView(true);
|
|
|
|
} else if (targetNode instanceof nsIDOMXULElement) {
|
|
|
|
var targetAcc = getAccessible(targetNode);
|
|
|
|
targetAcc.scrollTo(SCROLL_TYPE_ANYWHERE);
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
var x = 1, y = 1;
|
|
|
|
if (aArgs && ("where" in aArgs) && aArgs.where == "right") {
|
2011-10-29 20:03:55 +00:00
|
|
|
if (targetNode instanceof nsIDOMHTMLElement)
|
2011-09-28 01:46:11 +00:00
|
|
|
x = targetNode.offsetWidth - 1;
|
|
|
|
else if (targetNode instanceof nsIDOMXULElement)
|
|
|
|
x = targetNode.boxObject.width - 1;
|
|
|
|
}
|
|
|
|
synthesizeMouse(targetNode, x, y, aArgs ? aArgs : {});
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-29 02:36:36 +00:00
|
|
|
this.finalCheck = function synthClick_finalCheck()
|
|
|
|
{
|
|
|
|
// Scroll top window back.
|
|
|
|
window.top.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2010-01-20 11:16:32 +00:00
|
|
|
this.getID = function synthClick_getID()
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
return prettyName(aNodeOrID) + " click";
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:44:57 +00:00
|
|
|
/**
|
|
|
|
* Mouse move invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthMouseMove(aID, aCheckerOrEventSeq)
|
2010-03-18 05:44:57 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthAction(aID, aCheckerOrEventSeq);
|
2010-03-18 05:44:57 +00:00
|
|
|
|
|
|
|
this.invoke = function synthMouseMove_invoke()
|
|
|
|
{
|
|
|
|
synthesizeMouse(this.DOMNode, 1, 1, { type: "mousemove" });
|
|
|
|
synthesizeMouse(this.DOMNode, 2, 2, { type: "mousemove" });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthMouseMove_getID()
|
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
return prettyName(aID) + " mouse move";
|
2010-03-18 05:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 07:50:47 +00:00
|
|
|
/**
|
|
|
|
* General key press invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthKey(aNodeOrID, aKey, aArgs, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
|
|
|
|
this.invoke = function synthKey_invoke()
|
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
synthesizeKey(this.mKey, this.mArgs, this.mWindow);
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 11:16:32 +00:00
|
|
|
this.getID = function synthKey_getID()
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
var key = this.mKey;
|
|
|
|
switch (this.mKey) {
|
|
|
|
case "VK_TAB":
|
|
|
|
key = "tab";
|
|
|
|
break;
|
|
|
|
case "VK_DOWN":
|
|
|
|
key = "down";
|
|
|
|
break;
|
|
|
|
case "VK_UP":
|
|
|
|
key = "up";
|
|
|
|
break;
|
|
|
|
case "VK_LEFT":
|
|
|
|
key = "left";
|
|
|
|
break;
|
|
|
|
case "VK_RIGHT":
|
|
|
|
key = "right";
|
|
|
|
break;
|
|
|
|
case "VK_HOME":
|
|
|
|
key = "home";
|
|
|
|
break;
|
|
|
|
case "VK_ESCAPE":
|
|
|
|
key = "escape";
|
|
|
|
break;
|
|
|
|
case "VK_RETURN":
|
|
|
|
key = "enter";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aArgs) {
|
|
|
|
if (aArgs.shiftKey)
|
|
|
|
key += " shift";
|
|
|
|
if (aArgs.ctrlKey)
|
|
|
|
key += " ctrl";
|
|
|
|
if (aArgs.altKey)
|
|
|
|
key += " alt";
|
|
|
|
}
|
|
|
|
return prettyName(aNodeOrID) + " '" + key + " ' key";
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.mKey = aKey;
|
|
|
|
this.mArgs = aArgs ? aArgs : {};
|
2011-09-28 01:46:11 +00:00
|
|
|
this.mWindow = aArgs ? aArgs.window : null;
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tab key invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthTab(aNodeOrID, aCheckerOrEventSeq, aWindow)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB",
|
|
|
|
{ shiftKey: false, window: aWindow },
|
|
|
|
aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shift tab key invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthShiftTab(aNodeOrID, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB", { shiftKey: true },
|
2011-09-28 01:46:11 +00:00
|
|
|
aCheckerOrEventSeq);
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
/**
|
|
|
|
* Escape key invoker.
|
|
|
|
*/
|
|
|
|
function synthEscapeKey(aNodeOrID, aCheckerOrEventSeq)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_ESCAPE", null,
|
|
|
|
aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Down arrow key invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthDownKey(aNodeOrID, aCheckerOrEventSeq, aArgs)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_DOWN", aArgs,
|
|
|
|
aCheckerOrEventSeq);
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
/**
|
|
|
|
* Up arrow key invoker.
|
|
|
|
*/
|
|
|
|
function synthUpKey(aNodeOrID, aCheckerOrEventSeq, aArgs)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_UP", aArgs,
|
|
|
|
aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Right arrow key invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthRightKey(aNodeOrID, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_RIGHT", null, aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 11:16:32 +00:00
|
|
|
/**
|
|
|
|
* Home key invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthHomeKey(aNodeOrID, aCheckerOrEventSeq)
|
2010-01-20 11:16:32 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthKey(aNodeOrID, "VK_HOME", null, aCheckerOrEventSeq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter key invoker
|
|
|
|
*/
|
|
|
|
function synthEnterKey(aID, aCheckerOrEventSeq)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aID, "VK_RETURN", null, aCheckerOrEventSeq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synth alt + down arrow to open combobox.
|
|
|
|
*/
|
|
|
|
function synthOpenComboboxKey(aID, aCheckerOrEventSeq)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthDownKey(aID, aCheckerOrEventSeq, { altKey: true });
|
|
|
|
|
|
|
|
this.getID = function synthOpenComboboxKey_getID()
|
2010-01-20 11:16:32 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
return "open combobox (atl + down arrow) " + prettyName(aID);
|
2010-01-20 11:16:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 07:50:47 +00:00
|
|
|
/**
|
|
|
|
* Focus invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthFocus(aNodeOrID, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
var checkerOfEventSeq =
|
|
|
|
aCheckerOrEventSeq ? aCheckerOrEventSeq : new focusChecker(aNodeOrID);
|
|
|
|
this.__proto__ = new synthAction(aNodeOrID, checkerOfEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
|
|
|
|
this.invoke = function synthFocus_invoke()
|
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
if (this.DOMNode instanceof Components.interfaces.nsIDOMNSEditableElement &&
|
|
|
|
this.DOMNode.editor ||
|
2011-05-12 13:52:38 +00:00
|
|
|
this.DOMNode instanceof Components.interfaces.nsIDOMXULTextBoxElement) {
|
|
|
|
this.DOMNode.selectionStart = this.DOMNode.selectionEnd = this.DOMNode.value.length;
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
this.DOMNode.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthFocus_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " focus";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:44:57 +00:00
|
|
|
/**
|
|
|
|
* Focus invoker. Focus the HTML body of content document of iframe.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthFocusOnFrame(aNodeOrID, aCheckerOrEventSeq)
|
2010-03-18 05:44:57 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
var frameDoc = getNode(aNodeOrID).contentDocument;
|
|
|
|
var checkerOrEventSeq =
|
|
|
|
aCheckerOrEventSeq ? aCheckerOrEventSeq : new focusChecker(frameDoc);
|
|
|
|
this.__proto__ = new synthAction(frameDoc, checkerOrEventSeq);
|
|
|
|
|
2010-03-18 05:44:57 +00:00
|
|
|
this.invoke = function synthFocus_invoke()
|
|
|
|
{
|
|
|
|
this.DOMNode.body.focus();
|
|
|
|
}
|
2011-09-28 01:46:11 +00:00
|
|
|
|
2010-03-18 05:44:57 +00:00
|
|
|
this.getID = function synthFocus_getID()
|
|
|
|
{
|
|
|
|
return prettyName(aNodeOrID) + " frame document focus";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
/**
|
|
|
|
* Change the current item when the widget doesn't have a focus.
|
|
|
|
*/
|
|
|
|
function changeCurrentItem(aID, aItemID)
|
|
|
|
{
|
|
|
|
this.eventSeq = [ new nofocusChecker() ];
|
|
|
|
|
|
|
|
this.invoke = function changeCurrentItem_invoke()
|
|
|
|
{
|
|
|
|
var controlNode = getNode(aID);
|
|
|
|
var itemNode = getNode(aItemID);
|
|
|
|
|
|
|
|
// HTML
|
|
|
|
if (controlNode.localName == "input") {
|
|
|
|
if (controlNode.checked)
|
|
|
|
this.reportError();
|
|
|
|
|
|
|
|
controlNode.checked = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controlNode.localName == "select") {
|
|
|
|
if (controlNode.selectedIndex == itemNode.index)
|
|
|
|
this.reportError();
|
|
|
|
|
|
|
|
controlNode.selectedIndex = itemNode.index;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XUL
|
|
|
|
if (controlNode.localName == "tree") {
|
|
|
|
if (controlNode.currentIndex == aItemID)
|
|
|
|
this.reportError();
|
|
|
|
|
|
|
|
controlNode.currentIndex = aItemID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controlNode.localName == "menulist") {
|
|
|
|
if (controlNode.selectedItem == itemNode)
|
|
|
|
this.reportError();
|
|
|
|
|
|
|
|
controlNode.selectedItem = itemNode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controlNode.currentItem == itemNode)
|
|
|
|
ok(false, "Error in test: proposed current item is already current" + prettyName(aID));
|
|
|
|
|
|
|
|
controlNode.currentItem = itemNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function changeCurrentItem_getID()
|
|
|
|
{
|
|
|
|
return "current item change for " + prettyName(aID);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.reportError = function changeCurrentItem_reportError()
|
|
|
|
{
|
|
|
|
ok(false,
|
|
|
|
"Error in test: proposed current item '" + aItemID + "' is already current");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle top menu invoker.
|
|
|
|
*/
|
|
|
|
function toggleTopMenu(aID, aCheckerOrEventSeq)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthKey(aID, "VK_ALT", null,
|
|
|
|
aCheckerOrEventSeq);
|
|
|
|
|
|
|
|
this.getID = function toggleTopMenu_getID()
|
|
|
|
{
|
|
|
|
return "toggle top menu on " + prettyName(aID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context menu invoker.
|
|
|
|
*/
|
|
|
|
function synthContextMenu(aID, aCheckerOrEventSeq)
|
|
|
|
{
|
|
|
|
this.__proto__ = new synthClick(aID, aCheckerOrEventSeq,
|
|
|
|
{ button: 0, type: "contextmenu" });
|
|
|
|
|
|
|
|
this.getID = function synthContextMenu_getID()
|
|
|
|
{
|
|
|
|
return "context menu on " + prettyName(aID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open combobox, autocomplete and etc popup, check expandable states.
|
|
|
|
*/
|
|
|
|
function openCombobox(aComboboxID)
|
|
|
|
{
|
|
|
|
this.eventSeq = [
|
|
|
|
new stateChangeChecker(STATE_EXPANDED, false, true, aComboboxID)
|
|
|
|
];
|
|
|
|
|
|
|
|
this.invoke = function openCombobox_invoke()
|
|
|
|
{
|
|
|
|
getNode(aComboboxID).focus();
|
|
|
|
synthesizeKey("VK_DOWN", { altKey: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function openCombobox_getID()
|
|
|
|
{
|
|
|
|
return "open combobox " + prettyName(aComboboxID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close combobox, autocomplete and etc popup, check expandable states.
|
|
|
|
*/
|
|
|
|
function closeCombobox(aComboboxID)
|
|
|
|
{
|
|
|
|
this.eventSeq = [
|
|
|
|
new stateChangeChecker(STATE_EXPANDED, false, false, aComboboxID)
|
|
|
|
];
|
|
|
|
|
|
|
|
this.invoke = function closeCombobox_invoke()
|
|
|
|
{
|
|
|
|
synthesizeKey("VK_ESCAPE", { });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function closeCombobox_getID()
|
|
|
|
{
|
|
|
|
return "close combobox " + prettyName(aComboboxID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 07:50:47 +00:00
|
|
|
/**
|
|
|
|
* Select all invoker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthSelectAll(aNodeOrID, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq);
|
2009-10-06 07:50:47 +00:00
|
|
|
|
|
|
|
this.invoke = function synthSelectAll_invoke()
|
|
|
|
{
|
2011-02-15 16:33:54 +00:00
|
|
|
if (this.DOMNode instanceof Components.interfaces.nsIDOMHTMLInputElement ||
|
|
|
|
this.DOMNode instanceof Components.interfaces.nsIDOMXULTextBoxElement) {
|
2009-10-06 07:50:47 +00:00
|
|
|
this.DOMNode.select();
|
2011-02-15 16:33:54 +00:00
|
|
|
|
|
|
|
} else {
|
2009-10-06 07:50:47 +00:00
|
|
|
window.getSelection().selectAllChildren(this.DOMNode);
|
2011-02-15 16:33:54 +00:00
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.getID = function synthSelectAll_getID()
|
|
|
|
{
|
|
|
|
return aNodeOrID + " selectall";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue checkers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common invoker checker (see eventSeq of eventQueue).
|
|
|
|
*/
|
2011-07-19 08:30:32 +00:00
|
|
|
function invokerChecker(aEventType, aTargetOrFunc, aTargetFuncArg, aIsAsync)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
|
|
|
this.type = aEventType;
|
2011-07-19 08:30:32 +00:00
|
|
|
this.async = aIsAsync;
|
2010-06-08 16:39:58 +00: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);
|
2011-09-28 01:46:11 +00:00
|
|
|
if (typeof this.mTarget == "string")
|
|
|
|
return getNode(this.mTarget);
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
return this.mTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
function invokerChecker_targetSetter(aValue)
|
|
|
|
{
|
|
|
|
this.mTarget = aValue;
|
|
|
|
return this.mTarget;
|
|
|
|
}
|
|
|
|
|
2011-01-26 06:35:51 +00:00
|
|
|
this.__defineGetter__("targetDescr", invokerChecker_targetDescrGetter);
|
|
|
|
|
|
|
|
function invokerChecker_targetDescrGetter()
|
|
|
|
{
|
|
|
|
if (typeof this.mTarget == "function")
|
2011-01-28 08:42:22 +00:00
|
|
|
return this.mTarget.name + ", arg: " + this.mTargetFuncArg;
|
2011-01-26 06:35:51 +00:00
|
|
|
|
|
|
|
return prettyName(this.mTarget);
|
|
|
|
}
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
this.mTarget = aTargetOrFunc;
|
|
|
|
this.mTargetFuncArg = aTargetFuncArg;
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 08:30:32 +00:00
|
|
|
/**
|
|
|
|
* Common invoker checker for async events.
|
|
|
|
*/
|
|
|
|
function asyncInvokerChecker(aEventType, aTargetOrFunc, aTargetFuncArg)
|
|
|
|
{
|
|
|
|
this.__proto__ = new invokerChecker(aEventType, aTargetOrFunc,
|
|
|
|
aTargetFuncArg, true);
|
|
|
|
}
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
function focusChecker(aTargetOrFunc, aTargetFuncArg)
|
|
|
|
{
|
|
|
|
this.__proto__ = new invokerChecker(EVENT_FOCUS, aTargetOrFunc,
|
|
|
|
aTargetFuncArg, false);
|
|
|
|
|
|
|
|
this.unique = true; // focus event must be unique for invoker action
|
|
|
|
|
|
|
|
this.check = function focusChecker_check(aEvent)
|
|
|
|
{
|
|
|
|
testStates(aEvent.accessible, STATE_FOCUSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function nofocusChecker(aID)
|
|
|
|
{
|
|
|
|
this.__proto__ = new focusChecker(aID);
|
|
|
|
this.unexpected = true;
|
|
|
|
}
|
|
|
|
|
2010-12-15 21:23:19 +00:00
|
|
|
/**
|
|
|
|
* Text inserted/removed events checker.
|
|
|
|
*/
|
|
|
|
function textChangeChecker(aID, aStart, aEnd, aTextOrFunc, aIsInserted)
|
|
|
|
{
|
|
|
|
this.target = getNode(aID);
|
|
|
|
this.type = aIsInserted ? EVENT_TEXT_INSERTED : EVENT_TEXT_REMOVED;
|
|
|
|
|
|
|
|
this.check = function textChangeChecker_check(aEvent)
|
|
|
|
{
|
|
|
|
aEvent.QueryInterface(nsIAccessibleTextChangeEvent);
|
|
|
|
|
|
|
|
var modifiedText = (typeof aTextOrFunc == "function") ?
|
|
|
|
aTextOrFunc() : aTextOrFunc;
|
|
|
|
var modifiedTextLen = (aEnd == -1) ? modifiedText.length : aEnd - aStart;
|
|
|
|
|
|
|
|
is(aEvent.start, aStart, "Wrong start offset for " + prettyName(aID));
|
|
|
|
is(aEvent.length, modifiedTextLen, "Wrong length for " + prettyName(aID));
|
|
|
|
var changeInfo = (aIsInserted ? "inserted" : "removed");
|
|
|
|
is(aEvent.isInserted(), aIsInserted,
|
|
|
|
"Text was " + changeInfo + " for " + prettyName(aID));
|
|
|
|
is(aEvent.modifiedText, modifiedText,
|
|
|
|
"Wrong " + changeInfo + " text for " + prettyName(aID));
|
|
|
|
}
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
|
2011-02-15 16:33:54 +00:00
|
|
|
/**
|
|
|
|
* Caret move events checker.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function caretMoveChecker(aCaretOffset, aTargetOrFunc, aTargetFuncArg)
|
2011-02-15 16:33:54 +00:00
|
|
|
{
|
2011-09-28 01:46:11 +00:00
|
|
|
this.__proto__ = new invokerChecker(EVENT_TEXT_CARET_MOVED,
|
|
|
|
aTargetOrFunc, aTargetFuncArg);
|
|
|
|
|
2011-02-15 16:33:54 +00:00
|
|
|
this.check = function caretMoveChecker_check(aEvent)
|
|
|
|
{
|
|
|
|
is(aEvent.QueryInterface(nsIAccessibleCaretMoveEvent).caretOffset,
|
|
|
|
aCaretOffset,
|
|
|
|
"Wrong caret offset for " + prettyName(aEvent.accessible));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-11 11:45:36 +00:00
|
|
|
/**
|
|
|
|
* State change checker.
|
|
|
|
*/
|
|
|
|
function stateChangeChecker(aState, aIsExtraState, aIsEnabled,
|
|
|
|
aTargetOrFunc, aTargetFuncArg)
|
|
|
|
{
|
|
|
|
this.__proto__ = new invokerChecker(EVENT_STATE_CHANGE, aTargetOrFunc,
|
|
|
|
aTargetFuncArg);
|
|
|
|
|
|
|
|
this.check = function stateChangeChecker_check(aEvent)
|
|
|
|
{
|
|
|
|
var event = null;
|
|
|
|
try {
|
|
|
|
var event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent);
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, "State change event was expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
is(event.isExtraState(), aIsExtraState,
|
|
|
|
"Wrong extra state bit of the statechange event.");
|
2011-11-30 12:36:20 +00:00
|
|
|
isState(event.state, aState, aIsExtraState,
|
|
|
|
"Wrong state of the statechange event.");
|
2011-08-11 11:45:36 +00:00
|
|
|
is(event.isEnabled(), aIsEnabled,
|
|
|
|
"Wrong state of statechange event state");
|
|
|
|
|
|
|
|
var state = aIsEnabled ? (aIsExtraState ? 0 : aState) : 0;
|
|
|
|
var extraState = aIsEnabled ? (aIsExtraState ? aState : 0) : 0;
|
|
|
|
var unxpdState = aIsEnabled ? 0 : (aIsExtraState ? 0 : aState);
|
|
|
|
var unxpdExtraState = aIsEnabled ? 0 : (aIsExtraState ? aState : 0);
|
|
|
|
testStates(event.accessible, state, extraState, unxpdState, unxpdExtraState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expanded state change checker.
|
|
|
|
*/
|
|
|
|
function expandedStateChecker(aIsEnabled, aTargetOrFunc, aTargetFuncArg)
|
|
|
|
{
|
|
|
|
this.__proto__ = new invokerChecker(EVENT_STATE_CHANGE, aTargetOrFunc,
|
|
|
|
aTargetFuncArg);
|
|
|
|
|
|
|
|
this.check = function expandedStateChecker_check(aEvent)
|
|
|
|
{
|
|
|
|
var event = null;
|
|
|
|
try {
|
|
|
|
var event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent);
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, "State change event was expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
is(event.state, STATE_EXPANDED, "Wrong state of the statechange event.");
|
|
|
|
is(event.isExtraState(), false,
|
|
|
|
"Wrong extra state bit of the statechange event.");
|
|
|
|
is(event.isEnabled(), aIsEnabled,
|
|
|
|
"Wrong state of statechange event state");
|
|
|
|
|
|
|
|
testStates(event.accessible,
|
|
|
|
(aIsEnabled ? STATE_EXPANDED : STATE_COLLAPSED));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private implementation details.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
|
|
|
var gA11yEventListeners = {};
|
|
|
|
var gA11yEventApplicantsCount = 0;
|
|
|
|
|
|
|
|
var gA11yEventObserver =
|
|
|
|
{
|
2010-02-04 18:15:03 +00: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 20:30:14 +00:00
|
|
|
observerService :
|
|
|
|
Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(nsIObserverService),
|
2010-02-04 18:15:03 +00:00
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
observe: function observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic != "accessible-event")
|
|
|
|
return;
|
|
|
|
|
2010-02-04 18:15:03 +00: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-25 04:42:21 +00:00
|
|
|
var listenersArray = gA11yEventListeners[event.eventType];
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
var eventFromDumpArea = false;
|
2010-12-03 10:49:08 +00:00
|
|
|
if (gLogger.isEnabled()) { // debug stuff
|
2010-06-08 16:39:58 +00:00
|
|
|
eventFromDumpArea = true;
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
var target = event.DOMNode;
|
2010-12-03 10:49:08 +00:00
|
|
|
var dumpElm = gA11yEventDumpID ?
|
|
|
|
document.getElementById(gA11yEventDumpID) : null;
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
if (dumpElm) {
|
|
|
|
var parent = target;
|
|
|
|
while (parent && parent != dumpElm)
|
|
|
|
parent = parent.parentNode;
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
if (!dumpElm || parent != dumpElm) {
|
2009-02-27 10:45:21 +00:00
|
|
|
var type = eventTypeToString(event.eventType);
|
|
|
|
var info = "Event type: " + type;
|
2010-07-02 01:50:03 +00:00
|
|
|
|
|
|
|
if (event instanceof nsIAccessibleTextChangeEvent) {
|
|
|
|
info += ", start: " + event.start + ", length: " + event.length +
|
|
|
|
", " + (event.isInserted() ? "inserted" : "removed") +
|
|
|
|
" text: " + event.modifiedText;
|
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
info += ". Target: " + prettyName(event.accessible);
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2009-02-05 06:23:18 +00:00
|
|
|
if (listenersArray)
|
|
|
|
info += ". Listeners count: " + listenersArray.length;
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
eventFromDumpArea = false;
|
2010-12-03 10:49:08 +00:00
|
|
|
gLogger.log(info);
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
// Do not notify listeners if event is result of event log changes.
|
|
|
|
if (!listenersArray || eventFromDumpArea)
|
2009-01-25 04:42:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (var index = 0; index < listenersArray.length; index++)
|
|
|
|
listenersArray[index].handleEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function listenA11yEvents(aStartToListen)
|
|
|
|
{
|
2010-02-05 20:30:14 +00: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-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
if (!(aEventType in gA11yEventListeners))
|
|
|
|
gA11yEventListeners[aEventType] = new Array();
|
2010-12-15 21:22:51 +00:00
|
|
|
|
|
|
|
var listenersArray = gA11yEventListeners[aEventType];
|
|
|
|
var index = listenersArray.indexOf(aEventHandler);
|
|
|
|
if (index == -1)
|
|
|
|
listenersArray.push(aEventHandler);
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-05 06:23:18 +00:00
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
/**
|
2010-12-03 10:49:08 +00:00
|
|
|
* Used to dump debug information.
|
2009-05-11 01:32:09 +00:00
|
|
|
*/
|
2010-12-03 10:49:08 +00:00
|
|
|
var gLogger =
|
2009-02-05 06:23:18 +00:00
|
|
|
{
|
2010-12-03 10:49:08 +00:00
|
|
|
/**
|
|
|
|
* Return true if dump is enabled.
|
|
|
|
*/
|
|
|
|
isEnabled: function debugOutput_isEnabled()
|
|
|
|
{
|
|
|
|
return gA11yEventDumpID || gA11yEventDumpToConsole ||
|
|
|
|
gA11yEventDumpToAppConsole;
|
|
|
|
},
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
/**
|
|
|
|
* Dump information into DOM and console if applicable.
|
|
|
|
*/
|
|
|
|
log: function logger_log(aMsg)
|
|
|
|
{
|
|
|
|
this.logToConsole(aMsg);
|
|
|
|
this.logToAppConsole(aMsg);
|
|
|
|
this.logToDOM(aMsg);
|
|
|
|
},
|
2009-02-27 10:45:21 +00:00
|
|
|
|
2010-12-03 10:49:08 +00:00
|
|
|
/**
|
|
|
|
* Log message to DOM.
|
|
|
|
*
|
|
|
|
* @param aMsg [in] the primary message
|
|
|
|
* @param aHasIndent [in, optional] if specified the message has an indent
|
|
|
|
* @param aPreEmphText [in, optional] the text is colored and appended prior
|
|
|
|
* primary message
|
|
|
|
*/
|
|
|
|
logToDOM: function logger_logToDOM(aMsg, aHasIndent, aPreEmphText)
|
|
|
|
{
|
|
|
|
if (gA11yEventDumpID == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var dumpElm = document.getElementById(gA11yEventDumpID);
|
|
|
|
if (!dumpElm) {
|
|
|
|
ok(false,
|
|
|
|
"No dump element '" + gA11yEventDumpID + "' within the document!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var containerTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"div" : "description";
|
|
|
|
|
|
|
|
var container = document.createElement(containerTagName);
|
|
|
|
if (aHasIndent)
|
|
|
|
container.setAttribute("style", "padding-left: 10px;");
|
|
|
|
|
|
|
|
if (aPreEmphText) {
|
|
|
|
var inlineTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"span" : "description";
|
|
|
|
var emphElm = document.createElement(inlineTagName);
|
|
|
|
emphElm.setAttribute("style", "color: blue;");
|
|
|
|
emphElm.textContent = aPreEmphText;
|
|
|
|
|
|
|
|
container.appendChild(emphElm);
|
|
|
|
}
|
|
|
|
|
|
|
|
var textNode = document.createTextNode(aMsg);
|
|
|
|
container.appendChild(textNode);
|
|
|
|
|
|
|
|
dumpElm.appendChild(container);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log message to console.
|
|
|
|
*/
|
|
|
|
logToConsole: function logger_logToConsole(aMsg)
|
|
|
|
{
|
|
|
|
if (gA11yEventDumpToConsole)
|
|
|
|
dump("\n" + aMsg + "\n");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log message to error console.
|
|
|
|
*/
|
|
|
|
logToAppConsole: function logger_logToAppConsole(aMsg)
|
|
|
|
{
|
|
|
|
if (gA11yEventDumpToAppConsole)
|
|
|
|
consoleService.logStringMessage("events: " + aMsg);
|
|
|
|
},
|
|
|
|
|
|
|
|
consoleService: Components.classes["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Components.interfaces.nsIConsoleService)
|
|
|
|
};
|
2009-09-19 06:30:07 +00: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 07:50:47 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue invokers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoker base class for prepare an action.
|
|
|
|
*/
|
2011-09-28 01:46:11 +00:00
|
|
|
function synthAction(aNodeOrID, aCheckerOrEventSeq)
|
2009-10-06 07:50:47 +00:00
|
|
|
{
|
|
|
|
this.DOMNode = getNode(aNodeOrID);
|
2010-12-03 10:49:20 +00:00
|
|
|
|
|
|
|
if (aCheckerOrEventSeq) {
|
|
|
|
if (aCheckerOrEventSeq instanceof Array) {
|
|
|
|
this.eventSeq = aCheckerOrEventSeq;
|
|
|
|
} else {
|
2011-09-28 01:46:11 +00:00
|
|
|
this.eventSeq = [ aCheckerOrEventSeq ];
|
2010-12-03 10:49:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-06 07:50:47 +00:00
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
this.getID = function synthAction_getID()
|
|
|
|
{ return prettyName(aNodeOrID) + " action"; }
|
2009-10-06 07:50:47 +00:00
|
|
|
}
|