Bug 1085119 - Fixed wrong computed best matched style rule in DevTools draft
authortotorigolo <toto.rigolo@free.fr>
Sun, 27 Aug 2017 18:00:10 +0200
changeset 653722 c4c2d02e5425df09928df1875170a70c6e61b95d
parent 652116 484990c2529fce77510589da1d760cbe2c51b8ac
child 728398 0ef23b277cb25516b05b8143076c9353771047c6
push id76390
push userbmo:toto.rigolo@free.fr
push dateSun, 27 Aug 2017 16:02:40 +0000
bugs1085119
milestone57.0a1
Bug 1085119 - Fixed wrong computed best matched style rule in DevTools MozReview-Commit-ID: 2HYcMiRvhnP
devtools/server/css-logic.js
--- a/devtools/server/css-logic.js
+++ b/devtools/server/css-logic.js
@@ -1224,20 +1224,30 @@ CssPropertyInfo.prototype = {
       if (selectorInfo1.status > selectorInfo2.status) {
         return -1;
       } else if (selectorInfo2.status > selectorInfo1.status) {
         return 1;
       }
       return selectorInfo1.compareTo(selectorInfo2);
     });
 
-    // Now we know which of the matches is best, we can mark it BEST_MATCH.
-    if (this._matchedSelectors.length > 0 &&
-        this._matchedSelectors[0].status > STATUS.UNMATCHED) {
-      this._matchedSelectors[0].status = STATUS.BEST;
+    // Find which match is the best
+    if (this._matchedSelectors.length > 0) {
+      if (this._matchedSelectors[0].status > STATUS.UNMATCHED) {
+        let bestStatus = this._matchedSelectors[0].status;
+        let bestIndex = 0;
+
+        while (bestIndex + 1 < this._matchedSelectors.length &&
+            this._matchedSelectors[bestIndex + 1].status == bestStatus) {
+            bestIndex++;
+        }
+
+        // Now we know which of the matches is best, we can mark it BEST_MATCH.
+        this._matchedSelectors[bestStatus].status = STATUS.BEST;
+      }
     }
   },
 
   /**
    * Process a matched CssSelector object.
    *
    * @private
    * @param {CssSelector} selector the matched CssSelector object.