diff options
Diffstat (limited to 'devtools/shared/tests/unit/head_devtools.js')
-rw-r--r-- | devtools/shared/tests/unit/head_devtools.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/devtools/shared/tests/unit/head_devtools.js b/devtools/shared/tests/unit/head_devtools.js new file mode 100644 index 000000000..f0f47c93a --- /dev/null +++ b/devtools/shared/tests/unit/head_devtools.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +const {require, DevToolsLoader, devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const flags = require("devtools/shared/flags"); + +flags.testing = true; +do_register_cleanup(() => { + flags.testing = false; +}); + +// Register a console listener, so console messages don't just disappear +// into the ether. + +// If for whatever reason the test needs to post console errors that aren't +// failures, set this to true. +var ALLOW_CONSOLE_ERRORS = false; + +var errorCount = 0; +var listener = { + observe: function (aMessage) { + errorCount++; + try { + // If we've been given an nsIScriptError, then we can print out + // something nicely formatted, for tools like Emacs to pick up. + var scriptError = aMessage.QueryInterface(Ci.nsIScriptError); + dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " + + scriptErrorFlagsToKind(aMessage.flags) + ": " + + aMessage.errorMessage + "\n"); + var string = aMessage.errorMessage; + } catch (x) { + // Be a little paranoid with message, as the whole goal here is to lose + // no information. + try { + var string = "" + aMessage.message; + } catch (x) { + var string = "<error converting error message to string>"; + } + } + + // Make sure we exit all nested event loops so that the test can finish. + while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) { + DebuggerServer.xpcInspector.exitNestedEventLoop(); + } + + if (!ALLOW_CONSOLE_ERRORS) { + do_throw("head_devtools.js got console message: " + string + "\n"); + } + } +}; + +var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +consoleService.registerListener(listener); |