Bug 1297362 - Part 1: Eliminate CPOWs from Netmonitor mochitests A r?ochameau draft
authorJarda Snajdr <jsnajdr@gmail.com>
Tue, 23 Aug 2016 15:56:48 +0200
changeset 406765 d11a7a19af39aafb25051e23846b56e980ce5314
parent 406727 4f72b1d0526767db87007ed8f00f07cf90e49443
child 406766 32db2b3cdfe1832475c9c661dc34a8d9fd03e3fd
push id27819
push userbmo:jsnajdr@gmail.com
push dateMon, 29 Aug 2016 13:56:30 +0000
reviewersochameau
bugs1297362
milestone51.0a1
Bug 1297362 - Part 1: Eliminate CPOWs from Netmonitor mochitests A r?ochameau MozReview-Commit-ID: Adm8VjR4W1o
devtools/client/netmonitor/test/browser_net_aaa_leaktest.js
devtools/client/netmonitor/test/browser_net_accessibility-01.js
devtools/client/netmonitor/test/browser_net_accessibility-02.js
devtools/client/netmonitor/test/browser_net_api-calls.js
devtools/client/netmonitor/test/browser_net_autoscroll.js
--- a/devtools/client/netmonitor/test/browser_net_aaa_leaktest.js
+++ b/devtools/client/netmonitor/test/browser_net_aaa_leaktest.js
@@ -1,28 +1,28 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if the network monitor leaks on initialization and sudden destruction.
  * You can also use this initialization format as a template for other tests.
  */
 
-function test() {
-  initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
+add_task(function* () {
+  let [tab, , monitor] = yield initNetMonitor(SIMPLE_URL);
+  info("Starting test... ");
 
-    let { document, NetMonitorView, NetMonitorController } = aMonitor.panelWin;
-    let { RequestsMenu, NetworkDetails } = NetMonitorView;
+  let { document, NetMonitorView, NetMonitorController } = monitor.panelWin;
+  let { RequestsMenu, NetworkDetails } = NetMonitorView;
 
-    ok(aTab, "Should have a tab available.");
-    ok(aDebuggee, "Should have a debuggee available.");
-    ok(aMonitor, "Should have a network monitor pane available.");
+  ok(tab, "Should have a tab available.");
+  ok(monitor, "Should have a network monitor pane available.");
 
-    ok(document, "Should have a document available.");
-    ok(NetMonitorView, "Should have a NetMonitorView object available.");
-    ok(NetMonitorController, "Should have a NetMonitorController object available.");
-    ok(RequestsMenu, "Should have a RequestsMenu object available.");
-    ok(NetworkDetails, "Should have a NetworkDetails object available.");
+  ok(document, "Should have a document available.");
+  ok(NetMonitorView, "Should have a NetMonitorView object available.");
+  ok(NetMonitorController, "Should have a NetMonitorController object available.");
+  ok(RequestsMenu, "Should have a RequestsMenu object available.");
+  ok(NetworkDetails, "Should have a NetworkDetails object available.");
 
-    teardown(aMonitor).then(finish);
-  });
-}
+  yield teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/browser_net_accessibility-01.js
+++ b/devtools/client/netmonitor/test/browser_net_accessibility-01.js
@@ -1,83 +1,87 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if focus modifiers work for the SideMenuWidget.
  */
 
