Bug 1438979 - Fix browser_webconsole_network_messages_expand.js intermittent; r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 24 Oct 2018 06:14:16 +0000
changeset 491056 f266aa4cd4b04f7cec1fffeec4fccd1baafdf244
parent 491055 be829221e462a24668b46f6d11b00402b9c01cf4
child 491057 3a314e76d8c148e223cf683b15ba2a357ebe4b42
child 491068 5173779c1c5e750809d31d018e2f47657ca7fa10
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersHonza
bugs1438979
milestone65.0a1
Bug 1438979 - Fix browser_webconsole_network_messages_expand.js intermittent; r=Honza. This is an attempt to fix the intermittent on this test. It looks like we were setting the listeners on some events after the request message was received, which might have made us missed some events. We take this bug as an opportunity to do some cleanup on the test. Differential Revision: https://phabricator.services.mozilla.com/D9075
devtools/client/webconsole/test/mochitest/browser_webconsole_network_messages_expand.js
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_network_messages_expand.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_network_messages_expand.js
@@ -3,27 +3,20 @@
 
 "use strict";
 
 const TEST_FILE = "test-network-request.html";
 const TEST_PATH = "https://example.com/browser/devtools/client/webconsole/" +
                   "test/mochitest/";
 const TEST_URI = TEST_PATH + TEST_FILE;
 
-const NET_PREF = "devtools.webconsole.filter.net";
-const XHR_PREF = "devtools.webconsole.filter.netxhr";
-
 requestLongerTimeout(2);
 
-Services.prefs.setBoolPref(NET_PREF, false);
-Services.prefs.setBoolPref(XHR_PREF, true);
-registerCleanupFunction(() => {
-  Services.prefs.clearUserPref(NET_PREF);
-  Services.prefs.clearUserPref(XHR_PREF);
-});
+pushPref("devtools.webconsole.filter.net", false);
+pushPref("devtools.webconsole.filter.netxhr", true);
 
 const tabs = [{
   id: "headers",
   testEmpty: testEmptyHeaders,
   testContent: testHeaders,
 }, {
   id: "cookies",
   testEmpty: testEmptyCookies,
@@ -50,16 +43,17 @@ const tabs = [{
   testContent: testSecurity,
 }];
 
 /**
  * Main test for checking HTTP logs in the Console panel.
  */
 add_task(async function task() {
   const hud = await openNewTabAndConsole(TEST_URI);
+
   const currentTab = gBrowser.selectedTab;
   const target = await TargetFactory.forTab(currentTab);
 
   // Execute XHR and expand it after all network
   // update events are received. Consequently,
   // check out content of all (HTTP details) tabs.
   await openRequestAfterUpdates(target, hud);
 
@@ -74,86 +68,80 @@ add_task(async function task() {
     await openRequestBeforeUpdates(target, hud, tab);
   }
 });
 
 async function openRequestAfterUpdates(target, hud) {
   const toolbox = gDevTools.getToolbox(target);
 
   const xhrUrl = TEST_PATH + "sjs_slow-response-test-server.sjs";
-  const message = waitForMessage(hud, xhrUrl);
+  const onMessage = waitForMessage(hud, xhrUrl);
+  const onRequestUpdates = waitForRequestUpdates(hud);
+  const onPayloadReady = waitForPayloadReady(hud);
 
   // Fire an XHR POST request.
   ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
     content.wrappedJSObject.testXhrPostSlowResponse();
   });
 
-  const { node: messageNode } = await message;
-
-  info("Network message found.");
+  const { node: messageNode } = await onMessage;
+  ok(messageNode, "Network message found.");
 
-  await waitForRequestUpdates(toolbox);
-
-  const payload = waitForPayloadReady(toolbox);
+  await onRequestUpdates;
 
   // Expand network log
-  const urlNode = messageNode.querySelector(".url");
-  urlNode.click();
+  await expandXhrMessage(messageNode);
 
   const toggleButtonNode = messageNode.querySelector(".sidebar-toggle");
   ok(!toggleButtonNode, "Sidebar toggle button shouldn't be shown");
 
-  await payload;
+  await onPayloadReady;
   await testNetworkMessage(toolbox, messageNode);
 }
 
 async function openRequestBeforeUpdates(target, hud, tab) {
   const toolbox = gDevTools.getToolbox(target);
 
   hud.ui.clearOutput(true);
 
   const xhrUrl = TEST_PATH + "sjs_slow-response-test-server.sjs";
-  const message = waitForMessage(hud, xhrUrl);
+  const onMessage = waitForMessage(hud, xhrUrl);
+  const onRequestUpdates = waitForRequestUpdates(hud);
+  const onPayloadReady = waitForPayloadReady(hud);
 
   // Fire an XHR POST request.
   ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
     content.wrappedJSObject.testXhrPostSlowResponse();
   });
-
-  const { node: messageNode } = await message;
-
-  info("Network message found.");
-
-  const updates = waitForRequestUpdates(toolbox);
-  const payload = waitForPayloadReady(toolbox);
+  const { node: messageNode } = await onMessage;
+  ok(messageNode, "Network message found.");
 
   // Set the default panel.
   const state = hud.ui.consoleOutput.getStore().getState();
   state.ui.networkMessageActiveTabId = tab.id;
 
   // Expand network log
