test_blackboxing-06.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Test that we can black box source mapped sources.
  5. */
  6. var gDebuggee;
  7. var gClient;
  8. var gThreadClient;
  9. const {SourceNode} = require("source-map");
  10. function run_test()
  11. {
  12. initTestDebuggerServer();
  13. gDebuggee = addTestGlobal("test-black-box");
  14. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  15. gClient.connect().then(function () {
  16. attachTestTabAndResume(gClient, "test-black-box", function (aResponse, aTabClient, aThreadClient) {
  17. gThreadClient = aThreadClient;
  18. promise.resolve(setup_code())
  19. .then(black_box_code)
  20. .then(run_code)
  21. .then(test_correct_location)
  22. .then(null, function (error) {
  23. do_check_true(false, "Should not get an error, got " + error);
  24. })
  25. .then(function () {
  26. finishClient(gClient);
  27. });
  28. });
  29. });
  30. do_test_pending();
  31. }
  32. function setup_code() {
  33. let { code, map } = (new SourceNode(null, null, null, [
  34. new SourceNode(1, 0, "a.js", "" + function a() {
  35. return b();
  36. }),
  37. "\n",
  38. new SourceNode(1, 0, "b.js", "" + function b() {
  39. debugger; // Don't want to stop here.
  40. return c();
  41. }),
  42. "\n",
  43. new SourceNode(1, 0, "c.js", "" + function c() {
  44. debugger; // Want to stop here.
  45. }),
  46. "\n"
  47. ])).toStringWithSourceMap({
  48. file: "abc.js",
  49. sourceRoot: "http://example.com/"
  50. });
  51. code += "//# sourceMappingURL=data:text/json," + map.toString();
  52. Components.utils.evalInSandbox(code,
  53. gDebuggee,
  54. "1.8",
  55. "http://example.com/abc.js");
  56. }
  57. function black_box_code() {
  58. const d = promise.defer();
  59. gThreadClient.getSources(function ({ sources, error }) {
  60. do_check_true(!error, "Shouldn't get an error getting sources");
  61. const source = sources.filter((s) => {
  62. return s.url.indexOf("b.js") !== -1;
  63. })[0];
  64. do_check_true(!!source, "We should have our source in the sources list");
  65. gThreadClient.source(source).blackBox(function ({ error }) {
  66. do_check_true(!error, "Should not get an error black boxing");
  67. d.resolve(true);
  68. });
  69. });
  70. return d.promise;
  71. }
  72. function run_code() {
  73. const d = promise.defer();
  74. gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  75. d.resolve(aPacket);
  76. gThreadClient.resume();
  77. });
  78. gDebuggee.a();
  79. return d.promise;
  80. }
  81. function test_correct_location(aPacket) {
  82. do_check_eq(aPacket.why.type, "debuggerStatement",
  83. "Should hit a debugger statement.");
  84. do_check_eq(aPacket.frame.where.source.url, "http://example.com/c.js",
  85. "Should have skipped over the debugger statement in the black boxed source");
  86. }