Bug 1594743 - ensure that the keyboard audit does not interfere with other audit types. r=nchevobbe a=pascalc
authorYura Zenevich <yura.zenevich@gmail.com>
Tue, 12 Nov 2019 15:05:42 +0000
changeset 560076 73a6d9d8995febd9286859b6cc80979fa2455cc3
parent 560075 b6d13adc8be1ae29bf821bd0d1328d51d526efd5
child 560077 9ab34f36f0174f5b475517d155357ec7a84cfdbc
push id12320
push useropoprus@mozilla.com
push dateMon, 18 Nov 2019 14:50:50 +0000
treeherdermozilla-beta@a25e8472d4ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe, pascalc
bugs1594743
milestone71.0
Bug 1594743 - ensure that the keyboard audit does not interfere with other audit types. r=nchevobbe a=pascalc 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;