test_breakpoint-08.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, in a file with two scripts.
  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. gThreadClient.eval(aPacket.frame.actor, "foo", function (aResponse) {
  35. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  36. let obj = gThreadClient.pauseGrip(aPacket.why.frameFinished.return);
  37. obj.getDefinitionSite(runWithBreakpoint);
  38. });
  39. });
  40. function runWithBreakpoint(aPacket) {
  41. let source = gThreadClient.source(aPacket.source);
  42. let location = { line: gDebuggee.line0 + 3 };
  43. source.setBreakpoint(location, function (aResponse, bpClient) {
  44. // Check that the breakpoint has properly skipped forward one line.
  45. do_check_eq(aResponse.actualLocation.source.actor, source.actor);
  46. do_check_eq(aResponse.actualLocation.line, location.line + 1);
  47. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  48. // Check the return value.
  49. do_check_eq(aPacket.type, "paused");
  50. do_check_eq(aPacket.frame.where.source.actor, source.actor);
  51. do_check_eq(aPacket.frame.where.line, location.line + 1);
  52. do_check_eq(aPacket.why.type, "breakpoint");
  53. do_check_eq(aPacket.why.actors[0], bpClient.actor);
  54. // Check that the breakpoint worked.
  55. do_check_eq(gDebuggee.a, 1);
  56. do_check_eq(gDebuggee.b, undefined);
  57. // Remove the breakpoint.
  58. bpClient.remove(function (aResponse) {
  59. gThreadClient.resume(function () {
  60. gClient.close().then(gCallback);
  61. });
  62. });
  63. });
  64. // Continue until the breakpoint is hit.
  65. gThreadClient.resume();
  66. });
  67. }
  68. });
  69. Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
  70. "function foo() {\n" + // line0 + 1
  71. " this.a = 1;\n" + // line0 + 2
  72. " // A comment.\n" + // line0 + 3
  73. " this.b = 2;\n" + // line0 + 4
  74. "}\n", // line0 + 5
  75. gDebuggee,
  76. "1.7",
  77. "script1.js");
  78. Cu.evalInSandbox("var line1 = Error().lineNumber;\n" +
  79. "debugger;\n" + // line1 + 1
  80. "foo();\n", // line1 + 2
  81. gDebuggee,
  82. "1.7",
  83. "script2.js");
  84. }