Bug 1431912 - Test for timing columns; r=ochameau a=lizzard
authorJan Odvarko <odvarko@gmail.com>
Wed, 24 Jan 2018 19:29:08 +0100
changeset 454567 9be1431237814024bc5f7b817f7ef53dcd3f5585
parent 454566 175697dceadf58159572722e2b5633d0e9a92f1f
child 454568 02179e4a721788fa3c2bb523dc75d0364fc99ec9
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, lizzard
bugs1431912
milestone59.0
Bug 1431912 - Test for timing columns; r=ochameau a=lizzard MozReview-Commit-ID: 1nnMnLohQwN
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_columns_pref.js
devtools/client/netmonitor/test/browser_net_columns_reset.js
devtools/client/netmonitor/test/browser_net_columns_time.js
devtools/client/netmonitor/test/head.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -74,16 +74,17 @@ support-files =
 [browser_net_charts-06.js]
 [browser_net_charts-07.js]
 [browser_net_clear.js]
 [browser_net_column_headers_tooltips.js]
 [browser_net_columns_last_column.js]
 [browser_net_columns_pref.js]
 [browser_net_columns_reset.js]
 [browser_net_columns_showhide.js]
+[browser_net_columns_time.js]
 [browser_net_complex-params.js]
 [browser_net_content-type.js]
 [browser_net_brotli.js]
 [browser_net_curl-utils.js]
 [browser_net_copy_image_as_data_uri.js]
 subsuite = clipboard
 skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_net_copy_svg_image_as_data_uri.js]
--- a/devtools/client/netmonitor/test/browser_net_columns_pref.js
+++ b/devtools/client/netmonitor/test/browser_net_columns_pref.js
@@ -9,62 +9,36 @@
 
 add_task(function* () {
   Services.prefs.setCharPref("devtools.netmonitor.visibleColumns",
     '["status", "contentSize", "waterfall"]');
 
   let { monitor } = yield initNetMonitor(SIMPLE_URL);
   info("Starting test... ");
 
-  let { document, parent } = monitor.panelWin;
+  let { document } = monitor.panelWin;
 
   ok(document.querySelector("#requests-list-status-button"),
      "Status column should be shown");
   ok(document.querySelector("#requests-list-contentSize-button"),
      "Content size column should be shown");
 
-  yield hideColumn("status");
-  yield hideColumn("contentSize");
+  yield hideColumn(monitor, "status");
+  yield hideColumn(monitor, "contentSize");
 
   let visibleColumns = JSON.parse(
     Services.prefs.getCharPref("devtools.netmonitor.visibleColumns")
   );
 
   ok(!visibleColumns.includes("status"),
      "Pref should be synced for status");
   ok(!visibleColumns.includes("contentSize"),
     "Pref should be synced for contentSize");
 
-  yield showColumn("status");
+  yield showColumn(monitor, "status");
 
   visibleColumns = JSON.parse(
     Services.prefs.getCharPref("devtools.netmonitor.visibleColumns")
   );
 
   ok(visibleColumns.includes("status"),
     "Pref should be synced for status");
-
-  function* hideColumn(column) {
-    info(`Clicking context-menu item for ${column}`);
-    EventUtils.sendMouseEvent({ type: "contextmenu" },
-      document.querySelector(".devtools-toolbar.requests-list-headers"));
-
-    let onHeaderRemoved = waitForDOM(document, `#requests-list-${column}-button`, 0);
-    parent.document.querySelector(`#request-list-header-${column}-toggle`).click();
-
-    yield onHeaderRemoved;
-    ok(!document.querySelector(`#requests-list-${column}-button`),
-       `Column ${column} should be hidden`);
-  }
-
-  function* showColumn(column) {
-    info(`Clicking context-menu item for ${column}`);
-    EventUtils.sendMouseEvent({ type: "contextmenu" },
-      document.querySelector(".devtools-toolbar.requests-list-headers"));
-
-    let onHeaderAdded = waitForDOM(document, `#requests-list-${column}-button`, 1);
-    parent.document.querySelector(`#request-list-header-${column}-toggle`).click();
-
-    yield onHeaderAdded;
-    ok(document.querySelector(`#requests-list-${column}-button`),
-       `Column ${column} should be visible`);
-  }
 });
--- a/devtools/client/netmonitor/test/browser_net_columns_reset.js
+++ b/devtools/client/netmonitor/test/browser_net_columns_reset.js
@@ -1,42 +1,28 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /**
  * Tests reset column menu item
  */
