test_breakpoint-09.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Check that removing a breakpoint works.
  5. */
  6. var gDebuggee;
  7. var gClient;
  8. var gThreadClient;
  9. var gCallback;
  10. function run_test()
  11. {
  12. run_test_with_server(DebuggerServer, function () {
  13. run_test_with_server(WorkerDebuggerServer, do_test_finished);
  14. });
  15. do_test_pending();
  16. }
  17. function run_test_with_server(aServer, aCallback)
  18. {
  19. gCallback = aCallback;
  20. initTestDebuggerServer(aServer);
  21. gDebuggee = addTestGlobal("test-stack", aServer);
  22. gClient = new DebuggerClient(aServer.connectPipe());
  23. gClient.connect().then(function () {
  24. attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) {
  25. gThreadClient = aThreadClient;
  26. test_remove_breakpoint();
  27. });
  28. });
  29. }
  30. function test_remove_breakpoint()
  31. {
  32. let done = false;
  33. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  34. let source = gThreadClient.source(aPacket.frame.where.source);
  35. let location = { line: gDebuggee.line0 + 2 };
  36. source.setBreakpoint(location, function (aResponse, bpClient) {
  37. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  38. // Check the return value.
  39. do_check_eq(aPacket.type, "paused");
  40. do_check_eq(aPacket.frame.where.source.actor, source.actor);
  41. do_check_eq(aPacket.frame.where.line, location.line);
  42. do_check_eq(aPacket.why.type, "breakpoint");
  43. do_check_eq(aPacket.why.actors[0], bpClient.actor);
  44. // Check that the breakpoint worked.
  45. do_check_eq(gDebuggee.a, undefined);
  46. // Remove the breakpoint.
  47. bpClient.remove(function (aResponse) {
  48. done = true;
  49. gThreadClient.addOneTimeListener("paused",
  50. function (aEvent, aPacket) {
  51. // The breakpoint should not be hit again.
  52. gThreadClient.resume(function () {
  53. do_check_true(false);
  54. });
  55. });
  56. gThreadClient.resume();
  57. });
  58. });
  59. // Continue until the breakpoint is hit.
  60. gThreadClient.resume();
  61. });
  62. });
  63. Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
  64. "function foo(stop) {\n" + // line0 + 1
  65. " this.a = 1;\n" + // line0 + 2
  66. " if (stop) return;\n" + // line0 + 3
  67. " delete this.a;\n" + // line0 + 4
  68. " foo(true);\n" + // line0 + 5
  69. "}\n" + // line0 + 6
  70. "debugger;\n" + // line1 + 7
  71. "foo();\n", // line1 + 8
  72. gDebuggee);
  73. if (!done) {
  74. do_check_true(false);
  75. }
  76. gClient.close().then(gCallback);
  77. }