Bug 1116708 - xpcshell tests now log console messages. r=chmanchester
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 09 Jan 2015 10:00:05 +1100
changeset 248727 14e715ddc5ec94271cca2364578f916a10cd84fe
parent 248726 dec611deed2a0c27c0d23fdd8382b6ad1f43484f
child 248728 df2c68a00ffbcf52c5d1c2d86dbee5fb1fbe58c2
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1116708
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1116708 - xpcshell tests now log console messages. r=chmanchester
testing/xpcshell/head.js
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -106,16 +106,40 @@ try {
           .getService(Components.interfaces.nsICrashReporter)) {
       crashReporter.UpdateCrashEventsDir();
       crashReporter.minidumpPath = do_get_minidumpdir();
     }
   }
 }
 catch (e) { }
 
+// Configure a console listener so messages sent to it are logged as part
+// of the test.
+try {
+  let levelNames = {}
+  for (let level of ["debug", "info", "warn", "error"]) {
+    levelNames[Components.interfaces.nsIConsoleMessage[level]] = level;
+  }
+
+  let listener = {
+    QueryInterface : function(iid) {
+      if (!iid.equals(Components.interfaces.nsISupports) &&
+          !iid.equals(Components.interfaces.nsIConsoleListener)) {
+        throw Components.results.NS_NOINTERFACE;
+      }
+      return this;
+    },
+    observe : function (msg) {
+      do_print("CONSOLE_MESSAGE: (" + levelNames[msg.logLevel] + ") " + msg.toString());
+    }
+  };
+  Components.classes["@mozilla.org/consoleservice;1"]
+            .getService(Components.interfaces.nsIConsoleService)
+            .registerListener(listener);
+} catch (e) {}
 /**
  * Date.now() is not necessarily monotonically increasing (insert sob story
  * about times not being the right tool to use for measuring intervals of time,
  * robarnold can tell all), so be wary of error by erring by at least
  * _timerFuzz ms.
  */
 const _timerFuzz = 15;