test_blackboxing-02.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Test that we don't hit breakpoints in black boxed sources, and that when we
  5. * unblack box the source again, the breakpoint hasn't disappeared and we will
  6. * hit it again.
  7. */
  8. var gDebuggee;
  9. var gClient;
  10. var gThreadClient;
  11. function run_test()
  12. {
  13. initTestDebuggerServer();
  14. gDebuggee = addTestGlobal("test-black-box");
  15. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  16. gClient.connect().then(function () {
  17. attachTestTabAndResume(gClient, "test-black-box", function (aResponse, aTabClient, aThreadClient) {
  18. gThreadClient = aThreadClient;
  19. test_black_box();
  20. });
  21. });
  22. do_test_pending();
  23. }
  24. const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
  25. const SOURCE_URL = "http://example.com/source.js";
  26. function test_black_box()
  27. {
  28. gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  29. gThreadClient.eval(aPacket.frame.actor, "doStuff", function (aResponse) {
  30. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  31. let obj = gThreadClient.pauseGrip(aPacket.why.frameFinished.return);
  32. obj.getDefinitionSite(runWithSource);
  33. });
  34. });
  35. function runWithSource(aPacket) {
  36. let source = gThreadClient.source(aPacket.source);
  37. source.setBreakpoint({
  38. line: 2
  39. }, function (aResponse) {
  40. do_check_true(!aResponse.error, "Should be able to set breakpoint.");
  41. gThreadClient.resume(test_black_box_breakpoint);
  42. });
  43. }
  44. });
  45. Components.utils.evalInSandbox(
  46. "" + function doStuff(k) { // line 1
  47. let arg = 15; // line 2 - Break here
  48. k(arg); // line 3
  49. }, // line 4
  50. gDebuggee,
  51. "1.8",
  52. BLACK_BOXED_URL,
  53. 1
  54. );
  55. Components.utils.evalInSandbox(
  56. "" + function runTest() { // line 1
  57. doStuff( // line 2
  58. function (n) { // line 3
  59. debugger; // line 5
  60. } // line 6
  61. ); // line 7
  62. } // line 8
  63. + "\n debugger;", // line 9
  64. gDebuggee,
  65. "1.8",
  66. SOURCE_URL,
  67. 1
  68. );
  69. }
  70. function test_black_box_breakpoint() {
  71. gThreadClient.getSources(function ({error, sources}) {
  72. do_check_true(!error, "Should not get an error: " + error);
  73. let sourceClient = gThreadClient.source(sources.filter(s => s.url == BLACK_BOXED_URL)[0]);
  74. sourceClient.blackBox(function ({error}) {
  75. do_check_true(!error, "Should not get an error: " + error);
  76. gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  77. do_check_eq(aPacket.why.type, "debuggerStatement",
  78. "We should pass over the breakpoint since the source is black boxed.");
  79. gThreadClient.resume(test_unblack_box_breakpoint.bind(null, sourceClient));
  80. });
  81. gDebuggee.runTest();
  82. });
  83. });
  84. }
  85. function test_unblack_box_breakpoint(aSourceClient) {
  86. aSourceClient.unblackBox(function ({error}) {
  87. do_check_true(!error, "Should not get an error: " + error);
  88. gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  89. do_check_eq(aPacket.why.type, "breakpoint",
  90. "We should hit the breakpoint again");
  91. // We will hit the debugger statement on resume, so do this nastiness to skip over it.
  92. gClient.addOneTimeListener(
  93. "paused",
  94. gThreadClient.resume.bind(
  95. gThreadClient,
  96. finishClient.bind(null, gClient)));
  97. gThreadClient.resume();
  98. });
  99. gDebuggee.runTest();
  100. });
  101. }