test_breakpoint-05.js 2.5 KB

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