-function test() {
-  initNetMonitor(CUSTOM_GET_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
+add_task(function* () {
+  let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
+  info("Starting test... ");
 
-    // It seems that this test may be slow on Ubuntu builds running on ec2.
-    requestLongerTimeout(2);
+  // It seems that this test may be slow on Ubuntu builds running on ec2.
+  requestLongerTimeout(2);
 
-    let { NetMonitorView } = aMonitor.panelWin;
-    let { RequestsMenu } = NetMonitorView;
+  let { NetMonitorView } = monitor.panelWin;
+  let { RequestsMenu } = NetMonitorView;
 
-    RequestsMenu.lazyUpdate = false;
+  RequestsMenu.lazyUpdate = false;
 
-    waitForNetworkEvents(aMonitor, 2).then(() => {
-      check(-1, false);
+  let count = 0;
+  function check(selectedIndex, paneVisibility) {
+    info("Performing check " + (count++) + ".");
 
-      RequestsMenu.focusLastVisibleItem();
-      check(1, true);
-      RequestsMenu.focusFirstVisibleItem();
-      check(0, true);
-
-      RequestsMenu.focusNextItem();
-      check(1, true);
-      RequestsMenu.focusPrevItem();
-      check(0, true);
+    is(RequestsMenu.selectedIndex, selectedIndex,
+      "The selected item in the requests menu was incorrect.");
+    is(NetMonitorView.detailsPaneHidden, !paneVisibility,
+      "The network requests details pane visibility state was incorrect.");
+  }
 
-      RequestsMenu.focusItemAtDelta(+1);
-      check(1, true);
-      RequestsMenu.focusItemAtDelta(-1);
-      check(0, true);
+  let wait = waitForNetworkEvents(monitor, 2);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests(2);
+  });
+  yield wait;
 
-      RequestsMenu.focusItemAtDelta(+10);
-      check(1, true);
-      RequestsMenu.focusItemAtDelta(-10);
-      check(0, true);
+  check(-1, false);
+
+  RequestsMenu.focusLastVisibleItem();
+  check(1, true);
+  RequestsMenu.focusFirstVisibleItem();
+  check(0, true);
 
-      aDebuggee.performRequests(18);
-      return waitForNetworkEvents(aMonitor, 18);
-    })
-    .then(() => {
-      RequestsMenu.focusLastVisibleItem();
-      check(19, true);
-      RequestsMenu.focusFirstVisibleItem();
-      check(0, true);
+  RequestsMenu.focusNextItem();
+  check(1, true);
+  RequestsMenu.focusPrevItem();
+  check(0, true);
+
+  RequestsMenu.focusItemAtDelta(+1);
+  check(1, true);
+  RequestsMenu.focusItemAtDelta(-1);
+  check(0, true);
 
-      RequestsMenu.focusNextItem();
-      check(1, true);
-      RequestsMenu.focusPrevItem();
-      check(0, true);
+  RequestsMenu.focusItemAtDelta(+10);
+  check(1, true);
+  RequestsMenu.focusItemAtDelta(-10);
+  check(0, true);
 
-      RequestsMenu.focusItemAtDelta(+10);
-      check(10, true);
-      RequestsMenu.focusItemAtDelta(-10);
-      check(0, true);
+  wait = waitForNetworkEvents(monitor, 18);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests(18);
+  });
+  yield wait;
 
-      RequestsMenu.focusItemAtDelta(+100);
-      check(19, true);
-      RequestsMenu.focusItemAtDelta(-100);
-      check(0, true);
+  RequestsMenu.focusLastVisibleItem();
+  check(19, true);
+  RequestsMenu.focusFirstVisibleItem();
+  check(0, true);
 
-      teardown(aMonitor).then(finish);
-    });
-
-    let count = 0;
+  RequestsMenu.focusNextItem();
+  check(1, true);
+  RequestsMenu.focusPrevItem();
+  check(0, true);
 
-    function check(aSelectedIndex, aPaneVisibility) {
-      info("Performing check " + (count++) + ".");
+  RequestsMenu.focusItemAtDelta(+10);
+  check(10, true);
+  RequestsMenu.focusItemAtDelta(-10);
+  check(0, true);
 
-      is(RequestsMenu.selectedIndex, aSelectedIndex,
-        "The selected item in the requests menu was incorrect.");
-      is(NetMonitorView.detailsPaneHidden, !aPaneVisibility,
-        "The network requests details pane visibility state was incorrect.");
-    }
+  RequestsMenu.focusItemAtDelta(+100);
+  check(19, true);
+  RequestsMenu.focusItemAtDelta(-100);
+  check(0, true);
 
-    aDebuggee.performRequests(2);
-  });
-}
+  yield teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/browser_net_accessibility-02.js
+++ b/devtools/client/netmonitor/test/browser_net_accessibility-02.js
@@ -1,126 +1,130 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if keyboard and mouse navigation works in the network requests menu.
  */
 