-
 add_task(function* () {
   let { monitor } = yield initNetMonitor(SIMPLE_URL);
   info("Starting test... ");
 
   let { document, parent, windowRequire } = monitor.panelWin;
   let { Prefs } = windowRequire("devtools/client/netmonitor/src/utils/prefs");
 
   let prefBefore = Prefs.visibleColumns;
 
-  hideColumn("status");
-  hideColumn("waterfall");
+  hideColumn(monitor, "status");
+  hideColumn(monitor, "waterfall");
 
   EventUtils.sendMouseEvent({ type: "contextmenu" },
     document.querySelector("#requests-list-contentSize-button"));
 
   parent.document.querySelector("#request-list-header-reset-columns").click();
 
   ok(JSON.stringify(prefBefore) === JSON.stringify(Prefs.visibleColumns),
      "Reset columns item should reset columns pref");
-
-  function* hideColumn(column) {
-    info(`Clicking context-menu item for ${column}`);
-    EventUtils.sendMouseEvent({ type: "contextmenu" },
-      document.querySelector("#requests-list-contentSize-button"));
-
-    let onHeaderRemoved = waitForDOM(document, `#requests-list-${column}-button`, 0);
-    parent.document.querySelector(`#request-list-header-${column}-toggle`).click();
-
-    yield onHeaderRemoved;
-    ok(!document.querySelector(`#requests-list-${column}-button`),
-       `Column ${column} should be hidden`);
-  }
 });
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_columns_time.js
@@ -0,0 +1,49 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests for timings columns.
+ */
+add_task(async function () {
+  let { tab, monitor } = await initNetMonitor(SIMPLE_URL);
+  info("Starting test... ");
+
+  let { document, store, windowRequire } = monitor.panelWin;
+  let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  store.dispatch(Actions.batchEnable(false));
+
+  hideColumn(monitor, "waterfall");
+  showColumn(monitor, "endTime");
+  showColumn(monitor, "responseTime");
+  showColumn(monitor, "duration");
+  showColumn(monitor, "latency");
+
+  let onNetworkEvents = waitForNetworkEvents(monitor, 1);
+  let onEventTimings = waitFor(monitor.panelWin, EVENTS.RECEIVED_EVENT_TIMINGS);
+  tab.linkedBrowser.reload();
+  await Promise.all([onNetworkEvents, onEventTimings]);
+
+  // There should be one request in the list.
+  let requestItems = document.querySelectorAll(".request-list-item");
+  is(requestItems.length, 1, "There must be one visible item");
+
+  let item = requestItems[0];
+  let types = [
+    "end",
+    "response",
+    "duration",
+    "latency"
+  ];
+
+  for (let t of types) {
+    await waitUntil(() => {
+      let node = item.querySelector(".requests-list-" + t + "-time");
+      let value = parseInt(node.textContent, 10);
+      return value > 0;
+    });
+  }
+
+  await teardown(monitor);
+});
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -1,16 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* import-globals-from ../../framework/test/shared-head.js */
 /* exported Toolbox, restartNetMonitor, teardown, waitForExplicitFinish,
    verifyRequestItemTarget, waitFor, testFilterButtons, loadCommonFrameScript,
    performRequestsInContent, waitForNetworkEvents, selectIndexAndWaitForSourceEditor,
-   testColumnsAlignment */
+   testColumnsAlignment, hideColumn, showColumn */
 
 "use strict";
 
 // shared-head.js handles imports, constants, and utility functions
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
   this);
 
@@ -701,16 +701,46 @@ function testColumnsAlignment(headers, r
     let requestColumn = firstRequestLine.childNodes[i];
     is(headerColumn.getBoundingClientRect().left,
        requestColumn.getBoundingClientRect().left,
        "Headers for columns number " + i + " are aligned."
     );
   }
 }
 
+function* hideColumn(monitor, column) {
+  let { document, parent } = monitor.panelWin;
+
+  info(`Clicking context-menu item for ${column}`);
+  EventUtils.sendMouseEvent({ type: "contextmenu" },
+    document.querySelector(".devtools-toolbar.requests-list-headers"));
+
+  let onHeaderRemoved = waitForDOM(document, `#requests-list-${column}-button`, 0);
+  parent.document.querySelector(`#request-list-header-${column}-toggle`).click();
+  yield onHeaderRemoved;
+
+  ok(!document.querySelector(`#requests-list-${column}-button`),
+     `Column ${column} should be hidden`);
+}
+
+function* showColumn(monitor, column) {
+  let { document, parent } = monitor.panelWin;
+
+  info(`Clicking context-menu item for ${column}`);
+  EventUtils.sendMouseEvent({ type: "contextmenu" },
+    document.querySelector(".devtools-toolbar.requests-list-headers"));
+
+  let onHeaderAdded = waitForDOM(document, `#requests-list-${column}-button`, 1);
+  parent.document.querySelector(`#request-list-header-${column}-toggle`).click();
+  yield onHeaderAdded;
+
+  ok(document.querySelector(`#requests-list-${column}-button`),
+     `Column ${column} should be visible`);
+}
+
 /**
  * Select a request and switch to its response panel.
  *
  * @param {Number} index The request index to be selected
  */
 async function selectIndexAndWaitForSourceEditor(monitor, index) {
   let document = monitor.panelWin.document;
   let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);