Bug 1269102 - Part 3: Cleanup browser_net_pane-toggle.js test (task.js, eslint) r?ochameau draft
authorJarda Snajdr <jsnajdr@gmail.com>
Wed, 10 Aug 2016 13:43:08 +0200
changeset 401151 e333b8f2b011130aeb1ede312dfcd1a5fc4e5c4f
parent 401150 90a20a59c3c99fa76ef3b2408b9856c3ae0332f4
child 401152 1ebfb35f6b14e8adf180c136bdd6060895380c18
push id26375
push userbmo:jsnajdr@gmail.com
push dateTue, 16 Aug 2016 12:39:57 +0000
reviewersochameau
bugs1269102
milestone51.0a1
Bug 1269102 - Part 3: Cleanup browser_net_pane-toggle.js test (task.js, eslint) r?ochameau MozReview-Commit-ID: JhrDwO312RJ
devtools/client/netmonitor/test/browser_net_pane-toggle.js
--- a/devtools/client/netmonitor/test/browser_net_pane-toggle.js
+++ b/devtools/client/netmonitor/test/browser_net_pane-toggle.js
@@ -1,79 +1,74 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Tests if toggling the details pane works as expected.
  */
 
-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 } = aMonitor.panelWin;
-    let { RequestsMenu } = NetMonitorView;
+  let { $, NetMonitorView } = monitor.panelWin;
+  let { RequestsMenu } = NetMonitorView;
+  let { NETWORK_EVENT, TAB_UPDATED } = monitor.panelWin.EVENTS;
+  RequestsMenu.lazyUpdate = false;
 
-    RequestsMenu.lazyUpdate = false;
+  let toggleButton = $("#details-pane-toggle");
 
-    is(document.querySelector("#details-pane-toggle")
-      .hasAttribute("disabled"), true,
-      "The pane toggle button should be disabled when the frontend is opened.");
-    is(document.querySelector("#details-pane-toggle")
-      .classList.contains("pane-collapsed"), true,
-      "The pane toggle button should indicate that the details pane is " +
-      "collapsed when the frontend is opened.");
-    is(NetMonitorView.detailsPaneHidden, true,
-      "The details pane should be hidden when the frontend is opened.");
-    is(RequestsMenu.selectedItem, null,
-      "There should be no selected item in the requests menu.");
+  is(toggleButton.hasAttribute("disabled"), true,
+    "The pane toggle button should be disabled when the frontend is opened.");
+  is(toggleButton.classList.contains("pane-collapsed"), true,
+    "The pane toggle button should indicate that the details pane is " +
+    "collapsed when the frontend is opened.");
+  is(NetMonitorView.detailsPaneHidden, true,
+    "The details pane should be hidden when the frontend is opened.");
+  is(RequestsMenu.selectedItem, null,
+    "There should be no selected item in the requests menu.");
 
-    aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
-      is(document.querySelector("#details-pane-toggle")
-        .hasAttribute("disabled"), false,
-        "The pane toggle button should be enabled after the first request.");
-      is(document.querySelector("#details-pane-toggle")
-        .classList.contains("pane-collapsed"), true,
-        "The pane toggle button should still indicate that the details pane is " +
-        "collapsed after the first request.");
-      is(NetMonitorView.detailsPaneHidden, true,
-        "The details pane should still be hidden after the first request.");
-      is(RequestsMenu.selectedItem, null,
-        "There should still be no selected item in the requests menu.");
+  let networkEvent = monitor.panelWin.once(NETWORK_EVENT);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.location.reload();
+  });
+  yield networkEvent;
 
-      EventUtils.sendMouseEvent({ type: "mousedown" },
-        document.getElementById("details-pane-toggle"));
+  is(toggleButton.hasAttribute("disabled"), false,
+    "The pane toggle button should be enabled after the first request.");
+  is(toggleButton.classList.contains("pane-collapsed"), true,
+    "The pane toggle button should still indicate that the details pane is " +
+    "collapsed after the first request.");
+  is(NetMonitorView.detailsPaneHidden, true,
+    "The details pane should still be hidden after the first request.");
+  is(RequestsMenu.selectedItem, null,
+    "There should still be no selected item in the requests menu.");
 
-      is(document.querySelector("#details-pane-toggle")
-        .hasAttribute("disabled"), false,
-        "The pane toggle button should still be enabled after being pressed.");
-      is(document.querySelector("#details-pane-toggle")
-        .classList.contains("pane-collapsed"), false,
-        "The pane toggle button should now indicate that the details pane is " +
-        "not collapsed anymore after being pressed.");
-      is(NetMonitorView.detailsPaneHidden, false,
-        "The details pane should not be hidden after toggle button was pressed.");
-      isnot(RequestsMenu.selectedItem, null,
-        "There should be a selected item in the requests menu.");
-      is(RequestsMenu.selectedIndex, 0,
-        "The first item should be selected in the requests menu.");
+  EventUtils.sendMouseEvent({ type: "mousedown" }, toggleButton);
 
-      EventUtils.sendMouseEvent({ type: "mousedown" },
-        document.getElementById("details-pane-toggle"));
+  is(toggleButton.hasAttribute("disabled"), false,
+    "The pane toggle button should still be enabled after being pressed.");
+  is(toggleButton.classList.contains("pane-collapsed"), false,
+    "The pane toggle button should now indicate that the details pane is " +
+    "not collapsed anymore after being pressed.");
+  is(NetMonitorView.detailsPaneHidden, false,
+    "The details pane should not be hidden after toggle button was pressed.");
+  isnot(RequestsMenu.selectedItem, null,
+    "There should be a selected item in the requests menu.");
+  is(RequestsMenu.selectedIndex, 0,
+    "The first item should be selected in the requests menu.");
 
-      is(document.querySelector("#details-pane-toggle")
-        .hasAttribute("disabled"), false,
-        "The pane toggle button should still be enabled after being pressed again.");
-      is(document.querySelector("#details-pane-toggle")
-        .classList.contains("pane-collapsed"), true,
-        "The pane toggle button should now indicate that the details pane is " +
-        "collapsed after being pressed again.");
-      is(NetMonitorView.detailsPaneHidden, true,
-        "The details pane should now be hidden after the toggle button was pressed again.");
-      is(RequestsMenu.selectedItem, null,
-        "There should now be no selected item in the requests menu.");
+  EventUtils.sendMouseEvent({ type: "mousedown" }, toggleButton);
 
-      teardown(aMonitor).then(finish);
-    });
+  is(toggleButton.hasAttribute("disabled"), false,
+    "The pane toggle button should still be enabled after being pressed again.");
+  is(toggleButton.classList.contains("pane-collapsed"), true,
+    "The pane toggle button should now indicate that the details pane is " +
+    "collapsed after being pressed again.");
+  is(NetMonitorView.detailsPaneHidden, true,
+    "The details pane should now be hidden after the toggle button was pressed again.");
+  is(RequestsMenu.selectedItem, null,
+    "There should now be no selected item in the requests menu.");
 
-    aDebuggee.location.reload();
-  });
-}
+  yield teardown(monitor);
+});