Bug 1328254 - Fix browser_aboutperformance.js to correctly check the delta displays. r=jaws
authorMark Banner <standard8@mozilla.com>
Fri, 20 Jan 2017 13:47:55 +0000
changeset 464580 7ac654e1c42652c8a37c2919c870a32b61894597
parent 464579 772c8d7a210c803b8c5adbc03be7a5c1107a82d4
child 464581 9c0c8b1a1250b7c0314368f8cba9d8380ba4fc82
push id42370
push usermwein@mozilla.com
push dateSat, 21 Jan 2017 03:10:58 +0000
reviewersjaws
bugs1328254
milestone53.0a1
Bug 1328254 - Fix browser_aboutperformance.js to correctly check the delta displays. r=jaws MozReview-Commit-ID: 4MVvxbuzxxU
toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js
--- a/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js
+++ b/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js
@@ -62,17 +62,17 @@ function frameScript() {
     Services.obs.addObserver(observer, "about:performance-update-complete", false);
     Services.obs.notifyObservers(null, "test-about:performance-test-driver", JSON.stringify(options));
   });
 
   addMessageListener("aboutperformance-test:checkSanity", ({data: options}) => {
     let exn = null;
     try {
       let reFullname = /Full name: (.+)/;
-      let reFps = /Impact on framerate: (\d+)\/10( \((\d+) alerts\))?/;
+      let reFps = /Impact on framerate: ((\d+) high-impacts, (\d+) medium-impact|(\d+)\/10)?/;
       let reCPU = /CPU usage: (\d+)%/;
       let reCpow = /Blocking process calls: (\d+)%( \((\d+) alerts\))?/;
 
       let getContentOfSelector = function(eltContainer, selector, re) {
         let elt = eltContainer.querySelector(selector);
         if (!elt) {
           throw new Error(`No item ${selector}`);
         }
@@ -84,62 +84,71 @@ function frameScript() {
         let match = elt.textContent.match(re);
         if (!match) {
           throw new Error(`Item ${selector} doesn't match regexp ${re}: ${elt.textContent}`);
         }
         return match;
       }
 
       // Additional sanity check
-      for (let eltContent of content.document.querySelectorAll("delta")) {
+      let deltas = content.document.querySelectorAll(".delta");
+      if (!deltas.length) {
+        throw new Error("No deltas found to check!");
+      }
+
+      for (let eltContent of deltas) {
         // Do we have an attribute "impact"? Is it a number between 0 and 10?
-        let impact = eltContent.classList.getAttribute("impact");
+        let impact = eltContent.getAttribute("impact");
         let value = Number.parseInt(impact);
         if (isNaN(value) || value < 0 || value > 10) {
           throw new Error(`Incorrect value ${value}`);
         }
 
         // Do we have a button "more"?
         getContentOfSelector(eltContent, "a.more");
 
         // Do we have details?
         getContentOfSelector(eltContent, "ul.details");
 
         // Do we have a full name? Does it make sense?
         getContentOfSelector(eltContent, "li.name", reFullname);
 
+        let eltDetails = eltContent.querySelector("ul.details");
+
         // Do we have an impact on framerate? Does it make sense?
-        let [, jankStr,, alertsStr] = getContentOfSelector(eltDetails, "li.fps", reFps);
-        let jank = Number.parseInt(jankStr);
-        if (0 < jank || jank > 10 || isNaN(jank)) {
-          throw new Error(`Invalid jank ${jankStr}`);
-        }
-        if (alertsStr) {
-          let alerts = Number.parseInt(alertsStr);
-          if (0 < alerts || isNaN(alerts)) {
-            throw new Error(`Invalid alerts ${alertsStr}`);
+        if (!eltDetails.querySelector("li.fps").textContent.includes("no impact")) {
+          let [, jankStr,, alertsStr] = getContentOfSelector(eltDetails, "li.fps", reFps);
+          let jank = Number.parseInt(jankStr);
+          if (jank < 0 || jank > 10 || isNaN(jank)) {
+            throw new Error(`Invalid jank ${jankStr}`);
+          }
+          if (alertsStr) {
+            let alerts = Number.parseInt(alertsStr);
+            if (alerts < 0 || isNaN(alerts)) {
+              throw new Error(`Invalid alerts ${alertsStr}`);
+            }
           }
         }
 
         // Do we have a CPU usage? Does it make sense?
         let [, cpuStr] = getContentOfSelector(eltDetails, "li.cpu", reCPU);
         let cpu = Number.parseInt(cpuStr);
-        if (0 < cpu || isNaN(cpu)) { // Note that cpu can be > 100%.
+        if (cpu < 0 || isNaN(cpu)) { // Note that cpu can be > 100%.
           throw new Error(`Invalid CPU ${cpuStr}`);
         }
 
         // Do we have CPOW? Does it make sense?
         let [, cpowStr,, alertsStr2] = getContentOfSelector(eltDetails, "li.cpow", reCpow);
         let cpow = Number.parseInt(cpowStr);
-        if (0 < cpow || isNaN(cpow)) {
+        if (cpow < 0 || isNaN(cpow)) {
           throw new Error(`Invalid cpow ${cpowStr}`);
         }
         if (alertsStr2) {
           let alerts = Number.parseInt(alertsStr2);
-          if (0 < alerts || isNaN(alerts)) {
+          if (alerts < 0 || isNaN(alerts)) {
             throw new Error(`Invalid alerts ${alertsStr2}`);
           }
         }
       }
     } catch (ex) {
       dump(`aboutperformance-test:checkSanity: error ${ex}\n`);
       exn = ex;
     }