Bug 1278346 - Switch browser_net_statistics-01,02.js to add_task. r=ochameau
authorTim Nguyen <ntim.bugs@gmail.com>
Mon, 06 Jun 2016 23:46:32 +0200
changeset 300636 f10a5cdcf8a1b908bf2c25f15cc4c8e9df11addd
parent 300635 883b0a89b3212b6b55b7e6fde69d0438c39899ff
child 300637 529f3c1c7c1f476d48598455ab9ebd20bd55b83a
push id30320
push usercbook@mozilla.com
push dateTue, 07 Jun 2016 13:22:11 +0000
treeherdermozilla-central@bc9db3800f3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1278346
milestone49.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 1278346 - Switch browser_net_statistics-01,02.js to add_task. r=ochameau MozReview-Commit-ID: 5QDts08x0rv
devtools/client/netmonitor/test/browser_net_statistics-01.js
devtools/client/netmonitor/test/browser_net_statistics-02.js
--- a/devtools/client/netmonitor/test/browser_net_statistics-01.js
+++ b/devtools/client/netmonitor/test/browser_net_statistics-01.js
@@ -1,72 +1,75 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if the statistics view is populated correctly.
  */
 
-function test() {
-  initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
+add_task(function* () {
+  let [,, monitor] = yield initNetMonitor(STATISTICS_URL);
+  info("Starting test... ");
 
-    let panel = aMonitor.panelWin;
-    let { document, $, $all, EVENTS, NetMonitorView } = panel;
-
-    is(NetMonitorView.currentFrontendMode, "network-inspector-view",
-      "The initial frontend mode is correct.");
+  let panel = monitor.panelWin;
+  let { $, $all, EVENTS, NetMonitorView } = panel;
+  is(NetMonitorView.currentFrontendMode, "network-inspector-view",
+    "The initial frontend mode is correct.");
 
-    is($("#primed-cache-chart").childNodes.length, 0,
-      "There should be no primed cache chart created yet.");
-    is($("#empty-cache-chart").childNodes.length, 0,
-      "There should be no empty cache chart created yet.");
+  is($("#primed-cache-chart").childNodes.length, 0,
+    "There should be no primed cache chart created yet.");
+  is($("#empty-cache-chart").childNodes.length, 0,
+    "There should be no empty cache chart created yet.");
 
-    waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED).then(() => {
-      is($("#primed-cache-chart").childNodes.length, 1,
-        "There should be a placeholder primed cache chart created now.");
-      is($("#empty-cache-chart").childNodes.length, 1,
-        "There should be a placeholder empty cache chart created now.");
+  let onChartDisplayed = Promise.all([
+    waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
+    waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
+  ]);
+  let onPlaceholderDisplayed = waitFor(panel, EVENTS.PLACEHOLDER_CHARTS_DISPLAYED);
 
-      is($all(".pie-chart-container[placeholder=true]").length, 2,
-        "Two placeholder pie chart appear to be rendered correctly.");
-      is($all(".table-chart-container[placeholder=true]").length, 2,
-        "Two placeholder table chart appear to be rendered correctly.");
+  info("Displaying statistics view");
+  NetMonitorView.toggleFrontendMode();
+  is(NetMonitorView.currentFrontendMode, "network-statistics-view",
+    "The current frontend mode is correct.");
 
-      promise.all([
-        waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
-        waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
-      ]).then(() => {
-        is($("#primed-cache-chart").childNodes.length, 1,
-          "There should be a real primed cache chart created now.");
-        is($("#empty-cache-chart").childNodes.length, 1,
-          "There should be a real empty cache chart created now.");
+  info("Waiting for placeholder to display");
+  yield onPlaceholderDisplayed;
+  is($("#primed-cache-chart").childNodes.length, 1,
+    "There should be a placeholder primed cache chart created now.");
+  is($("#empty-cache-chart").childNodes.length, 1,
+    "There should be a placeholder empty cache chart created now.");
 
-        Task.spawn(function* () {
-          yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2);
-          ok(true, "Two real pie charts appear to be rendered correctly.");
+  is($all(".pie-chart-container[placeholder=true]").length, 2,
+    "Two placeholder pie chart appear to be rendered correctly.");
+  is($all(".table-chart-container[placeholder=true]").length, 2,
+    "Two placeholder table chart appear to be rendered correctly.");
 
-          yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2);
-          ok(true, "Two real table charts appear to be rendered correctly.");
+  info("Waiting for chart to display");
+  yield onChartDisplayed;
+  is($("#primed-cache-chart").childNodes.length, 1,
+    "There should be a real primed cache chart created now.");
+  is($("#empty-cache-chart").childNodes.length, 1,
+    "There should be a real empty cache chart created now.");
 
-          teardown(aMonitor).then(finish);
-        });
-      });
-    });
+  yield until(() => $all(".pie-chart-container:not([placeholder=true])").length == 2);
+  ok(true, "Two real pie charts appear to be rendered correctly.");
 
