Bug 1594743 - ensure that the keyboard audit does not interfere with other audit types. r=nchevobbe
authorYura Zenevich <yura.zenevich@gmail.com>
Tue, 12 Nov 2019 15:05:42 +0000
changeset 501966 e727898953edb7c1b536cace1e7add0a7de2a536
parent 501965 6e1a7f2f6bb2a106ba490556ee1effd411726651
child 501967 2eaeb35d81d6ff8aff7b3944a5bfe7dd5693dac7
push id36803
push userrmaries@mozilla.com
push dateThu, 14 Nov 2019 21:46:28 +0000
treeherdermozilla-central@0fb79a3edf1b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1594743
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594743 - ensure that the keyboard audit does not interfere with other audit types. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D52378
devtools/server/actors/accessibility/accessible.js
--- a/devtools/server/actors/accessibility/accessible.js
+++ b/devtools/server/actors/accessibility/accessible.js
@@ -521,22 +521,47 @@ const AccessibleActor = ActorClassWithSp
     }
 
     const { types } = options;
     let auditTypes = Object.values(AUDIT_TYPE);
     if (types && types.length > 0) {
       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;
         }
 
         const audit = results.reduce((auditResults, result, index) => {
           auditResults[auditTypes[index]] = result;
           return auditResults;