-  const urlNode = messageNode.querySelector(".url");
-  urlNode.click();
+  await expandXhrMessage(messageNode);
 
   // Except the security tab. It isn't available till the
   // "securityInfo" packet type is received, so doesn't
   // fit this part of the test.
   if (tab.id != "security") {
     // Make sure the current tab is the expected one.
     const currentTab = messageNode.querySelector(`#${tab.id}-tab`);
     is(currentTab.getAttribute("aria-selected"), "true",
       "The correct tab is selected");
 
     // The tab should be empty now.
     tab.testEmpty(messageNode);
   }
 
   // Wait till all updates and payload are received.
-  await updates;
-  await payload;
+  await onRequestUpdates;
+  await onPayloadReady;
 
   // Test content of the default tab.
   await tab.testContent(messageNode);
 
   // Test all tabs in the network log.
   await testNetworkMessage(toolbox, messageNode);
 }
 
@@ -186,37 +174,33 @@ function testEmptyHeaders(messageNode) {
 }
 
 async function testHeaders(messageNode) {
   const headersTab = messageNode.querySelector("#headers-tab");
   ok(headersTab, "Headers tab is available");
 
   // Select Headers tab and check the content.
   headersTab.click();
-  await waitUntil(() => {
-    return !!messageNode.querySelector("#headers-panel .headers-overview");
-  });
+  await waitFor(() => messageNode.querySelector("#headers-panel .headers-overview"));
 }
 
 // Cookies
 
 function testEmptyCookies(messageNode) {
   const emptyNotice = messageNode.querySelector("#cookies-panel .empty-notice");
   ok(emptyNotice, "Cookies tab is empty");
 }
 
 async function testCookies(messageNode) {
   const cookiesTab = messageNode.querySelector("#cookies-tab");
   ok(cookiesTab, "Cookies tab is available");
 
   // Select tab and check the content.
   cookiesTab.click();
-  await waitUntil(() => {
-    return !!messageNode.querySelector("#cookies-panel .treeValueCell");
-  });
+  await waitFor(() => messageNode.querySelector("#cookies-panel .treeValueCell"));
 }
 
 // Params
 
 function testEmptyParams(messageNode) {
   const emptyNotice = messageNode.querySelector("#params-panel .empty-notice");
   ok(emptyNotice, "Params tab is empty");
 }
@@ -266,20 +250,18 @@ function testEmptyTimings(messageNode) {
 }
 
 async function testTimings(messageNode) {
   const timingsTab = messageNode.querySelector("#timings-tab");
   ok(timingsTab, "Timings tab is available");
 
   // Select Timings tab and check the content.
   timingsTab.click();
-  await waitUntil(() => {
-    return !!messageNode.querySelector(
-      "#timings-panel .timings-container .timings-label");
-  });
+  await waitFor(() =>
+    messageNode.querySelector("#timings-panel .timings-container .timings-label"));
   const timingsContent = messageNode.querySelector(
     "#timings-panel .timings-container .timings-label");
   ok(timingsContent, "Timings content is available");
   ok(timingsContent.textContent, "Timings text is available");
 }
 
 // Stack Trace
 
@@ -289,65 +271,55 @@ function testEmptyStackTrace(messageNode
 }
 
 async function testStackTrace(messageNode) {
   const stackTraceTab = messageNode.querySelector("#stack-trace-tab");
   ok(stackTraceTab, "StackTrace tab is available");
 
   // Select Timings tab and check the content.
   stackTraceTab.click();
-  await waitUntil(() => {
-    return !!messageNode.querySelector("#stack-trace-panel .frame-link");
-  });
+  await waitFor(() => messageNode.querySelector("#stack-trace-panel .frame-link"));
 }
 
 // Security
 
 function testEmptySecurity(messageNode) {
   const panel = messageNode.querySelector("#security-panel .tab-panel");
   is(panel.textContent, "", "Security tab is empty");
 }
 
 async function testSecurity(messageNode) {
   const securityTab = messageNode.querySelector("#security-tab");
   ok(securityTab, "Security tab is available");
 
   // Select Timings tab and check the content.
   securityTab.click();
-  await waitUntil(() => {
-    return !!messageNode.querySelector("#security-panel .treeTable .treeRow");
-  });
+  await waitFor(() => messageNode.querySelector("#security-panel .treeTable .treeRow"));
 }
 
 // Waiting helpers
 
-async function waitForPayloadReady(toolbox) {
-  const {ui} = toolbox.getCurrentPanel().hud;
-  return new Promise(resolve => {
-    ui.jsterm.hud.on("network-request-payload-ready", () => {
-      info("network-request-payload-ready received");
-      resolve();
-    });
-  });
+async function waitForPayloadReady(hud) {
+  return hud.ui.once("network-request-payload-ready");
 }
 
 async function waitForSourceEditor(panel) {
   return waitUntil(() => {
     return !!panel.querySelector(".CodeMirror");
   });
 }
 
-async function waitForRequestUpdates(toolbox) {
-  const {ui} = toolbox.getCurrentPanel().hud;
-  return new Promise(resolve => {
-    ui.jsterm.hud.on("network-message-updated", () => {
-      info("network-message-updated received");
-      resolve();
-    });
-  });
+async function waitForRequestUpdates(hud) {
+  return hud.ui.once("network-message-updated");
+}
+
+function expandXhrMessage(node) {
+  info("Click on XHR message and wait for the network detail panel to be displayed");
+  node.querySelector(".url").click();
+  return waitFor(() => node.querySelector(".network-info"));
 }
 
 /**
  * Wait until all lazily fetch requests in netmonitor get finished.
  * Otherwise test will be shutdown too early and cause failure.
  */
 async function waitForLazyRequests(toolbox) {
   const {ui} = toolbox.getCurrentPanel().hud;