Bug 492956 - mochitest-a11y failed, summary reports unexpected huge numbers for pass/fail; (Bv2) Fix potential edge cases in listenA11yEvents().

r=surkov.alexander
This commit is contained in:
Serge Gautherie 2010-02-05 21:30:14 +01:00
Родитель 26ad4e5a5b
Коммит 50d6bc0b0d
1 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@ -73,8 +73,6 @@ function waitForEvent(aEventType, aTarget, aFunc, aContext, aArg1, aArg2)
function registerA11yEventListener(aEventType, aEventHandler)
{
listenA11yEvents(true);
gA11yEventApplicantsCount++;
addA11yEventListener(aEventType, aEventHandler);
}
@ -86,8 +84,6 @@ function registerA11yEventListener(aEventType, aEventHandler)
function unregisterA11yEventListener(aEventType, aEventHandler)
{
removeA11yEventListener(aEventType, aEventHandler);
gA11yEventApplicantsCount--;
listenA11yEvents(false);
}
@ -173,7 +169,6 @@ function eventQueue(aEventType)
this.invoke = function eventQueue_invoke()
{
listenA11yEvents(true);
gA11yEventApplicantsCount++;
// XXX: Intermittent test_events_caretmove.html fails withouth timeout,
// see bug 474952.
@ -195,7 +190,7 @@ function eventQueue(aEventType)
*/
this.processNextInvoker = function eventQueue_processNextInvoker()
{
// Finish rocessing of the current invoker.
// Finish processing of the current invoker.
var testFailed = false;
var invoker = this.getInvoker();
@ -244,7 +239,6 @@ function eventQueue(aEventType)
// Check if need to stop the test.
if (testFailed || this.mIndex == this.mInvokers.length - 1) {
gA11yEventApplicantsCount--;
listenA11yEvents(false);
var res = this.onFinish();
@ -774,7 +768,9 @@ var gA11yEventObserver =
{
// The service reference needs to live in the observer, instead of as a global var,
// to be available in observe() catch case too.
observerService : null,
observerService :
Components.classes["@mozilla.org/observer-service;1"]
.getService(nsIObserverService),
observe: function observe(aSubject, aTopic, aData)
{
@ -823,17 +819,17 @@ var gA11yEventObserver =
function listenA11yEvents(aStartToListen)
{
if (aStartToListen && !gA11yEventObserver.observerService) {
gA11yEventObserver.observerService =
Components.classes["@mozilla.org/observer-service;1"].getService(nsIObserverService);
gA11yEventObserver.observerService
.addObserver(gA11yEventObserver, "accessible-event", false);
} else if (!gA11yEventApplicantsCount) {
gA11yEventObserver.observerService
.removeObserver(gA11yEventObserver, "accessible-event");
// Release service (variable), so listenA11yEvents(true) can be called again if need be and work.
gA11yEventObserver.observerService = null;
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");
}
}