test_invisible_loader.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
  5. addDebuggerToGlobal(this);
  6. /**
  7. * Ensure that sandboxes created via the Dev Tools loader respect the
  8. * invisibleToDebugger flag.
  9. */
  10. function run_test() {
  11. visible_loader();
  12. invisible_loader();
  13. }
  14. function visible_loader() {
  15. let loader = new DevToolsLoader();
  16. loader.invisibleToDebugger = false;
  17. loader.require("devtools/shared/indentation");
  18. let dbg = new Debugger();
  19. let sandbox = loader._provider.loader.sharedGlobalSandbox;
  20. try {
  21. dbg.addDebuggee(sandbox);
  22. do_check_true(true);
  23. } catch (e) {
  24. do_throw("debugger could not add visible value");
  25. }
  26. // Check that for common loader used for tabs, promise modules is Promise.jsm
  27. // Which is required to support unhandled promises rejection in mochitests
  28. const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
  29. do_check_eq(loader.require("promise"), promise);
  30. }
  31. function invisible_loader() {
  32. let loader = new DevToolsLoader();
  33. loader.invisibleToDebugger = true;
  34. loader.require("devtools/shared/indentation");
  35. let dbg = new Debugger();
  36. let sandbox = loader._provider.loader.sharedGlobalSandbox;
  37. try {
  38. dbg.addDebuggee(sandbox);
  39. do_throw("debugger added invisible value");
  40. } catch (e) {
  41. do_check_true(true);
  42. }
  43. // But for browser toolbox loader, promise is loaded as a regular modules out
  44. // of Promise-backend.js, that to be invisible to the debugger and not step
  45. // into it.
  46. const promise = loader.require("promise");
  47. const promiseModule = loader._provider.loader.modules["resource://gre/modules/Promise-backend.js"];
  48. do_check_eq(promise, promiseModule.exports);
  49. }