-function test() {
-  initNetMonitor(CUSTOM_GET_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
+add_task(function* () {
+  let [tab, , monitor] = yield initNetMonitor(CUSTOM_GET_URL);
+  info("Starting test... ");
 
-    // It seems that this test may be slow on Ubuntu builds running on ec2.
-    requestLongerTimeout(2);
+  // It seems that this test may be slow on Ubuntu builds running on ec2.
+  requestLongerTimeout(2);
 
-    let { window, $, NetMonitorView } = aMonitor.panelWin;
-    let { RequestsMenu } = NetMonitorView;
+  let { window, $, NetMonitorView } = monitor.panelWin;
+  let { RequestsMenu } = NetMonitorView;
 
-    RequestsMenu.lazyUpdate = false;
+  RequestsMenu.lazyUpdate = false;
 
-    waitForNetworkEvents(aMonitor, 2).then(() => {
-      check(-1, false);
+  let count = 0;
+  function check(selectedIndex, paneVisibility) {
+    info("Performing check " + (count++) + ".");
 
-      EventUtils.sendKey("DOWN", window);
-      check(0, true);
-      EventUtils.sendKey("UP", window);
-      check(0, true);
+    is(RequestsMenu.selectedIndex, selectedIndex,
+      "The selected item in the requests menu was incorrect.");
+    is(NetMonitorView.detailsPaneHidden, !paneVisibility,
+      "The network requests details pane visibility state was incorrect.");
+  }
 
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(1, true);
-      EventUtils.sendKey("PAGE_UP", window);
-      check(0, true);
+  let wait = waitForNetworkEvents(monitor, 2);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests(2);
+  });
+  yield wait;
+
+  check(-1, false);
 
-      EventUtils.sendKey("END", window);
-      check(1, true);
-      EventUtils.sendKey("HOME", window);
-      check(0, true);
+  EventUtils.sendKey("DOWN", window);
+  check(0, true);
+  EventUtils.sendKey("UP", window);
+  check(0, true);
+
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(1, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(0, true);
+
+  EventUtils.sendKey("END", window);
+  check(1, true);
+  EventUtils.sendKey("HOME", window);
+  check(0, true);
 
-      aDebuggee.performRequests(18);
-      return waitForNetworkEvents(aMonitor, 18);
-    })
-    .then(() => {
-      EventUtils.sendKey("DOWN", window);
-      check(1, true);
-      EventUtils.sendKey("DOWN", window);
-      check(2, true);
-      EventUtils.sendKey("UP", window);
-      check(1, true);
-      EventUtils.sendKey("UP", window);
-      check(0, true);
+  wait = waitForNetworkEvents(monitor, 18);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests(18);
+  });
+  yield wait;
 
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(4, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(8, true);
-      EventUtils.sendKey("PAGE_UP", window);
-      check(4, true);
-      EventUtils.sendKey("PAGE_UP", window);
-      check(0, true);
+  EventUtils.sendKey("DOWN", window);
+  check(1, true);
+  EventUtils.sendKey("DOWN", window);
+  check(2, true);
+  EventUtils.sendKey("UP", window);
+  check(1, true);
+  EventUtils.sendKey("UP", window);
+  check(0, true);
 
-      EventUtils.sendKey("HOME", window);
-      check(0, true);
-      EventUtils.sendKey("HOME", window);
-      check(0, true);
-      EventUtils.sendKey("PAGE_UP", window);
-      check(0, true);
-      EventUtils.sendKey("HOME", window);
-      check(0, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(4, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(8, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(4, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(0, true);
 
-      EventUtils.sendKey("END", window);
-      check(19, true);
-      EventUtils.sendKey("END", window);
-      check(19, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(19, true);
-      EventUtils.sendKey("END", window);
-      check(19, true);
+  EventUtils.sendKey("HOME", window);
+  check(0, true);
+  EventUtils.sendKey("HOME", window);
+  check(0, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(0, true);
+  EventUtils.sendKey("HOME", window);
+  check(0, true);
+
+  EventUtils.sendKey("END", window);
+  check(19, true);
+  EventUtils.sendKey("END", window);
+  check(19, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(19, true);
+  EventUtils.sendKey("END", window);
+  check(19, true);
 
-      EventUtils.sendKey("PAGE_UP", window);
-      check(15, true);
-      EventUtils.sendKey("PAGE_UP", window);
-      check(11, true);
-      EventUtils.sendKey("UP", window);
-      check(10, true);
-      EventUtils.sendKey("UP", window);
-      check(9, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(13, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(17, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(19, true);
-      EventUtils.sendKey("PAGE_DOWN", window);
-      check(19, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(15, true);
+  EventUtils.sendKey("PAGE_UP", window);
+  check(11, true);
+  EventUtils.sendKey("UP", window);
+  check(10, true);
+  EventUtils.sendKey("UP", window);
+  check(9, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(13, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(17, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(19, true);
+  EventUtils.sendKey("PAGE_DOWN", window);
+  check(19, true);
 
-      EventUtils.sendKey("HOME", window);
-      check(0, true);
-      EventUtils.sendKey("DOWN", window);
-      check(1, true);
-      EventUtils.sendKey("END", window);
-      check(19, true);
-      EventUtils.sendKey("DOWN", window);
-      check(19, true);
-
-      EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
-      check(-1, false);
-
-      EventUtils.sendMouseEvent({ type: "mousedown" }, $(".side-menu-widget-item"));
-      check(0, true);
+  EventUtils.sendKey("HOME", window);
+  check(0, true);
+  EventUtils.sendKey("DOWN", window);
+  check(1, true);
+  EventUtils.sendKey("END", window);
+  check(19, true);
+  EventUtils.sendKey("DOWN", window);
+  check(19, true);
 
-      teardown(aMonitor).then(finish);
-    });
-
-    let count = 0;
-
-    function check(aSelectedIndex, aPaneVisibility) {
-      info("Performing check " + (count++) + ".");
+  EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));
+  check(-1, false);
 
-      is(RequestsMenu.selectedIndex, aSelectedIndex,
-        "The selected item in the requests menu was incorrect.");
-      is(NetMonitorView.detailsPaneHidden, !aPaneVisibility,
-        "The network requests details pane visibility state was incorrect.");
-    }
+  EventUtils.sendMouseEvent({ type: "mousedown" }, $(".side-menu-widget-item"));
+  check(0, true);
 
-    aDebuggee.performRequests(2);
-  });
-}
+  yield teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/browser_net_api-calls.js
+++ b/devtools/client/netmonitor/test/browser_net_api-calls.js
@@ -1,40 +1,39 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
- * Tests whether API call URLs (without a filename) are correctly displayed (including Unicode)
+ * Tests whether API call URLs (without a filename) are correctly displayed
+ * (including Unicode)
  */
 
-function test() {
-  initNetMonitor(API_CALLS_URL).then(([aTab, aDebuggee, aMonitor]) => {
-    info("Starting test... ");
-
-    let { document, L10N, EVENTS, Editor, NetMonitorView } = aMonitor.panelWin;
-    let { RequestsMenu, NetworkDetails } = NetMonitorView;
+add_task(function* () {
+  let [tab, , monitor] = yield initNetMonitor(API_CALLS_URL);
+  info("Starting test... ");
 
-    RequestsMenu.lazyUpdate = false;
+  let { NetMonitorView } = monitor.panelWin;
+  let { RequestsMenu } = NetMonitorView;
 
-    const REQUEST_URIS = [
-      "http://example.com/api/fileName.xml",
-      "http://example.com/api/file%E2%98%A2.xml",
-      "http://example.com/api/ascii/get/",
-      "http://example.com/api/unicode/%E2%98%A2/",
-      "http://example.com/api/search/?q=search%E2%98%A2"
-    ];
+  RequestsMenu.lazyUpdate = false;
 
-    Task.spawn(function* () {
-      yield waitForNetworkEvents(aMonitor, 5);
-
-      REQUEST_URIS.forEach(function (uri, index) {
-        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(index), "GET", uri);
-      });
+  const REQUEST_URIS = [
+    "http://example.com/api/fileName.xml",
+    "http://example.com/api/file%E2%98%A2.xml",
+    "http://example.com/api/ascii/get/",
+    "http://example.com/api/unicode/%E2%98%A2/",
+    "http://example.com/api/search/?q=search%E2%98%A2"
+  ];
 
-      yield teardown(aMonitor);
-      finish();
-    });
+  let wait = waitForNetworkEvents(monitor, 5);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests();
+  });
+  yield wait;
 
-    aDebuggee.performRequests();
+  REQUEST_URIS.forEach(function (uri, index) {
+    verifyRequestItemTarget(RequestsMenu.getItemAtIndex(index), "GET", uri);
   });
-}
 
-
+  yield teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/browser_net_autoscroll.js
+++ b/devtools/client/netmonitor/test/browser_net_autoscroll.js
@@ -1,86 +1,75 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-// /////////////////
-//
-// Whitelisting this test.
-// As part of bug 1077403, the leaking uncaught rejection should be fixed.
-//
-thisTestLeaksUncaughtRejectionsAndShouldBeFixed("TypeError: aValue.content is undefined");
+"use strict";
 
 /**
  * Bug 863102 - Automatically scroll down upon new network requests.
  */
 add_task(function* () {
   requestLongerTimeout(2);
-  let monitor, debuggee, requestsContainer, scrollTop;
 
-  let [aTab, aDebuggee, aMonitor] = yield initNetMonitor(INFINITE_GET_URL);
-  monitor = aMonitor;
-  debuggee = aDebuggee;
+  let [, , monitor] = yield initNetMonitor(INFINITE_GET_URL);
   let win = monitor.panelWin;
   let topNode = win.document.getElementById("requests-menu-contents");
-  requestsContainer = topNode.getElementsByTagName("scrollbox")[0];
+  let requestsContainer = topNode.getElementsByTagName("scrollbox")[0];
   ok(!!requestsContainer, "Container element exists as expected.");
 
   // (1) Check that the scroll position is maintained at the bottom
   // when the requests overflow the vertical size of the container.
-  yield waitForRequestsToOverflowContainer(monitor, requestsContainer);
-  yield waitForScroll(monitor);
+  yield waitForRequestsToOverflowContainer();
+  yield waitForScroll();
   ok(scrolledToBottom(requestsContainer), "Scrolled to bottom on overflow.");
 
   // (2) Now set the scroll position somewhere in the middle and check
   // that additional requests do not change the scroll position.
   let children = requestsContainer.childNodes;
   let middleNode = children.item(children.length / 2);
   middleNode.scrollIntoView();
   ok(!scrolledToBottom(requestsContainer), "Not scrolled to bottom.");
-  scrollTop = requestsContainer.scrollTop; // save for comparison later
+  // save for comparison later
+  let scrollTop = requestsContainer.scrollTop;
   yield waitForNetworkEvents(monitor, 8);
   yield waitSomeTime();
   is(requestsContainer.scrollTop, scrollTop, "Did not scroll.");
 
   // (3) Now set the scroll position back at the bottom and check that
   // additional requests *do* cause the container to scroll down.
   requestsContainer.scrollTop = requestsContainer.scrollHeight;
   ok(scrolledToBottom(requestsContainer), "Set scroll position to bottom.");
   yield waitForNetworkEvents(monitor, 8);
-  yield waitForScroll(monitor);
+  yield waitForScroll();
   ok(scrolledToBottom(requestsContainer), "Still scrolled to bottom.");
 
   // (4) Now select an item in the list and check that additional requests
   // do not change the scroll position.
   monitor.panelWin.NetMonitorView.RequestsMenu.selectedIndex = 0;
   yield waitForNetworkEvents(monitor, 8);
   yield waitSomeTime();
   is(requestsContainer.scrollTop, 0, "Did not scroll.");
 
   // Done: clean up.
   yield teardown(monitor);
 
-  finish();
-
-  function waitForRequestsToOverflowContainer(aMonitor, aContainer) {
-    return waitForNetworkEvents(aMonitor, 1).then(() => {
-      if (aContainer.scrollHeight > aContainer.clientHeight) {
-        return promise.resolve();
-      } else {
-        return waitForRequestsToOverflowContainer(aMonitor, aContainer);
+  function* waitForRequestsToOverflowContainer() {
+    while (true) {
+      yield waitForNetworkEvents(monitor, 1);
+      if (requestsContainer.scrollHeight > requestsContainer.clientHeight) {
+        return;
       }
-    });
+    }
   }
 
-  function scrolledToBottom(aElement) {
-    return aElement.scrollTop + aElement.clientHeight >= aElement.scrollHeight;
+  function scrolledToBottom(element) {
+    return element.scrollTop + element.clientHeight >= element.scrollHeight;
   }
 
   function waitSomeTime() {
-    let waitSomeTime = promise.defer();
-    setTimeout(waitSomeTime.resolve, 50); // Wait to make sure no scrolls happen
-    return waitSomeTime.promise;
+    // Wait to make sure no scrolls happen
+    return wait(50);
   }
 
-  function waitForScroll(aMonitor) {
-    return aMonitor._view.RequestsMenu.widget.once("scroll-to-bottom");
+  function waitForScroll() {
+    return monitor._view.RequestsMenu.widget.once("scroll-to-bottom");
   }
 });