Bug 1328254 - Fix browser_aboutperformance.js to correctly check the delta displays. r?jaws draft
authorMark Banner <standard8@mozilla.com>
Fri, 20 Jan 2017 13:47:55 +0000
changeset 464144 88beb77a339e3bb2caeca3bb48c3140ddc689e9e
parent 464075 aa3e49299a3aa5cb0db570532e3df9e75d30c2d1
child 542867 533cd3d33439e393812e053482357e948a4b3bb6
push id42283
push userbmo:standard8@mozilla.com
push dateFri, 20 Jan 2017 13:48:25 +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;
     }