From dabe0349ceaf06be43bf20777beb74d7d23f2c44 Mon Sep 17 00:00:00 2001 From: Yura Zenevich Date: Tue, 12 Nov 2019 15:05:42 +0000 Subject: [PATCH] Bug 1594743 - ensure that the keyboard audit does not interfere with other audit types. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D52378 --HG-- extra : moz-landing-system : lando --- .../server/actors/accessibility/accessible.js | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/devtools/server/actors/accessibility/accessible.js b/devtools/server/actors/accessibility/accessible.js index 05e22ec0eb06..7935e51a37a1 100644 --- a/devtools/server/actors/accessibility/accessible.js +++ b/devtools/server/actors/accessibility/accessible.js @@ -526,12 +526,37 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, { auditTypes = auditTypes.filter(auditType => types.includes(auditType)); } - // More audit steps will be added here in the near future. In addition to - // colour contrast ratio we will add autits for to the missing names, - // invalid states, etc. (For example see bug 1518808). - this._auditing = Promise.all( - auditTypes.map(auditType => this._getAuditByType(auditType)) - ) + // For some reason keyboard checks for focus styling affect values (that are + // used by other types of checks (text names and values)) returned by + // accessible objects. This happens only when multiple checks are run at the + // same time (asynchronously) and the audit might return unexpected + // failures. We thus split the execution of the checks into two parts, first + // performing keyboard checks and only after the rest of the checks. See bug + // 1594743 for more detail. + let keyboardAuditResult; + const keyboardAuditIndex = auditTypes.indexOf(AUDIT_TYPE.KEYBOARD); + if (keyboardAuditIndex > -1) { + // If we are performing a keyboard audit, remove its value from the + // complete list and run it. + auditTypes.splice(keyboardAuditIndex, 1); + keyboardAuditResult = this._getAuditByType(AUDIT_TYPE.KEYBOARD); + } + + this._auditing = Promise.resolve(keyboardAuditResult) + .then(keyboardResult => { + const audits = auditTypes.map(auditType => + this._getAuditByType(auditType) + ); + + // If we are also performing a keyboard audit, add its type and its + // result back to the complete list of audits. + if (keyboardAuditIndex > -1) { + auditTypes.splice(keyboardAuditIndex, 0, AUDIT_TYPE.KEYBOARD); + audits.splice(keyboardAuditIndex, 0, keyboardResult); + } + + return Promise.all(audits); + }) .then(results => { if (this.isDefunct || this.isDestroyed) { return null;