Bug 1113552 - Use add_task in all browser/devtools/timeline browser mochitests; r=paul
authorPatrick Brosset <pbrosset@mozilla.com>
Fri, 19 Dec 2014 02:59:00 +0100
changeset 220906 92d9d1663eb9379fc9a52dd7182162ecc13b4681
parent 220905 4eb4d48d4538f0ea0beb478a9a3a178453eed543
child 220907 0aa625346f8966ee1a06842f1de5c96b7d453ee6
push id28003
push userryanvm@gmail.com
push dateMon, 22 Dec 2014 22:44:16 +0000
treeherdermozilla-central@d5167dc0ded3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul
bugs1113552
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1113552 - Use add_task in all browser/devtools/timeline browser mochitests; r=paul
browser/devtools/timeline/test/browser_timeline_aaa_run_first_leaktest.js
browser/devtools/timeline/test/browser_timeline_blueprint.js
browser/devtools/timeline/test/browser_timeline_overview-initial-selection-01.js
browser/devtools/timeline/test/browser_timeline_overview-initial-selection-02.js
browser/devtools/timeline/test/browser_timeline_overview-update.js
browser/devtools/timeline/test/browser_timeline_panels.js
browser/devtools/timeline/test/browser_timeline_recording-without-memory.js
browser/devtools/timeline/test/browser_timeline_recording.js
browser/devtools/timeline/test/browser_timeline_waterfall-background.js
browser/devtools/timeline/test/browser_timeline_waterfall-generic.js
browser/devtools/timeline/test/browser_timeline_waterfall-sidebar.js
browser/devtools/timeline/test/browser_timeline_waterfall-styles.js
browser/devtools/timeline/test/head.js
--- a/browser/devtools/timeline/test/browser_timeline_aaa_run_first_leaktest.js
+++ b/browser/devtools/timeline/test/browser_timeline_aaa_run_first_leaktest.js
@@ -1,21 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the timeline leaks on initialization and sudden destruction.
  * You can also use this initialization format as a template for other tests.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
 
   ok(target, "Should have a target available.");
   ok(panel, "Should have a panel available.");
 
   ok(panel.panelWin.gToolbox, "Should have a toolbox reference on the panel window.");
   ok(panel.panelWin.gTarget, "Should have a target reference on the panel window.");
   ok(panel.panelWin.gFront, "Should have a front reference on the panel window.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_blueprint.js
+++ b/browser/devtools/timeline/test/browser_timeline_blueprint.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the timeline blueprint has a correct structure.
  */
 
-function test() {
+add_task(function*() {
   let { TIMELINE_BLUEPRINT } = devtools.require("devtools/timeline/global");
 
   ok(TIMELINE_BLUEPRINT,
     "A timeline blueprint should be available.");
 
   ok(Object.keys(TIMELINE_BLUEPRINT).length,
     "The timeline blueprint has at least one entry.");
 
@@ -19,11 +19,9 @@ function test() {
       "Each entry in the timeline blueprint contains a `group` key.");
     ok("fill" in value,
       "Each entry in the timeline blueprint contains a `fill` key.");
     ok("stroke" in value,
       "Each entry in the timeline blueprint contains a `stroke` key.");
     ok("label" in value,
       "Each entry in the timeline blueprint contains a `label` key.");
   }
-
-  finish();
-}
+});
--- a/browser/devtools/timeline/test/browser_timeline_overview-initial-selection-01.js
+++ b/browser/devtools/timeline/test/browser_timeline_overview-initial-selection-01.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the overview has an initial selection when recording has finished
  * and there is data available.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;
   let { OVERVIEW_INITIAL_SELECTION_RATIO: selectionRatio } = panel.panelWin;
 
   $("#memory-checkbox").checked = true;
   yield TimelineController.updateMemoryRecording();
 
   yield TimelineController.toggleRecording();
