test_bug895340.xul 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
  4. type="text/css"?>
  5. <!--
  6. https://bugzilla.mozilla.org/show_bug.cgi?id=895340
  7. -->
  8. <window title="Mozilla Bug 895340"
  9. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  10. <script type="application/javascript"
  11. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  12. <!-- test results are displayed in the html:body -->
  13. <body xmlns="http://www.w3.org/1999/xhtml">
  14. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=895340 "
  15. target="_blank">Mozilla Bug 895340 </a>
  16. </body>
  17. <!-- test code goes here -->
  18. <script type="application/javascript"><![CDATA[
  19. SimpleTest.waitForExplicitFinish();
  20. SimpleTest.expectUncaughtException();
  21. const Cu = Components.utils;
  22. Cu.import("resource://gre/modules/Services.jsm", this);
  23. var finished = false;
  24. var console = Components.classes["@mozilla.org/consoleservice;1"]
  25. .getService(Components.interfaces.nsIConsoleService);
  26. let listener = {
  27. QueryInterface: function(iid) {
  28. if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
  29. !iid.equals(Components.interfaces.nsISupports))
  30. {
  31. throw Components.results.NS_ERROR_NO_INTERFACE;
  32. }
  33. return this;
  34. }
  35. };
  36. listener.observe = function(aMessage) {
  37. if (aMessage.message.indexOf("Will you report me?") != -1 && !finished) {
  38. finished = true;
  39. ok(true, "exception reported");
  40. console.unregisterListener(listener);
  41. SimpleTest.finish();
  42. }
  43. };
  44. console.registerListener(listener);
  45. /* Throw an exception and verify that it gets reported. */
  46. let foo_obs = function() {
  47. throw new Error("Will you report me?");
  48. };
  49. Services.obs.addObserver(foo_obs, "foo", false);
  50. Services.obs.notifyObservers(null, "foo", "foo");
  51. Services.obs.removeObserver(foo_obs, "foo");
  52. ]]></script>
  53. </window>