Bug 1066474 - Avoid races in browser_timelineMarkers-02.js test. r=paul
authorTom Tromey <tromey@mozilla.com>
Wed, 17 Dec 2014 06:58:00 -0500
changeset 220237 0d78284bbf8b0801f1adcc6e4845d83fbd6b7012
parent 220236 396c9b403e26e0eb53dde463506a647fd12105b9
child 220238 1e94e7f8a32d1d8184d7a1758d95e78369a1f0fa
push id10459
push userryanvm@gmail.com
push dateThu, 18 Dec 2014 02:56:54 +0000
treeherderfx-team@14e17056fc81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul
bugs1066474
milestone37.0a1
Bug 1066474 - Avoid races in browser_timelineMarkers-02.js test. r=paul
docshell/test/browser/browser_timelineMarkers-02.js
--- a/docshell/test/browser/browser_timelineMarkers-02.js
+++ b/docshell/test/browser/browser_timelineMarkers-02.js
@@ -11,16 +11,17 @@ let URL = '<!DOCTYPE html><style>' +
           'div {width:100px;height:100px;background:red;} ' +
           '.resize-change-color {width:50px;height:50px;background:blue;} ' +
           '.change-color {width:50px;height:50px;background:yellow;} ' +
           '.add-class {}' +
           '</style><div></div>';
 
 let TESTS = [{
   desc: "Changing the width of the test element",
+  searchFor: "Paint",
   setup: function(div) {
     div.setAttribute("class", "resize-change-color");
   },
   check: function(markers) {
     ok(markers.length > 0, "markers were returned");
     console.log(markers);
     info(JSON.stringify(markers.filter(m => m.name == "Paint")));
     ok(markers.some(m => m.name == "Reflow"), "markers includes Reflow");
@@ -30,16 +31,17 @@ let TESTS = [{
       ok(marker.rectangles.length >= 1, "marker has one rectangle");
       // One of the rectangles should contain the div.
       ok(marker.rectangles.some(r => rectangleContains(r, 0, 0, 100, 100)));
     }
     ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
   }
 }, {
   desc: "Changing the test element's background color",
+  searchFor: "Paint",
   setup: function(div) {
     div.setAttribute("class", "change-color");
   },
   check: function(markers) {
     ok(markers.length > 0, "markers were returned");
     ok(!markers.some(m => m.name == "Reflow"), "markers doesn't include Reflow");
     ok(markers.some(m => m.name == "Paint"), "markers includes Paint");
     for (let marker of markers.filter(m => m.name == "Paint")) {
@@ -47,27 +49,29 @@ let TESTS = [{
       ok(marker.rectangles.length >= 1, "marker has one rectangle");
       // One of the rectangles should contain the div.
       ok(marker.rectangles.some(r => rectangleContains(r, 0, 0, 50, 50)));
     }
     ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
   }
 }, {
   desc: "Changing the test element's classname",
+  searchFor: "Paint",
   setup: function(div) {
     div.setAttribute("class", "change-color add-class");
   },
   check: function(markers) {
     ok(markers.length > 0, "markers were returned");
     ok(!markers.some(m => m.name == "Reflow"), "markers doesn't include Reflow");
     ok(!markers.some(m => m.name == "Paint"), "markers doesn't include Paint");
     ok(markers.some(m => m.name == "Styles"), "markers includes Restyle");
   }
 }, {
   desc: "sync console.time/timeEnd",
+  searchFor: "ConsoleTime",
   setup: function(div, docShell) {
     content.console.time("FOOBAR");
     content.console.timeEnd("FOOBAR");
     let markers = docShell.popProfileTimelineMarkers();
     is(markers.length, 1, "Got one marker");
     is(markers[0].name, "ConsoleTime", "Got ConsoleTime marker");
     is(markers[0].causeName, "FOOBAR", "Got ConsoleTime FOOBAR detail");
     content.console.time("FOO");
@@ -97,25 +101,25 @@ let test = Task.async(function*() {
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIDocShell);
 
   let div = content.document.querySelector("div");
 
   info("Start recording");
   docShell.recordProfileTimelineMarkers = true;
 
-  for (let {desc, setup, check} of TESTS) {
+  for (let {desc, searchFor, setup, check} of TESTS) {
 
     info("Running test: " + desc);
 
     info("Flushing the previous markers if any");
     docShell.popProfileTimelineMarkers();
 
     info("Running the test setup function");
-    let onMarkers = waitForMarkers(docShell);
+    let onMarkers = waitForMarkers(docShell, searchFor);
     setup(div, docShell);
     info("Waiting for new markers on the docShell");
     let markers = yield onMarkers;
 
     info("Running the test check function");
     check(markers);
   }
 
@@ -135,31 +139,30 @@ function openUrl(url) {
 
     linkedBrowser.addEventListener("load", function onload() {
       linkedBrowser.removeEventListener("load", onload, true);
       resolve(tab);
     }, true);
   });
 }
 
-function waitForMarkers(docshell) {
+function waitForMarkers(docshell, searchFor) {
   return new Promise(function(resolve, reject) {
     let waitIterationCount = 0;
     let maxWaitIterationCount = 10; // Wait for 2sec maximum
+    let markers = [];
 
     let interval = setInterval(() => {
-      let markers = docshell.popProfileTimelineMarkers();
-      if (markers.length > 0) {
+      let newMarkers = docshell.popProfileTimelineMarkers();
+      markers = [...markers, ...newMarkers];
+      if (newMarkers.some(m => m.name == searchFor) ||
+          waitIterationCount > maxWaitIterationCount) {
         clearInterval(interval);
         resolve(markers);
       }
-      if (waitIterationCount > maxWaitIterationCount) {
-        clearInterval(interval);
-        resolve([]);
-      }
       waitIterationCount++;
     }, 200);
   });
 }
 
 function rectangleContains(rect, x, y, width, height) {
   return rect.x <= x && rect.y <= y && rect.width >= width &&
     rect.height >= height;