-    NetMonitorView.toggleFrontendMode();
+  yield until(() => $all(".table-chart-container:not([placeholder=true])").length == 2);
+  ok(true, "Two real table charts appear to be rendered correctly.");
 
-    is(NetMonitorView.currentFrontendMode, "network-statistics-view",
-      "The current frontend mode is correct.");
-  });
-}
+  yield teardown(monitor);
+});
 
 function waitForTick() {
   let deferred = promise.defer();
   executeSoon(deferred.resolve);
   return deferred.promise;
 }
 
 function until(predicate) {
   return Task.spawn(function* () {
-    while (!predicate()) yield waitForTick();
+    while (!predicate()) {
+      yield waitForTick();
+    }
   });
 }
--- a/devtools/client/netmonitor/test/browser_net_statistics-02.js
+++ b/devtools/client/netmonitor/test/browser_net_statistics-02.js
@@ -1,43 +1,42 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if the network inspector view is shown when the target navigates
  * away while in the statistics view.
  */
 
-function test() {
-  initNetMonitor(STATISTICS_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
+add_task(function* () {
+  let [, debuggee, monitor] = yield initNetMonitor(STATISTICS_URL);
+  info("Starting test... ");
 
-    let panel = aMonitor.panelWin;
-    let { document, EVENTS, NetMonitorView } = panel;
-
-    is(NetMonitorView.currentFrontendMode, "network-inspector-view",
+  let panel = monitor.panelWin;
+  let { EVENTS, NetMonitorView } = panel;
+  is(NetMonitorView.currentFrontendMode, "network-inspector-view",
       "The initial frontend mode is correct.");
 
-    promise.all([
-      waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
-      waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
-    ]).then(() => {
-      is(NetMonitorView.currentFrontendMode, "network-statistics-view",
+  let onChartDisplayed = Promise.all([
+    waitFor(panel, EVENTS.PRIMED_CACHE_CHART_DISPLAYED),
+    waitFor(panel, EVENTS.EMPTY_CACHE_CHART_DISPLAYED)
+  ]);
+
+  info("Displaying statistics view");
+  NetMonitorView.toggleFrontendMode();
+  yield onChartDisplayed;
+  is(NetMonitorView.currentFrontendMode, "network-statistics-view",
         "The frontend mode is currently in the statistics view.");
 
-      waitFor(panel, EVENTS.TARGET_WILL_NAVIGATE).then(() => {
-        is(NetMonitorView.currentFrontendMode, "network-inspector-view",
+  info("Reloading page");
+  let onWillNavigate = waitFor(panel, EVENTS.TARGET_WILL_NAVIGATE);
+  let onDidNavigate = waitFor(panel, EVENTS.TARGET_DID_NAVIGATE);
+  debuggee.location.reload();
+  yield onWillNavigate;
+  is(NetMonitorView.currentFrontendMode, "network-inspector-view",
           "The frontend mode switched back to the inspector view.");
-
-        waitFor(panel, EVENTS.TARGET_DID_NAVIGATE).then(() => {
-          is(NetMonitorView.currentFrontendMode, "network-inspector-view",
+  yield onDidNavigate;
+  is(NetMonitorView.currentFrontendMode, "network-inspector-view",
             "The frontend mode is still in the inspector view.");
-
-          teardown(aMonitor).then(finish);
-        });
-      });
-
-      aDebuggee.location.reload();
-    });
-
-    NetMonitorView.toggleFrontendMode();
-  });
-}
+  yield teardown(monitor);
+});