head_devtools.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. var Cc = Components.classes;
  5. var Ci = Components.interfaces;
  6. var Cu = Components.utils;
  7. var Cr = Components.results;
  8. const {require, DevToolsLoader, devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
  9. const DevToolsUtils = require("devtools/shared/DevToolsUtils");
  10. const flags = require("devtools/shared/flags");
  11. flags.testing = true;
  12. do_register_cleanup(() => {
  13. flags.testing = false;
  14. });
  15. // Register a console listener, so console messages don't just disappear
  16. // into the ether.
  17. // If for whatever reason the test needs to post console errors that aren't
  18. // failures, set this to true.
  19. var ALLOW_CONSOLE_ERRORS = false;
  20. var errorCount = 0;
  21. var listener = {
  22. observe: function (aMessage) {
  23. errorCount++;
  24. try {
  25. // If we've been given an nsIScriptError, then we can print out
  26. // something nicely formatted, for tools like Emacs to pick up.
  27. var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
  28. dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
  29. scriptErrorFlagsToKind(aMessage.flags) + ": " +
  30. aMessage.errorMessage + "\n");
  31. var string = aMessage.errorMessage;
  32. } catch (x) {
  33. // Be a little paranoid with message, as the whole goal here is to lose
  34. // no information.
  35. try {
  36. var string = "" + aMessage.message;
  37. } catch (x) {
  38. var string = "<error converting error message to string>";
  39. }
  40. }
  41. // Make sure we exit all nested event loops so that the test can finish.
  42. while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) {
  43. DebuggerServer.xpcInspector.exitNestedEventLoop();
  44. }
  45. if (!ALLOW_CONSOLE_ERRORS) {
  46. do_throw("head_devtools.js got console message: " + string + "\n");
  47. }
  48. }
  49. };
  50. var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
  51. consoleService.registerListener(listener);