@@ -36,12 +36,9 @@ let test = Task.async(function*() {
 
   is((selection.start) | 0,
      ((markers[0].start - interval.startTime) * TimelineView.markersOverview.dataScaleX) | 0,
     "The initial selection start is correct.");
 
   is((selection.end - selection.start) | 0,
      (selectionRatio * TimelineView.markersOverview.width) | 0,
     "The initial selection end is correct.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_overview-initial-selection-02.js
+++ b/browser/devtools/timeline/test/browser_timeline_overview-initial-selection-02.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the overview has no initial selection when recording has finished
  * and there is no data available.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;
   let { OVERVIEW_INITIAL_SELECTION_RATIO: selectionRatio } = panel.panelWin;
 
   $("#memory-checkbox").checked = true;
   yield TimelineController.updateMemoryRecording();
 
   yield TimelineController.toggleRecording();
@@ -27,12 +27,9 @@ let test = Task.async(function*() {
   is(markers.length, 0,
     "There are no markers available.");
   is(memory.length, 0,
     "There are no memory measurements available.");
   is(selection.start, null,
     "The initial selection start is correct.");
   is(selection.end, null,
     "The initial selection end is correct.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_overview-update.js
+++ b/browser/devtools/timeline/test/browser_timeline_overview-update.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the markers and memory overviews are continuously updated.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel("about:blank");
   let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;
 
   $("#memory-checkbox").checked = true;
   yield TimelineController.updateMemoryRecording();
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
@@ -63,12 +63,9 @@ let test = Task.async(function*() {
     "The selection should now be enabled for the markers overview.");
   is(TimelineView.markersOverview.hasSelection(), false,
     "The markers overview should not have a selection after recording.");
 
   is(TimelineView.memoryOverview.selectionEnabled, true,
     "The selection should now be enabled for the memory overview.");
   is(TimelineView.memoryOverview.hasSelection(), false,
     "The memory overview should not have a selection after recording.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_panels.js
+++ b/browser/devtools/timeline/test/browser_timeline_panels.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the timeline panels are correctly shown and hidden when
  * recording starts and stops.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, EVENTS } = panel.panelWin;
 
   is($("#record-button").hasAttribute("checked"), false,
     "The record button should not be checked yet.");
   is($("#timeline-pane").selectedPanel, $("#empty-notice"),
     "An empty notice is initially displayed instead of the waterfall view.");
 
@@ -31,12 +31,9 @@ let test = Task.async(function*() {
   yield whenRecEnded;
 
   ok(true, "Recording has ended.");
 
   is($("#record-button").hasAttribute("checked"), false,
     "The record button should be unchecked again.");
   is($("#timeline-pane").selectedPanel, $("#timeline-waterfall-container"),
     "A waterfall view is now displayed.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_recording-without-memory.js
+++ b/browser/devtools/timeline/test/browser_timeline_recording-without-memory.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the timeline actor isn't unnecessarily asked to record memory.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
 
   let updated = 0;
   panel.panelWin.on(EVENTS.OVERVIEW_UPDATED, () => updated++);
@@ -25,12 +25,9 @@ let test = Task.async(function*() {
 
   let markers = TimelineController.getMarkers();
   let memory = TimelineController.getMemory();
 
   isnot(markers.length, 0,
     "There are some markers available.");
   is(memory.length, 0,
     "There are no memory measurements available.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_recording.js
+++ b/browser/devtools/timeline/test/browser_timeline_recording.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the timeline can properly start and stop a recording.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, gFront, TimelineController } = panel.panelWin;
 
   $("#memory-checkbox").checked = true;
   yield TimelineController.updateMemoryRecording();
 
   is((yield gFront.isRecording()), false,
     "The timeline actor should not be recording when the tool starts.");
@@ -29,12 +29,9 @@ let test = Task.async(function*() {
   ok("startTime" in TimelineController.getInterval(),
     "A `startTime` field was set on the recording data.");
   ok("endTime" in TimelineController.getInterval(),
     "An `endTime` field was set on the recording data.");
 
   ok(TimelineController.getInterval().endTime >
      TimelineController.getInterval().startTime,
     "Some time has passed since the recording started.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_waterfall-background.js
+++ b/browser/devtools/timeline/test/browser_timeline_waterfall-background.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the waterfall background is a 1px high canvas stretching across
  * the container bounds.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
 
   let updated = 0;
   panel.panelWin.on(EVENTS.OVERVIEW_UPDATED, () => updated++);
@@ -36,12 +36,9 @@ let test = Task.async(function*() {
     "A canvas should be created after the recording ended.");
   ok(TimelineView.waterfall._ctx,
     "A 2d context should be created after the recording ended.");
 
   is(TimelineView.waterfall._canvas.width, waterfallWidth,
     "The canvas width is correct.");
   is(TimelineView.waterfall._canvas.height, 1,
     "The canvas height is correct.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_waterfall-generic.js
+++ b/browser/devtools/timeline/test/browser_timeline_waterfall-generic.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the waterfall is properly built after finishing a recording.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, $$, EVENTS, TimelineController } = panel.panelWin;
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
 
   let updated = 0;
   panel.panelWin.on(EVENTS.OVERVIEW_UPDATED, () => updated++);
@@ -57,12 +57,9 @@ let test = Task.async(function*() {
     "Some marker name labels should have been created inside the sidebar.");
 
   // Test the markers waterfall (right).
 
   ok($$(".waterfall-marker-item").length,
     "Some marker waterfall nodes should have been created.");
   ok($$(".waterfall-marker-item:not(spacer) > .waterfall-marker-bar").length,
     "Some marker color bars should have been created inside the waterfall.");
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_waterfall-sidebar.js
+++ b/browser/devtools/timeline/test/browser_timeline_waterfall-sidebar.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Tests if the sidebar is properly updated when a marker is selected.
  */
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { $, $$, EVENTS, TimelineController, TimelineView } = panel.panelWin;
   let { L10N } = devtools.require("devtools/timeline/global");
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
 
   yield waitUntil(() => {
@@ -48,12 +48,9 @@ let test = Task.async(function*() {
 
     let toMs = ms => L10N.getFormatStrWithNumbers("timeline.tick", ms);
 
     // Values are rounded. We don't use a strict equality.
     is(toMs(m.start), printedStartTime, "sidebar start time is valid");
     is(toMs(m.end), printedEndTime, "sidebar end time is valid");
     is(toMs(m.end - m.start), printedDuration, "sidebar duration is valid");
   }
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/browser_timeline_waterfall-styles.js
+++ b/browser/devtools/timeline/test/browser_timeline_waterfall-styles.js
@@ -12,17 +12,17 @@ var gRGB_TO_HSL = {
  "rgb(161, 223, 138)": "hsl(104,57%,71%)",
  "rgb(96, 201, 58)": "hsl(104,57%,51%)",
  "rgb(240, 195, 111)": "hsl(39,82%,69%)",
  "rgb(227, 155, 22)": "hsl(39,82%,49%)",
  "rgb(204, 204, 204)": "hsl(0,0%,80%)",
  "rgb(153, 153, 153)": "hsl(0,0%,60%)",
 };
 
-let test = Task.async(function*() {
+add_task(function*() {
   let { target, panel } = yield initTimelinePanel(SIMPLE_URL);
   let { TIMELINE_BLUEPRINT } = devtools.require("devtools/timeline/global");
   let { $, $$, EVENTS, TimelineController } = panel.panelWin;
 
   yield TimelineController.toggleRecording();
   ok(true, "Recording has started.");
 
   let updated = 0;
@@ -80,12 +80,9 @@ let test = Task.async(function*() {
     is(gRGB_TO_HSL[bar.style.borderColor], TIMELINE_BLUEPRINT[type].stroke,
       "The bar's border color is correct.");
 
     ok(bar.getAttribute("width") > 0,
       "The bar appears to have a proper width.");
     ok(bar.style.transform.match(/^translateX\(.*px\)$/),
       "The bar appears to have proper translations.");
   }
-
-  yield teardown(panel);
-  finish();
 });
--- a/browser/devtools/timeline/test/head.js
+++ b/browser/devtools/timeline/test/head.js
@@ -31,48 +31,42 @@ const SIMPLE_URL = EXAMPLE_URL + "doc_si
 waitForExplicitFinish();
 
 registerCleanupFunction(() => {
   info("finish() was called, cleaning up...");
   Services.prefs.setBoolPref("devtools.debugger.log", gEnableLogging);
   Services.prefs.setBoolPref("devtools.timeline.enabled", gToolEnabled);
 });
 
+// Close the toolbox and all opened tabs automatically.
+registerCleanupFunction(function*() {
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
+  yield gDevTools.closeToolbox(target);
+
+  while (gBrowser.tabs.length > 1) {
+    gBrowser.removeCurrentTab();
+  }
+});
+
 function addTab(url) {
   info("Adding tab: " + url);
 
   let deferred = promise.defer();
   let tab = gBrowser.selectedTab = gBrowser.addTab(url);
   let linkedBrowser = tab.linkedBrowser;
 
   linkedBrowser.addEventListener("load", function onLoad() {
     linkedBrowser.removeEventListener("load", onLoad, true);
     info("Tab added and finished loading: " + url);
     deferred.resolve(tab);
   }, true);
 
   return deferred.promise;
 }
 
-function removeTab(tab) {
-  info("Removing tab.");
-
-  let deferred = promise.defer();
-  let tabContainer = gBrowser.tabContainer;
-
-  tabContainer.addEventListener("TabClose", function onClose(aEvent) {
-    tabContainer.removeEventListener("TabClose", onClose, false);
-    info("Tab removed and finished closing.");
-    deferred.resolve();
-  }, false);
-
-  gBrowser.removeTab(tab);
-  return deferred.promise;
-}
-
 /**
  * Spawns a new tab and starts up a toolbox with the timeline panel
  * automatically selected.
  *
  * Must be used within a task.
  *
  * @param string url
  *        The location of the new tab to spawn.
@@ -89,35 +83,16 @@ function* initTimelinePanel(url) {
   yield target.makeRemote();
 
   let toolbox = yield gDevTools.showToolbox(target, "timeline");
   let panel = toolbox.getCurrentPanel();
   return { target, panel };
 }
 
 /**
- * Closes a tab and destroys the toolbox holding a timeline panel.
- *
- * Must be used within a task.
- *
- * @param object panel
- *        The timeline panel, created by the toolbox.
- * @return object
- *         A promise resolved once the timeline, toolbox and debuggee tab
- *         are destroyed.
- */
-function* teardown(panel) {
-  info("Destroying the specified timeline.");
-
-  let tab = panel.target.tab;
-  yield panel._toolbox.destroy();
-  yield removeTab(tab);
-}
-
-/**
  * Waits until a predicate returns true.
  *
  * @param function predicate
  *        Invoked once in a while until it returns true.
  * @param number interval [optional]
  *        How often the predicate is invoked, in milliseconds.
  */
 function waitUntil(predicate, interval = 10) {