test_breakpoint-20.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Verify that when two of the "same" source are loaded concurrently (like e10s
  5. * frame scripts), breakpoints get hit in scripts defined by all sources.
  6. */
  7. var gDebuggee;
  8. var gClient;
  9. var gTraceClient;
  10. var gThreadClient;
  11. function run_test()
  12. {
  13. initTestDebuggerServer();
  14. gDebuggee = addTestGlobal("test-breakpoints");
  15. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  16. gClient.connect().then(function () {
  17. attachTestThread(gClient, "test-breakpoints", testBreakpoint);
  18. });
  19. do_test_pending();
  20. }
  21. const testBreakpoint = Task.async(function* (threadResponse, tabClient, threadClient, tabResponse) {
  22. evalSetupCode();
  23. // Load the test source once.
  24. evalTestCode();
  25. equal(gDebuggee.functions.length, 1,
  26. "The test code should have added a function.");
  27. // Set a breakpoint in the test source.
  28. const source = yield getSource(threadClient, "test.js");
  29. const [response, bpClient] = yield setBreakpoint(source, {
  30. line: 3
  31. });
  32. ok(!response.error, "Shouldn't get an error setting the BP.");
  33. ok(!response.actualLocation,
  34. "Shouldn't get an actualLocation, the location we provided was good.");
  35. const bpActor = response.actor;
  36. yield resume(threadClient);
  37. // Load the test source again.
  38. evalTestCode();
  39. equal(gDebuggee.functions.length, 2,
  40. "The test code should have added another function.");
  41. // Should hit our breakpoint in a script defined by the first instance of the
  42. // test source.
  43. const bpPause1 = yield executeOnNextTickAndWaitForPause(gDebuggee.functions[0],
  44. gClient);
  45. equal(bpPause1.why.type, "breakpoint",
  46. "Should pause because of hitting our breakpoint (not debugger statement).");
  47. equal(bpPause1.why.actors[0], bpActor,
  48. "And the breakpoint actor should be correct.");
  49. const dbgStmtPause1 = yield executeOnNextTickAndWaitForPause(() => resume(threadClient),
  50. gClient);
  51. equal(dbgStmtPause1.why.type, "debuggerStatement",
  52. "And we should hit the debugger statement after the pause.");
  53. yield resume(threadClient);
  54. // Should also hit our breakpoint in a script defined by the second instance
  55. // of the test source.
  56. const bpPause2 = yield executeOnNextTickAndWaitForPause(gDebuggee.functions[1],
  57. gClient);
  58. equal(bpPause2.why.type, "breakpoint",
  59. "Should pause because of hitting our breakpoint (not debugger statement).");
  60. equal(bpPause2.why.actors[0], bpActor,
  61. "And the breakpoint actor should be correct.");
  62. const dbgStmtPause2 = yield executeOnNextTickAndWaitForPause(() => resume(threadClient),
  63. gClient);
  64. equal(dbgStmtPause2.why.type, "debuggerStatement",
  65. "And we should hit the debugger statement after the pause.");
  66. finishClient(gClient);
  67. });
  68. function evalSetupCode() {
  69. Cu.evalInSandbox(
  70. "this.functions = [];",
  71. gDebuggee,
  72. "1.8",
  73. "setup.js",
  74. 1
  75. );
  76. }
  77. function evalTestCode() {
  78. Cu.evalInSandbox(
  79. ` // 1
  80. this.functions.push(function () { // 2
  81. var setBreakpointHere = 1; // 3
  82. debugger; // 4
  83. }); // 5
  84. `,
  85. gDebuggee,
  86. "1.8",
  87. "test.js",
  88. 1
  89. );
  90. }