Bug 1408944 - Rewrite and enable browser_webconsole_network_requests_from_chrome.js; r=nchevobbe
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 22 Nov 2017 16:16:03 +0100
changeset 437736 01298c757565d7277b81c396e873d7f8fb07cc42
parent 437735 a40ffd441b9a724a6a11a41f282f8b69050b98c0
child 437737 fc4036a8b9e8ddc4007faa49d96384e06d5f47a9
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersnchevobbe
bugs1408944
milestone59.0a1
Bug 1408944 - Rewrite and enable browser_webconsole_network_requests_from_chrome.js; r=nchevobbe MozReview-Commit-ID: EPzTQhqhVFE
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_network_requests_from_chrome.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -354,17 +354,16 @@ skip-if = true # Bug 1408942
 [browser_webconsole_netlogging_reset_filter.js]
 skip-if = true #	Bug 1405636
 [browser_webconsole_network_attach.js]
 [browser_webconsole_network_exceptions.js]
 skip-if = true # Bug 1408943
 [browser_webconsole_network_messages_expand.js]
 [browser_webconsole_network_messages_openinnet.js]
 [browser_webconsole_network_requests_from_chrome.js]
-skip-if = true # Bug 1408944
 [browser_webconsole_nodes_highlight.js]
 [browser_webconsole_nodes_select.js]
 [browser_webconsole_notifications.js]
 skip-if = true #	Bug 1405637
 [browser_webconsole_object_inspector.js]
 [browser_webconsole_object_inspector_entries.js]
 [browser_webconsole_observer_notifications.js]
 [browser_webconsole_optimized_out_vars.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_network_requests_from_chrome.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_network_requests_from_chrome.js
@@ -5,48 +5,45 @@
 
 // Tests that network requests from chrome don't cause the Web Console to
 // throw exceptions. See Bug 597136.
 
 "use strict";
 
 const TEST_URI = "http://example.com/";
 
-var good = true;
-var listener = {
-  QueryInterface: XPCOMUtils.generateQI([ Ci.nsIObserver ]),
-  observe: function (subject) {
-    if (subject instanceof Ci.nsIScriptError &&
-        subject.category === "XPConnect JavaScript" &&
-        subject.sourceName.includes("webconsole")) {
-      good = false;
+add_task(async function () {
+  // Start a listener on the console service.
+  let good = true;
+  const listener = {
+    QueryInterface: XPCOMUtils.generateQI([ Ci.nsIObserver ]),
+    observe: function (subject) {
+      if (subject instanceof Ci.nsIScriptError &&
+          subject.category === "XPConnect JavaScript" &&
+          subject.sourceName.includes("webconsole")) {
+        good = false;
+      }
     }
-  }
-};
-
-var xhr;
-
-function test() {
+  };
   Services.console.registerListener(listener);
 
   // trigger a lazy-load of the HUD Service
   HUDService;
 
-  xhr = new XMLHttpRequest();
-  xhr.addEventListener("load", xhrComplete);
-  xhr.open("GET", TEST_URI, true);
-  xhr.send(null);
-}
+  await sendRequestFromChrome();
 
-function xhrComplete() {
-  xhr.removeEventListener("load", xhrComplete);
-  window.setTimeout(checkForException, 0);
-}
-
-function checkForException() {
-  ok(good, "no exception was thrown when sending a network request from a " +
-     "chrome window");
+  ok(good, "No exception was thrown when sending a network request from a chrome window");
 
   Services.console.unregisterListener(listener);
-  listener = xhr = null;
+});
+
+function sendRequestFromChrome() {
+  return new Promise(resolve => {
+    const xhr = new XMLHttpRequest();
 
-  finishTest();
+    xhr.addEventListener("load", () => {
+      window.setTimeout(resolve, 0);
+    }, { once: true });
+
+    xhr.open("GET", TEST_URI, true);
+    xhr.send(null);
+  });
 }